From 624e6072afd14b78f6a0e2bc7dd2415810f97188 Mon Sep 17 00:00:00 2001 From: Randy Merrill Date: Mon, 7 Feb 2022 17:10:43 -0700 Subject: [PATCH] fix: Fix the sorting of partials and the placement of priority config. --- src/ts/editor/api.ts | 30 ++++++++++---------- src/ts/example/exampleApi.ts | 2 +- src/ts/projectType/generic/field/partials.ts | 13 ++++++--- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/ts/editor/api.ts b/src/ts/editor/api.ts index 7159a20d..a8af3963 100644 --- a/src/ts/editor/api.ts +++ b/src/ts/editor/api.ts @@ -517,26 +517,11 @@ export interface PartialData { * in content files. */ partial: string; - /** - * Is the partial hidden? - * - * Partials can opt to not show the partial in the listing of partials. - * This is helpful for partials that are part of the design such as - * header and footer partials. - */ - isHidden?: boolean; /** * Configuration for how the editor should present the partial in the * editor. */ editor?: PartialEditorConfig; - /** - * When displaying lists of paritals the priority will affect the - * sort order of the partials. - * - * Default priority is 1000 - */ - priority?: number; } /** @@ -555,6 +540,14 @@ export interface PartialEditorConfig { * Field configurations for the editor. */ fields: Array; + /** + * Is the partial hidden? + * + * Partials can opt to not show the partial in the listing of partials. + * This is helpful for partials that are part of the design such as + * header and footer partials. + */ + isHidden?: boolean; /** * Preview field key. * @@ -569,6 +562,13 @@ export interface PartialEditorConfig { * the value to show for the preview. */ previewFields?: Array; + /** + * When displaying lists of paritals the priority will affect the + * sort order of the partials. + * + * Default priority is 1000 + */ + priority?: number; } /** diff --git a/src/ts/example/exampleApi.ts b/src/ts/example/exampleApi.ts index 34121fd3..168ab87a 100644 --- a/src/ts/example/exampleApi.ts +++ b/src/ts/example/exampleApi.ts @@ -2116,8 +2116,8 @@ export class ExampleAmagakiApi implements AmagakiProjectTypeApi { label: 'title', } as TextFieldConfig, ], + isHidden: true, }, - isHidden: true, } as PartialData, }, this.options diff --git a/src/ts/projectType/generic/field/partials.ts b/src/ts/projectType/generic/field/partials.ts index e8ef2efb..7ecd2c02 100644 --- a/src/ts/projectType/generic/field/partials.ts +++ b/src/ts/projectType/generic/field/partials.ts @@ -229,19 +229,24 @@ export class GenericPartialsField for (const [partialKey, partial] of Object.entries(this.partials || {})) { // Without the editor config there are no fields to add for a partial. // Also don't show the hidden partials. - if (!partial.editor || partial.isHidden) { + if (!partial.editor || partial.editor.isHidden) { continue; } options.push({ label: partial.editor.label || partialKey, value: partialKey, - priority: partial.priority ?? 1000, + priority: partial.editor.priority ?? 1000, }); } - // Sort the options by priority. - options.sort((a, b) => a.priority - b.priority); + // Sort the options by priority, then label. + options.sort((a, b) => { + if (a.priority === b.priority) { + return a.label > b.label ? 1 : -1; + } + return a.priority - b.priority; + }); const selectiveConfig = merge( {},