thiagoelg commented on code in PR #4069:
URL:
https://github.com/apache/incubator-kie-tools/pull/4069#discussion_r4473558322
##########
packages/runtime-tools-process-enveloped-components/src/formsList/envelope/components/FormsTable/FormsTable.tsx:
##########
@@ -79,11 +79,11 @@ const FormsTable: React.FC<FormsTableProps> = ({
channelApi, formsData, setForms
[columns, formsData, setFormsData]
);
+ // Applies the initial sort only when loading finishes. It must not depend
on `formsData`,
+ // otherwise sorting (which creates a new array) would re-trigger this
effect in an infinite loop.
useEffect(() => {
- if (!_.isEmpty(formsData)) {
- onSort(2, "desc");
- }
- }, [formsData, isLoading, onSort]);
+ setFormsData((current) => (_.isEmpty(current) ? current :
_.orderBy(current, ["lastModified"], ["desc"])));
Review Comment:
Like this:
```ts
const onSort = useCallback(
async (index: number, direction: "asc" | "desc"): Promise<void> => {
const sortObj: SortBy = {
property: columns[index].path,
direction: direction,
};
setFormsData((current) => {
const sortedData = _.orderBy(
current,
_.keys({
[sortObj.property]: sortObj.direction,
}),
_.values({
[sortObj.property]: sortObj.direction,
})
);
return sortedData;
});
setSortBy(sortObj);
},
[columns, setFormsData]
);
```
(I haven't tested it)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]