Skip to content

Commit 97ee7e8

Browse files
authored
WB Attachments: Fix moving attachments column (#7390)
* Use visual column index of attachments column * Lint code with ESLint and Prettier Triggered by 35eca19 on branch refs/heads/issue-7389
1 parent b45cef2 commit 97ee7e8

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

specifyweb/frontend/js_src/lib/components/WorkBench/WbAttachmentsPreview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function fetchRowAttachments(
173173
) => void
174174
): void {
175175
// Look for Attachments column
176-
const attachmentColumnIndex = getAttachmentsColumn(dataset);
176+
const attachmentColumnIndex = hot.toVisualColumn(getAttachmentsColumn(dataset));
177177
if (attachmentColumnIndex === -1) return;
178178

179179
// Each row should have comma-separated IDs for SpDataSetAttachments

specifyweb/frontend/js_src/lib/components/WorkBench/attachmentHelpers.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ export function usesAttachments(dataset: Dataset): boolean {
7373
return dataset.columns.includes(ATTACHMENTS_COLUMN);
7474
}
7575

76+
/**
77+
* Returns the *physical* column index of the attachment JSON data.
78+
*/
7679
export function getAttachmentsColumn(dataset: Dataset): number {
7780
if (!usesAttachments(dataset)) {
7881
return -1;

specifyweb/frontend/js_src/lib/components/WorkBench/handsontable.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,13 @@ function setColumnWidths(hot: Handsontable, dataset: Dataset): void {
226226
* For simplicity, the width is limited to 100px to reflect the likely shorter displayed text.
227227
*/
228228
const attachmentColumnMaxWidth = 100;
229-
const attachmentsColumnIndex = getAttachmentsColumn(dataset);
230-
if (attachmentsColumnIndex !== -1) {
229+
const attachmentsColumnIndex = hot.toVisualColumn(
230+
getAttachmentsColumn(dataset)
231+
);
232+
if (
233+
attachmentsColumnIndex !== -1 &&
234+
hot.getColWidth(attachmentsColumnIndex) > attachmentColumnMaxWidth
235+
) {
231236
colWidths = [];
232237
colWidths[attachmentsColumnIndex] = Math.min(
233238
hot.getColWidth(attachmentsColumnIndex),

0 commit comments

Comments
 (0)