Skip to content

Commit 8934a00

Browse files
authored
Avoided extending query objects in the configuration (#127)
Avoided extending query objects in the configuration
1 parent 435a3ac commit 8934a00

File tree

13 files changed

+110
-76
lines changed

13 files changed

+110
-76
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717

1818
- Fixed the broken production version due to a missing package (#123).
1919
- Corrected the counting of the total number of items in the result list (#120).
20+
- Avoided extending query objects in the configuration (#126).
2021

2122
## [1.2.0] - 2024-05-07
2223

src/App.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ function App() {
6464
authProvider={authenticationProvider}
6565
loginPage={SolidLoginForm}
6666
requireAuth={false}
67-
dashboard={() => {
68-
return Dashboard({ title: config.title, text: config.introductionText })
69-
}}
67+
dashboard={Dashboard}
7068
>
7169
{config.queries.map((query) => {
7270
return (

src/components/ActionBar/ActionBar.jsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import SourceFetchStatusIcon from "./SourceFetchStatusIcon/SourceFetchStatusIcon
2020
import SourceVerificationIcon from "./SourceVerificationIcon/SourceVerificationIcon.jsx";
2121

2222
import configManager from "../../configManager/configManager.js";
23-
const config = configManager.getConfig();
2423

2524
/**
2625
*
@@ -31,10 +30,6 @@ function ActionBar() {
3130
const [time, setTime] = useState(0);
3231
const [sourceInfoOpen, setSourceInfoOpen] = useState(false);
3332

34-
const context = config.queries.filter((query) => query.id === resource)[0]
35-
.comunicaContext;
36-
37-
const sources = context.sources;
3833
useEffect(() => {
3934
if (isLoading) {
4035
setTime(0);
@@ -49,6 +44,10 @@ function ActionBar() {
4944
return () => clearInterval(intervalId);
5045
}, [time, isLoading]);
5146

47+
const config = configManager.getConfig();
48+
const query = configManager.getQueryWorkingCopyById(resource);
49+
const context = query.comunicaContext;
50+
const sources = context.sources;
5251
const resultCount = total <= perPage ? total : perPage;
5352

5453
return (
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
11
import Card from '@mui/material/Card';
22
import CardContent from '@mui/material/CardContent';
33
import {Title} from 'react-admin';
4-
import PropTypes from 'prop-types';
54
import './Dashboard.css';
65

6+
import configManager from '../../configManager/configManager';
7+
78
/**
89
* This function returns a function that creates a dashboard with an introduction for <Admin>.
9-
* @param {object} props - This has the properties `title` (text for the app bar) and `text` (the introduction text).
1010
* @returns {function(): *} - A function that creates a dashboard with an introduction for <Admin>.
1111
*/
12-
function Dashboard(props) {
13-
let {title, text} = props;
14-
15-
title = title || 'You change this title via the config file.';
16-
text = text || 'You change this text via the config file.';
12+
function Dashboard() {
13+
const config = configManager.getConfig();
14+
const title = config.title || 'You change this title via the config file.';
15+
const introductionText = config.introductionText || 'You change this introduction text via the config file.';
1716

1817
return (
1918
<Card>
2019
<Title title={title}/>
21-
<CardContent>{text}</CardContent>
20+
<CardContent>{introductionText}</CardContent>
2221
</Card>
2322
);
2423
}
2524

26-
Dashboard.propTypes = {
27-
title: PropTypes.string,
28-
text: PropTypes.string
29-
};
30-
3125
export default Dashboard;

src/components/InteractionLayout/NavigationBar/NavigationBar.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { IconButton } from '@mui/material';
88
import { Tooltip } from '@mui/material';
99

1010
import configManager from "../../../configManager/configManager";
11-
const config = configManager.getConfig();
1211

1312
function InvalidateButton() {
1413
const refresh = useRefresh();
@@ -31,6 +30,7 @@ function InvalidateButton() {
3130
* @returns {Component} custom AppBar as defined by react-admin
3231
*/
3332
function NavigationBar(props) {
33+
const config = configManager.getConfig();
3434
return (
3535
<AppBar {...props} userMenu={<AuthenticationMenu />}>
3636
<img

src/components/InteractionLayout/SelectionMenu/SelectionMenu.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ import IconProvider from "../../../IconProvider/IconProvider";
1414
import ListAltIcon from '@mui/icons-material/ListAlt';
1515

1616
import configManager from '../../../configManager/configManager';
17-
const config = configManager.getConfig();
1817

1918
/**
2019
* A custom menu as defined in React Admin for selecting the query the user whishes to execute.
2120
* @returns {Component} the selection menu component
2221
*/
2322
function SelectionMenu() {
24-
25-
const resources = useResourceDefinitions();
23+
const config = configManager.getConfig();
2624
const queryGroups = config.queryGroups || [];
25+
const resources = useResourceDefinitions();
2726

2827
// adding a list to the group that will contain all the queries for said group
2928
queryGroups.forEach(group => group.queries = [])

src/components/ListResultTable/ListResultTable.jsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import PropTypes from "prop-types";
33
import {Component} from "react";
44
import QueryResultList from "./QueryResultList/QueryResultList";
55

6+
import configManager from "../../configManager/configManager";
7+
68
/**
79
* @param {object} props - the props passed down to the component
810
* @returns {Component} custom List as defined by react-admin which either shows a loading indicator or the query results
@@ -18,8 +20,6 @@ function ListResultTable(props) {
1820
resource,
1921
sort,
2022
variables,
21-
changeVariables,
22-
submitted,
2323
...rest
2424
} = props;
2525

@@ -31,6 +31,8 @@ function ListResultTable(props) {
3131
}
3232
});
3333

34+
const query = configManager.getQueryWorkingCopyById(resource);
35+
3436
return (
3537
<ListBase
3638
debounce={debounce}
@@ -45,7 +47,7 @@ function ListResultTable(props) {
4547
sort={sort}
4648
>
4749
{isLoading && <Loading loadingSecondary={"The page is loading. Just a moment please."} />}
48-
{!isLoading && <QueryResultList {...rest} changeVariables={changeVariables} submitted={submitted} />}
50+
{!isLoading && <QueryResultList resource={resource} { ...rest } />}
4951
</ListBase>
5052
);
5153
}
@@ -59,9 +61,9 @@ ListResultTable.propTypes = {
5961
filterDefaultValues: PropTypes.object,
6062
perPage: PropTypes.number,
6163
queryOptions: PropTypes.object,
62-
resource: PropTypes.string,
64+
resource: PropTypes.string.isRequired,
6365
sort: PropTypes.object,
64-
variables: PropTypes.object,
66+
variables: PropTypes.object.isRequired
6567
};
6668

6769
export default ListResultTable;

src/components/ListResultTable/QueryResultList/QueryResultList.jsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ import TableHeader from "./TableHeader/TableHeader";
77
import Button from '@mui/material/Button';
88
import SearchOffIcon from '@mui/icons-material/SearchOff';
99
import { SvgIcon, Box, Typography } from "@mui/material";
10+
import PropTypes from "prop-types";
1011

1112
import configManager from "../../../configManager/configManager";
12-
const config = configManager.getConfig();
1313

1414
/**
1515
* @param {object} props - the props passed down to the component
1616
* @returns {Component} custom ListViewer as defined by react-admin containing the results of the query with each variable its generic field.
1717
*/
1818
function QueryResultList(props) {
19-
const QueryTitle = useResourceDefinition().options.label;
19+
const queryTitle = useResourceDefinition().options.label;
2020
const { data } = useListContext(props);
21-
const {changeVariables, submitted} = props;
21+
const { resource, changeVariables, submitted} = props;
2222
const [values, setValues] = useState(undefined);
2323
useEffect(() => {
2424
if (data && data.length > 0) {
@@ -28,15 +28,18 @@ function QueryResultList(props) {
2828
}
2929
}, [data]);
3030

31+
const config = configManager.getConfig();
32+
const query = configManager.getQueryWorkingCopyById(resource);
33+
3134
return (
3235
<div style={{ paddingLeft: '20px' , paddingRight: '10px' }}>
3336
<Title title={config.title} />
3437

3538
{submitted && <Aside changeVariables={changeVariables}/> /* Adding button to make a new query - top left corner */ }
36-
<Typography fontSize={"2rem"} mt={2} > {QueryTitle} </Typography>
39+
<Typography fontSize={"2rem"} mt={2} > {queryTitle} </Typography>
3740
{values ?(
38-
<ListView title=" " actions={<ActionBar />} {...props} >
39-
<Datagrid header={<TableHeader config={config}/>} bulkActionButtons={false}>
41+
<ListView title=" " actions={<ActionBar />} {...props} >
42+
<Datagrid header={<TableHeader query={query}/>} bulkActionButtons={false}>
4043
{Object.keys(values).map((key) => {
4144
return (
4245
<GenericField
@@ -49,12 +52,18 @@ function QueryResultList(props) {
4952
</Datagrid>
5053
</ListView>
5154
):
52-
<NoValuesDiplay/>
55+
<NoValuesDisplay/>
5356
}
5457
</div>
5558
);
5659
}
5760

61+
QueryResultList.propTypes = {
62+
resource: PropTypes.string.isRequired,
63+
changeVariables: PropTypes.func.isRequired,
64+
submitted: PropTypes.bool.isRequired
65+
};
66+
5867
/**
5968
*
6069
* @param {Array<Term>} data - a list of data objects
@@ -81,7 +90,7 @@ const Aside = (props) => {
8190
</div>
8291
)}
8392

84-
const NoValuesDiplay = () => {
93+
const NoValuesDisplay = () => {
8594
return(
8695
<div>
8796
<Box display="flex" alignItems="center" sx={{m:3}}>

src/components/ListResultTable/QueryResultList/TableHeader/TableHeader.jsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,16 @@ import LinkIcon from "@mui/icons-material/Link";
88
import PropTypes from "prop-types";
99
import { Component } from "react";
1010

11+
import configManager from "../../../../configManager/configManager";
12+
1113
/**
1214
*
1315
* @param {object} props - the props passed down to the component
1416
* @param {Array<Component>} props.children - the children of the component
15-
* @param {object} props.config - the config object of the application
1617
* @returns {Component} the header of the table containing the column names, the sort icons and ontology links
1718
*/
18-
function TableHeader({ children, config }) {
19+
function TableHeader({ children }) {
1920
const { sort, setSort, resource } = useListContext();
20-
const { variableOntology } = config.queries.filter(
21-
(query) => query.id === resource
22-
)[0];
2321

2422
/**
2523
* Handles the click on a header and sets the sort state accordingly
@@ -37,6 +35,9 @@ function TableHeader({ children, config }) {
3735
setSort(newSort);
3836
}
3937

38+
const query = configManager.getQueryWorkingCopyById(resource);
39+
const variableOntology = query.variableOntology;
40+
4041
return (
4142
<TableHead>
4243
<TableRow>
@@ -90,8 +91,6 @@ function TableHeader({ children, config }) {
9091
}
9192

9293
TableHeader.propTypes = {
93-
children: PropTypes.node,
94-
config: PropTypes.object.isRequired,
95-
94+
children: PropTypes.node
9695
}
9796
export default TableHeader;

src/components/ListResultTable/TemplatedListResultTable.jsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import TemplatedQueryForm from "./TemplatedQueryForm.jsx";
66
import ListResultTable from "./ListResultTable.jsx";
77

88
import configManager from '../../configManager/configManager.js';
9-
const config = configManager.getConfig();
109

1110
/**
1211
* A wrapper component around ListResultTable, to support templated queries
@@ -22,15 +21,10 @@ const TemplatedListResultTable = (props) => {
2221
const [submitted, setSubmitted] = useState(false);
2322
const [searchPar, setSearchPar] = useState({});
2423

25-
const query = config.queries.filter(
26-
(query) => query.id === resource
27-
)[0];
28-
24+
const query = configManager.getQueryWorkingCopyById(resource);
2925
const isTemplatedQuery = query.variables !== undefined;
3026
let tableEnabled = !isTemplatedQuery;
3127

32-
33-
3428
if (isTemplatedQuery) {
3529
// Update variables from query parameters
3630
const queryParams = new URLSearchParams(location.search);
@@ -83,7 +77,7 @@ const TemplatedListResultTable = (props) => {
8377
searchPar={searchPar}
8478
/>
8579
}
86-
{tableEnabled && <ListResultTable {...props} variables={variables} changeVariables={changeVariables} submitted={submitted}/>}
80+
{tableEnabled && <ListResultTable {...props} resource={resource} variables={variables} changeVariables={changeVariables} submitted={submitted}/>}
8781
</>
8882
)
8983
}

0 commit comments

Comments
 (0)