Skip to content

Commit

Permalink
[Dashboard] fix themes filters in dashboard list
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed Feb 6, 2025
1 parent 922bd80 commit 0fe8f48
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function Filters({ orientation = 'row' }: { orientation?: Orientation })
key={regulatoryTheme}
onDelete={() => onDeleteTag(regulatoryTheme, 'regulatoryThemes', regulatoryThemes)}
>
{String(`Thématique réglementaire ${getTitle(regulatoryTheme)}`)}
{String(`Thématique ${getTitle(regulatoryTheme)}`)}
</SingleTag>
))}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ export function RegulatoryAreasThemesCell({ themeIds }: { themeIds: number[] })
return '-'
}

const regulatoryAreasThemes = uniq(themeIds.map(themeId => regulatoryAreas.entities[themeId]?.thematique))
.filter(Boolean)
.join(', ')
const uniqueThemes = uniq(
themeIds.map(themeId => regulatoryAreas.entities[themeId]?.thematique.split(', ')).flatMap(theme => theme)
)

const regulatoryAreasThemes = uniqueThemes.filter(Boolean).join(', ')

return <span title={regulatoryAreasThemes}>{regulatoryAreasThemes}</span>
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { uniq } from 'lodash'

import type { Dashboard } from '@features/Dashboard/types'
import type { RegulatoryLayerWithMetadata } from 'domain/entities/regulatory'

export function filterByRegulatoryThemes(
regulatoryThemes: string[],
regulatoryThemesFilter: string[],
dashboard: Dashboard.DashboardFromApi,
regulatoryAreas: RegulatoryLayerWithMetadata[]
): boolean {
if (regulatoryThemes.length === 0) {
if (regulatoryThemesFilter.length === 0) {
return true
}

const filteredRegulatoryAreas = regulatoryAreas.filter(regulatoryArea =>
dashboard.regulatoryAreaIds?.includes(regulatoryArea.id)
)
const uniqueThemes = uniq(
filteredRegulatoryAreas.map(regulatoryArea => regulatoryArea?.thematique.split(', ')).flatMap(theme => theme)
)

return filteredRegulatoryAreas.some(reg => regulatoryThemes.includes(reg.thematique))
return uniqueThemes.some(reg => regulatoryThemesFilter.includes(reg))
}

0 comments on commit 0fe8f48

Please sign in to comment.