Skip to content

Commit

Permalink
feat(web): support infobox for plugin layer (#1134)
Browse files Browse the repository at this point in the history
  • Loading branch information
airslice authored Sep 9, 2024
1 parent fc813b3 commit 06aa781
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export default ({

const addLayer = useCallback(
(layer: NaiveLayer) => {
return layersRef?.add(layer)?.id;
const layerId = layersRef?.add(layer)?.id;
// TODO: handle infobox
return layerId;
},
[layersRef]
);
Expand Down
35 changes: 25 additions & 10 deletions web/src/beta/features/Visualizer/Crust/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,30 @@ export default function Crust({
});

const featuredInfobox = useMemo(() => {
const selected = layers?.find((l) => l.id === selectedLayer?.layerId);
return selectedLayerId?.featureId && selected?.infobox
? {
property: selected?.infobox?.property,
blocks: [...(selected?.infobox?.blocks ?? [])],
featureId: selectedLayerId.featureId
}
: undefined;
}, [layers, selectedLayer, selectedLayerId?.featureId]);
if (!selectedLayerId?.featureId) return undefined;
const selectedDataLayer = layers?.find(
(l) => l.id === selectedLayer?.layerId
);
if (selectedDataLayer?.infobox) {
return {
property: selectedDataLayer?.infobox?.property,
blocks: [...(selectedDataLayer?.infobox?.blocks ?? [])],
featureId: selectedLayerId.featureId
};
}
const selected = mapRef?.current?.layers?.find(
(l) => l.id === selectedLayer?.layerId
);
if (selected?.infobox) {
return {
property: selected?.infobox?.property,
blocks: [...(selected?.infobox?.blocks ?? [])],
featureId: selectedLayerId.featureId,
readOnly: true
};
}
return undefined;
}, [mapRef, layers, selectedLayer, selectedLayerId?.featureId]);

return (
<Plugins
Expand Down Expand Up @@ -312,7 +327,7 @@ export default function Crust({
<Infobox
infobox={featuredInfobox}
installableInfoboxBlocks={installableInfoboxBlocks}
isEditable={!!inEditor}
isEditable={!!inEditor && !featuredInfobox?.readOnly}
renderBlock={renderBlock}
onBlockCreate={onInfoboxBlockCreate}
onBlockDelete={onInfoboxBlockDelete}
Expand Down

0 comments on commit 06aa781

Please sign in to comment.