-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lint: fix more missing hook dependencies
- Loading branch information
1 parent
85bd1eb
commit 434e7da
Showing
23 changed files
with
136 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,46 @@ | ||
import { useMemo } from "react"; | ||
import { useCallback, useMemo } from "react"; | ||
|
||
export const useSortedColumns = (data, tableSortOrder, columnsDefinition) => { | ||
const sortColumnKey = tableSortOrder?.sortColumnKey; | ||
const sortOrder = tableSortOrder?.sortOrder; | ||
|
||
const sortData = (dataToSort, sortKey, order) => { | ||
const column = columnsDefinition.find((col) => col.dataIndex === sortKey); | ||
if (column && column.sorter) { | ||
return [...dataToSort].sort((a, b) => { | ||
return order === "ascend" ? column.sorter(a, b) : column.sorter(b, a); | ||
}); | ||
} | ||
return dataToSort; | ||
}; | ||
const sortData = useCallback( | ||
(dataToSort, sortKey, order) => { | ||
const column = columnsDefinition.find((col) => col.dataIndex === sortKey); | ||
if (column && column.sorter) { | ||
return [...dataToSort].sort((a, b) => { | ||
return order === "ascend" ? column.sorter(a, b) : column.sorter(b, a); | ||
}); | ||
} | ||
return dataToSort; | ||
}, | ||
[columnsDefinition], | ||
); | ||
|
||
const sortedData = useMemo(() => { | ||
return sortData(data, sortColumnKey, sortOrder); | ||
}, [data, sortColumnKey, sortOrder, columnsDefinition]); | ||
const sortedData = useMemo( | ||
() => sortData(data, sortColumnKey, sortOrder), | ||
[data, sortData, sortColumnKey, sortOrder], | ||
); | ||
|
||
const columnsWithSortOrder = useMemo(() => { | ||
return columnsDefinition.map((column) => { | ||
if (column.dataIndex === sortColumnKey) { | ||
return { ...column, sortOrder }; | ||
} | ||
return column; | ||
}); | ||
}, [sortColumnKey, sortOrder, columnsDefinition]); | ||
const columnsWithSortOrder = useMemo( | ||
() => | ||
columnsDefinition.map((column) => { | ||
if (column.dataIndex === sortColumnKey) { | ||
return { ...column, sortOrder }; | ||
} | ||
return column; | ||
}), | ||
[sortColumnKey, sortOrder, columnsDefinition], | ||
); | ||
|
||
return { sortedData, columnsWithSortOrder }; | ||
}; | ||
|
||
export const useDynamicTableFilterOptions = (data, key) => { | ||
return useMemo(() => { | ||
export const useDynamicTableFilterOptions = (data, key) => | ||
useMemo(() => { | ||
const uniqueValues = new Set(data.map((item) => item[key])); | ||
return Array.from(uniqueValues).map((value) => ({ | ||
text: value, | ||
value: value, | ||
})); | ||
}, [data, key]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.