Skip to content

Commit

Permalink
Fix default values and error cells disappearing when toggling results
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadsw committed May 13, 2024
1 parent 5497c85 commit a4a5a8a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
38 changes: 23 additions & 15 deletions specifyweb/frontend/js_src/lib/components/WbActions/useResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import type Handsontable from 'handsontable';
import React from 'react';

import { useBooleanState } from '../../hooks/useBooleanState';
import { getHotPlugin } from '../WorkBench/handsontable';
import { getHotPlugin, identifyDefaultValues } from '../WorkBench/handsontable';
import type { Workbench } from '../WorkBench/WbView';

export function useResults({
hot,
workbench,
triggerDatasetRefresh,
}: {
readonly hot: Handsontable | undefined;
readonly workbench: Workbench;
readonly triggerDatasetRefresh: () => void;
}) {
const [showResults, _, closeResults, toggleResults] = useBooleanState();

Expand Down Expand Up @@ -57,21 +59,27 @@ export function useResults({
)
.map(hot.toVisualColumn);

if (showResults) {
getHotPlugin(hot, 'hiddenRows').hideRows(rowsToHide);
getHotPlugin(hot, 'hiddenColumns').hideColumns(colsToHide);
hot.batch(() => {
if (showResults) {
identifyDefaultValues(hot, workbench.mappings);
getHotPlugin(hot, 'hiddenRows').hideRows(rowsToHide);
getHotPlugin(hot, 'hiddenColumns').hideColumns(colsToHide);

workbench.utils.toggleCellTypes('newCells', 'remove');
} else {
getHotPlugin(hot, 'hiddenRows').showRows(
rowsToHide.filter((visualRow) => !initialHiddenRows.includes(visualRow))
);
getHotPlugin(hot, 'hiddenColumns').showColumns(
colsToHide.filter((visualCol) => !initialHiddenCols.includes(visualCol))
);
}

hot.render();
workbench.utils.toggleCellTypes('newCells', 'remove');
} else {
getHotPlugin(hot, 'hiddenRows').showRows(
rowsToHide.filter(
(visualRow) => !initialHiddenRows.includes(visualRow)
)
);
getHotPlugin(hot, 'hiddenColumns').showColumns(
colsToHide.filter(
(visualCol) => !initialHiddenCols.includes(visualCol)
)
);
triggerDatasetRefresh();
}
});
}, [showResults]);

return { showResults, closeResults, toggleResults };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export function WbView({
const { showResults, closeResults, toggleResults } = useResults({
hot,
workbench,
triggerDatasetRefresh,
});

const { openDisambiguationDialog, disambiguationDialogs } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function configureHandsontable(
setSort(hot, dataset);
}

function identifyDefaultValues(
export function identifyDefaultValues(
hot: Handsontable,
mappings: WbMapping | undefined
): void {
Expand Down

0 comments on commit a4a5a8a

Please sign in to comment.