Skip to content

Commit

Permalink
feat: scroll to current dry run
Browse files Browse the repository at this point in the history
  • Loading branch information
devcatalin committed Oct 5, 2023
1 parent d5b2e25 commit a6ae883
Showing 1 changed file with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useRef} from 'react';
import {useLayoutEffect, useRef} from 'react';

import {Skeleton} from 'antd';

Expand Down Expand Up @@ -27,6 +27,8 @@ const DryRunsPane: React.FC = () => {
const list = useAppSelector(dryRunNodesSelector);
const isLoading = useAppSelector(state => (state.main.previewOptions.isLoading ? true : state.ui.isFolderLoading));

const preview = useAppSelector(state => state.main.preview);

const ref = useRef<HTMLUListElement>(null);

const rowVirtualizer = useVirtualizer({
Expand All @@ -36,6 +38,30 @@ const DryRunsPane: React.FC = () => {
scrollToFn: elementScroll,
});

useLayoutEffect(() => {
if (!preview) {
return;
}

const index = list.findIndex(item => {
if (item.type === 'command' && preview.type === 'command') {
return item.commandId === preview.commandId;
}
if (item.type === 'helm-values' && preview.type === 'helm') {
return item.valuesId === preview.valuesFileId;
}
if (item.type === 'helm-config' && preview.type === 'helm-config') {
return item.configId === preview.configId;
}
if (item.type === 'kustomize' && preview.type === 'kustomize') {
return item.kustomizationId === preview.kustomizationId;
}
return false;
});

rowVirtualizer.scrollToIndex(index);
}, [preview, list, rowVirtualizer]);

if (isLoading) {
return (
<div style={{padding: '16px'}}>
Expand Down

0 comments on commit a6ae883

Please sign in to comment.