@@ -16,6 +16,14 @@ import {
1616import { cloneObject } from "../../../util" ;
1717import type { IArcGISContext } from "../../../types/IArcGISContext" ;
1818import { ICardEditorModuleType } from "../types" ;
19+ import { MetricSchema } from "./metrics/MetricSchema" ;
20+ import { FollowSchema } from "./follow/FollowSchema" ;
21+ import { EmbedCardSchema } from "./embed/EmbedSchema" ;
22+ import { EventGalleryCardSchema } from "./events/EventGalleryCardSchema" ;
23+ import * as buildStatUiSchema from "./metrics/StatCardUiSchema" ;
24+ import * as buildFollowUiSchema from "./follow/FollowCardUiSchema" ;
25+ import * as buildEmbedSchema from "./embed/EmbedUiSchema" ;
26+ import * as buildEventGalleryCardSchema from "./events/EventGalleryCardUiSchema" ;
1927
2028/**
2129 * get the editor schema and uiSchema defined for a layout card.
@@ -35,85 +43,48 @@ export async function getCardEditorSchemas(
3543 context : IArcGISContext
3644) : Promise < IEditorConfig > {
3745 const cardType = getCardType ( type ) ;
38-
39- // schema and uiSchema are dynamically imported based
40- // on the previous editor types
41-
4246 let schema ;
4347 let uiSchema ;
44- let schemaPromise ;
45- let uiSchemaPromise ;
46- // defaults is used below... but maybe in a closure?
47- // tslint:disable-next-line:no-unused-variable
4848 let defaults ;
4949
5050 switch ( cardType ) {
5151 case "stat" : {
52- // get correct module
53- schemaPromise = import ( "./metrics/MetricSchema" ) ;
54- uiSchemaPromise = {
55- "hub:card:stat" : ( ) : Promise <
56- typeof import ( "./metrics/StatCardUiSchema" )
57- > => import ( "./metrics/StatCardUiSchema" ) ,
58- } [ type as StatCardEditorType ] ;
59-
60- // Allow imports to run in parallel
61- await Promise . all ( [ schemaPromise , uiSchemaPromise ( ) ] ) . then (
62- async ( [ schemaModuleResolved , uiSchemaModuleResolved ] ) => {
63- const { MetricSchema } = schemaModuleResolved ;
64- schema = cloneObject ( MetricSchema ) ;
65- uiSchema = await uiSchemaModuleResolved . buildUiSchema (
66- i18nScope ,
67- options as StatCardEditorOptions ,
68- context
69- ) ;
70-
71- // if we have buildDefaults, build the defaults
72- // TODO: when first implementing buildDefaults for initiative templates, remove the ignore line
73-
74- /* istanbul ignore next */
75- if ( ( uiSchemaModuleResolved as ICardEditorModuleType ) . buildDefaults ) {
76- defaults = (
77- uiSchemaModuleResolved as ICardEditorModuleType
78- ) . buildDefaults ( i18nScope , options , context ) ;
79- }
80- }
52+ const MODULES : Record < StatCardEditorType , ICardEditorModuleType > = {
53+ "hub:card:stat" : buildStatUiSchema ,
54+ } as Record < StatCardEditorType , ICardEditorModuleType > ;
55+ const module = MODULES [ type as StatCardEditorType ] ;
56+ schema = cloneObject ( MetricSchema ) ;
57+ uiSchema = await module . buildUiSchema (
58+ i18nScope ,
59+ options as StatCardEditorOptions ,
60+ context
8161 ) ;
62+ // if we have buildDefaults, build the defaults
63+ // TODO: when first implementing buildDefaults for initiative templates, remove the ignore line
64+
65+ /* istanbul ignore next */
66+ if ( module . buildDefaults ) {
67+ defaults = module . buildDefaults ( i18nScope , options , context ) ;
68+ }
8269
8370 break ;
8471 }
8572 case "follow" : {
86- // get correct module
87- schemaPromise = import ( "./follow/FollowSchema" ) ;
88- uiSchemaPromise = {
89- "hub:card:follow" : ( ) : Promise <
90- typeof import ( "./follow/FollowCardUiSchema" )
91- > => import ( "./follow/FollowCardUiSchema" ) ,
92- } [ type as FollowCardEditorType ] ;
93-
94- // Allow imports to run in parallel
95- await Promise . all ( [ schemaPromise , uiSchemaPromise ( ) ] ) . then (
96- ( [ schemaModuleResolved , uiSchemaModuleResolved ] ) => {
97- const { FollowSchema : FollowSchema } = schemaModuleResolved ;
98- schema = cloneObject ( FollowSchema ) ;
99- uiSchema = uiSchemaModuleResolved . buildUiSchema (
100- i18nScope ,
101- options as FollowCardEditorOptions ,
102- context
103- ) ;
104- }
73+ const MODULES : Record < FollowCardEditorType , ICardEditorModuleType > = {
74+ "hub:card:follow" : buildFollowUiSchema ,
75+ } as Record < FollowCardEditorType , ICardEditorModuleType > ;
76+ const module = MODULES [ type as FollowCardEditorType ] ;
77+ schema = cloneObject ( FollowSchema ) ;
78+ uiSchema = await module . buildUiSchema (
79+ i18nScope ,
80+ options as FollowCardEditorOptions ,
81+ context
10582 ) ;
10683 break ;
10784 }
10885 case "embed" : {
109- schemaPromise = import ( "./embed/EmbedSchema" ) ;
110- uiSchemaPromise = import ( "./embed/EmbedUiSchema" ) ;
111- const [ { EmbedCardSchema } , { buildUiSchema } ] = await Promise . all ( [
112- schemaPromise ,
113- uiSchemaPromise ,
114- ] ) ;
11586 schema = cloneObject ( EmbedCardSchema ) ;
116- uiSchema = buildUiSchema (
87+ uiSchema = buildEmbedSchema . buildUiSchema (
11788 i18nScope ,
11889 options as EmbedCardEditorOptions ,
11990 context
@@ -122,13 +93,8 @@ export async function getCardEditorSchemas(
12293 break ;
12394 }
12495 case "eventGallery" : {
125- schemaPromise = import ( "./events/EventGalleryCardSchema" ) ;
126- uiSchemaPromise = import ( "./events/EventGalleryCardUiSchema" ) ;
127- const [ { EventGalleryCardSchema } , { buildUiSchema } ] = await Promise . all (
128- [ schemaPromise , uiSchemaPromise ]
129- ) ;
13096 schema = cloneObject ( EventGalleryCardSchema ) ;
131- uiSchema = await buildUiSchema (
97+ uiSchema = await buildEventGalleryCardSchema . buildUiSchema (
13298 i18nScope ,
13399 options as EventGalleryCardEditorOptions ,
134100 context
0 commit comments