-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add owners count and prepare for disabling
- Loading branch information
1 parent
7f3a073
commit 7876bf5
Showing
9 changed files
with
102 additions
and
53 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
25 changes: 12 additions & 13 deletions
25
portals-ui/sites/ngs-portal/src/pages/projects/components/project-filters.tsx
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
5 changes: 2 additions & 3 deletions
5
portals-ui/sites/ngs-portal/src/pages/projects/hooks/use-project-filters.ts
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
41 changes: 28 additions & 13 deletions
41
portals-ui/sites/ngs-portal/src/pages/projects/hooks/use-project-tags.ts
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,28 +1,43 @@ | ||
import type { Project } from '@cloud-pipeline/core'; | ||
import { useMemo } from 'react'; | ||
import type { Tag } from '../types'; | ||
|
||
export const useProjectTags = (projects: Project[]) => { | ||
export const useProjectTags = (projects?: Project[]) => { | ||
return useMemo(() => { | ||
if (!projects) { | ||
if (!projects?.length) { | ||
return {}; | ||
} | ||
|
||
const tags: Record<string, Set<string>> = {}; | ||
// Map for faster lookup | ||
const tagsMap: Record<string, Map<string, Tag>> = {}; | ||
|
||
for (const project of projects) { | ||
if (project.data) { | ||
for (const [key, { value }] of Object.entries(project.data)) { | ||
if (!tags[key]) { | ||
tags[key] = new Set(); | ||
} | ||
for (const { data } of projects) { | ||
if (!data) { | ||
continue; | ||
} | ||
|
||
for (const [key, { value }] of Object.entries(data)) { | ||
if (!tagsMap[key]) { | ||
tagsMap[key] = new Map(); | ||
} | ||
|
||
tags[key].add(value); | ||
const currentTagMap = tagsMap[key]; | ||
const tag = currentTagMap.get(value); | ||
|
||
if (tag) { | ||
tag.count++; | ||
} else { | ||
currentTagMap.set(value, { id: value, count: 1 }); | ||
} | ||
} | ||
} | ||
|
||
return Object.fromEntries( | ||
Object.entries(tags).map(([key, values]) => [key, Array.from(values)]), | ||
); | ||
// Convert maps to arrays | ||
const tags: Record<string, Tag[]> = {}; | ||
for (const [key, tagMap] of Object.entries(tagsMap)) { | ||
tags[key] = Array.from(tagMap.values()); | ||
} | ||
|
||
return tags; | ||
}, [projects]); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type Tag = { | ||
id: string; | ||
count: number; | ||
}; | ||
|
||
export type TagFilters = Record<string, string[]>; |