From a2490f64fe18bb718fc461cfc85f2c45b63a9e92 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 31 May 2022 13:05:51 +0200 Subject: [PATCH] scaffolder: remove unnecessary TemplateFileSystemAccess interface Signed-off-by: Patrik Oldsberg --- .../TemplateEditorPage/TemplateEditorPage.tsx | 3 +-- .../src/lib/filesystem/WebFileSystemAccess.ts | 20 +++++-------------- .../scaffolder/src/lib/filesystem/index.ts | 6 +----- .../scaffolder/src/lib/filesystem/types.ts | 4 ---- 4 files changed, 7 insertions(+), 26 deletions(-) diff --git a/plugins/scaffolder/src/components/TemplateEditorPage/TemplateEditorPage.tsx b/plugins/scaffolder/src/components/TemplateEditorPage/TemplateEditorPage.tsx index 3741a6fc3d..fce2881190 100644 --- a/plugins/scaffolder/src/components/TemplateEditorPage/TemplateEditorPage.tsx +++ b/plugins/scaffolder/src/components/TemplateEditorPage/TemplateEditorPage.tsx @@ -64,8 +64,7 @@ export function TemplateEditorPage(props: TemplateEditorPageProps) { { if (option === 'local') { - WebFileSystemAccess.get() - .requestDirectoryAccess() + WebFileSystemAccess.requestDirectoryAccess() .then(directory => setSelection({ type: 'local', directory })) .catch(() => {}); } else if (option === 'form') { diff --git a/plugins/scaffolder/src/lib/filesystem/WebFileSystemAccess.ts b/plugins/scaffolder/src/lib/filesystem/WebFileSystemAccess.ts index 2de3bd296f..36e7b11de2 100644 --- a/plugins/scaffolder/src/lib/filesystem/WebFileSystemAccess.ts +++ b/plugins/scaffolder/src/lib/filesystem/WebFileSystemAccess.ts @@ -14,11 +14,7 @@ * limitations under the License. */ -import { - TemplateFileSystemAccess, - TemplateDirectoryAccess, - TemplateFileAccess, -} from './types'; +import { TemplateDirectoryAccess, TemplateFileAccess } from './types'; type WritableFileHandle = FileSystemFileHandle & { createWritable(): Promise<{ @@ -82,24 +78,18 @@ class WebDirectoryAccess implements TemplateDirectoryAccess { } /** @internal */ -export class WebFileSystemAccess implements TemplateFileSystemAccess { - private static instance = new WebFileSystemAccess(); - - static get(): TemplateFileSystemAccess { - return this.instance; - } - +export class WebFileSystemAccess { static isSupported(): boolean { return Boolean(showDirectoryPicker); } - private constructor() {} - - async requestDirectoryAccess(): Promise { + static async requestDirectoryAccess(): Promise { if (!showDirectoryPicker) { throw new Error('File system access is not supported'); } const handle = await showDirectoryPicker(); return new WebDirectoryAccess(handle); } + + private constructor() {} } diff --git a/plugins/scaffolder/src/lib/filesystem/index.ts b/plugins/scaffolder/src/lib/filesystem/index.ts index c57fc35756..1f485d0743 100644 --- a/plugins/scaffolder/src/lib/filesystem/index.ts +++ b/plugins/scaffolder/src/lib/filesystem/index.ts @@ -14,10 +14,6 @@ * limitations under the License. */ -export type { - TemplateFileAccess, - TemplateDirectoryAccess, - TemplateFileSystemAccess, -} from './types'; +export type { TemplateFileAccess, TemplateDirectoryAccess } from './types'; export { blobToBase64 } from './helpers'; export { WebFileSystemAccess } from './WebFileSystemAccess'; diff --git a/plugins/scaffolder/src/lib/filesystem/types.ts b/plugins/scaffolder/src/lib/filesystem/types.ts index 820ae5f99d..11de159b2a 100644 --- a/plugins/scaffolder/src/lib/filesystem/types.ts +++ b/plugins/scaffolder/src/lib/filesystem/types.ts @@ -23,7 +23,3 @@ export interface TemplateFileAccess { export interface TemplateDirectoryAccess { listFiles(): Promise>; } - -export interface TemplateFileSystemAccess { - requestDirectoryAccess(): Promise; -}