From a218a92169755d471e001143e9bb318cc6a48898 Mon Sep 17 00:00:00 2001 From: mluena Date: Wed, 10 Apr 2024 13:04:12 +0200 Subject: [PATCH] legend types --- .../map/legend/legend-item/basic.tsx | 67 +++++++++---------- .../map/legend/legend-item/choropleth.tsx | 10 ++- .../map/legend/legend-item/gradient.tsx | 10 ++- .../map/legend/legend-item/index.tsx | 13 ++-- client/src/types/generated/strapi.schemas.ts | 24 +++++-- 5 files changed, 69 insertions(+), 55 deletions(-) diff --git a/client/src/containers/map/legend/legend-item/basic.tsx b/client/src/containers/map/legend/legend-item/basic.tsx index 9ff490e1..a7867d78 100644 --- a/client/src/containers/map/legend/legend-item/basic.tsx +++ b/client/src/containers/map/legend/legend-item/basic.tsx @@ -1,5 +1,6 @@ 'use-client'; +import type { Layer } from '@/types/generated/strapi.schemas'; import type { LayerSettings } from '@/types/layers'; import type { Legend } from '@/types/map'; @@ -7,45 +8,43 @@ import LegendSettings from '@/containers/legend-settings'; const BasicLegendItem = ({ name, + legend_config, settings, - items, - notes, -}: { - name: Legend['name']; - settings: LayerSettings; - items: Legend['items']; - notes?: Legend['notes']; -}) => ( -
- {items.length === 1 ? ( -
-
-
-
-

{name}

-
- -
- {items[0]?.notes &&

{items[0]?.notes}

} -
- ) : ( -
-
+}: Layer & { settings: LayerSettings }) => { + const { items, notes } = legend_config as Legend; + + return ( +
+ {items.length === 1 ? ( +
-

{name}

+
+
+

{name}

+
+ {items[0]?.notes &&

{items[0]?.notes}

}
- {items.map((item) => ( -
-
-

{item.value}

+ ) : ( +
+
+
+

{name}

+ +
- ))} - {notes &&

{notes}

} -
- )} -
-); + {items.map((item) => ( +
+
+

{item.value}

+
+ ))} + {notes &&

{notes}

} +
+ )} +
+ ); +}; export default BasicLegendItem; diff --git a/client/src/containers/map/legend/legend-item/choropleth.tsx b/client/src/containers/map/legend/legend-item/choropleth.tsx index aa0abd30..a0d92534 100644 --- a/client/src/containers/map/legend/legend-item/choropleth.tsx +++ b/client/src/containers/map/legend/legend-item/choropleth.tsx @@ -1,5 +1,6 @@ 'use-client'; +import type { Layer } from '@/types/generated/strapi.schemas'; import type { LayerSettings } from '@/types/layers'; import type { Legend } from '@/types/map'; @@ -7,13 +8,10 @@ import LegendSettings from '@/containers/legend-settings'; const ChoroplethLegendItem = ({ name, + legend_config, settings, - items, -}: { - name: Legend['name']; - settings: LayerSettings; - items: Legend['items']; -}) => { +}: Layer & { settings: LayerSettings }) => { + const { items } = legend_config as Legend; return (
diff --git a/client/src/containers/map/legend/legend-item/gradient.tsx b/client/src/containers/map/legend/legend-item/gradient.tsx index 36720791..2fbe0206 100644 --- a/client/src/containers/map/legend/legend-item/gradient.tsx +++ b/client/src/containers/map/legend/legend-item/gradient.tsx @@ -2,6 +2,7 @@ import { cn } from '@/lib/classnames'; +import type { Layer } from '@/types/generated/strapi.schemas'; import type { LayerSettings } from '@/types/layers'; import type { Legend } from '@/types/map'; @@ -9,13 +10,10 @@ import LegendSettings from '@/containers/legend-settings'; const GradientLegendItem = ({ name, - items, + legend_config, settings, -}: { - name: Legend['name']; - items: Legend['items']; - settings: LayerSettings; -}) => { +}: Layer & { settings: LayerSettings }) => { + const { items } = legend_config as Legend; return (
diff --git a/client/src/containers/map/legend/legend-item/index.tsx b/client/src/containers/map/legend/legend-item/index.tsx index 5de80316..fd15a498 100644 --- a/client/src/containers/map/legend/legend-item/index.tsx +++ b/client/src/containers/map/legend/legend-item/index.tsx @@ -2,6 +2,7 @@ import { useGetLayersId } from '@/types/generated/layer'; import type { LayerSettings } from '@/types/layers'; +import type { Legend } from '@/types/map'; import BasicLegendItem from './basic'; import ChoroplethLegendItem from './choropleth'; @@ -15,18 +16,22 @@ const MapLegendItem = ({ settings }: { settings: LayerSettings }) => { if (!data?.data?.attributes) return null; const { legend_config, name } = data.data.attributes; - const { type, items } = legend_config; + const { type } = legend_config as Legend; return (
- {type === 'gradient' && } + {type === 'gradient' && ( + + )} {type === 'choropleth' && ( - + + )} + {type === 'basic' && ( + )} - {type === 'basic' && }
); }; diff --git a/client/src/types/generated/strapi.schemas.ts b/client/src/types/generated/strapi.schemas.ts index abe9b631..8e4ae769 100644 --- a/client/src/types/generated/strapi.schemas.ts +++ b/client/src/types/generated/strapi.schemas.ts @@ -1478,15 +1478,29 @@ export type LayerCreatedBy = { data?: LayerCreatedByData; }; +export const LEGEND_TYPE = ['basic', 'choropleth', 'gradient'] as const; + +export type LegendType = (typeof LEGEND_TYPE)[number]; + +export type LegendConfig = { + type: LegendType; + name?: string; + info?: string; + description?: string; + items: { color: string; value: string; notes?: string }[]; + intersections?: { id: number; color: string }[]; + notes?: string; +}; + export interface Layer { name?: string; config?: unknown; params_config?: unknown; decode_function?: string; legend_config?: unknown; - description?: string; - info?: string; slug?: string; + description?: string; + dialog?: string; createdAt?: string; updatedAt?: string; publishedAt?: string; @@ -1672,7 +1686,7 @@ export type LayerListResponseMeta = { }; export interface LayerListResponseDataItem { - id: number; + id?: number; attributes?: Layer; } @@ -1687,9 +1701,9 @@ export type LayerRequestData = { params_config?: unknown; decode_function?: string; legend_config?: unknown; - description?: string; - info?: unknown; slug?: string; + description?: string; + dialog?: string; }; export interface LayerRequest {