diff --git a/packages/app/schema/archived_vr_collection/__index.json b/packages/app/schema/archived_vr_collection/__index.json new file mode 100644 index 0000000000..11b3923afd --- /dev/null +++ b/packages/app/schema/archived_vr_collection/__index.json @@ -0,0 +1,32 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "title": "archived_vr_collection", + "additionalProperties": false, + "required": [ + "last_generated", + "proto_name", + "name", + "code" + ], + "properties": { + "last_generated": { + "type": "string" + }, + "proto_name": { + "$ref": "#/$defs/archived_vr_collection_id" + }, + "name": { + "$ref": "#/$defs/archived_vr_collection_id" + }, + "code": { + "$ref": "#/$defs/archived_vr_collection_id" + } + }, + "$defs": { + "archived_vr_collection_id": { + "type": "string", + "enum": ["VR_COLLECTION"] + } + } +} \ No newline at end of file diff --git a/packages/app/src/components/choropleth/logic/types.ts b/packages/app/src/components/choropleth/logic/types.ts index 30e350258a..352b7bc5a2 100644 --- a/packages/app/src/components/choropleth/logic/types.ts +++ b/packages/app/src/components/choropleth/logic/types.ts @@ -5,6 +5,7 @@ import type { GmCollectionTestedOverall, GmCollectionVaccineCoveragePerAgeGroup, VrCollection, + ArchivedVrCollection, VrCollectionDisabilityCareArchived_20230126, VrCollectionElderlyAtHomeArchived_20230126, VrCollectionVulnerableNursingHome, @@ -45,9 +46,15 @@ export const mapToCodeType: Record = { export type ChoroplethCollection = GmCollection | VrCollection; -export type InferedMapType = T extends GmDataItem ? 'gm' : T extends VrDataItem ? 'vr' : never; +export type InferedMapType = T extends GmDataItem ? 'gm' : T extends VrDataItem | ArchivedVrDataItem ? 'vr' : never; -export type InferedDataCollection = T extends GmDataItem ? GmCollection : T extends VrDataItem ? VrCollection : never; +export type InferedDataCollection = T extends GmDataItem + ? GmCollection + : T extends VrDataItem + ? VrCollection + : T extends ArchivedVrDataItem + ? ArchivedVrCollection + : never; export type VrDataCollection = VrCollectionDisabilityCareArchived_20230126[] | VrCollectionElderlyAtHomeArchived_20230126[] | VrCollectionVulnerableNursingHome[]; export type VrDataItem = VrDataCollection[number]; @@ -55,17 +62,10 @@ export type VrDataItem = VrDataCollection[number]; export type GmDataCollection = GmCollectionHospitalNice[] | GmCollectionTestedOverall[] | GmCollectionSewer[] | GmCollectionVaccineCoveragePerAgeGroup[]; export type GmDataItem = GmDataCollection[number]; -/** - * Here we map a MapType to a corresponding DataCollection type - */ -export type MappedDataCollection = T extends 'gm' ? GmCollection : T extends 'vr' ? VrCollection : never; - -/** - * Here we map a MapType to a corresponding DataItem type - */ -export type MappedDataItem = T extends 'gm' ? GmDataItem : T extends 'vr' ? VrDataItem : never; +export type ArchivedVrDataCollection = []; +export type ArchivedVrDataItem = ArchivedVrDataCollection[number]; -export type ChoroplethDataItem = GmDataItem | VrDataItem; +export type ChoroplethDataItem = GmDataItem | VrDataItem | ArchivedVrDataItem; export type CodedGeoProperties = { code: string; diff --git a/packages/app/src/static-props/get-data.ts b/packages/app/src/static-props/get-data.ts index fcaaf45c40..0b54d95843 100644 --- a/packages/app/src/static-props/get-data.ts +++ b/packages/app/src/static-props/get-data.ts @@ -1,4 +1,16 @@ -import { ArchivedGm, ArchivedNl, assert, Gm, GmCollection, gmData, Nl, sortTimeSeriesInDataInPlace, VrCollection } from '@corona-dashboard/common'; +import { + ArchivedGm, + ArchivedGmCollection, + ArchivedNl, + ArchivedVrCollection, + assert, + Gm, + GmCollection, + gmData, + Nl, + sortTimeSeriesInDataInPlace, + VrCollection, +} from '@corona-dashboard/common'; import { SanityClient } from '@sanity/client'; import { get } from 'lodash'; import set from 'lodash/set'; @@ -48,6 +60,8 @@ const json = { gmCollection: initializeFeatureFlaggedData(loadJsonFromDataFile('GM_COLLECTION.json'), 'gm_collection'), archived: { nl: initializeFeatureFlaggedData(loadJsonFromDataFile('NL.json', 'json/archived'), 'nl'), + vrCollection: initializeFeatureFlaggedData(loadJsonFromDataFile('VR_COLLECTION.json', 'json/archived'), 'vr_collection'), + gmCollection: initializeFeatureFlaggedData(loadJsonFromDataFile('GM_COLLECTION.json', 'json/archived'), 'gm_collection'), }, }; @@ -288,6 +302,23 @@ export function createGetChoroplethData(settings?: { }; } +export function createGetArchivedChoroplethData(settings?: { + vr?: (collection: ArchivedVrCollection, context: GetStaticPropsContext) => T1; + gm?: (collection: ArchivedGmCollection, context: GetStaticPropsContext) => T2; +}) { + return (context: GetStaticPropsContext) => { + const filterVr = settings?.vr ?? NOOP; + const filterGm = settings?.gm ?? NOOP; + + return { + archivedChoropleth: { + vr: filterVr(json.archived.vrCollection, context) as T1, + gm: filterGm(json.archived.gmCollection, context) as T2, + }, + }; + }; +} + /** * This function makes sure that for metrics with inaccurate data for the last x * items, the last_value is replaced with the last accurate value. For now only diff --git a/packages/common/src/types/data.ts b/packages/common/src/types/data.ts index 413568d401..4f822b55ec 100644 --- a/packages/common/src/types/data.ts +++ b/packages/common/src/types/data.ts @@ -267,6 +267,15 @@ export interface NlReproductionValue { date_of_insertion_unix: number; } +export type ArchivedVrCollectionId = 'VR_COLLECTION'; + +export interface ArchivedVrCollection { + last_generated: string; + proto_name: ArchivedVrCollectionId; + name: ArchivedVrCollectionId; + code: ArchivedVrCollectionId; +} + export type GmCode = string; export interface Gm {