Skip to content

Commit

Permalink
fix: Fix the sorting of partials and the placement of priority config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoramite committed Feb 8, 2022
1 parent 1206b5f commit 624e607
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
30 changes: 15 additions & 15 deletions src/ts/editor/api.ts
Expand Up @@ -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;
}

/**
Expand All @@ -555,6 +540,14 @@ export interface PartialEditorConfig {
* Field configurations for the editor.
*/
fields: Array<FieldConfig>;
/**
* 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.
*
Expand All @@ -569,6 +562,13 @@ export interface PartialEditorConfig {
* the value to show for the preview.
*/
previewFields?: Array<string>;
/**
* When displaying lists of paritals the priority will affect the
* sort order of the partials.
*
* Default priority is 1000
*/
priority?: number;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ts/example/exampleApi.ts
Expand Up @@ -2116,8 +2116,8 @@ export class ExampleAmagakiApi implements AmagakiProjectTypeApi {
label: 'title',
} as TextFieldConfig,
],
isHidden: true,
},
isHidden: true,
} as PartialData,
},
this.options
Expand Down
13 changes: 9 additions & 4 deletions src/ts/projectType/generic/field/partials.ts
Expand Up @@ -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(
{},
Expand Down

0 comments on commit 624e607

Please sign in to comment.