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

Custom and dynamic columns in spreadsheet #2272

Merged
merged 13 commits into from
Oct 2, 2024

Conversation

anistouri
Copy link
Contributor

No description provided.

anistouri and others added 3 commits September 18, 2024 19:12
Signed-off-by: TOURI ANIS <anis-1.touri@rte-france.com>
Signed-off-by: TOURI ANIS <anis-1.touri@rte-france.com>
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

license-eye has totally checked 631 files.

Valid Invalid Ignored Fixed
586 2 43 0
Click to see the invalid file list
  • src/components/spreadsheet/custom-columns/custom-column-table.tsx
  • src/components/spreadsheet/custom-columns/use-custom-column.ts

Signed-off-by: TOURI ANIS <anis-1.touri@rte-france.com>
package.json Outdated Show resolved Hide resolved
src/translations/spreadsheet-fr.ts Outdated Show resolved Hide resolved
src/translations/spreadsheet-fr.ts Outdated Show resolved Hide resolved
src/components/spreadsheet/table-wrapper.jsx Outdated Show resolved Hide resolved
src/components/utils/dnd-table/dnd-table.jsx Show resolved Hide resolved
Signed-off-by: TOURI ANIS <anis-1.touri@rte-france.com>
@anistouri anistouri force-pushed the custom-and-dynamic-columns-in-spreadsheet branch from c6554db to 0035c25 Compare October 1, 2024 14:31
src/redux/reducer.ts Outdated Show resolved Hide resolved
Comment on lines 23 to 25
const numberColumns = useStateNumber(0);
const dialogOpen = useStateBoolean(false);
const allDefinitions = useSelector((state: AppState) => state.allCustomColumnsDefinitions[TABLES_NAMES[indexTab]]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const numberColumns = useStateNumber(0);
const dialogOpen = useStateBoolean(false);
const allDefinitions = useSelector((state: AppState) => state.allCustomColumnsDefinitions[TABLES_NAMES[indexTab]]);
const dialogOpen = useStateBoolean(false);
const customColumnsNumber = useSelector(
(state: AppState) => state.allCustomColumnsDefinitions[TABLES_NAMES[indexTab]].columns.length
);

We can do this directly, no ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm passing this value in the props and removed the useSelector in the child component


const { handleSubmit, reset } = formMethods;
const dispatch = useDispatch<AppDispatch>();
const columnsDefinitions = useSelector((state: AppState) => state.allCustomColumnsDefinitions);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const columnsDefinitions = useSelector((state: AppState) => state.allCustomColumnsDefinitions);
const columnsDefinitions = useSelector(
(state: AppState) => state.allCustomColumnsDefinitions[TABLES_NAMES[indexTab]]?.columns
);

Also directly this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it's retrieved from the props

src/components/utils/dnd-table/dnd-table.jsx Show resolved Hide resolved
Signed-off-by: TOURI ANIS <anis-1.touri@rte-france.com>
@anistouri anistouri force-pushed the custom-and-dynamic-columns-in-spreadsheet branch from 2941620 to 0a83c19 Compare October 1, 2024 17:01
Comment on lines 23 to 53
const numberColumns = useStateNumber(0);
const dialogOpen = useStateBoolean(false);
const customColumnsDefinitions = useSelector(
(state: AppState) => state.allCustomColumnsDefinitions[TABLES_NAMES[indexTab]]
);

useEffect(() => {
numberColumns.setValue(customColumnsDefinitions.columns.length);
}, [customColumnsDefinitions.columns.length, numberColumns]);

return (
<>
<Button color="inherit" onClick={dialogOpen.setTrue}>
<FormattedMessage id="spreadsheet/custom_column/main_button" />
<Badge
color="secondary"
anchorOrigin={{
vertical: 'top',
horizontal: 'left',
}}
badgeContent={numberColumns.value}
>
<CalculateIcon />
</Badge>
</Button>
<CustomColumnDialog
indexTab={indexTab}
open={dialogOpen}
customColumnsDefinitions={customColumnsDefinitions.columns}
/>
</>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const numberColumns = useStateNumber(0);
const dialogOpen = useStateBoolean(false);
const customColumnsDefinitions = useSelector(
(state: AppState) => state.allCustomColumnsDefinitions[TABLES_NAMES[indexTab]]
);
useEffect(() => {
numberColumns.setValue(customColumnsDefinitions.columns.length);
}, [customColumnsDefinitions.columns.length, numberColumns]);
return (
<>
<Button color="inherit" onClick={dialogOpen.setTrue}>
<FormattedMessage id="spreadsheet/custom_column/main_button" />
<Badge
color="secondary"
anchorOrigin={{
vertical: 'top',
horizontal: 'left',
}}
badgeContent={numberColumns.value}
>
<CalculateIcon />
</Badge>
</Button>
<CustomColumnDialog
indexTab={indexTab}
open={dialogOpen}
customColumnsDefinitions={customColumnsDefinitions.columns}
/>
</>
const dialogOpen = useStateBoolean(false);
const customColumnsDefinitions = useSelector(
(state: AppState) => state.allCustomColumnsDefinitions[TABLES_NAMES[indexTab]].columns
);
return (
<>
<Button color="inherit" onClick={dialogOpen.setTrue}>
<FormattedMessage id="spreadsheet/custom_column/main_button" />
<Badge
color="secondary"
anchorOrigin={{
vertical: 'top',
horizontal: 'left',
}}
badgeContent={customColumnsDefinitions.length}
>
<CalculateIcon />
</Badge>
</Button>
<CustomColumnDialog
indexTab={indexTab}
open={dialogOpen}
customColumnsDefinitions={customColumnsDefinitions}
/>
</>

This can still be simplified

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

headerName: colWithFormula.name,
field: colWithFormula.name,
numeric: true,
cellRenderer: PropertiesCellRenderer,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't put any specific cellRenderer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it won't have the same style as the others, and it won't be rounded like all the values in the spreadsheet

return makeAgGridCustomHeaderColumn({
headerName: colWithFormula.name,
field: colWithFormula.name,
numeric: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove numeric, filterParams, cellDataType, cellRenderer for now because it can be several data types. We will improve that later on :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For cellRender, the same remark as above

Copy link

sonarcloud bot commented Oct 2, 2024

@anistouri anistouri merged commit 27d6321 into main Oct 2, 2024
4 checks passed
@anistouri anistouri deleted the custom-and-dynamic-columns-in-spreadsheet branch October 2, 2024 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants