Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Component for the Handsontable React wrapper
*/

import { HotTable } from '@handsontable/react';
import { HotTable, HotTableClass } from '@handsontable/react';
import type Handsontable from 'handsontable';
import type { DetailedSettings } from 'handsontable/plugins/contextMenu';
import { registerAllModules } from 'handsontable/registry';
Expand Down Expand Up @@ -47,7 +47,7 @@ function WbSpreadsheetComponent({
onClickDisambiguate: handleClickDisambiguate,
}: {
readonly dataset: Dataset;
readonly setHotTable: React.RefCallback<HotTable>;
readonly setHotTable: React.RefCallback<HotTableClass>;
readonly hot: Handsontable | undefined;
readonly isUploaded: boolean;
readonly data: RA<RA<string | null>>;
Expand Down Expand Up @@ -163,10 +163,10 @@ function WbSpreadsheetComponent({
!disambiguation.isAmbiguousCell() || isReadOnly,
callback: handleClickDisambiguate,
},
['separator_1' as 'undo']: '---------',
separator_1: '---------',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

['separator_1' as 'undo'] was showing me an error, so I changed it to just separator_1.
It was originally done to avoid a type error in the first place 3d3eb1d, but it seems to be fine now, I hope.

fill_down: fillCellsContextMenuItem(hot, 'down', isReadOnly),
fill_up: fillCellsContextMenuItem(hot, 'up', isReadOnly),
['separator_2' as 'redo']: '---------',
separator_2: '---------',
undo: {
disabled: () => !hot.isUndoAvailable() || isReadOnly,
},
Expand Down Expand Up @@ -224,8 +224,9 @@ function WbSpreadsheetComponent({
});

return (
<section className="flex-1 overflow-hidden overscroll-none">
<section className="flex-1 overflow-hidden overscroll-none h-full">
<HotTable
autoColumnSize={true}
autoWrapCol={autoWrapCol}
autoWrapRow={autoWrapRow}
colHeaders={colHeaders}
Expand All @@ -248,7 +249,7 @@ function WbSpreadsheetComponent({
readOnly={isReadOnly}
ref={setHotTable}
rowHeaders
stretchH="all"
viewportRowRenderingOffset={30}
tabMoves={tabMoves}
contextMenu={contextMenuConfig}
// eslint-disable-next-line functional/prefer-readonly-type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import '../../../css/workbench.css';

import type { HotTable } from '@handsontable/react';
import type { HotTableClass } from '@handsontable/react';
import type Handsontable from 'handsontable';
import React from 'react';

Expand Down Expand Up @@ -87,7 +87,7 @@ export function WbView({
);

const spreadsheetContainerRef = React.useRef<HTMLElement>(null);
const [hotTable, setHotTable] = React.useState<HotTable | null>(null);
const [hotTable, setHotTable] = React.useState<HotTableClass | null>(null);
const hot = hotTable?.hotInstance ?? undefined;

const isUploaded =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,4 @@ export function getHotPlugin<NAME extends keyof Plugins>(
if (plugins[pluginName] === undefined)
plugins[pluginName] = hot.getPlugin(pluginName);
return plugins[pluginName]!;
}
}
31 changes: 27 additions & 4 deletions specifyweb/frontend/js_src/lib/components/WorkBench/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type Handsontable from 'handsontable';
import type { CellChange } from 'handsontable/common';
import type { Events } from 'handsontable/pluginHooks';
import type { Events } from 'handsontable';
import type { Action } from 'handsontable/plugins/undoRedo';
import React from 'react';

Expand Down Expand Up @@ -88,7 +88,7 @@ export function useHotHooks({
if (Boolean(value) || workbench.hot === undefined) return value;

const visualCol = workbench.hot.propToCol(property);
const physicalCol = workbench.hot.toPhysicalColumn(visualCol);
const physicalCol = workbench.hot.toPhysicalColumn(visualCol as number);

return workbench.mappings?.defaultValues[physicalCol] ?? value;
},
Expand All @@ -103,7 +103,7 @@ export function useHotHooks({
const visualCol = workbench.hot.propToCol(property);

const physicalRow = workbench.hot.toPhysicalRow(visualRow);
const physicalCol = workbench.hot.toPhysicalColumn(visualCol);
const physicalCol = workbench.hot.toPhysicalColumn(visualCol as number);
const issues = workbench.cells.getCellMeta(
physicalRow,
physicalCol,
Expand Down Expand Up @@ -221,7 +221,9 @@ export function useHotHooks({
const changes = unfilteredChanges
.map(([visualRow, property, oldValue, newValue]) => ({
visualRow,
visualCol: workbench.hot!.propToCol(property),
visualCol: workbench.hot!.propToCol(
property as number | string
) as number,
physicalRow: workbench.hot!.toPhysicalRow(visualRow),
physicalCol:
typeof property === 'number'
Expand Down Expand Up @@ -547,6 +549,27 @@ export function useHotHooks({
workbench.hot?.selectCells(newSelection);
}
},

/*
* As of Handsontable 16.0.1 column sizes on large data sets need to be manually recalculated
*/
afterScrollHorizontally: () => {
if (workbench.hot === undefined) return;
getHotPlugin(
workbench.hot,
'autoColumnSize'
).calculateVisibleColumnsWidth();
workbench.hot.render();
},

afterScrollVertically: () => {
if (workbench.hot === undefined) return;
getHotPlugin(
workbench.hot,
'autoColumnSize'
).calculateVisibleColumnsWidth();
workbench.hot.render();
},
};
}

Expand Down
Loading