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

Add ability to reorder fields in DatagridConfigurable and SimpleFormConfigurable #8416

Merged
merged 5 commits into from
Nov 28, 2022

Conversation

fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented Nov 21, 2022

Enregistrement.de.l.ecran.2022-11-21.a.18.28.25.mov
Enregistrement.de.l.ecran.2022-11-21.a.18.31.40.mov

@@ -177,7 +182,7 @@ const StyledPaper = styled(Paper, {
overridesResolver: (props, styles) => styles.root,
})(({ theme }) => ({
position: 'fixed',
zIndex: theme.zIndex.modal,
zIndex: theme.zIndex.modal + 1,
Copy link
Member Author

Choose a reason for hiding this comment

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

This one is a fix for a regression appearing since #8395: the configure button appears on top of the inspector

Copy link
Contributor

@WiXSL WiXSL left a comment

Choose a reason for hiding this comment

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

I believe you forgot to update the screencast.
And maybe a few tests wouldn't hurt 😃

@fzaninotto
Copy link
Member Author

Screencasts added. As for the tests, they are left as an exercise for the reader ;)

Comment on lines 45 to 80
const handleMove = (index1, index2) => {
const index1Pos = availableFields.findIndex(
// eslint-disable-next-line eqeqeq
field => field.index == index1
);
const index2Pos = availableFields.findIndex(
// eslint-disable-next-line eqeqeq
field => field.index == index2
);
if (index1Pos === -1 || index2Pos === -1) {
return;
}
let newAvailableFields;
if (index1Pos > index2Pos) {
newAvailableFields = [
...availableFields.slice(0, index2Pos),
availableFields[index1Pos],
...availableFields.slice(index2Pos, index1Pos),
...availableFields.slice(index1Pos + 1),
];
} else {
newAvailableFields = [
...availableFields.slice(0, index1Pos),
...availableFields.slice(index1Pos + 1, index2Pos + 1),
availableFields[index1Pos],
...availableFields.slice(index2Pos + 1),
];
}
setAvailableFields(newAvailableFields);
setFields(fields =>
newAvailableFields
.filter(field => !omit?.includes(field.source))
.filter(field => fields.includes(field.index))
.map(field => field.index)
);
};
Copy link
Member Author

Choose a reason for hiding this comment

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

Fun fact: this method was almost entirely written by gitHub Copilot!

@slax57 slax57 added this to the 4.6 milestone Nov 28, 2022
@slax57 slax57 merged commit 8c1c27b into next Nov 28, 2022
@slax57 slax57 deleted the configurable-column-order branch November 28, 2022 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants