-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from Vizzuality/SKY30-103-fe-implement-the-dat…
…a-table [SKY30-103] Implement the National/High Seas data table
- Loading branch information
Showing
13 changed files
with
637 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const applyFilters = (data, filters) => { | ||
const filteredData = data.filter((item) => { | ||
for (const key in filters) { | ||
if (!filters[key].includes(item[key])) return false; | ||
} | ||
return true; | ||
}); | ||
return filteredData; | ||
}; |
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
9 changes: 9 additions & 0 deletions
9
...tend/src/containers/data-tool/content/details/tables/global-regional/useFiltersOptions.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { LOCATION_TYPES_FILTER_OPTIONS } from '@/containers/data-tool/constants'; | ||
|
||
const useFiltersOptions = () => { | ||
return { | ||
locationTypes: LOCATION_TYPES_FILTER_OPTIONS, | ||
}; | ||
}; | ||
|
||
export default useFiltersOptions; |
60 changes: 0 additions & 60 deletions
60
frontend/src/containers/data-tool/content/details/tables/national-highseas/columns.tsx
This file was deleted.
Oops, something went wrong.
108 changes: 104 additions & 4 deletions
108
frontend/src/containers/data-tool/content/details/tables/national-highseas/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,111 @@ | ||
import { useMemo, useState } from 'react'; | ||
|
||
import { useAtomValue } from 'jotai'; | ||
|
||
import Table from '@/containers/data-tool/content/details/table'; | ||
import columns from '@/containers/data-tool/content/details/tables/national-highseas/columns'; | ||
import mockedData from '@/containers/data-tool/content/details/tables/national-highseas/mocked-data'; | ||
import useColumns from '@/containers/data-tool/content/details/tables/national-highseas/useColumns'; | ||
import { locationAtom } from '@/store/location'; | ||
import { useGetMpaProtectionCoverageStats } from '@/types/generated/mpa-protection-coverage-stat'; | ||
import { MpaProtectionCoverageStatListResponseDataItem } from '@/types/generated/strapi.schemas'; | ||
import { applyFilters } from '@/containers/data-tool/content/details/helpers'; | ||
|
||
const NationalHighseasTable: React.FC = () => { | ||
const data = mockedData; | ||
const location = useAtomValue(locationAtom); | ||
|
||
const [filters, setFilters] = useState({ | ||
// ! This shouldn't be hardcoded. The setup needs to be able to work the same without any default filters here. | ||
protectedAreaType: ['mpa', 'oecm'], | ||
establishmentStage: [ | ||
'designated-implemented', | ||
'designated-unimplemented', | ||
'proposed-committed', | ||
], | ||
protectionLevel: ['fully-highly-protected', 'less-protected-unknown'], | ||
fishingProtectionLevel: ['highly', 'moderately', 'less'], | ||
}); | ||
|
||
const handleOnFiltersChange = (field, values) => { | ||
setFilters({ ...filters, [field]: values }); | ||
}; | ||
|
||
const columns = useColumns({ filters, onFiltersChange: handleOnFiltersChange }); | ||
|
||
const { data: coverageData }: { data: MpaProtectionCoverageStatListResponseDataItem[] } = | ||
useGetMpaProtectionCoverageStats( | ||
{ | ||
filters: { | ||
location: { | ||
code: { | ||
$eq: location.code, | ||
}, | ||
}, | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
fields: ['area'], | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
populate: { | ||
mpa: { | ||
fields: ['name', 'wdpaid', 'area'], | ||
populate: { | ||
mpaa_establishment_stage: { | ||
fields: ['slug', 'name'], | ||
}, | ||
protection_status: { | ||
fields: ['slug', 'name'], | ||
}, | ||
}, | ||
}, | ||
location: { | ||
fields: ['code', 'total_marine_area'], | ||
}, | ||
fishing_protection_level: { | ||
fields: ['slug', 'name'], | ||
}, | ||
mpaa_protection_level: { | ||
fields: ['slug', 'name'], | ||
}, | ||
}, | ||
}, | ||
{ | ||
query: { | ||
select: ({ data }) => data, | ||
placeholderData: { data: [] }, | ||
}, | ||
} | ||
); | ||
|
||
const parsedData = useMemo(() => { | ||
return coverageData.map(({ attributes: coverageStats }) => { | ||
const mpa = coverageStats?.mpa?.data?.attributes; | ||
const protectionStatus = mpa?.protection_status?.data?.attributes; | ||
const establishmentStage = mpa?.mpaa_establishment_stage?.data?.attributes; | ||
const mpaaProtectionLevel = coverageStats?.mpaa_protection_level?.data?.attributes; | ||
const fishingProtectionLevel = coverageStats?.fishing_protection_level?.data?.attributes; | ||
const coverageArea = coverageStats?.area; | ||
const location = coverageStats?.location?.data?.attributes; | ||
|
||
// Calculate coverage percentage | ||
const coveragePercentage = (coverageArea / location?.totalMarineArea) * 100; | ||
|
||
return { | ||
protectedArea: mpa.name, | ||
coverage: coveragePercentage, | ||
protectedAreaType: protectionStatus?.slug, | ||
establishmentStage: establishmentStage?.slug, | ||
protectionLevel: mpaaProtectionLevel?.slug, | ||
fishingProtectionLevel: fishingProtectionLevel?.slug, | ||
area: coverageArea, | ||
}; | ||
}); | ||
}, [coverageData]); | ||
|
||
const tableData = useMemo(() => { | ||
return applyFilters(parsedData, filters); | ||
}, [filters, parsedData]); | ||
|
||
return <Table columns={columns} data={data} />; | ||
return <Table columns={columns} data={tableData} />; | ||
}; | ||
|
||
export default NationalHighseasTable; |
22 changes: 0 additions & 22 deletions
22
frontend/src/containers/data-tool/content/details/tables/national-highseas/mocked-data.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.