From 27b1b3c1eec138342545187c9bb8596936300d1b Mon Sep 17 00:00:00 2001 From: Randy Merrill Date: Mon, 7 Feb 2022 17:25:25 -0700 Subject: [PATCH] feat: Partial list filtering by key using include/exclude filter. --- src/ts/projectType/generic/field/partials.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/ts/projectType/generic/field/partials.ts b/src/ts/projectType/generic/field/partials.ts index 7ecd2c02..025970e3 100644 --- a/src/ts/projectType/generic/field/partials.ts +++ b/src/ts/projectType/generic/field/partials.ts @@ -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, @@ -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. */ @@ -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 || {})) { @@ -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,