-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Ability to sort on setting tables #5772
Comments
Disclaimer: This comment was automatically generated with AI. It can give some useful hints as to where to look for, but sometimes it can also give very inaccurate answers so takes this with a pinch of salt :). To implement sorting on tables in settings, follow these steps:
Example for import { useState } from 'react';
const useSorting = (initialColumn) => {
const [sortConfig, setSortConfig] = useState({ key: initialColumn, direction: 'ascending' });
const sortedData = (data) => {
return [...data].sort((a, b) => {
if (a[sortConfig.key] < b[sortConfig.key]) {
return sortConfig.direction === 'ascending' ? -1 : 1;
}
if (a[sortConfig.key] > b[sortConfig.key]) {
return sortConfig.direction === 'ascending' ? 1 : -1;
}
return 0;
});
};
const requestSort = (key) => {
let direction = 'ascending';
if (sortConfig.key === key && sortConfig.direction === 'ascending') {
direction = 'descending';
}
setSortConfig({ key, direction });
};
return { sortedData, requestSort, sortConfig };
};
export default useSorting; Use the References |
Sorting should always be applied by default. Clicking on a header should change the sorting direction. Clicking on a different header should cancel and replace the previous sorting. The arrow should be on the right for text, relation, and tag headers, and on the left for number headers. CleanShot.2024-06-07.at.17.47.17.mp4 |
Thanks! Adding "good first issue" tag as it doesn't require much context on the overall project but it needs to be someone experienced to do this well |
Hey @Bonapara |
Hey @Anand-Krishnan-M-J thanks 🙏 |
Hi @Anand-Krishnan-M-J, thanks for contributing & your PR draft! I was wondering, are you still on it? |
Yeah, I am still on it. Would it be okay if I update the PR by July 04? |
@Anand-Krishnan-M-J Sure! Thanks a lot for working on it 😊 |
Updated PR: #5787 |
## Proposed Changes - Introduce a new custom hook - useTableSort to sort table content - Add test cases for the new custom hook - Integrate useTableSort hook on to the table in settings object and settings object field pages ## Related Issue #5772 ## Evidence https://github.com/twentyhq/twenty/assets/87609792/8be456ce-2fa5-44ec-8bbd-70fb6c8fdb30 ## Evidence after addressing review comments https://github.com/twentyhq/twenty/assets/87609792/c267e3da-72f9-4c0e-8c94-a38122d6395e ## Further comments Apologies for the large PR. Looking forward for the review --------- Co-authored-by: Félix Malfait <[email protected]> Co-authored-by: Lucas Bordeau <[email protected]>
We should be able to sort tables in settings.
Mostly SettingsObjects, SettingsObjectDetail, but also potentially other ones (e.g. webhooks/api keys)
We want to do this in a clean and generic way. Avoid having too much duplicated code :)
CC @Bonapara fyi if you want to add arrow up/down keys on table header upon click?
The text was updated successfully, but these errors were encountered: