Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Update filter function
Browse files Browse the repository at this point in the history
  • Loading branch information
khelif96 committed Sep 8, 2023
1 parent 2f28abd commit eb81f50
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/pages/task/taskTabs/FileTableTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,23 @@ const FilesTableTab: React.FC<FilesTableTabProps> = ({ execution, taskId }) => {
);
const { taskFiles } = data?.task ?? {};

const filteredFiles = taskFiles?.groupedFiles?.map((groupedFile) => ({
...groupedFile,
files: groupedFile?.files?.filter((file) =>
const { groupedFiles = [] } = taskFiles ?? {};
const filteredGroupedFiles = groupedFiles.reduce((acc, groupedFile) => {
const filteredFiles = groupedFile?.files?.filter((file) =>
file?.name?.toLowerCase().includes(search.toLowerCase())
),
}));
);
if (filteredFiles?.length) {
acc.push({
...groupedFile,
files: filteredFiles,
});
}
return acc;
}, [] as (typeof taskFiles)["groupedFiles"]);

// We only want to show the file group name if there are multiple file groups.
const hasMultipleFileGroups = taskFiles?.groupedFiles?.length > 1;
const hasMultipleFileGroups = groupedFiles.length > 1;

return loading ? (
<FilesTableTabSkeleton />
) : (
Expand All @@ -49,7 +57,7 @@ const FilesTableTab: React.FC<FilesTableTabProps> = ({ execution, taskId }) => {
onChange={(e) => setSearch(e.target.value)}
value={search}
/>
{filteredFiles?.map((groupedFile) => (
{filteredGroupedFiles.map((groupedFile) => (
<GroupedFilesTable
key={groupedFile?.taskName}
files={groupedFile?.files}
Expand Down

0 comments on commit eb81f50

Please sign in to comment.