Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"By variable" groups #569

Merged
merged 5 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/modules/RA/Scene/assets/List.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion src/modules/RA/Scene/components/GeolayerSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { LinearProgress, withDataProvider, GET_LIST } from 'react-admin';
import debounce from 'lodash.debounce';
import uniqBy from 'lodash.uniqby';

import Box from '@material-ui/core/Box';
import FormControl from '@material-ui/core/FormControl';
import InputLabel from '@material-ui/core/InputLabel';
import MenuItem from '@material-ui/core/MenuItem';
Expand Down Expand Up @@ -120,7 +121,11 @@ const GeolayerSelect = ({ dataProvider, onChange, excludeIds = [], includeIds =
* Display progress bar until we have geolayers
*/
if (!geolayers) {
return <LinearProgress />;
return (
<Box>
<LinearProgress timeout={0} style={{ marginTop: 30, marginBottom: 30 }} />
</Box>
);
}

if (!geolayers.length) {
Expand Down
3 changes: 2 additions & 1 deletion src/modules/RA/Scene/components/TreeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const generateNodeProps = (treeData, setTreeData, includeIds) =>
className: classnames({
treeGroup: node.group,
treeGroupExclusive: node.exclusive,
treeGroupByVariable: node.byVariable,
}),
buttons: [<TreeNodeToolbar {...menuProps} />],
};
Expand Down Expand Up @@ -91,7 +92,7 @@ const TreeInput = ({ input: { value, onChange }, ...props }) => {
*/
const addGroup = () => onChange([
...value,
{ label: 'New group name', group: true },
{ label: 'New group name', group: true, children: [], expanded: true },
]);

if (!value) {
Expand Down
6 changes: 6 additions & 0 deletions src/modules/RA/Scene/components/TreeInput.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@
background-image: url(../assets/RadioButton.svg);
}
}

&ByVariable {
.rst__moveHandle {
background-image: url(../assets/List.svg);
}
}
}
27 changes: 25 additions & 2 deletions src/modules/RA/Scene/components/TreeNodeLabelInput.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

import { changeNodeAtPath } from 'react-sortable-tree';
import { changeNodeAtPath, getNodeAtPath } from 'react-sortable-tree';
import Box from '@material-ui/core/Box';

import TextField from '@material-ui/core/TextField';

Expand All @@ -16,9 +17,31 @@ const NodeLabel = ({ treeData, setTreeData, path, node }) => {
newNode: { ...node, label },
}));


const parentVariables = React.useMemo(
() => getNodeAtPath({
treeData,
path: path.slice(0, -1),
getNodeKey: ({ treeIndex }) => treeIndex,
})?.node?.variables,
[path, treeData],
);

/* Only groups have editable labels */
if (!node.group) {
return node.label;
return (
<>
{node.label}

{Boolean(parentVariables?.length) && (
<Box style={{ fontWeight: 400, fontSize: '0.8em' }}>
{parentVariables.map(({ id, label }) =>
// eslint-disable-next-line no-irregular-whitespace
`${label} : ${node.variables?.[id]}`).join(', ')}
</Box>
)}
</>
);
}

return <TextField onChange={handleChange} value={node.label} />;
Expand Down
Loading