Skip to content
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
9 changes: 9 additions & 0 deletions public/reearth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ extensions:
field: data_source_type
type: string
value: cms_public_api
- id: field_type_overrides
title: Field Type Overrides
description: "Optional, specify field type overrides. Example: field_key_1:markdown,field_key_2:geometryObject"
type: string
ui: multiline
availableIf:
field: data_source_type
type: string
value: cms_public_api
- id: visualization
title: Visualization
fields:
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/inspector_block/main/PropertyValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const PropertyValue: FC<Props> = ({ property }) => {
</div>
) : property.type === "object" ? (
<div className="whitespace-pre-wrap break-words">
{JSON.stringify(property.value)}
{JSON.stringify(property.value, null, 2)}
</div>
) : (
<div className="whitespace-pre-wrap break-words">
Expand Down
2 changes: 2 additions & 0 deletions src/extensions/visualizer/main/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type WidgetProperty = {
cms_project_id_for_public_api?: string;
cms_model_id_for_public_api?: string;
value_filters_for_public_api?: string;
field_type_overrides?: string;
};
appearance: {
marker_appearance?: string;
Expand Down Expand Up @@ -134,6 +135,7 @@ export default () => {
projectId: widgetProperty.api.cms_project_id_for_public_api,
modelId: widgetProperty.api.cms_model_id_for_public_api,
valueFilters: widgetProperty.api.value_filters_for_public_api,
fieldTypeOverrides: widgetProperty.api.field_type_overrides,
});
postMsg("addLayer", items);
} catch (error) {
Expand Down
59 changes: 31 additions & 28 deletions src/extensions/visualizer/main/utils/getItemsFromPublicAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ export const getItemsFromPublicAPI = async ({
projectId,
modelId,
valueFilters,
fieldTypeOverrides,
}: {
baseUrl: string;
workspaceId: string;
projectId: string;
modelId: string;
valueFilters?: string;
fieldTypeOverrides?: string;
}): Promise<Item[]> => {
const url = `${baseUrl}/p/${workspaceId}/${projectId}/${modelId}`;

Expand Down Expand Up @@ -104,6 +106,19 @@ export const getItemsFromPublicAPI = async ({

flattenProperties(schema.properties);

// Field type overrides
const typeOverrides: Record<string, string> = {};
if (fieldTypeOverrides) {
const overrides = fieldTypeOverrides.split(",");
for (const override of overrides) {
const [fieldKey, fieldType] = override.split(":");
if (fieldKey && fieldType) {
typeOverrides[fieldKey] = fieldType;
}
}
}

// Process properties
const processProperties = (
properties: PropertyObject,
item: Item,
Expand All @@ -118,34 +133,22 @@ export const getItemsFromPublicAPI = async ({
const fieldId = Math.random().toString(36).substring(2, 9);

// check if it is a group
const type = flatSchemaProperties[key]?.type;
const field: Field =
type === "group"
? {
id: fieldId,
key,
value: fieldId,
type,
name: flatSchemaProperties[key]?.title || key,
}
: // support array of assets only
Array.isArray(value) &&
value.length > 0 &&
value[0].type === "asset"
? {
id: fieldId,
key,
value: value.map((v) => v.url),
type: value[0].type,
name: flatSchemaProperties[key]?.title || key,
}
: {
id: fieldId,
key,
value,
type: flatSchemaProperties[key]?.type,
name: flatSchemaProperties[key]?.title || key,
};
const type = typeOverrides[key] || flatSchemaProperties[key]?.type;

const field: Field = {
id: fieldId,
key,
value:
type === "group"
? fieldId
: type === "asset"
? Array.isArray(value)
? value.map((v) => v.url)
: value
: value,
type,
name: flatSchemaProperties[key]?.title || key,
};

if (groupId) field.group = groupId;

Expand Down