Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

fix: support tree-structured layers and tags in published pages #168

Merged
merged 1 commit into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 32 additions & 22 deletions src/components/organisms/Published/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
} from "@reearth/components/molecules/Visualizer";
import { LayerStore } from "@reearth/components/molecules/Visualizer";

import { PublishedData, WidgetZone, WidgetSection, WidgetArea } from "./types";
import { PublishedData, WidgetZone, WidgetSection, WidgetArea, Layer as RawLayer } from "./types";

export default (alias?: string) => {
const [data, setData] = useState<PublishedData>();
Expand All @@ -32,30 +32,14 @@ export default (alias?: string) => {
() =>
new LayerStore({
id: "",
children: data?.layers?.map<Layer>(l => ({
id: l.id,
title: l.name || "",
pluginId: l.pluginId,
extensionId: l.extensionId,
isVisible: true,
property: processProperty(l.property),
infobox: l.infobox
? {
property: processProperty(l.infobox.property),
blocks: l.infobox.fields.map<Block>(f => ({
id: f.id,
pluginId: f.pluginId,
extensionId: f.extensionId,
property: processProperty(f.property),
})),
}
: undefined,
})),
children: data?.layers?.map(processLayer),
}),
[data],
);

const widgetSystem = useMemo<
const tags = data?.tags; // Currently no need to convert tags

const widgets = useMemo<
{ floatingWidgets: Widget[]; alignSystem: WidgetAlignSystem | undefined } | undefined
>(() => {
if (!data || !data.widgets) return undefined;
Expand Down Expand Up @@ -190,13 +174,39 @@ export default (alias?: string) => {
sceneProperty,
pluginProperty,
layers,
tags,
clusterProperty,
widgets: widgetSystem,
widgets,
ready,
error,
};
};

function processLayer(l: RawLayer): Layer {
return {
id: l.id,
title: l.name || "",
pluginId: l.pluginId,
extensionId: l.extensionId,
isVisible: l.isVisible ?? true,
propertyId: l.propertyId,
property: processProperty(l.property),
infobox: l.infobox
? {
property: processProperty(l.infobox.property),
blocks: l.infobox.fields.map<Block>(f => ({
id: f.id,
pluginId: f.pluginId,
extensionId: f.extensionId,
property: processProperty(f.property),
})),
}
: undefined,
tags: l.tags, // Currently no need to convert tags
children: l.children?.map(processLayer),
};
}

function processProperty(p: any): any {
if (typeof p !== "object") return p;
return mapValues(p, g =>
Expand Down
3 changes: 2 additions & 1 deletion src/components/organisms/Published/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type Props = {
};

export default function Published({ className, alias }: Props) {
const { sceneProperty, pluginProperty, layers, widgets, ready, error, clusterProperty } =
const { sceneProperty, pluginProperty, layers, widgets, tags, ready, error, clusterProperty } =
useHooks(alias);

return error ? (
Expand All @@ -22,6 +22,7 @@ export default function Published({ className, alias }: Props) {
engine="cesium"
layers={layers}
widgets={widgets}
tags={tags}
sceneProperty={sceneProperty}
pluginProperty={pluginProperty}
clusterProperty={clusterProperty}
Expand Down
12 changes: 12 additions & 0 deletions src/components/organisms/Published/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type PublishedData = {
widgets?: Widget[];
widgetAlignSystem?: WidgetAlignSystem;
clusters: Cluster[];
tags?: Tag[];
};

export type Plugin = {
Expand All @@ -22,11 +23,22 @@ export type Layer = {
name?: string;
pluginId: string;
extensionId: string;
propertyId?: string;
/** If undefined, it should be treated as true. */
isVisible?: boolean;
property: any;
infobox?: {
fields: Block[];
property: any;
} | null;
tags?: Tag[];
children?: Layer[];
};

export type Tag = {
id: string;
label: string;
tags?: Tag[];
};

export type Block = {
Expand Down