From dd9025715f25f4335e4d70819f284faa908bd9e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Prod=27homme?= Date: Fri, 22 Nov 2024 15:01:51 +0100 Subject: [PATCH 1/2] feat(cms): Add `order` attribute to Sub-Topic and Dataset --- client/src/types/generated/strapi.schemas.ts | 10 +++++ .../sync/admin-role.strapi-super-admin.json | 18 ++++++--- ...n_content_types##api##dataset.dataset.json | 21 +++++++++- ...ntent_types##api##sub-topic.sub-topic.json | 27 +++++++++++-- .../dataset/content-types/dataset/schema.json | 3 ++ .../content-types/sub-topic/schema.json | 3 ++ .../1.0.0/full_documentation.json | 32 ++++++++++++++- cms/types/generated/components.d.ts | 40 +++++++++---------- cms/types/generated/contentTypes.d.ts | 2 + 9 files changed, 124 insertions(+), 32 deletions(-) diff --git a/client/src/types/generated/strapi.schemas.ts b/client/src/types/generated/strapi.schemas.ts index 1e93e8e..520e021 100644 --- a/client/src/types/generated/strapi.schemas.ts +++ b/client/src/types/generated/strapi.schemas.ts @@ -603,6 +603,7 @@ export interface SubTopic { createdAt?: string; createdBy?: SubTopicCreatedBy; name: string; + order?: number; updatedAt?: string; updatedBy?: SubTopicUpdatedBy; } @@ -763,6 +764,7 @@ export interface SubTopicListResponse { export type SubTopicRequestData = { name: string; + order?: number; }; export interface SubTopicRequest { @@ -1173,6 +1175,7 @@ export type LayerDatasetDataAttributes = { layers?: LayerDatasetDataAttributesLayers; metadata?: LayerDatasetDataAttributesMetadata; name?: string; + order?: number; short_description?: string; sub_topic?: LayerDatasetDataAttributesSubTopic; topic?: LayerDatasetDataAttributesTopic; @@ -1266,6 +1269,7 @@ export type LayerDatasetDataAttributesSubTopicDataAttributes = { createdAt?: string; createdBy?: LayerDatasetDataAttributesSubTopicDataAttributesCreatedBy; name?: string; + order?: number; updatedAt?: string; updatedBy?: LayerDatasetDataAttributesSubTopicDataAttributesUpdatedBy; }; @@ -1700,6 +1704,7 @@ export interface Dataset { layers?: DatasetLayers; metadata?: MetadataItemComponent; name: string; + order?: number; short_description?: string; sub_topic?: DatasetSubTopic; topic?: DatasetTopic; @@ -1824,6 +1829,7 @@ export type DatasetLayersDataItemAttributesDatasetDataAttributes = { layers?: DatasetLayersDataItemAttributesDatasetDataAttributesLayers; metadata?: DatasetLayersDataItemAttributesDatasetDataAttributesMetadata; name?: string; + order?: number; short_description?: string; sub_topic?: DatasetLayersDataItemAttributesDatasetDataAttributesSubTopic; topic?: DatasetLayersDataItemAttributesDatasetDataAttributesTopic; @@ -2041,6 +2047,7 @@ export type DatasetLayersDataItemAttributesDatasetDataAttributesSubTopicDataAttr createdAt?: string; createdBy?: DatasetLayersDataItemAttributesDatasetDataAttributesSubTopicDataAttributesCreatedBy; name?: string; + order?: number; updatedAt?: string; updatedBy?: DatasetLayersDataItemAttributesDatasetDataAttributesSubTopicDataAttributesUpdatedBy; }; @@ -2245,6 +2252,7 @@ export type DatasetRequestData = { layers?: DatasetRequestDataLayersItem[]; metadata?: MetadataItemComponent; name: string; + order?: number; short_description?: string; sub_topic?: DatasetRequestDataSubTopic; topic?: DatasetRequestDataTopic; @@ -2368,6 +2376,7 @@ export type ChartDataLayerDataAttributesDatasetDataAttributes = { layers?: ChartDataLayerDataAttributesDatasetDataAttributesLayers; metadata?: ChartDataLayerDataAttributesDatasetDataAttributesMetadata; name?: string; + order?: number; short_description?: string; sub_topic?: ChartDataLayerDataAttributesDatasetDataAttributesSubTopic; topic?: ChartDataLayerDataAttributesDatasetDataAttributesTopic; @@ -2585,6 +2594,7 @@ export type ChartDataLayerDataAttributesDatasetDataAttributesSubTopicDataAttribu createdAt?: string; createdBy?: ChartDataLayerDataAttributesDatasetDataAttributesSubTopicDataAttributesCreatedBy; name?: string; + order?: number; updatedAt?: string; updatedBy?: ChartDataLayerDataAttributesDatasetDataAttributesSubTopicDataAttributesUpdatedBy; }; diff --git a/cms/config/sync/admin-role.strapi-super-admin.json b/cms/config/sync/admin-role.strapi-super-admin.json index b156f51..0cff370 100644 --- a/cms/config/sync/admin-role.strapi-super-admin.json +++ b/cms/config/sync/admin-role.strapi-super-admin.json @@ -75,7 +75,8 @@ "metadata.units", "metadata.full_name", "metadata.temporal_resolution", - "short_description" + "short_description", + "order" ] }, "conditions": [] @@ -107,7 +108,8 @@ "metadata.units", "metadata.full_name", "metadata.temporal_resolution", - "short_description" + "short_description", + "order" ] }, "conditions": [] @@ -132,7 +134,8 @@ "metadata.units", "metadata.full_name", "metadata.temporal_resolution", - "short_description" + "short_description", + "order" ] }, "conditions": [] @@ -280,7 +283,8 @@ "subject": "api::sub-topic.sub-topic", "properties": { "fields": [ - "name" + "name", + "order" ] }, "conditions": [] @@ -298,7 +302,8 @@ "subject": "api::sub-topic.sub-topic", "properties": { "fields": [ - "name" + "name", + "order" ] }, "conditions": [] @@ -309,7 +314,8 @@ "subject": "api::sub-topic.sub-topic", "properties": { "fields": [ - "name" + "name", + "order" ] }, "conditions": [] diff --git a/cms/config/sync/core-store.plugin_content_manager_configuration_content_types##api##dataset.dataset.json b/cms/config/sync/core-store.plugin_content_manager_configuration_content_types##api##dataset.dataset.json index 0e293a5..8d3e28e 100644 --- a/cms/config/sync/core-store.plugin_content_manager_configuration_content_types##api##dataset.dataset.json +++ b/cms/config/sync/core-store.plugin_content_manager_configuration_content_types##api##dataset.dataset.json @@ -121,6 +121,20 @@ "sortable": true } }, + "order": { + "edit": { + "label": "order", + "description": "Define the order of the dataset within a sub-topic. The value is relative to the other datasets.", + "placeholder": "", + "visible": true, + "editable": true + }, + "list": { + "label": "order", + "searchable": true, + "sortable": true + } + }, "createdAt": { "edit": { "label": "createdAt", @@ -186,6 +200,10 @@ { "name": "name", "size": 6 + }, + { + "name": "order", + "size": 6 } ], [ @@ -225,7 +243,8 @@ "id", "topic", "sub_topic", - "name" + "name", + "order" ] }, "uid": "api::dataset.dataset" diff --git a/cms/config/sync/core-store.plugin_content_manager_configuration_content_types##api##sub-topic.sub-topic.json b/cms/config/sync/core-store.plugin_content_manager_configuration_content_types##api##sub-topic.sub-topic.json index d286400..ad87547 100644 --- a/cms/config/sync/core-store.plugin_content_manager_configuration_content_types##api##sub-topic.sub-topic.json +++ b/cms/config/sync/core-store.plugin_content_manager_configuration_content_types##api##sub-topic.sub-topic.json @@ -33,6 +33,20 @@ "sortable": true } }, + "order": { + "edit": { + "label": "order", + "description": "Define the order of the sub-topic within a topic. The value is relative to the other sub-topics.", + "placeholder": "", + "visible": true, + "editable": true + }, + "list": { + "label": "order", + "searchable": true, + "sortable": true + } + }, "createdAt": { "edit": { "label": "createdAt", @@ -93,17 +107,22 @@ } }, "layouts": { - "list": [ - "id", - "name" - ], "edit": [ [ { "name": "name", "size": 6 + }, + { + "name": "order", + "size": 4 } ] + ], + "list": [ + "id", + "name", + "order" ] }, "uid": "api::sub-topic.sub-topic" diff --git a/cms/src/api/dataset/content-types/dataset/schema.json b/cms/src/api/dataset/content-types/dataset/schema.json index 0d488ea..024c5ef 100644 --- a/cms/src/api/dataset/content-types/dataset/schema.json +++ b/cms/src/api/dataset/content-types/dataset/schema.json @@ -44,6 +44,9 @@ "short_description": { "type": "text", "maxLength": 100 + }, + "order": { + "type": "integer" } } } diff --git a/cms/src/api/sub-topic/content-types/sub-topic/schema.json b/cms/src/api/sub-topic/content-types/sub-topic/schema.json index 800c45d..4945fcd 100644 --- a/cms/src/api/sub-topic/content-types/sub-topic/schema.json +++ b/cms/src/api/sub-topic/content-types/sub-topic/schema.json @@ -15,6 +15,9 @@ "name": { "type": "string", "required": true + }, + "order": { + "type": "integer" } } } diff --git a/cms/src/extensions/documentation/documentation/1.0.0/full_documentation.json b/cms/src/extensions/documentation/documentation/1.0.0/full_documentation.json index b87879b..275220a 100644 --- a/cms/src/extensions/documentation/documentation/1.0.0/full_documentation.json +++ b/cms/src/extensions/documentation/documentation/1.0.0/full_documentation.json @@ -14,7 +14,7 @@ "name": "Apache 2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0.html" }, - "x-generation-date": "2024-11-22T10:48:59.215Z" + "x-generation-date": "2024-11-22T14:00:12.515Z" }, "x-strapi-config": { "path": "/documentation", @@ -642,6 +642,9 @@ "name": { "type": "string" }, + "order": { + "type": "integer" + }, "createdAt": { "type": "string", "format": "date-time" @@ -728,6 +731,9 @@ "short_description": { "type": "string" }, + "order": { + "type": "integer" + }, "createdAt": { "type": "string", "format": "date-time" @@ -1051,6 +1057,9 @@ }, "short_description": { "type": "string" + }, + "order": { + "type": "integer" } } } @@ -1568,6 +1577,9 @@ "name": { "type": "string" }, + "order": { + "type": "integer" + }, "createdAt": { "type": "string", "format": "date-time" @@ -1654,6 +1666,9 @@ "short_description": { "type": "string" }, + "order": { + "type": "integer" + }, "createdAt": { "type": "string", "format": "date-time" @@ -1902,6 +1917,9 @@ "short_description": { "type": "string" }, + "order": { + "type": "integer" + }, "createdAt": { "type": "string", "format": "date-time" @@ -2737,6 +2755,9 @@ "name": { "type": "string" }, + "order": { + "type": "integer" + }, "createdAt": { "type": "string", "format": "date-time" @@ -2823,6 +2844,9 @@ "short_description": { "type": "string" }, + "order": { + "type": "integer" + }, "createdAt": { "type": "string", "format": "date-time" @@ -3554,6 +3578,9 @@ "properties": { "name": { "type": "string" + }, + "order": { + "type": "integer" } } } @@ -3614,6 +3641,9 @@ "name": { "type": "string" }, + "order": { + "type": "integer" + }, "createdAt": { "type": "string", "format": "date-time" diff --git a/cms/types/generated/components.d.ts b/cms/types/generated/components.d.ts index ff7c4e4..0fcf675 100644 --- a/cms/types/generated/components.d.ts +++ b/cms/types/generated/components.d.ts @@ -1,24 +1,5 @@ import type { Schema, Attribute } from '@strapi/strapi'; -export interface MetadataItem extends Schema.Component { - collectionName: 'components_metadata_item'; - info: { - displayName: 'Item'; - description: ''; - }; - attributes: { - source: Attribute.String; - website: Attribute.String; - description: Attribute.Text; - main_applications: Attribute.RichText; - temporal_coverage: Attribute.RichText; - spatial_resolution: Attribute.String; - units: Attribute.String; - full_name: Attribute.String & Attribute.Required; - temporal_resolution: Attribute.RichText; - }; -} - export interface LegendLegendConfig extends Schema.Component { collectionName: 'components_legend_legend_configs'; info: { @@ -54,12 +35,31 @@ export interface LegendItems extends Schema.Component { }; } +export interface MetadataItem extends Schema.Component { + collectionName: 'components_metadata_item'; + info: { + displayName: 'Item'; + description: ''; + }; + attributes: { + source: Attribute.String; + website: Attribute.String; + description: Attribute.Text; + main_applications: Attribute.RichText; + temporal_coverage: Attribute.RichText; + spatial_resolution: Attribute.String; + units: Attribute.String; + full_name: Attribute.String & Attribute.Required; + temporal_resolution: Attribute.RichText; + }; +} + declare module '@strapi/types' { export module Shared { export interface Components { - 'metadata.item': MetadataItem; 'legend.legend-config': LegendLegendConfig; 'legend.items': LegendItems; + 'metadata.item': MetadataItem; } } } diff --git a/cms/types/generated/contentTypes.d.ts b/cms/types/generated/contentTypes.d.ts index 819ada2..72c5e1c 100644 --- a/cms/types/generated/contentTypes.d.ts +++ b/cms/types/generated/contentTypes.d.ts @@ -871,6 +871,7 @@ export interface ApiDatasetDataset extends Schema.CollectionType { Attribute.SetMinMaxLength<{ maxLength: 100; }>; + order: Attribute.Integer; createdAt: Attribute.DateTime; updatedAt: Attribute.DateTime; createdBy: Attribute.Relation< @@ -996,6 +997,7 @@ export interface ApiSubTopicSubTopic extends Schema.CollectionType { }; attributes: { name: Attribute.String & Attribute.Required; + order: Attribute.Integer; createdAt: Attribute.DateTime; updatedAt: Attribute.DateTime; createdBy: Attribute.Relation< From 45785d2f3e7c7aa53320c650186f9a138eec0ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Prod=27homme?= Date: Fri, 22 Nov 2024 15:08:46 +0100 Subject: [PATCH 2/2] feat(client): Respect Sub-topic and Dataset order --- client/src/components/panels/contextual-layers/index.tsx | 7 +------ client/src/components/panels/drought/index.tsx | 1 - client/src/components/panels/flood/index.tsx | 1 - client/src/components/panels/hydrometeorological/index.tsx | 1 - client/src/hooks/use-datasets-by-sub-topic.ts | 7 +++---- client/src/hooks/use-topic-tab-layer-management.ts | 2 +- .../documentation/1.0.0/full_documentation.json | 2 +- 7 files changed, 6 insertions(+), 15 deletions(-) diff --git a/client/src/components/panels/contextual-layers/index.tsx b/client/src/components/panels/contextual-layers/index.tsx index ee6965a..5ebcd8e 100644 --- a/client/src/components/panels/contextual-layers/index.tsx +++ b/client/src/components/panels/contextual-layers/index.tsx @@ -9,12 +9,7 @@ import XMarkIcon from "@/svgs/xmark.svg"; import Item from "./item"; const ContextualLayersPanel = () => { - const { data, isLoading } = useDatasetsBySubTopic( - "contextual", - "sub_topic.name,name", - ["layer", "download_link"], - true, - ); + const { data, isLoading } = useDatasetsBySubTopic("contextual", ["layer", "download_link"], true); return ( <> diff --git a/client/src/components/panels/drought/index.tsx b/client/src/components/panels/drought/index.tsx index 2dc8c4b..c5341da 100644 --- a/client/src/components/panels/drought/index.tsx +++ b/client/src/components/panels/drought/index.tsx @@ -8,7 +8,6 @@ import useDatasetsBySubTopic from "@/hooks/use-datasets-by-sub-topic"; const DroughtPanel = () => { const { data, isLoading } = useDatasetsBySubTopic( "drought", - "sub_topic.name:desc,name", ["name", "params_config", "download_link"], true, ); diff --git a/client/src/components/panels/flood/index.tsx b/client/src/components/panels/flood/index.tsx index 597564d..0b8db01 100644 --- a/client/src/components/panels/flood/index.tsx +++ b/client/src/components/panels/flood/index.tsx @@ -8,7 +8,6 @@ import useDatasetsBySubTopic from "@/hooks/use-datasets-by-sub-topic"; const FloodPanel = () => { const { data, isLoading } = useDatasetsBySubTopic( "flood", - "sub_topic.name:desc,name", ["name", "params_config", "download_link"], true, ); diff --git a/client/src/components/panels/hydrometeorological/index.tsx b/client/src/components/panels/hydrometeorological/index.tsx index b57d1c1..6828639 100644 --- a/client/src/components/panels/hydrometeorological/index.tsx +++ b/client/src/components/panels/hydrometeorological/index.tsx @@ -9,7 +9,6 @@ import HydrometeorologicalImage from "../../../../public/assets/images/hydromete const HydrometeorologicalPanel = () => { const { data, isLoading } = useDatasetsBySubTopic( "hydrometeorological", - "sub_topic.name:desc,name", ["name", "params_config", "download_link"], true, ); diff --git a/client/src/hooks/use-datasets-by-sub-topic.ts b/client/src/hooks/use-datasets-by-sub-topic.ts index 1bd4c27..6409a4f 100644 --- a/client/src/hooks/use-datasets-by-sub-topic.ts +++ b/client/src/hooks/use-datasets-by-sub-topic.ts @@ -15,7 +15,6 @@ type DatasetsBySubTopic = { export default function useDatasetsBySubTopic( topicSlug: string, - sort = "sub_topic.name,name", layersFields = ["name"], includeMetadata = false, ) { @@ -25,10 +24,10 @@ export default function useDatasetsBySubTopic( { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore-error - fields: ["name", "short_description"], + fields: ["name", "short_description", "order"], populate: { sub_topic: { - fields: ["name"], + fields: ["name", "order"], }, default_layer: { fields: ["id"], @@ -46,7 +45,7 @@ export default function useDatasetsBySubTopic( }, }, }, - sort, + sort: "sub_topic.order,order", }, { query: { diff --git a/client/src/hooks/use-topic-tab-layer-management.ts b/client/src/hooks/use-topic-tab-layer-management.ts index b49431a..2fe3ef3 100644 --- a/client/src/hooks/use-topic-tab-layer-management.ts +++ b/client/src/hooks/use-topic-tab-layer-management.ts @@ -10,7 +10,7 @@ export default function useTopicTabLayerManagement() { const [layers, { addLayer, removeLayer }] = useMapLayers(); - const { data, isLoading } = useDatasetsBySubTopic(tab, "sub_topic.name:desc,name"); + const { data, isLoading } = useDatasetsBySubTopic(tab); // The ids of all the layers that belong to the topic const topicLayerIds = useMemo(() => { diff --git a/cms/src/extensions/documentation/documentation/1.0.0/full_documentation.json b/cms/src/extensions/documentation/documentation/1.0.0/full_documentation.json index 275220a..3785c14 100644 --- a/cms/src/extensions/documentation/documentation/1.0.0/full_documentation.json +++ b/cms/src/extensions/documentation/documentation/1.0.0/full_documentation.json @@ -14,7 +14,7 @@ "name": "Apache 2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0.html" }, - "x-generation-date": "2024-11-22T14:00:12.515Z" + "x-generation-date": "2024-11-22T14:01:53.948Z" }, "x-strapi-config": { "path": "/documentation",