-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(): add structure for getting card editor schemas (#1277)
* feat(): add initial scaffolding for getCardConfig * feat(): bring schema and uiSchema and update getEditorConfig * test(): add testing * refactor(): rename to metricSchema * refactor(): change to metric schema * fix(): add required array * refactor(): implement EditorOptions type and move IEditorConfig to schemas * refactor(): use EditorOptions instead of ConfigurableEntity * refactor(): create EditorType from EntityEditorType and CardEditorType * refactor(): getEntityEditorSchemas is now getEditorSchemas * refactor(): make EntityEditorOptions into an entity partial * refactor(): change test name to match refactor * test(): update tests and promise.all implementation * fix(): make typing stronger for CardEditorOptions * fix(): make typing stronger for CardEditorOptions * docs(): strengthen comments around option types * refactor(): move alignments/corners/dropshadows to generic types folder * fix(): fix typing exports * docs(): change config * refactor(): feedback and start expecting IEntityEditorOptions in buildUiSchema site * refactor(): update all buildUiSchema in discussions to take Ientityeditoroptions * refactor(): update project to options * refactor(): update initaitive * refactor(): update pages * refactor(): update content * refactor(): template * refactor(): groups * refactor(): init template * fix(): update interfaces file * refactor(): strengthen typing in initiative template and remove unnecessary tests * refactor(): require only a partial hubentity from getTypeFromEntity * docs(): update imports and comments * refactor(): fix imports to import from file directly * refactor(): fix other imports to be direct * refactor(): implement function overloads and update options types * test(): ensure tests use correct typing and not any * test(): fix test options * refactor(): entityeditoroptions is HubEntity and record * test(): ensure typing for test * test(): ensure typing for test * test(): ensure typing for test
- Loading branch information
1 parent
d16a88d
commit 6b82f03
Showing
55 changed files
with
1,449 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,52 @@ | ||
import { IEditorConfig } from "../behaviors/IWithEditorBehavior"; | ||
import { EntityEditorType, IEditorConfig, StatCardEditorType } from "./types"; | ||
import { IArcGISContext } from "../../ArcGISContext"; | ||
import { ConfigurableEntity } from "./internal/ConfigurableEntity"; | ||
import { getEntityEditorSchemas } from "./internal/getEntityEditorSchemas"; | ||
import { | ||
EditorOptions, | ||
EntityEditorOptions, | ||
IStatCardEditorOptions, | ||
} from "./internal/EditorOptions"; | ||
import { getEditorSchemas } from "./internal/getEditorSchemas"; | ||
import { EditorType } from "./types"; | ||
|
||
/** | ||
* Construct the Editor Configuration for a given entity type | ||
* NOTE: We use the concept of function overloading to write getEditorConfig. | ||
* In doing so, we create multiple signatures for the function. | ||
* When the function is called, its types will need to agree with one of the signatures. | ||
* This prevents a function call from having an EntityEditorType type, and IStatCardEditorOptions options, for example. | ||
*/ | ||
|
||
/** | ||
* Construct the Editor Configuration (schema + uiSchema) | ||
* for a given entity editor type | ||
* @param i18nScope | ||
* @param type | ||
* @param entity | ||
* @param options - options to integrate into the schema + uiSchema | ||
* @param context | ||
* @returns | ||
*/ | ||
|
||
// Entity editor overload | ||
export async function getEditorConfig( | ||
i18nScope: string, | ||
type: EntityEditorType, | ||
options: EntityEditorOptions, | ||
context: IArcGISContext | ||
): Promise<IEditorConfig>; | ||
|
||
// Stat card editor overload | ||
export async function getEditorConfig( | ||
i18nScope: string, | ||
type: StatCardEditorType, | ||
options: IStatCardEditorOptions, | ||
context: IArcGISContext | ||
): Promise<IEditorConfig>; | ||
|
||
// General function | ||
export async function getEditorConfig( | ||
i18nScope: string, | ||
type: EditorType, | ||
entity: ConfigurableEntity, | ||
options: EditorOptions, | ||
context: IArcGISContext | ||
): Promise<IEditorConfig> { | ||
return getEntityEditorSchemas(i18nScope, type, entity, context); | ||
return getEditorSchemas(i18nScope, type, options, context); | ||
} |
4 changes: 0 additions & 4 deletions
4
packages/common/src/core/schemas/internal/ConfigurableEntity.ts
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
packages/common/src/core/schemas/internal/EditorOptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { HubEntity } from "../../types"; | ||
|
||
/** Intersection type of all EditorOptions */ | ||
export type EditorOptions = EntityEditorOptions | CardEditorOptions; | ||
|
||
/** | ||
* Options to use when constructing a schema and uiSchema for | ||
* an entity's editor. Often times, this can just be the entity | ||
* object itself. | ||
* | ||
* However, it must always have "type" on the options, even if not the entire entity. | ||
*/ | ||
export type EntityEditorOptions = HubEntity & Record<string, any>; | ||
|
||
/** | ||
* Options to use when constructing a schema and uiSchema for | ||
* a layout card's editor. This should be a union of all of the different | ||
* layout card editor options, i.e. IStatCardEditorOptions | ICountdownCardEditorOptions | ... | ||
*/ | ||
export type CardEditorOptions = IStatCardEditorOptions; | ||
|
||
/** | ||
* Options to use when constructing a schema and uiSchema for | ||
* a stat card editor. | ||
*/ | ||
export interface IStatCardEditorOptions { | ||
themeColors: string[]; | ||
} |
59 changes: 59 additions & 0 deletions
59
packages/common/src/core/schemas/internal/getCardEditorSchemas.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { CardEditorType, IEditorConfig, StatCardEditorType } from "../types"; | ||
import { getCardType } from "./getCardType"; | ||
import { filterSchemaToUiSchema } from "./filterSchemaToUiSchema"; | ||
import { CardEditorOptions } from "./EditorOptions"; | ||
import { cloneObject } from "../../../util"; | ||
import { IArcGISContext } from "../../../ArcGISContext"; | ||
|
||
/** | ||
* get the editor schema and uiSchema defined for a layout card. | ||
* The schema and uiSchema that are returned can be used to | ||
* render a form UI (using the configuration editor). | ||
* | ||
* @param i18nScope translation scope to be interpolated into the uiSchema | ||
* @param type editor type - corresponds to the returned uiSchema | ||
* @param options optional hash of dynamic uiSchema element options | ||
* @param context | ||
* @returns | ||
*/ | ||
export async function getCardEditorSchemas( | ||
i18nScope: string, | ||
type: CardEditorType, | ||
options: CardEditorOptions, | ||
context: IArcGISContext | ||
): Promise<IEditorConfig> { | ||
const cardType = getCardType(type); | ||
|
||
// schema and uiSchema are dynamically imported based | ||
// on the previous editor types | ||
|
||
let schema; | ||
let uiSchema; | ||
|
||
switch (cardType) { | ||
case "stat": | ||
// get correct module | ||
const schemaPromise = import("./metrics/MetricSchema"); | ||
const uiSchemaPromise = { | ||
"hub:card:stat": () => import("./metrics/StatCardUiSchema"), | ||
}[type as StatCardEditorType]; | ||
|
||
// Allow imports to run in parallel | ||
await Promise.all([schemaPromise, uiSchemaPromise()]).then( | ||
([schemaModuleResolved, statModuleResolved]) => { | ||
const { MetricSchema } = schemaModuleResolved; | ||
schema = cloneObject(MetricSchema); | ||
uiSchema = statModuleResolved.buildUiSchema( | ||
i18nScope, | ||
options, | ||
context | ||
); | ||
} | ||
); | ||
break; | ||
} | ||
// filter out properties not used in uiSchema | ||
schema = filterSchemaToUiSchema(schema, uiSchema); | ||
|
||
return Promise.resolve({ schema, uiSchema }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { CardEditorType } from "../types"; | ||
|
||
/** | ||
* Helper function to get card type string from full type | ||
*/ | ||
export function getCardType(type: CardEditorType): string { | ||
return type && type.split(":")[2]; | ||
} |
Oops, something went wrong.