Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
feat: INT-2283 ensured discarded jobs do not reappear
Browse files Browse the repository at this point in the history
  • Loading branch information
grzpab committed Dec 7, 2023
1 parent 4cb374f commit 2d10218
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 39 deletions.
5 changes: 5 additions & 0 deletions intuita-webview/src/main/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@
flex-direction: column;
align-items: center;
}

.clearing-progress-ring {
height: 4em;
width: 100%;
}
32 changes: 24 additions & 8 deletions intuita-webview/src/main/CodemodRuns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 & {
Expand Down Expand Up @@ -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 (
<div className="w-full h-full">
<PanelGroup
Expand All @@ -59,13 +77,7 @@ export const CodemodRuns = (
>
<SectionHeader
title={'Results'}
commands={[
{
icon: 'clear-all',
title: 'Clear all',
command: 'intuita.clearState',
},
]}
commands={commands}
collapsed={props.resultsCollapsed}
onClick={(event) => {
event.preventDefault();
Expand All @@ -92,7 +104,11 @@ export const CodemodRuns = (
});
}}
>
<CampaignManager {...props} />
{props.clearingInProgress ? (
<VSCodeProgressRing className="clearing-progress-ring" />
) : (
<CampaignManager {...props} />
)}
</ResizablePanel>
<PanelResizeHandle className="resize-handle" />
<SectionHeader
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "intuita-vscode-extension",
"displayName": "Intuita",
"description": " Discover, run & manage codemods faster & easier.",
"version": "0.37.1",
"version": "0.38.0",
"publisher": "Intuita",
"icon": "img/intuita_square128.png",
"repository": {
Expand Down Expand Up @@ -282,7 +282,7 @@
},
"dependencies": {
"@effect/schema": "0.30.3",
"@intuita-inc/utilities": "^1.0.1",
"@intuita-inc/utilities": "^1.0.2",
"@reduxjs/toolkit": "^1.9.5",
"@vscode/extension-telemetry": "^0.7.7",
"axios": "^1.2.2",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions src/commands/clearStateCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { FileType, Uri, workspace } from 'vscode';
import { actions } from '../data/slice';
import { doesJobAddNewFile } from '../selectors/comparePersistedJobs';
import { Store } from '../data';
import { FileService } from '../components/fileService';
import { homedir } from 'node:os';
import { join } from 'node:path';

type Dependencies = Readonly<{
store: Store;
fileService: FileService;
}>;

export const createClearStateCommand =
({ fileService, store }: Dependencies) =>
async () => {
const state = store.getState();

store.dispatch(actions.clearState());

try {
const uris: Uri[] = [];

for (const job of Object.values(state.job.entities)) {
if (
!job ||
!doesJobAddNewFile(job.kind) ||
job.newContentUri === null ||
job.newContentUri.includes('.intuita/cases')
) {
continue;
}

uris.push(Uri.parse(job.newContentUri));
}

await fileService.deleteFiles({ uris });
} catch (error) {
console.error(error);
}

try {
const casesDirectoryUri = Uri.parse(
join(homedir(), '.intuita', 'cases'),
);

const files = await workspace.fs.readDirectory(casesDirectoryUri);

const caseDirectoryUris = files
.filter(([, fileType]) => fileType === FileType.Directory)
.map(([name]) => Uri.joinPath(casesDirectoryUri, name));

await fileService.deleteDirectories({ uris: caseDirectoryUris });
} catch (error) {
console.error(error);
}

store.dispatch(actions.onStateCleared());
};
3 changes: 2 additions & 1 deletion src/components/webview/MainProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ export class MainViewProvider implements WebviewViewProvider {

if (
prevProps.activeTabId !== nextProps.activeTabId &&
nextProps.activeTabId === 'codemodRuns'
nextProps.activeTabId === 'codemodRuns' &&
!nextProps.clearingInProgress
) {
this.__messageBus.publish({
kind: MessageKind.loadHomeDirectoryData,
Expand Down
6 changes: 6 additions & 0 deletions src/data/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const jobAdapter = createEntityAdapter<PersistedJob>({

export const getInitialState = (): RootState => {
return {
clearingInProgress: false,
codemod: codemodAdapter.getInitialState(),
privateCodemods: privateCodemodAdapter.getInitialState(),
case: caseAdapter.getInitialState(),
Expand Down Expand Up @@ -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);

Expand All @@ -157,6 +160,9 @@ const rootSlice = createSlice({
state.reviewedExplorerNodes = {};
state.focusedExplorerNodes = {};
},
onStateCleared(state) {
state.clearingInProgress = false;
},
setCodemods(state, action: PayloadAction<ReadonlyArray<CodemodEntry>>) {
codemodAdapter.setAll(state.codemod, action.payload);
},
Expand Down
33 changes: 9 additions & 24 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
CodemodNodeHashDigest,
selectCodemodArguments,
} from './selectors/selectCodemodTree';
import { doesJobAddNewFile } from './selectors/comparePersistedJobs';
import { buildHash, isNeitherNullNorUndefined } from './utilities';
import { mkdir, readFile, writeFile } from 'fs/promises';
import { homedir } from 'os';
Expand All @@ -47,6 +46,7 @@ import { parsePrivateCodemodsEnvelope } from './data/privateCodemodsEnvelopeSche
import { GlobalStateTokenStorage, UserService } from './components/userService';
import { HomeDirectoryService } from './data/readHomeDirectoryCases';
import { isLeft } from 'fp-ts/lib/Either';
import { createClearStateCommand } from './commands/clearStateCommand';

export const enum SEARCH_PARAMS_KEYS {
ENGINE = 'engine',
Expand Down Expand Up @@ -849,30 +849,15 @@ export async function activate(context: vscode.ExtensionContext) {
);

context.subscriptions.push(
vscode.commands.registerCommand('intuita.clearState', () => {
const state = store.getState();

const uris: vscode.Uri[] = [];

for (const job of Object.values(state.job.entities)) {
if (
!job ||
!doesJobAddNewFile(job.kind) ||
job.newContentUri === null ||
job.newContentUri.includes('.intuita/cases')
) {
continue;
}

uris.push(vscode.Uri.parse(job.newContentUri));
}

store.dispatch(actions.clearState());
vscode.commands.registerCommand(
'intuita.clearState',
createClearStateCommand({ fileService, store }),
),
);

messageBus.publish({
kind: MessageKind.deleteDirectories,
uris: [vscode.Uri.parse(join(homedir(), '.intuita', 'cases'))],
});
context.subscriptions.push(
vscode.commands.registerCommand('intuita.stopStateClearing', () => {
store.dispatch(actions.onStateCleared());
}),
);

Expand Down
1 change: 1 addition & 0 deletions src/persistedState/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const panelGroupSettingsCodec = t.record(t.string, t.array(t.number));
export type PanelGroupSettings = t.TypeOf<typeof panelGroupSettingsCodec>;

export const persistedStateCodecNew = buildTypeCodec({
clearingInProgress: withFallback(t.boolean, false),
case: buildCollectionCodec(caseCodec),
codemod: buildCollectionCodec(codemodEntryCodec),
privateCodemods: buildCollectionCodec(privateCodemodEntryCodec),
Expand Down
1 change: 1 addition & 0 deletions src/selectors/selectMainWebviewViewProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const selectMainWebviewViewProps = (

if (state.activeTabId === 'codemodRuns') {
return {
clearingInProgress: state.clearingInProgress,
activeTabId: state.activeTabId,
toaster: state.toaster,
applySelectedInProgress: state.applySelectedInProgress,
Expand Down

0 comments on commit 2d10218

Please sign in to comment.