Skip to content

Commit

Permalink
Add default to Layer to fix issue w/ default layer
Browse files Browse the repository at this point in the history
  • Loading branch information
clementprdhomme committed Aug 30, 2024
1 parent 0e1ded0 commit c477f55
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 31 deletions.
9 changes: 6 additions & 3 deletions cms/config/sync/admin-role.strapi-super-admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,8 @@
"legend_config.items.icon",
"legend_config.items.color",
"legend_config.items.value",
"legend_config.items.description"
"legend_config.items.description",
"default"
],
"locales": [
"en",
Expand Down Expand Up @@ -937,7 +938,8 @@
"legend_config.items.icon",
"legend_config.items.color",
"legend_config.items.value",
"legend_config.items.description"
"legend_config.items.description",
"default"
],
"locales": [
"en",
Expand Down Expand Up @@ -969,7 +971,8 @@
"legend_config.items.icon",
"legend_config.items.color",
"legend_config.items.value",
"legend_config.items.description"
"legend_config.items.description",
"default"
],
"locales": [
"en",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,6 @@
"sortable": false
}
},
"legend_config": {
"edit": {
"label": "legend_config",
"description": "",
"placeholder": "",
"visible": true,
"editable": true
},
"list": {
"label": "legend_config",
"searchable": false,
"sortable": false
}
},
"interaction_config": {
"edit": {
"label": "interaction_config",
Expand Down Expand Up @@ -133,6 +119,34 @@
"sortable": true
}
},
"legend_config": {
"edit": {
"label": "legend_config",
"description": "",
"placeholder": "",
"visible": true,
"editable": true
},
"list": {
"label": "legend_config",
"searchable": false,
"sortable": false
}
},
"default": {
"edit": {
"label": "default",
"description": "Whether the layer is shown by default on the map",
"placeholder": "",
"visible": true,
"editable": true
},
"list": {
"label": "default",
"searchable": true,
"sortable": true
}
},
"createdAt": {
"edit": {
"label": "createdAt",
Expand Down Expand Up @@ -193,12 +207,6 @@
}
},
"layouts": {
"list": [
"id",
"title",
"type",
"metadata"
],
"edit": [
[
{
Expand All @@ -210,6 +218,16 @@
"size": 6
}
],
[
{
"name": "dataset",
"size": 6
},
{
"name": "default",
"size": 4
}
],
[
{
"name": "config",
Expand Down Expand Up @@ -239,13 +257,13 @@
"name": "metadata",
"size": 12
}
],
[
{
"name": "dataset",
"size": 6
}
]
],
"list": [
"id",
"title",
"type",
"metadata"
]
}
},
Expand Down
9 changes: 9 additions & 0 deletions cms/src/api/layer/content-types/layer/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@
}
},
"component": "legend.legend"
},
"default": {
"pluginOptions": {
"i18n": {
"localized": false
}
},
"type": "boolean",
"default": false
}
}
}
7 changes: 7 additions & 0 deletions cms/types/generated/contentTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,13 @@ export interface ApiLayerLayer extends Schema.CollectionType {
localized: true;
};
}>;
default: Attribute.Boolean &
Attribute.SetPluginOptions<{
i18n: {
localized: false;
};
}> &
Attribute.DefaultTo<false>;
createdAt: Attribute.DateTime;
updatedAt: Attribute.DateTime;
publishedAt: Attribute.DateTime;
Expand Down
27 changes: 26 additions & 1 deletion frontend/src/containers/map/content/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import EEZLayerPopup from '@/containers/map/content/map/popup/eez';
import GenericPopup from '@/containers/map/content/map/popup/generic';
import ProtectedAreaPopup from '@/containers/map/content/map/popup/protected-area';
import RegionsPopup from '@/containers/map/content/map/popup/regions';
import { useSyncMapSettings } from '@/containers/map/content/map/sync-settings';
import { useSyncMapLayers, useSyncMapSettings } from '@/containers/map/content/map/sync-settings';
import { sidebarAtom } from '@/containers/map/store';
import {
bboxLocation,
Expand All @@ -45,6 +45,7 @@ const MainMap: FCWithMessages = () => {
const locale = useLocale();

const [{ bbox: URLBbox }, setMapSettings] = useSyncMapSettings();
const [, setMapLayers] = useSyncMapLayers();
const { default: map } = useMap();
const drawState = useAtomValue(drawStateAtom);
const isSidebarOpen = useAtomValue(sidebarAtom);
Expand Down Expand Up @@ -92,6 +93,30 @@ const MainMap: FCWithMessages = () => {
}
);

const { data: defaultLayers } = useGetLayers(
{
locale,
fields: 'id',
filters: {
default: {
$eq: true,
},
},
},
{
query: {
select: ({ data }) => data.map(({ id }) => id),
},
}
);

// Once we have fetched from the CMS which layers are active by default, we set toggle them on
useEffect(() => {
if (defaultLayers) {
setMapLayers(defaultLayers);
}
}, [setMapLayers, defaultLayers]);

useEffect(() => {
setLocationBbox(locationsQuery?.data?.bounds as CustomMapProps['bounds']['bbox']);
}, [locationCode, locationsQuery, setLocationBbox]);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/containers/map/content/map/sync-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const useSyncMapSettings = () => {
};

export const useSyncMapLayers = () => {
return useQueryState('layers', parseAsArrayOf(parseAsInteger).withDefault([6, 7]));
return useQueryState('layers', parseAsArrayOf(parseAsInteger).withDefault([]));
};

export const useSyncMapLayerSettings = () => {
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/types/generated/strapi.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6695,6 +6695,7 @@ export interface Layer {
metadata?: DocumentationMetadataComponent;
dataset?: LayerDataset;
legend_config?: LegendLegendComponent;
default?: boolean;
createdAt?: string;
updatedAt?: string;
publishedAt?: string;
Expand Down Expand Up @@ -6756,6 +6757,7 @@ export type LayerDatasetDataAttributesLayersDataItemAttributes = {
metadata?: LayerDatasetDataAttributesLayersDataItemAttributesMetadata;
dataset?: LayerDatasetDataAttributesLayersDataItemAttributesDataset;
legend_config?: LayerDatasetDataAttributesLayersDataItemAttributesLegendConfig;
default?: boolean;
createdAt?: string;
updatedAt?: string;
publishedAt?: string;
Expand Down Expand Up @@ -7095,6 +7097,7 @@ export type LayerRequestData = {
metadata?: DocumentationMetadataComponent;
dataset?: LayerRequestDataDataset;
legend_config?: LegendLegendComponent;
default?: boolean;
locale?: string;
};

Expand Down Expand Up @@ -7123,6 +7126,7 @@ export interface LayerLocalizationRequest {
metadata?: DocumentationMetadataComponent;
dataset?: LayerLocalizationRequestDataset;
legend_config?: LegendLegendComponent;
default?: boolean;
locale: string;
}

Expand Down Expand Up @@ -9195,6 +9199,7 @@ export type DatasetLayersDataItemAttributes = {
metadata?: DatasetLayersDataItemAttributesMetadata;
dataset?: DatasetLayersDataItemAttributesDataset;
legend_config?: DatasetLayersDataItemAttributesLegendConfig;
default?: boolean;
createdAt?: string;
updatedAt?: string;
publishedAt?: string;
Expand Down

0 comments on commit c477f55

Please sign in to comment.