From 717f34bc8536769fc758199b86739e2a87f8976a Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Wed, 10 Nov 2021 11:54:39 +0100 Subject: [PATCH] #174 - Enhancement for excluding sub-directories --- package.json | 5 ++++ src/commands/Dashboard.ts | 2 +- src/commands/Folders.ts | 10 ++++---- .../components/Header/Breadcrumb.tsx | 5 ++-- .../components/Header/Folders.tsx | 24 +++++++++---------- .../components/Header/Header.tsx | 2 +- src/dashboardWebView/models/Settings.ts | 2 +- src/helpers/Extension.ts | 2 +- src/models/ContentFolder.ts | 2 ++ 9 files changed, 32 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 64b9e75c..03395028 100644 --- a/package.json +++ b/package.json @@ -154,6 +154,11 @@ "path": { "type": "string", "description": "Path of the folder" + }, + "excludeSubdir": { + "type": "boolean", + "default": false, + "description": "Exclude sub-directories" } }, "additionalProperties": false, diff --git a/src/commands/Dashboard.ts b/src/commands/Dashboard.ts index 716b486b..a0fc4679 100644 --- a/src/commands/Dashboard.ts +++ b/src/commands/Dashboard.ts @@ -280,7 +280,7 @@ export class Dashboard { mediaSnippet: SettingsHelper.get(SETTINGS_DASHBOARD_MEDIA_SNIPPET) || [], contentTypes: SettingsHelper.get(SETTING_TAXONOMY_CONTENT_TYPES) || [], draftField: SettingsHelper.get(SETTINGS_CONTENT_DRAFT_FIELD), - contentFolders: Folders.get().map(f => f.path), + contentFolders: Folders.get(), crntFramework: SettingsHelper.get(SETTINGS_FRAMEWORK_ID), framework: (!isInitialized && wsFolder) ? FrameworkDetector.get(wsFolder.fsPath) : null, } as Settings diff --git a/src/commands/Folders.ts b/src/commands/Folders.ts index f528a2b4..9a586a11 100644 --- a/src/commands/Folders.ts +++ b/src/commands/Folders.ts @@ -210,8 +210,8 @@ export class Folders { if (projectStart) { projectStart = projectStart.replace(/\\/g, '/'); projectStart = projectStart.startsWith('/') ? projectStart.substr(1) : projectStart; - const mdFiles = await workspace.findFiles(join(projectStart, '**/*.md')); - const mdxFiles = await workspace.findFiles(join(projectStart, '**/*.mdx')); + const mdFiles = await workspace.findFiles(join(projectStart, folder.excludeSubdir ? '/' : '**/', '*.md')); + const mdxFiles = await workspace.findFiles(join(projectStart, folder.excludeSubdir ? '/' : '**/', '*.mdx')); let files = [...mdFiles, ...mdxFiles]; if (files) { let fileStats: FileInfo[] = []; @@ -263,7 +263,7 @@ export class Folders { const folders: ContentFolder[] = Settings.get(SETTINGS_CONTENT_PAGE_FOLDERS) as ContentFolder[]; return folders.map(folder => ({ - title: folder.title, + ...folder, path: Folders.absWsFolder(folder, wsFolder) })); } @@ -274,10 +274,12 @@ export class Folders { */ private static async update(folders: ContentFolder[]) { const wsFolder = Folders.getWorkspaceFolder(); + let folderDetails = folders.map(folder => ({ - title: folder.title, + ...folder, path: Folders.relWsFolder(folder, wsFolder) })); + await Settings.update(SETTINGS_CONTENT_PAGE_FOLDERS, folderDetails, true); } diff --git a/src/dashboardWebView/components/Header/Breadcrumb.tsx b/src/dashboardWebView/components/Header/Breadcrumb.tsx index 24c70f1d..3675354c 100644 --- a/src/dashboardWebView/components/Header/Breadcrumb.tsx +++ b/src/dashboardWebView/components/Header/Breadcrumb.tsx @@ -31,9 +31,10 @@ export const Breadcrumb: React.FunctionComponent = (props: Rea return false; } } - +1 for (let i = 0; i < contentFolders.length; i++) { - const contentFolder = parseWinPath(contentFolders[i]) as string; + const folder = contentFolders[i]; + const contentFolder = parseWinPath(folder.path) as string; const relContentPath = folderPath.replace(contentFolder, ''); return relContentPath.length > 1 && folderPath.startsWith(contentFolder); } diff --git a/src/dashboardWebView/components/Header/Folders.tsx b/src/dashboardWebView/components/Header/Folders.tsx index 654c5db3..1d5af07b 100644 --- a/src/dashboardWebView/components/Header/Folders.tsx +++ b/src/dashboardWebView/components/Header/Folders.tsx @@ -1,19 +1,19 @@ import { Menu } from '@headlessui/react'; import * as React from 'react'; -import { useRecoilState } from 'recoil'; -import { FolderAtom } from '../../state'; +import { useRecoilState, useRecoilValue } from 'recoil'; +import { FolderAtom, SettingsSelector } from '../../state'; import { MenuButton, MenuItem, MenuItems } from '../Menu'; -export interface IFoldersProps { - folders: string[]; -} +export interface IFoldersProps {} const DEFAULT_TYPE = "All types"; -export const Folders: React.FunctionComponent = ({folders}: React.PropsWithChildren) => { +export const Folders: React.FunctionComponent = ({}: React.PropsWithChildren) => { const [ crntFolder, setCrntFolder ] = useRecoilState(FolderAtom); + const settings = useRecoilValue(SettingsSelector); + const contentFolders = settings?.contentFolders || []; - if (folders.length <= 1) { + if (contentFolders.length <= 1) { return null; } @@ -29,12 +29,12 @@ export const Folders: React.FunctionComponent = ({folders}: React isCurrent={!crntFolder} onClick={(value) => setCrntFolder(value)} /> - {folders.map((option) => ( + {contentFolders.map((option) => ( setCrntFolder(value)} /> ))} diff --git a/src/dashboardWebView/components/Header/Header.tsx b/src/dashboardWebView/components/Header/Header.tsx index 34e13635..f4e068ec 100644 --- a/src/dashboardWebView/components/Header/Header.tsx +++ b/src/dashboardWebView/components/Header/Header.tsx @@ -98,7 +98,7 @@ export const Header: React.FunctionComponent = ({totalPages, folde
- + setCrntTag(value)} /> diff --git a/src/dashboardWebView/models/Settings.ts b/src/dashboardWebView/models/Settings.ts index 36b8d5c2..2292cab8 100644 --- a/src/dashboardWebView/models/Settings.ts +++ b/src/dashboardWebView/models/Settings.ts @@ -16,7 +16,7 @@ export interface Settings { pageViewType: ViewType | undefined; mediaSnippet: string[]; contentTypes: ContentType[]; - contentFolders: string[]; + contentFolders: ContentFolder[]; crntFramework: string; framework: Framework | null | undefined; draftField: DraftField | null | undefined; diff --git a/src/helpers/Extension.ts b/src/helpers/Extension.ts index a445a379..d8bcc043 100644 --- a/src/helpers/Extension.ts +++ b/src/helpers/Extension.ts @@ -115,7 +115,7 @@ export class Extension { const projectFolder = basename(workspace?.fsPath || ""); const paths = folders.map((folder: any) => ({ - title: folder.title, + ...folder, path: `${WORKSPACE_PLACEHOLDER}${folder.fsPath.split(projectFolder).slice(1).join('')}`.split('\\').join('/') })); diff --git a/src/models/ContentFolder.ts b/src/models/ContentFolder.ts index 1a5e6cb2..115c6713 100644 --- a/src/models/ContentFolder.ts +++ b/src/models/ContentFolder.ts @@ -1,4 +1,6 @@ export interface ContentFolder { title: string; path: string; + + excludeSubdir?: boolean; } \ No newline at end of file