From cc0a7f13cdec7ea5a954a6325ebee3c590880deb Mon Sep 17 00:00:00 2001 From: Greg Pabian <35925521+grzpab@users.noreply.github.com> Date: Thu, 7 Dec 2023 12:52:05 +0100 Subject: [PATCH] wip --- intuita-webview/src/main/CodemodRuns.tsx | 38 ++++++++++++++++----- package.json | 1 - pnpm-lock.yaml | 33 ------------------ src/data/slice.ts | 6 ++++ src/extension.ts | 22 ++++++++++-- src/persistedState/codecs.ts | 1 + src/selectors/selectMainWebviewViewProps.ts | 1 + 7 files changed, 56 insertions(+), 46 deletions(-) diff --git a/intuita-webview/src/main/CodemodRuns.tsx b/intuita-webview/src/main/CodemodRuns.tsx index 79b527e2..c3540b7b 100644 --- a/intuita-webview/src/main/CodemodRuns.tsx +++ b/intuita-webview/src/main/CodemodRuns.tsx @@ -13,6 +13,8 @@ import { App as FileExplorer } from '../fileExplorer/App'; import { MainWebviewViewProps } from '../../../src/selectors/selectMainWebviewViewProps'; import { vscode } from '../shared/utilities/vscode'; import { useEffect, useMemo, useRef } from 'react'; +import { Command } from '../shared/types'; +import { VSCodeProgressRing } from '@vscode/webview-ui-toolkit/react'; export const CodemodRuns = ( props: MainWebviewViewProps & { @@ -50,6 +52,22 @@ export const CodemodRuns = ( [props.panelGroupSettings], ); + const commands: (Command & { icon: string })[] = []; + + if (props.clearingInProgress) { + commands.push({ + icon: 'circle-slash', + title: 'Stop clearing', + command: 'intuita.stopStateClearing', + }); + } else { + commands.push({ + icon: 'clear-all', + title: 'Clear all', + command: 'intuita.clearState', + }); + } + return (
{ event.preventDefault(); @@ -92,7 +106,13 @@ export const CodemodRuns = ( }); }} > - + {props.clearingInProgress ? ( + + ) : ( + + )} =12'} @@ -785,15 +772,6 @@ packages: resolution: {integrity: sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==} dev: true - /@intuita-inc/utilities@1.0.1(effect@2.0.0-next.59)(fast-check@3.14.0): - resolution: {integrity: sha512-qTIp9n5Jh00fst3l3T8qZ/Wd81j+I3NgjPp9IVMSZoe3JWb9YUujRJLh0BbGJysQ7Ve0vHcEF/s1K3yVMCvxlw==} - dependencies: - '@effect/schema': 0.52.0(effect@2.0.0-next.59)(fast-check@3.14.0) - transitivePeerDependencies: - - effect - - fast-check - dev: false - /@jridgewell/gen-mapping@0.3.3: resolution: {integrity: sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==} engines: {node: '>=6.0.0'} @@ -2047,10 +2025,6 @@ packages: is-obj: 2.0.0 dev: true - /effect@2.0.0-next.59: - resolution: {integrity: sha512-EE87vFl0/zIN5lKDtFccU3YCnbPqjxg9rY72obNN65/GE4JOJsXciyX8XC4pIDr3lE6KeJ0le8IXf+A7d92ntQ==} - dev: false - /electron-to-chromium@1.4.387: resolution: {integrity: sha512-tutLf+alr1/0YqJwKPdstVvDLmxmLb5xNyDLNS0RZmenHcEYk9qKfpKDCVZEKJ00JVbnayJm1MZAbYhYDFpcOw==} dev: true @@ -2297,13 +2271,6 @@ packages: pure-rand: 6.0.2 dev: false - /fast-check@3.14.0: - resolution: {integrity: sha512-9Z0zqASzDNjXBox/ileV/fd+4P+V/f3o4shM6QawvcdLFh8yjPG4h5BrHUZ8yzY6amKGDTAmRMyb/JZqe+dCgw==} - engines: {node: '>=8.0.0'} - dependencies: - pure-rand: 6.0.2 - dev: false - /fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} diff --git a/src/data/slice.ts b/src/data/slice.ts index d090c4e6..68bb4f5a 100644 --- a/src/data/slice.ts +++ b/src/data/slice.ts @@ -45,6 +45,7 @@ export const jobAdapter = createEntityAdapter({ export const getInitialState = (): RootState => { return { + clearingInProgress: false, codemod: codemodAdapter.getInitialState(), privateCodemods: privateCodemodAdapter.getInitialState(), case: caseAdapter.getInitialState(), @@ -142,6 +143,8 @@ const rootSlice = createSlice({ jobAdapter.upsertMany(state.job, action.payload); }, clearState(state) { + state.clearingInProgress = true; + caseAdapter.removeAll(state.case); jobAdapter.removeAll(state.job); @@ -157,6 +160,9 @@ const rootSlice = createSlice({ state.reviewedExplorerNodes = {}; state.focusedExplorerNodes = {}; }, + onStateCleared(state) { + state.clearingInProgress = false; + }, setCodemods(state, action: PayloadAction>) { codemodAdapter.setAll(state.codemod, action.payload); }, diff --git a/src/extension.ts b/src/extension.ts index 37628aaf..a3dcf5ee 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -849,9 +849,11 @@ export async function activate(context: vscode.ExtensionContext) { ); context.subscriptions.push( - vscode.commands.registerCommand('intuita.clearState', () => { + vscode.commands.registerCommand('intuita.clearState', async () => { const state = store.getState(); + store.dispatch(actions.clearState()); + const uris: vscode.Uri[] = []; for (const job of Object.values(state.job.entities)) { @@ -867,12 +869,26 @@ export async function activate(context: vscode.ExtensionContext) { uris.push(vscode.Uri.parse(job.newContentUri)); } - store.dispatch(actions.clearState()); + await fileService.deleteFiles({ uris }); + + const casesDirectoryUri = vscode.Uri.parse( + join(homedir(), '.intuita', 'cases'), + ); + + const files = await vscode.workspace.fs.readDirectory( + casesDirectoryUri, + ); + + const directoryNames = files.filter( + ([, fileType]) => fileType === vscode.FileType.Directory, + ); messageBus.publish({ kind: MessageKind.deleteDirectories, - uris: [vscode.Uri.parse(join(homedir(), '.intuita', 'cases'))], + uris: [], }); + + store.dispatch(actions.onStateCleared()); }), ); diff --git a/src/persistedState/codecs.ts b/src/persistedState/codecs.ts index 3ff807a5..cd808b6c 100644 --- a/src/persistedState/codecs.ts +++ b/src/persistedState/codecs.ts @@ -53,6 +53,7 @@ export const panelGroupSettingsCodec = t.record(t.string, t.array(t.number)); export type PanelGroupSettings = t.TypeOf; export const persistedStateCodecNew = buildTypeCodec({ + clearingInProgress: withFallback(t.boolean, false), case: buildCollectionCodec(caseCodec), codemod: buildCollectionCodec(codemodEntryCodec), privateCodemods: buildCollectionCodec(privateCodemodEntryCodec), diff --git a/src/selectors/selectMainWebviewViewProps.ts b/src/selectors/selectMainWebviewViewProps.ts index e48d55a9..75e0be52 100644 --- a/src/selectors/selectMainWebviewViewProps.ts +++ b/src/selectors/selectMainWebviewViewProps.ts @@ -39,6 +39,7 @@ export const selectMainWebviewViewProps = ( if (state.activeTabId === 'codemodRuns') { return { + clearingInProgress: state.clearingInProgress, activeTabId: state.activeTabId, toaster: state.toaster, applySelectedInProgress: state.applySelectedInProgress,