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
r4zendev committed Jan 16, 2024
1 parent b1f0371 commit 2a8e8f8
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 48 deletions.
23 changes: 23 additions & 0 deletions intuita-webview/src/codemodList/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type { MainWebviewViewProps } from '../../../src/selectors/selectMainWebv
import cn from 'classnames';
import { SectionHeader } from '../shared/SectionHeader';
import styles from './style.module.css';
import { WebviewMessage } from '../shared/types';

const setSearchPhrase = (searchPhrase: string) => {
vscode.postMessage({
Expand All @@ -35,6 +36,28 @@ export const App = memo(
const publicRegistryRef = useRef<ImperativePanelHandle | null>(null);
const privateRegistryRef = useRef<ImperativePanelHandle | null>(null);

useEffect(() => {
const handler = (e: MessageEvent<WebviewMessage>) => {
const message = e.data;

if (message.kind === 'webview.global.scrollToCodemod') {
const element = document.getElementById(
`${message.hashDigest}-body`,
);

if (element) {
element.scrollIntoView();
}
}
};

window.addEventListener('message', handler);

return () => {
window.removeEventListener('message', handler);
};
}, []);

useEffect(() => {
if (props.publicRegistryCollapsed) {
publicRegistryRef.current?.collapse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ const Codemod = ({
<span className={cn('codicon', 'codicon-verified')} />
)}
</IntuitaPopover>
<span className={styles.labelContainer}>
<span
className={styles.labelContainer}
id={`${hashDigest}-body`}
>
<span
className={styles.label}
style={getLabelStyle(areButtonsVisible, screenWidth)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/webview/MainProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export class MainViewProvider implements WebviewViewProvider {
});
}

private __postMessage(message: WebviewMessage) {
public __postMessage(message: WebviewMessage) {
this.__view?.webview.postMessage(message);
}

Expand Down
4 changes: 4 additions & 0 deletions src/components/webview/webviewEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export type WebviewMessage =
}>
| Readonly<{
kind: 'webview.global.codemodExecutionHalted';
}>
| Readonly<{
kind: 'webview.global.scrollToCodemod';
hashDigest: string;
}>;

export type WebviewResponse =
Expand Down
100 changes: 54 additions & 46 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1098,60 +1098,63 @@ export async function activate(context: vscode.ExtensionContext) {
);

// Expand collapsed parent directories of the relevant codemod
if (codemodHashDigest !== null) {
const privateCodemod =
state.privateCodemods.entities[codemodHashDigest] ??
null;

if (privateCodemod !== null) {
store.dispatch(
actions.setFocusedCodemodHashDigest(
codemodHashDigest as unknown as CodemodNodeHashDigest,
),
);
return;
}
const privateCodemod =
state.privateCodemods.entities[codemodHashDigest] ??
null;

const codemod =
state.codemod.entities[codemodHashDigest] ?? null;
if (codemod === null) {
return;
}
const { name } = codemod;
const sep = name.indexOf('/') !== -1 ? '/' : ':';
if (privateCodemod !== null) {
store.dispatch(
actions.setFocusedCodemodHashDigest(
codemodHashDigest as unknown as CodemodNodeHashDigest,
),
);

const pathParts = name
.split(sep)
.filter((part) => part !== '');
mainViewProvider.__postMessage({
kind: 'webview.global.scrollToCodemod',
hashDigest: codemodHashDigest,
});
return;
}

if (pathParts.length === 0) {
return;
}
const codemod =
state.codemod.entities[codemodHashDigest] ?? null;
if (codemod === null) {
return;
}
const { name } = codemod;
const sep = name.indexOf('/') !== -1 ? '/' : ':';

pathParts.forEach((name, idx) => {
const path = pathParts.slice(0, idx + 1).join(sep);
const pathParts = name
.split(sep)
.filter((part) => part !== '');

if (idx === pathParts.length - 1) {
return;
}
if (pathParts.length === 0) {
return;
}

const parentHashDigest = buildHash(
[path, name].join('_'),
) as CodemodNodeHashDigest;
pathParts.forEach((name, idx) => {
const path = pathParts.slice(0, idx + 1).join(sep);

if (idx === pathParts.length - 1) {
return;
}

if (
state.codemodDiscoveryView.expandedNodeHashDigests.includes(
parentHashDigest,
)
) {
return;
}
const parentHashDigest = buildHash(
[path, name].join('_'),
) as CodemodNodeHashDigest;

store.dispatch(
actions.flipCodemodHashDigest(parentHashDigest),
);
});
}
if (
state.codemodDiscoveryView.expandedNodeHashDigests.includes(
parentHashDigest,
)
) {
return;
}

store.dispatch(
actions.flipCodemodHashDigest(parentHashDigest),
);
});

if (state.codemodDiscoveryView.searchPhrase.length > 0) {
store.dispatch(actions.setCodemodSearchPhrase(''));
Expand All @@ -1162,6 +1165,11 @@ export async function activate(context: vscode.ExtensionContext) {
codemodHashDigest as unknown as CodemodNodeHashDigest,
),
);

mainViewProvider.__postMessage({
kind: 'webview.global.scrollToCodemod',
hashDigest: codemodHashDigest,
});
} else if (accessToken !== null) {
const routeUserToStudioToAuthenticate = async () => {
const result = await vscode.window.showErrorMessage(
Expand Down

0 comments on commit 2a8e8f8

Please sign in to comment.