Skip to content

Commit

Permalink
add: external layer option inside project
Browse files Browse the repository at this point in the history
  • Loading branch information
majkshkurti committed Sep 6, 2024
1 parent c9037dc commit 08b5629
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion apps/web/app/[lng]/(dashboard)/datasets/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const Datasets = () => {
},
{
sourceType: AddLayerSourceType.DataSourceExternal,
iconName: ICON_NAME.GLOBE,
iconName: ICON_NAME.LINK,
label: t("dataset_external"),
},
];
Expand Down
9 changes: 9 additions & 0 deletions apps/web/components/map/panels/layer/Layer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import Container from "@/components/map/panels/Container";
import CatalogExplorerModal from "@/components/modals/CatalogExplorer";
import ContentDialogWrapper from "@/components/modals/ContentDialogWrapper";
import DatasetExplorerModal from "@/components/modals/DatasetExplorer";
import DatasetExternalModal from "@/components/modals/DatasetExternal";
import DatasetUploadModal from "@/components/modals/DatasetUpload";
import MapLayerChartModal from "@/components/modals/MapLayerChart";

Expand Down Expand Up @@ -183,6 +184,11 @@ const AddLayerSection = ({ projectId }: { projectId: string }) => {
iconName: ICON_NAME.UPLOAD,
label: t("dataset_upload"),
},
{
sourceType: AddLayerSourceType.DataSourceExternal,
iconName: ICON_NAME.LINK,
label: t("dataset_external"),
},
{
sourceType: AddLayerSourceType.CatalogExplorer,
iconName: ICON_NAME.GLOBE,
Expand Down Expand Up @@ -245,6 +251,9 @@ const AddLayerSection = ({ projectId }: { projectId: string }) => {
{addLayerSourceOpen === AddLayerSourceType.DatasourceUpload && (
<DatasetUploadModal open={true} onClose={closeAddLayerSourceModal} projectId={projectId} />
)}
{addLayerSourceOpen === AddLayerSourceType.DataSourceExternal && (
<DatasetExternalModal open={true} onClose={closeAddLayerSourceModal} projectId={projectId} />
)}
{addLayerSourceOpen === AddLayerSourceType.CatalogExplorer && (
<CatalogExplorerModal open={true} onClose={closeAddLayerSourceModal} projectId={projectId} />
)}
Expand Down
16 changes: 10 additions & 6 deletions apps/web/components/modals/DatasetExternal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { useTranslation } from "@/i18n/client";
import { useFolders } from "@/lib/api/folders";
import { useJobs } from "@/lib/api/jobs";
import { createFeatureLayer, createRasterLayer, layerFeatureUrlUpload } from "@/lib/api/layers";
import { addProjectLayers, useProject, useProjectLayers } from "@/lib/api/projects";
import { setRunningJobIds } from "@/lib/store/jobs/slice";
import { generateLayerGetLegendGraphicUrl, generateWmsUrl } from "@/lib/transformers/wms";
import { convertWmtsToXYZUrl, getWmtsFlatLayers } from "@/lib/transformers/wmts";
Expand Down Expand Up @@ -238,7 +239,6 @@ const getNestedLayerMultiSelectionTableBody = (
type
) => {
if (depth > 4) return null;
console.log(layers);
return (
<React.Fragment>
{layers.map((layer) => (
Expand Down Expand Up @@ -300,8 +300,6 @@ const getFlatLayerSingleSelectionTableBody = (
const DatasetsSelectTable = ({ options, type, selectedDatasets, setSelectedDatasets }) => {
const { t } = useTranslation("common");

console.log(selectedDatasets);

const handleSelectDataset = (dataset) => {
setSelectedDatasets((prevSelectedDatasets) => {
if (type === vectorDataType.Enum.wfs || type === imageryDataType.Enum.wmts) {
Expand Down Expand Up @@ -386,6 +384,8 @@ const DatasetExternal: React.FC<DatasetExternalProps> = ({ open, onClose, projec
const { mutate } = useJobs({
read: false,
});
const { mutate: mutateProjectLayers } = useProjectLayers(projectId);
const { mutate: mutateProject } = useProject(projectId);
// Step 0: Enter URL
const steps = [t("enter_url"), t("select_dataset"), t("destination_and_metadata"), t("confirmation")];

Expand Down Expand Up @@ -448,6 +448,7 @@ const DatasetExternal: React.FC<DatasetExternalProps> = ({ open, onClose, projec
// eslint-disable-next-line @typescript-eslint/no-explicit-any

const handleNext = () => {
console.log(selectedDatasets);
// STEP 0: Parse URL.
if (activeStep === 0) {
if (!externalUrl) return;
Expand Down Expand Up @@ -496,7 +497,6 @@ const DatasetExternal: React.FC<DatasetExternalProps> = ({ open, onClose, projec
}

const capabilities = parser.read(text);
console.log(capabilities);
setCapabilities({ type, capabilities });
setActiveStep((prevActiveStep) => prevActiveStep + 1);
})
Expand Down Expand Up @@ -618,9 +618,13 @@ const DatasetExternal: React.FC<DatasetExternalProps> = ({ open, onClose, projec
...(legendUrls.length && { legend_urls: legendUrls }),
},
});
await createRasterLayer(payload);
const response = await createRasterLayer(payload, projectId);
if (projectId) {
await addProjectLayers(projectId, [response.id]);
mutateProjectLayers();
mutateProject();
}
}

toast.success(t("success_adding_external_dataset"));
} catch (_error) {
toast.error(t("error_adding_external_dataset"));
Expand Down
13 changes: 8 additions & 5 deletions apps/web/lib/api/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ export const useProjects = (queryParams?: GetContentQueryParams) => {
};
};

export const useProject = (projectId: string) => {
export const useProject = (projectId?: string) => {

const { data, isLoading, error, mutate, isValidating } = useSWR<Project>(
[`${PROJECTS_API_BASE_URL}/${projectId}`],
() => (projectId ? [`${PROJECTS_API_BASE_URL}/${projectId}`] : null),
fetcher
);

return {
project: data,
isLoading: isLoading,
Expand All @@ -47,11 +49,13 @@ export const useProject = (projectId: string) => {
};
};

export const useProjectLayers = (projectId: string) => {
export const useProjectLayers = (projectId?: string) => {

const { data, isLoading, error, mutate, isValidating } = useSWR<ProjectLayer[]>(
[`${PROJECTS_API_BASE_URL}/${projectId}/layer`],
() => (projectId ? [`${PROJECTS_API_BASE_URL}/${projectId}/layer`] : null),
fetcher
);

return {
layers: data,
isLoading: isLoading,
Expand All @@ -78,7 +82,6 @@ export const useProjectScenarios = (projectId: string) => {
export const useProjectScenarioFeatures = (projectId: string, scenarioId?: string | null) => {
const { data, isLoading, error, mutate, isValidating } = useSWR<ScenarioFeatures>(
() => (scenarioId ? [`${PROJECTS_API_BASE_URL}/${projectId}/scenario/${scenarioId}/features`] : null),

fetcher
);
return {
Expand Down

0 comments on commit 08b5629

Please sign in to comment.