Skip to content

Commit 9305664

Browse files
Merge pull request #27 from developmentseed/feature/widgets
Improve core plugin schema
2 parents 670507c + a9a4329 commit 9305664

File tree

4 files changed

+65
-4
lines changed

4 files changed

+65
-4
lines changed

packages/data-plugins/lib/collections/core.ts

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,22 @@ export class PluginCore extends Plugin {
9393
stac_extensions: {
9494
type: 'array',
9595
label: 'STAC Extensions',
96+
'ui:widget': 'tagger',
9697
items: {
97-
label: 'Extension',
98-
type: 'string'
98+
type: 'string',
99+
allowOther: {
100+
type: 'string'
101+
},
102+
enum: [
103+
[
104+
'https://stac-extensions.github.io/item-assets/v1.0.0/schema.json',
105+
'Item Assets Defenition'
106+
],
107+
[
108+
'https://stac-extensions.github.io/render/v2.0.0/schema.json',
109+
'Render'
110+
]
111+
]
99112
}
100113
},
101114
spatial: {
@@ -189,6 +202,21 @@ export class PluginCore extends Plugin {
189202
}
190203
}
191204
},
205+
thumbnail: {
206+
type: 'object',
207+
'ui:widget': 'object:fieldset',
208+
label: 'Thumbnail',
209+
properties: {
210+
title: {
211+
label: 'Title',
212+
type: 'string'
213+
},
214+
href: {
215+
label: 'Href',
216+
type: 'string'
217+
}
218+
}
219+
},
192220
assets: {
193221
type: 'array',
194222
label: 'Assets',
@@ -247,6 +275,10 @@ export class PluginCore extends Plugin {
247275
spatial: data?.extent?.spatial.bbox || [],
248276
temporal: data?.extent?.temporal.interval.map(null2EmptyString) || [],
249277
links: data?.links || [],
278+
thumbnail: {
279+
title: data?.assets?.thumbnail?.title || '',
280+
href: data?.assets?.thumbnail?.href || ''
281+
},
250282
assets: Object.entries<Record<string, any>>(data?.assets || {}).map(
251283
([key, value]) => ({
252284
id: key,
@@ -258,6 +290,19 @@ export class PluginCore extends Plugin {
258290
}
259291

260292
exitData(data: any) {
293+
const thumbnail = data.thumbnail.title
294+
? {
295+
thumbnail: {
296+
href: data.thumbnail.href,
297+
title: data.thumbnail.title,
298+
roles: ['thumbnail'],
299+
type: data.thumbnail.href.match(/\.jpe?g$/)
300+
? 'image/jpeg'
301+
: 'image/png'
302+
}
303+
}
304+
: {};
305+
261306
return {
262307
type: 'Collection',
263308
stac_version: '1.0.0',
@@ -286,7 +331,7 @@ export class PluginCore extends Plugin {
286331
[asset.id]: asset
287332
};
288333
},
289-
{}
334+
{ ...thumbnail }
290335
),
291336
summaries: data.summaries
292337
};

packages/data-widgets/lib/config/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { WidgetNumber } from '../widgets/number';
55
import { WidgetRadio } from '../widgets/radio';
66
import { WidgetCheckbox } from '../widgets/checkbox';
77
import { WidgetObject } from '../widgets/object';
8+
import { WidgetObjectFieldset } from '../widgets/object-fieldset';
89
import { WidgetArray } from '../widgets/array';
910
import { WidgetArrayInput } from '../widgets/array-input';
1011
import { WidgetSelect } from '../widgets/select';
@@ -14,6 +15,7 @@ import { WidgetTagger } from '../widgets/tagger';
1415
export const defaultPluginWidgetConfig = extendPluginConfig({
1516
'ui:widget': {
1617
object: WidgetObject,
18+
'object:fieldset': WidgetObjectFieldset,
1719
text: WidgetText,
1820
number: WidgetNumber,
1921
radio: WidgetRadio,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
import { WidgetProps } from '@stac-manager/data-core';
3+
4+
import { WidgetObject } from './object';
5+
import { ArrayFieldset } from '../components/elements';
6+
7+
export function WidgetObjectFieldset(props: WidgetProps) {
8+
return (
9+
<ArrayFieldset label={props.field.label}>
10+
<WidgetObject {...props} />
11+
</ArrayFieldset>
12+
);
13+
}

packages/data-widgets/lib/widgets/object.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ export function WidgetObject(props: WidgetProps) {
3838

3939
const ctx = useFormikContext();
4040
const values = pointer ? get(ctx.values, pointer) : ctx.values;
41+
4142
const schemaKeys = Object.keys(field.properties);
42-
const valueKeys = Object.keys(values);
43+
const valueKeys = Object.keys(values || {});
4344
const unlistedKeys = valueKeys.filter((key) => !schemaKeys.includes(key));
4445

4546
return (

0 commit comments

Comments
 (0)