Skip to content

Commit

Permalink
Merge pull request #22
Browse files Browse the repository at this point in the history
Allow users to download Contextual layers
  • Loading branch information
clementprdhomme authored Nov 8, 2024
2 parents 4fde3f7 + 1fad138 commit 462963a
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 13 deletions.
3 changes: 2 additions & 1 deletion client/src/components/panels/contextual-layers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import XMarkIcon from "@/svgs/xmark.svg";
import Item from "./item";

const ContextualLayersPanel = () => {
const { data, isLoading } = useDatasetsBySubTopic("contextual");
const { data, isLoading } = useDatasetsBySubTopic("contextual", ["layer", "download_link"]);

return (
<>
Expand Down Expand Up @@ -71,6 +71,7 @@ const ContextualLayersPanel = () => {
// Assuming the dataset has just one layer, which is currently the case
id: dataset.layers[0].id!,
name: dataset.layers[0].attributes!.name!,
downloadLink: dataset.layers[0].attributes!.download_link,
}))}
/>
))}
Expand Down
32 changes: 30 additions & 2 deletions client/src/components/panels/contextual-layers/item.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import Link from "next/link";

import { Button } from "@/components/ui/button";
import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import useMapLayers from "@/hooks/use-map-layers";
import { cn } from "@/lib/utils";
import DownloadIcon from "@/svgs/download.svg";
import { Dataset, Layer } from "@/types/generated/strapi.schemas";

interface ItemProps {
name: Dataset["name"];
layers: { id: number; name: Layer["name"] }[];
layers: { id: number; name: Layer["name"]; downloadLink?: Layer["download_link"] }[];
}

const Item = ({ name, layers }: ItemProps) => {
Expand All @@ -20,7 +25,30 @@ const Item = ({ name, layers }: ItemProps) => {
<Label htmlFor={`${layer.id}-toggle`} className="text-xl">
{layer.name}
</Label>
<div className="pt-1">
<div className="flex items-center gap-0.5 pt-1">
<Button
variant="ghost"
size="icon-sm"
className={cn({
"group/download": true,
"pointer-events-none opacity-20": !layer.downloadLink,
})}
aria-disabled={!layer.downloadLink}
tabIndex={!layer.downloadLink ? -1 : undefined}
asChild
>
<Link
href={layer.downloadLink ?? ""}
rel="noopener noreferrer"
download={layer.name}
>
<span className="sr-only">Download</span>
<DownloadIcon
className="!size-4 transition-colors group-hover/download:text-casper-blue-300"
aria-hidden
/>
</Link>
</Button>
<Switch
id={`${layer.id}-toggle`}
checked={layersConfiguration.findIndex(({ id }) => id === layer.id) !== -1}
Expand Down
4 changes: 4 additions & 0 deletions client/src/svgs/download.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions client/src/types/generated/strapi.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ export interface Layer {
createdAt?: string;
createdBy?: LayerCreatedBy;
dataset?: LayerDataset;
download_link?: string;
legend_config: LegendLegendConfigComponent;
mapbox_config: unknown;
name: string;
Expand Down Expand Up @@ -1206,6 +1207,7 @@ export type LayerDatasetDataAttributesLayersDataItemAttributes = {
createdAt?: string;
createdBy?: LayerDatasetDataAttributesLayersDataItemAttributesCreatedBy;
dataset?: LayerDatasetDataAttributesLayersDataItemAttributesDataset;
download_link?: string;
legend_config?: LayerDatasetDataAttributesLayersDataItemAttributesLegendConfig;
mapbox_config?: unknown;
name?: string;
Expand Down Expand Up @@ -1476,6 +1478,7 @@ export type LayerRequestDataDataset = number | string;

export type LayerRequestData = {
dataset?: LayerRequestDataDataset;
download_link?: string;
legend_config: LegendLegendConfigComponent;
mapbox_config: unknown;
name: string;
Expand Down Expand Up @@ -1552,6 +1555,7 @@ export type DatasetLayersDataItemAttributes = {
createdAt?: string;
createdBy?: DatasetLayersDataItemAttributesCreatedBy;
dataset?: DatasetLayersDataItemAttributesDataset;
download_link?: string;
legend_config?: DatasetLayersDataItemAttributesLegendConfig;
mapbox_config?: unknown;
name?: string;
Expand Down
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 @@ -70,7 +70,8 @@
"legend_config.items.value",
"legend_config.items.pattern",
"legend_config.unit",
"dataset"
"dataset",
"download_link"
]
},
"conditions": []
Expand All @@ -97,7 +98,8 @@
"legend_config.items.value",
"legend_config.items.pattern",
"legend_config.unit",
"dataset"
"dataset",
"download_link"
]
},
"conditions": []
Expand All @@ -117,7 +119,8 @@
"legend_config.items.value",
"legend_config.items.pattern",
"legend_config.unit",
"dataset"
"dataset",
"download_link"
]
},
"conditions": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@
"sortable": true
}
},
"download_link": {
"edit": {
"label": "download_link",
"description": "",
"placeholder": "",
"visible": true,
"editable": true
},
"list": {
"label": "download_link",
"searchable": true,
"sortable": true
}
},
"createdAt": {
"edit": {
"label": "createdAt",
Expand Down Expand Up @@ -164,6 +178,12 @@
}
},
"layouts": {
"list": [
"id",
"dataset",
"type",
"name"
],
"edit": [
[
{
Expand Down Expand Up @@ -198,13 +218,13 @@
"name": "legend_config",
"size": 12
}
],
[
{
"name": "download_link",
"size": 6
}
]
],
"list": [
"id",
"dataset",
"type",
"name"
]
},
"uid": "api::layer.layer"
Expand Down
4 changes: 4 additions & 0 deletions cms/src/api/layer/content-types/layer/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
"type": "relation",
"relation": "oneToOne",
"target": "api::dataset.dataset"
},
"download_link": {
"type": "string",
"regex": "^(https?:\\/\\/)?(www\\.)?[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)+((\\/[\\w\\-\\._~:\\/\\?#\\[\\]@!$&'\\(\\)\\*+,;=]*)*)$"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
},
"x-generation-date": "2024-11-05T12:51:46.101Z"
"x-generation-date": "2024-11-08T08:14:51.291Z"
},
"x-strapi-config": {
"path": "/documentation",
Expand Down Expand Up @@ -753,6 +753,9 @@
}
}
},
"download_link": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
Expand Down Expand Up @@ -960,6 +963,9 @@
}
],
"example": "string or id"
},
"download_link": {
"type": "string"
}
}
}
Expand Down Expand Up @@ -1133,6 +1139,9 @@
}
}
},
"download_link": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
Expand Down Expand Up @@ -1628,6 +1637,9 @@
}
}
},
"download_link": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
Expand Down
1 change: 1 addition & 0 deletions cms/types/generated/contentTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ export interface ApiLayerLayer extends Schema.CollectionType {
'oneToOne',
'api::dataset.dataset'
>;
download_link: Attribute.String;
createdAt: Attribute.DateTime;
updatedAt: Attribute.DateTime;
createdBy: Attribute.Relation<
Expand Down

0 comments on commit 462963a

Please sign in to comment.