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

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
grzpab committed Dec 7, 2023
1 parent 4cb374f commit cc0a7f1
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 46 deletions.
38 changes: 29 additions & 9 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,14 +77,10 @@ export const CodemodRuns = (
>
<SectionHeader
title={'Results'}
commands={[
{
icon: 'clear-all',
title: 'Clear all',
command: 'intuita.clearState',
},
]}
collapsed={props.resultsCollapsed}
commands={commands}
collapsed={
props.clearingInProgress || props.resultsCollapsed
}
onClick={(event) => {
event.preventDefault();

Expand All @@ -92,7 +106,13 @@ export const CodemodRuns = (
});
}}
>
<CampaignManager {...props} />
{props.clearingInProgress ? (
<VSCodeProgressRing
style={{ height: '4em', width: '100%' }}
/>
) : (
<CampaignManager {...props} />
)}
</ResizablePanel>
<PanelResizeHandle className="resize-handle" />
<SectionHeader
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@
},
"dependencies": {
"@effect/schema": "0.30.3",
"@intuita-inc/utilities": "^1.0.1",
"@reduxjs/toolkit": "^1.9.5",
"@vscode/extension-telemetry": "^0.7.7",
"axios": "^1.2.2",
Expand Down
33 changes: 0 additions & 33 deletions pnpm-lock.yaml

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

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
22 changes: 19 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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());
}),
);

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 cc0a7f1

Please sign in to comment.