From 246d3527617e28d54efff9f7eb753791c9c60ce3 Mon Sep 17 00:00:00 2001 From: Lightling Date: Sat, 19 Apr 2025 17:22:43 -0400 Subject: [PATCH] introduce tag exclusion --- libs/types/src/content/templates/shared.d.ts | 9 +++++++++ .../api/media-list/content-types/media-list/schema.json | 6 ++++++ projects/cms/types/generated/contentTypes.d.ts | 2 ++ projects/frontend/src/components/shared/filter-panel.vue | 8 ++++++-- projects/frontend/src/views/shared/media-list.vue | 3 ++- projects/manager/scripts/cms-to-static.js | 6 ++++++ 6 files changed, 31 insertions(+), 3 deletions(-) diff --git a/libs/types/src/content/templates/shared.d.ts b/libs/types/src/content/templates/shared.d.ts index 0f449c8..80c8407 100644 --- a/libs/types/src/content/templates/shared.d.ts +++ b/libs/types/src/content/templates/shared.d.ts @@ -32,6 +32,15 @@ export type ListWithEntries = { * Entries that are embedded directly in the list config */ embeddedEntries?: ListEntries + /** + * Array of `tag.tagId`s that will be excluded from global tags for a given media list + */ + excludeTags: string[] + /** + * Array of `tag.category` that will be excluded from global tags for a given media list; + * to exclude tags without categories given, add `'NoCategory'` to this array. + */ + excludeTagCategories: string[] } /** diff --git a/projects/cms/src/api/media-list/content-types/media-list/schema.json b/projects/cms/src/api/media-list/content-types/media-list/schema.json index 14014fc..7561a30 100644 --- a/projects/cms/src/api/media-list/content-types/media-list/schema.json +++ b/projects/cms/src/api/media-list/content-types/media-list/schema.json @@ -24,6 +24,12 @@ }, "description": { "type": "richtext" + }, + "excludeTags": { + "type": "string" + }, + "excludeTagCategories": { + "type": "string" } } } diff --git a/projects/cms/types/generated/contentTypes.d.ts b/projects/cms/types/generated/contentTypes.d.ts index 4752e3d..5d8f0b0 100644 --- a/projects/cms/types/generated/contentTypes.d.ts +++ b/projects/cms/types/generated/contentTypes.d.ts @@ -468,6 +468,8 @@ export interface ApiMediaListMediaList extends Struct.CollectionTypeSchema { 'manyToMany', 'api::media-entry.media-entry' >; + excludeTagCategories: Schema.Attribute.String; + excludeTags: Schema.Attribute.String; locale: Schema.Attribute.String & Schema.Attribute.Private; localizations: Schema.Attribute.Relation< 'oneToMany', diff --git a/projects/frontend/src/components/shared/filter-panel.vue b/projects/frontend/src/components/shared/filter-panel.vue index 9a498ea..874a8e9 100644 --- a/projects/frontend/src/components/shared/filter-panel.vue +++ b/projects/frontend/src/components/shared/filter-panel.vue @@ -5,6 +5,8 @@ import { fetchAndParseConfig } from 'src/utilities/fetch' const props = defineProps<{ tags: string | MediaEntryTag[] + excludeTags?: string[] + excludeTagCategories?: string[] }>() const emits = defineEmits<{ @@ -56,9 +58,11 @@ const resetTags = () => { } onMounted(async () => { - tagsLoaded.value = Array.isArray(props.tags) - ? tagsLoaded.value = props.tags + const tags = Array.isArray(props.tags) + ? props.tags : await fetchAndParseConfig(props.tags) + + tagsLoaded.value = tags.filter(tag => !props.excludeTags?.includes(tag.tagId) && !props.excludeTagCategories?.includes(tag.category || 'NoCategory')) }) diff --git a/projects/frontend/src/views/shared/media-list.vue b/projects/frontend/src/views/shared/media-list.vue index 1bbb979..25e7836 100644 --- a/projects/frontend/src/views/shared/media-list.vue +++ b/projects/frontend/src/views/shared/media-list.vue @@ -4,7 +4,6 @@ import type { ConfigfulRouteDefinition, ListWithWarnings, MediaEntry, - ResolvedListEntries, } from '@goldenwere/mackenzii-types' import { fetchAndParseConfig, fetchConfigsFromList, storage } from 'src/utilities/fetch' import { getCurrentRoute } from 'src/utilities/vuetils' @@ -121,6 +120,8 @@ onMounted(async () => { FilterPanel( v-if='ready && globalConfig.tags' :tags='globalConfig.tags' + :excludeTags='config.excludeTags' + :excludeTagCategories='config.excludeTagCategories' @toggledTagsChanged='onToggledTagsChanged($event)' ) Transition diff --git a/projects/manager/scripts/cms-to-static.js b/projects/manager/scripts/cms-to-static.js index 72ac355..3812528 100644 --- a/projects/manager/scripts/cms-to-static.js +++ b/projects/manager/scripts/cms-to-static.js @@ -122,6 +122,12 @@ const mapStrapiResponseToMackenzii = async (inVal) => { // handle list basic fields outVal.title = data.title; + if (!!data.excludeTags) { + outVal.excludeTags = data.excludeTags.split(/,| |;/).filter(val => val !== ''); + } + if (!!data.excludeTagCategories) { + outVal.excludeTagCategories = data.excludeTagCategories.split(/,| |;/).filter(val => val !== ''); + } // handle list entries outVal.entries = {};