diff --git a/package.json b/package.json index 3145e98f..b1b8fd78 100644 --- a/package.json +++ b/package.json @@ -533,7 +533,12 @@ ], "markdownDescription": "%setting.frontMatter.content.filters.markdownDescription%", "items": [{ - "type": "string" + "type": "string", + "enum": [ + "contentFolders", + "tags", + "categories" + ] }, { "type": "object", diff --git a/src/dashboardWebView/components/Header/Filters.tsx b/src/dashboardWebView/components/Header/Filters.tsx index 3733e605..a0c4d626 100644 --- a/src/dashboardWebView/components/Header/Filters.tsx +++ b/src/dashboardWebView/components/Header/Filters.tsx @@ -18,7 +18,7 @@ export const Filters: React.FunctionComponent = (_: React.PropsWi const settings = useRecoilValue(SettingsSelector); const location = useLocation(); - const otherFilters = useMemo(() => settings?.filters?.filter((filter) => filter !== "pageFolders" && filter !== "tags" && filter !== "categories"), [settings?.filters]); + const otherFilters = useMemo(() => settings?.filters?.filter((filter) => filter !== "contentFolders" && filter !== "tags" && filter !== "categories"), [settings?.filters]); const otherFilterValues = useMemo(() => { return otherFilters?.map((filter) => { diff --git a/src/dashboardWebView/hooks/usePages.tsx b/src/dashboardWebView/hooks/usePages.tsx index a43a585b..76cf0612 100644 --- a/src/dashboardWebView/hooks/usePages.tsx +++ b/src/dashboardWebView/hooks/usePages.tsx @@ -204,7 +204,7 @@ export default function usePages(pages: Page[]) { setTabInfo(draftTypes); if (Object.keys(filters).length === 0) { - const availableFilters = (settings?.filters || []).filter((f) => f !== 'pageFolders' && f !== 'tags' && f !== 'categories'); + const availableFilters = (settings?.filters || []).filter((f) => f !== 'contentFolders' && f !== 'tags' && f !== 'categories'); if (availableFilters.length > 0) { const allFilters: { [filter: string]: string[]; } = {}; for (const filter of availableFilters) { diff --git a/src/dashboardWebView/models/Settings.ts b/src/dashboardWebView/models/Settings.ts index 2b677a71..f96f6a9d 100644 --- a/src/dashboardWebView/models/Settings.ts +++ b/src/dashboardWebView/models/Settings.ts @@ -6,6 +6,7 @@ import { CustomScript, CustomTaxonomy, DraftField, + FilterType, Framework, GitSettings, MediaContentType, @@ -38,7 +39,7 @@ export interface Settings { framework: Framework | null | undefined; draftField: DraftField | null | undefined; customSorting: SortingSetting[] | undefined; - filters: (string | { title: string; name: string })[] | undefined; + filters: (FilterType | { title: string; name: string })[] | undefined; dashboardState: DashboardState; scripts: CustomScript[]; dataFiles: DataFile[] | undefined; diff --git a/src/helpers/DashboardSettings.ts b/src/helpers/DashboardSettings.ts index 407f22d2..e8bc15d3 100644 --- a/src/helpers/DashboardSettings.ts +++ b/src/helpers/DashboardSettings.ts @@ -42,6 +42,7 @@ import { CustomScript, DEFAULT_MEDIA_CONTENT_TYPE, DraftField, + FilterType, MediaContentType, Snippets, SortingSetting, @@ -111,7 +112,8 @@ export class DashboardSettings { draftField: Settings.get(SETTING_CONTENT_DRAFT_FIELD), customSorting: Settings.get(SETTING_CONTENT_SORTING), contentFolders: Folders.get(), - filters: Settings.get(SETTING_CONTENT_FILTERS), + filters: + Settings.get<(FilterType | { title: string; name: string })[]>(SETTING_CONTENT_FILTERS), crntFramework: Settings.get(SETTING_FRAMEWORK_ID), framework: !isInitialized && wsFolder ? await FrameworkDetector.get(wsFolder.fsPath) : null, scripts: Settings.get(SETTING_CUSTOM_SCRIPTS) || [], diff --git a/src/helpers/SettingsHelper.ts b/src/helpers/SettingsHelper.ts index 92ab8d5b..19139bf4 100644 --- a/src/helpers/SettingsHelper.ts +++ b/src/helpers/SettingsHelper.ts @@ -43,7 +43,8 @@ import { SETTING_CONFIG_DYNAMIC_FILE_PATH, SETTING_PROJECTS, SETTING_TAXONOMY_TAGS, - SETTING_TAXONOMY_CATEGORIES + SETTING_TAXONOMY_CATEGORIES, + SETTING_CONTENT_FILTERS } from '../constants'; import { Folders } from '../commands/Folders'; import { join, basename, dirname, parse } from 'path'; @@ -804,7 +805,8 @@ export class Settings { settingName === SETTING_GLOBAL_NOTIFICATIONS || settingName === SETTING_GLOBAL_NOTIFICATIONS_DISABLED || settingName === SETTING_MEDIA_SUPPORTED_MIMETYPES || - settingName === SETTING_COMMA_SEPARATED_FIELDS + settingName === SETTING_COMMA_SEPARATED_FIELDS || + settingName === SETTING_CONTENT_FILTERS ) { if (typeof originalConfig[key] === 'undefined') { Settings.globalConfig[key] = value; diff --git a/src/models/FilterType.ts b/src/models/FilterType.ts new file mode 100644 index 00000000..4ff3a294 --- /dev/null +++ b/src/models/FilterType.ts @@ -0,0 +1 @@ +export type FilterType = 'contentFolders' | 'tags' | 'categories'; diff --git a/src/models/index.ts b/src/models/index.ts index a118d63b..82b09148 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -11,6 +11,7 @@ export * from './DataFile'; export * from './DataFolder'; export * from './DataType'; export * from './DraftField'; +export * from './FilterType'; export * from './Framework'; export * from './GitRepository'; export * from './GitSettings';