Skip to content

Commit

Permalink
feat: Partial list filtering by key using include/exclude filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoramite committed Feb 8, 2022
1 parent 624e607 commit 27b1b3c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/ts/projectType/generic/field/partials.ts
Expand Up @@ -12,6 +12,10 @@ import {
html,
} from '@blinkk/selective-edit';
import {DialogActionLevel, FormDialogModal} from '../../../editor/ui/modal';
import {
IncludeExcludeFilter,
IncludeExcludeFilterConfig,
} from '../../../utility/filter';
import {
ListFieldComponent,
ListFieldItem,
Expand Down Expand Up @@ -62,6 +66,10 @@ export interface GenericPartialsFieldConfig extends FieldConfig {
* Label for when the list is empty.
*/
emptyLabel?: string;
/**
* Filtering for valid partials to show in the list.
*/
filter?: IncludeExcludeFilterConfig;
/**
* Label for partial.
*/
Expand Down Expand Up @@ -224,6 +232,9 @@ export class GenericPartialsField
): FormDialogModal {
const editor = this.globalConfig.editor as LiveEditor;
if (!editor.ui.partModals.modals[MODAL_KEY_NEW]) {
// Determine the possible filtering.
const partialFilter = new IncludeExcludeFilter(this.config.filter ?? {});

// Setup the editor.
const options = [];
for (const [partialKey, partial] of Object.entries(this.partials || {})) {
Expand All @@ -233,6 +244,11 @@ export class GenericPartialsField
continue;
}

// If there is a filter, only show the partials that match the filter.
if (!partialFilter.matches(partialKey)) {
continue;
}

options.push({
label: partial.editor.label || partialKey,
value: partialKey,
Expand Down

0 comments on commit 27b1b3c

Please sign in to comment.