Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
242 commits
Select commit Hold shift + click to select a range
a676e59
Add new WB attachment import page
alesan99 Feb 10, 2025
203eb52
Create new data set from attachments
alesan99 Feb 19, 2025
b8d1889
WIP add import button
alesan99 Feb 20, 2025
abb3893
Lint code with ESLint and Prettier
alesan99 Feb 20, 2025
bf9a7eb
Fix creating new datasets
alesan99 Feb 21, 2025
afbb7a9
Lint code with ESLint and Prettier
alesan99 Feb 21, 2025
ce811a1
Merge branch 'issue-6074' into issue-6075
alesan99 Mar 4, 2025
4ebf273
Merge branch 'issue-6074' into issue-6075
alesan99 Mar 5, 2025
882decd
Merge branch 'issue-6074' into issue-6075
alesan99 Mar 10, 2025
db29925
WIP Upload attachments and show IDs in dataset
alesan99 Mar 11, 2025
cd32ab5
Merge branch 'issue-6075' of https://github.com/specify/specify7 into…
alesan99 Mar 11, 2025
fd2c42c
Create SpDataSetAttachment records on wb attachment import
alesan99 Mar 12, 2025
664a000
Lint code with ESLint and Prettier
alesan99 Mar 12, 2025
d93a3ac
Fix dataSetAttachments getting deleted upon dataSet creation
alesan99 Mar 14, 2025
72bb36b
Lint code with ESLint and Prettier
alesan99 Mar 14, 2025
3844401
Fix array being readonly
alesan99 Mar 14, 2025
af95077
Merge branch 'issue-6074' into issue-6075
alesan99 Mar 31, 2025
44be10a
Lint code with ESLint and Prettier
alesan99 Mar 31, 2025
e7f5281
Add dataset preview
alesan99 Apr 2, 2025
dce7102
Lint code with ESLint and Prettier
alesan99 Apr 2, 2025
38106ee
Add progress bar
alesan99 Apr 3, 2025
2624d9a
Merge branch 'issue-6075' of https://github.com/specify/specify7 into…
alesan99 Apr 3, 2025
68b16de
Fix duplicate line
alesan99 Apr 3, 2025
7af5f3e
Use FilesPreview Component
alesan99 Apr 4, 2025
0a31424
Lint code with ESLint and Prettier
alesan99 Apr 4, 2025
5d982da
Delete data set if attachment uploads fail
alesan99 Apr 11, 2025
4e9109f
Fix attachment records not being deleted
alesan99 Apr 14, 2025
6b3b771
Add Workbench Attachments side bar
alesan99 Apr 14, 2025
90a8d0f
Simplify error handling
alesan99 Apr 14, 2025
88a1252
Merge branch 'issue-6074' into issue-6075
alesan99 Apr 15, 2025
30ff2dc
Save dataset attachments using bulk endpoint
alesan99 Apr 15, 2025
40e9350
Lint code with ESLint and Prettier
alesan99 Apr 15, 2025
2dc59fd
Improve failed upload handling
alesan99 Apr 16, 2025
16c1ee1
Merge branch 'issue-6075' of https://github.com/specify/specify7 into…
alesan99 Apr 16, 2025
d877117
Fix merge error
alesan99 Apr 16, 2025
a00a42b
Merge branch 'issue-6074' into issue-6075
alesan99 Apr 16, 2025
ee69e0d
Merge branch 'production' into issue-6075
alesan99 Apr 16, 2025
580f58a
Merge branch 'issue-6075' into issue-6076
alesan99 Apr 16, 2025
d75dc6e
Add attachment preview
alesan99 Apr 17, 2025
0fe6256
Add Workbench Image Window
alesan99 Apr 18, 2025
5ff151e
Lint code with ESLint and Prettier
alesan99 Apr 18, 2025
4ab022b
Break up attachment upload process
alesan99 Apr 21, 2025
c2fc2b3
Lint code with ESLint and Prettier
alesan99 Apr 21, 2025
8b92cca
Merge branch 'production' into issue-6075
alesan99 Apr 21, 2025
cd2be87
Merge branch 'issue-6075' into issue-6076
alesan99 Apr 22, 2025
78b8aa2
Add support for multiple attachments in a single row
alesan99 Apr 22, 2025
e7e8819
Lint code with ESLint and Prettier
alesan99 Apr 22, 2025
997c669
Add loading skeleton
alesan99 Apr 23, 2025
693dad8
Hide attachments button on datasets without attachments
alesan99 Apr 23, 2025
455d399
Lint code with ESLint and Prettier
alesan99 Apr 23, 2025
b51650c
Fix Image Viewer lag
alesan99 Apr 24, 2025
85cc818
Merge branch 'issue-6076' of https://github.com/specify/specify7 into…
alesan99 Apr 24, 2025
475ea48
Lint code with ESLint and Prettier
alesan99 Apr 24, 2025
cff0f1c
Split ImageViewer from Dialog
alesan99 Apr 25, 2025
9a73fc9
Support non-images in Image Window
alesan99 Apr 28, 2025
f9bf7ef
Lint code with ESLint and Prettier
alesan99 Apr 28, 2025
6e82d5b
Make attachments column readonly
alesan99 Apr 29, 2025
9bdfa2d
Lint code with ESLint and Prettier
alesan99 Apr 29, 2025
42d5d90
Format attachments in attachments column
alesan99 Apr 30, 2025
f317eaf
Merge branch 'issue-6076' of https://github.com/specify/specify7 into…
alesan99 Apr 30, 2025
7114d33
Fix dependency merge error
alesan99 Apr 30, 2025
012113b
Update column name
alesan99 May 1, 2025
6328f70
Merge branch 'production' into issue-6075
alesan99 May 1, 2025
b55e746
Merge branch 'issue-6075' into issue-6076
alesan99 May 1, 2025
65b7779
Add refresh icon
alesan99 May 5, 2025
6fc9bfb
Limit size of image in ImageViewer
alesan99 May 6, 2025
470c214
Lint code with ESLint and Prettier
alesan99 May 6, 2025
4ce3166
Lint code with ESLint and Prettier
alesan99 May 6, 2025
bcca71e
Fix attachments not being deleted upon deleting dataset
alesan99 May 9, 2025
0adad9a
Merge branch 'issue-6075' into issue-6076
alesan99 May 9, 2025
92faff7
Merge branch 'issue-6076' into issue-6077
alesan99 May 9, 2025
1393dd8
Merge branch 'issue-6076' into issue-6077
alesan99 May 9, 2025
f17b099
WIP Select only base tables with attachments
alesan99 May 9, 2025
48f02bf
Add Attachment table selector
alesan99 May 12, 2025
29b3e19
Change separator to semicolon
alesan99 May 12, 2025
1d7f80a
Lint code with ESLint and Prettier
alesan99 May 12, 2025
242fa6f
Simplify parsing error handling
alesan99 May 13, 2025
9e67c49
Refresh hot when Attachments panel is toggled
alesan99 May 16, 2025
29e1593
Merge branch 'issue-6076' into issue-6077
alesan99 May 16, 2025
2a341d6
WIP Check if table supports attachments
alesan99 May 19, 2025
2352821
WIP Error on validation
alesan99 May 19, 2025
836566f
Inject attachments into WB upload plan
alesan99 May 20, 2025
8b4da6e
test
alesan99 May 20, 2025
a411e0f
fix test
alesan99 May 20, 2025
d2d57d8
Move attachment uploading logic
alesan99 May 20, 2025
d918f8c
Move attachment column creation logic
alesan99 May 20, 2025
047e984
Fix type error
alesan99 May 20, 2025
03a0d69
Merge branch 'main' into issue-6075
alesan99 May 21, 2025
57dc2db
Merge remote-tracking branch 'origin/issue-6075' into issue-6076
alesan99 May 21, 2025
b919c49
Lint code with ESLint and Prettier
alesan99 May 21, 2025
c78e56a
Merge remote-tracking branch 'origin/issue-6076' into issue-6077
alesan99 May 21, 2025
a1290b4
Lint code with ESLint and Prettier
alesan99 May 21, 2025
74f069c
Merge branch 'issue-6076' into issue-6077
alesan99 May 21, 2025
b5abced
Fix attachments being deleted when deleting uploaded data sets
alesan99 May 21, 2025
a6aa351
Add baseTable target table for attachments
alesan99 May 21, 2025
9b00ccb
Ignore typecheck (Bad)
alesan99 May 21, 2025
7104f1c
Attempt to fix type error
alesan99 May 21, 2025
e801cac
Fix roll backs for attachment table ids
alesan99 May 22, 2025
ab23042
Refactor attachment upload plan insertion
alesan99 May 22, 2025
5b1a034
Fix type errors
alesan99 May 22, 2025
d8b6ff8
Fix type errors again
alesan99 May 22, 2025
2e6afe9
fix type errors again
alesan99 May 22, 2025
ba4672e
Add error for deleted attachments in data set
alesan99 May 22, 2025
c27ba2b
Fix imports
alesan99 May 22, 2025
2aee16f
Fix base upload plan being modified
alesan99 Jun 2, 2025
67de1cb
Fix checking for uploaded att when deleting data set
alesan99 Jun 3, 2025
700996a
Add error messages
alesan99 Jun 3, 2025
d0d9ee9
Add error messages
alesan99 Jun 3, 2025
8bf2d17
Hide attachments column from data mapper
alesan99 Jun 3, 2025
dd8a2cb
Fix AttachmentFailure type
alesan99 Jun 3, 2025
60b0124
Change attachment column export name so it cant be imported
alesan99 Jun 3, 2025
9871bcd
Fix types
alesan99 Jun 3, 2025
36ed12d
Fix types
alesan99 Jun 3, 2025
2bf7557
Add error message for attempting to link already linked atts
alesan99 Jun 3, 2025
1f72401
Fix types
alesan99 Jun 3, 2025
1bfec51
Update attachments column preivew header
alesan99 Jun 4, 2025
12e692c
Merge branch 'main' into issue-6075
alesan99 Jun 4, 2025
c0007fc
Lint code with ESLint and Prettier
alesan99 Jun 4, 2025
6c12cfd
Update attachment column name
alesan99 Jun 4, 2025
c7a567a
Reduce flicker on Image Window
alesan99 Jun 4, 2025
073676b
Merge branch 'issue-6076' of https://github.com/specify/specify7 into…
alesan99 Jun 4, 2025
a72cf96
Lint code with ESLint and Prettier
alesan99 Jun 4, 2025
ff3ab2b
Merge branch 'issue-6076' into issue-6077
alesan99 Jun 4, 2025
b13d408
Remove unused string
alesan99 Jun 4, 2025
06ad4d1
Add Dialog for attachment base tables
alesan99 Jun 9, 2025
2b3f2e6
Filter system tables
alesan99 Jun 9, 2025
f22cad0
Lint code with ESLint and Prettier
alesan99 Jun 9, 2025
dcc5874
Add dialog title for attachment tables
alesan99 Jun 9, 2025
548babc
Merge branch 'issue-6600' of https://github.com/specify/specify7 into…
alesan99 Jun 9, 2025
e5c4739
Limit attachment column width
alesan99 Jun 10, 2025
1ff1176
Merge branch 'main' into issue-6075
alesan99 Jun 10, 2025
a352028
Use RA
alesan99 Jun 10, 2025
4ac80ac
Merge branch 'issue-6075' into issue-6076
alesan99 Jun 10, 2025
176cabb
Lint code with ESLint and Prettier
alesan99 Jun 10, 2025
72bdc64
Update types
alesan99 Jun 10, 2025
fe5e95c
Merge branch 'issue-6076' into issue-6077
alesan99 Jun 10, 2025
0ae56ff
Lint code with ESLint and Prettier
alesan99 Jun 10, 2025
cef5f25
Fix error when adding new rows
alesan99 Jun 10, 2025
6bb82f2
Lint code with ESLint and Prettier
alesan99 Jun 10, 2025
a7a92fd
Merge branch 'main' into issue-6075
alesan99 Jul 1, 2025
c1eb439
Lint code with ESLint and Prettier
alesan99 Jul 1, 2025
a304a1b
Use sp types
alesan99 Jul 7, 2025
0c306df
Use sp types
alesan99 Jul 7, 2025
a0505b0
Lint code with ESLint and Prettier
alesan99 Jul 7, 2025
1f3e2d7
Merge branch 'issue-6077' into issue-6600
alesan99 Jul 9, 2025
852216f
Fix import
alesan99 Jul 9, 2025
5a7a1c1
Lint code with ESLint and Prettier
alesan99 Jul 14, 2025
d26db5b
Add upload button to attachment preview panel
alesan99 Jul 14, 2025
364d00d
Merge branch 'issue-6078' of https://github.com/specify/specify7 into…
alesan99 Jul 14, 2025
2b877e0
Merge remote-tracking branch 'origin/main' into issue-6075
alesan99 Aug 19, 2025
064ede8
Add Workbench Attachments Side Bar and Image Window (#6420)
alesan99 Aug 19, 2025
407e38a
Add Workbench Attachments side bar
alesan99 Apr 14, 2025
61a1f07
Add attachment preview
alesan99 Apr 17, 2025
fe215cb
Add Workbench Image Window
alesan99 Apr 18, 2025
ea1dd4c
Lint code with ESLint and Prettier
alesan99 Apr 18, 2025
17e24ff
Hide attachments button on datasets without attachments
alesan99 Apr 23, 2025
d832717
Fix Image Viewer lag
alesan99 Apr 24, 2025
d3b5b93
Lint code with ESLint and Prettier
alesan99 Apr 23, 2025
d51f19f
Lint code with ESLint and Prettier
alesan99 Apr 24, 2025
f9acfb7
Split ImageViewer from Dialog
alesan99 Apr 25, 2025
5b5683a
Support non-images in Image Window
alesan99 Apr 28, 2025
6288488
Make attachments column readonly
alesan99 Apr 29, 2025
d83d36b
Format attachments in attachments column
alesan99 Apr 30, 2025
f475e13
Lint code with ESLint and Prettier
alesan99 Apr 29, 2025
d5d8668
Lint code with ESLint and Prettier
alesan99 May 6, 2025
7a97a41
Add refresh icon
alesan99 May 5, 2025
ff6f198
Limit size of image in ImageViewer
alesan99 May 6, 2025
5f4a422
WIP Select only base tables with attachments
alesan99 May 9, 2025
0109522
Add Attachment table selector
alesan99 May 12, 2025
f23ef5e
Change separator to semicolon
alesan99 May 12, 2025
8fd85e2
Lint code with ESLint and Prettier
alesan99 May 12, 2025
30a8342
Simplify parsing error handling
alesan99 May 13, 2025
a29250b
WIP Check if table supports attachments
alesan99 May 19, 2025
2c41664
WIP Error on validation
alesan99 May 19, 2025
7bb7da0
Inject attachments into WB upload plan
alesan99 May 20, 2025
28043d4
test
alesan99 May 20, 2025
7ffad90
fix test
alesan99 May 20, 2025
0feeff5
Move attachment uploading logic
alesan99 May 20, 2025
b63ae5e
Move attachment column creation logic
alesan99 May 20, 2025
bea915e
Fix type error
alesan99 May 20, 2025
e72867c
Lint code with ESLint and Prettier
alesan99 May 21, 2025
c39ec2e
Fix attachments being deleted when deleting uploaded data sets
alesan99 May 21, 2025
241adb5
Add baseTable target table for attachments
alesan99 May 21, 2025
869308f
Ignore typecheck (Bad)
alesan99 May 21, 2025
7d7683c
Attempt to fix type error
alesan99 May 21, 2025
b019d7c
Fix roll backs for attachment table ids
alesan99 May 22, 2025
c61c6cb
Refactor attachment upload plan insertion
alesan99 May 22, 2025
7770143
Fix type errors
alesan99 May 22, 2025
bebb23e
Fix type errors again
alesan99 May 22, 2025
4847531
fix type errors again
alesan99 May 22, 2025
7bae080
Add error for deleted attachments in data set
alesan99 May 22, 2025
366dcef
Fix imports
alesan99 May 22, 2025
5ef886d
Fix base upload plan being modified
alesan99 Jun 2, 2025
419a148
Fix checking for uploaded att when deleting data set
alesan99 Jun 3, 2025
ecbb562
Add error messages
alesan99 Jun 3, 2025
03babb1
Add error messages
alesan99 Jun 3, 2025
62ff526
Hide attachments column from data mapper
alesan99 Jun 3, 2025
451174f
Fix AttachmentFailure type
alesan99 Jun 3, 2025
1e963cd
Change attachment column export name so it cant be imported
alesan99 Jun 3, 2025
dd8c2fa
Fix types
alesan99 Jun 3, 2025
843c158
Fix types
alesan99 Jun 3, 2025
c695c66
Add error message for attempting to link already linked atts
alesan99 Jun 3, 2025
72075dd
Fix types
alesan99 Jun 3, 2025
ba47920
Update attachment column name
alesan99 Jun 4, 2025
66c5dd7
Remove unused string
alesan99 Jun 4, 2025
edc65e9
Limit attachment column width
alesan99 Jun 10, 2025
345241c
Lint code with ESLint and Prettier
alesan99 Jun 10, 2025
7d4e844
Fix error when adding new rows
alesan99 Jun 10, 2025
f09505b
Lint code with ESLint and Prettier
alesan99 Jun 10, 2025
a391516
Use sp types
alesan99 Jul 7, 2025
3aa8f2f
Use sp types
alesan99 Jul 7, 2025
6c95713
Lint code with ESLint and Prettier
alesan99 Jul 7, 2025
ac2672f
Update import
alesan99 Aug 20, 2025
e366a7e
Update import
alesan99 Aug 20, 2025
1e4ac7a
Fix missing type
alesan99 Aug 20, 2025
f32497a
Merge branch 'issue-6077' into issue-6600
alesan99 Aug 20, 2025
65511cf
Remove ATTACHMENT_COLUMN import
alesan99 Aug 20, 2025
5382daa
Merge branch 'issue-6600' into issue-6078
alesan99 Aug 20, 2025
8a9b266
Merge remote-tracking branch 'origin/main' into issue-6078
alesan99 Sep 1, 2025
d37807a
Lint code with ESLint and Prettier
alesan99 Sep 1, 2025
4ce8d72
Update api endpoint
alesan99 Sep 1, 2025
9cc313f
Lint code with ESLint and Prettier
alesan99 Sep 1, 2025
2998853
WIP add remove and move buttons
alesan99 Sep 1, 2025
6811df9
Lint code with ESLint and Prettier
alesan99 Sep 1, 2025
0cec515
Automatically save upon uploading attachments
alesan99 Sep 1, 2025
bba0eb7
Merge branch 'issue-6078' of https://github.com/specify/specify7 into…
alesan99 Sep 1, 2025
3376a9d
Lint code with ESLint and Prettier
alesan99 Sep 1, 2025
181e65c
WIP Prevent deleting row if it contains an attachment
alesan99 Sep 1, 2025
24ef417
Merge branch 'issue-6078' of https://github.com/specify/specify7 into…
alesan99 Sep 1, 2025
6c0b60f
Lint code with ESLint and Prettier
alesan99 Sep 1, 2025
27201ec
Refactor uploadAttachmentsToRow
alesan99 Sep 2, 2025
88dd7ca
Lint code with ESLint and Prettier
alesan99 Sep 2, 2025
2d57f3f
WIP add deleteAttachmentsFromRow
alesan99 Sep 2, 2025
7cfeae1
Merge branch 'issue-6078' of https://github.com/specify/specify7 into…
alesan99 Sep 2, 2025
a112beb
Remove attachments visually from row
alesan99 Sep 3, 2025
a3a0c07
WIP Add attachment switching to preview dialog
alesan99 Sep 3, 2025
063279b
Allow deleting the latest attachment only
alesan99 Sep 4, 2025
e154489
Fix loading
alesan99 Sep 4, 2025
a9ffc6c
Lint code with ESLint and Prettier
alesan99 Sep 4, 2025
f8daaa3
WIP Delete attachment file when removed from row
alesan99 Sep 4, 2025
4efedad
Merge branch 'issue-6078' of https://github.com/specify/specify7 into…
alesan99 Sep 8, 2025
0ac69f6
Fix error with possible missing attachments
alesan99 Sep 8, 2025
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
61 changes: 38 additions & 23 deletions specifyweb/frontend/js_src/lib/components/WbActions/WbSave.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,34 @@ import { loadingBar } from '../Molecules';
import { Dialog } from '../Molecules/Dialog';
import type { Workbench } from '../WorkBench/WbView';

export const handleWorkbenchSave = async (
workbench: Workbench,
searchRef: React.MutableRefObject<HTMLInputElement | null>,
checkDeletedFail: (statusCode: number) => void,
handleSpreadsheetUpToDate: () => void,
) => {
// Clear validation
overwriteReadOnly(workbench.dataset, 'rowresults', null);
workbench.validation.stopLiveValidation();

// Send data
ping(`/api/workbench/rows/${workbench.dataset.id}/`, {
method: 'PUT',
body: workbench.data,
expectedErrors: [Http.NO_CONTENT, Http.NOT_FOUND],
})
.then((status) => checkDeletedFail(status))
.then(() => {
handleSpreadsheetUpToDate();
workbench.cells.cellMeta = [];
workbench.utils?.searchCells(
{ key: 'SettingsChange' },
searchRef.current
);
workbench.hot?.render();
});
};

export function WbSave({
workbench,
hasUnsavedChanges,
Expand All @@ -28,32 +56,19 @@ export function WbSave({
const [showProgressBar, openProgressBar, closeProgressBar] =
useBooleanState();

const handleSave = () => {
// Clear validation
overwriteReadOnly(workbench.dataset, 'rowresults', null);
workbench.validation.stopLiveValidation();

const handleSave = async (): Promise<void> => {
// Show saving progress bar
openProgressBar();

// Send data
ping(`/api/workbench/rows/${workbench.dataset.id}/`, {
method: 'PUT',
body: workbench.data,
expectedErrors: [Http.NO_CONTENT, Http.NOT_FOUND],
})
.then((status) => checkDeletedFail(status))
.then(() => {
handleSpreadsheetUpToDate();
workbench.cells.cellMeta = [];
workbench.utils?.searchCells(
{ key: 'SettingsChange' },
searchRef.current
);
workbench.hot?.render();
closeProgressBar();
});
};
await handleWorkbenchSave(
workbench,
searchRef,
checkDeletedFail,
handleSpreadsheetUpToDate,
);

closeProgressBar();
}

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { serializeResource } from '../DataModel/serializers';
import type { Attachment } from '../DataModel/types';
import { Dialog, dialogClassNames } from '../Molecules/Dialog';
import { NotFoundView } from '../Router/NotFoundView';
import { Slider } from '../FormSliders/Slider';

const { parseCacheKey } = exportsForTests;

Expand Down Expand Up @@ -131,6 +132,13 @@ export function WbAttachmentViewerView(): JSX.Element {
header={attachmentsText.attachments()}
headerButtons={
<div className="flex items-center gap-2 md:gap-2 ml-auto">
<Slider
value={selectedAttachment}
count={attachmentIds?.length ?? 1}
onChange={(newValue: number) => {
setSelectedAttachment(newValue)
}}
/>
<Button.Secondary
onClick={(): void => {
removeCache('workBenchAttachmentViewer', viewerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,15 @@ import { useNavigate } from 'react-router-dom';
import { useBooleanState } from '../../hooks/useBooleanState';
import { attachmentsText } from '../../localization/attachments';
import { commonText } from '../../localization/common';
import { ajax } from '../../utils/ajax';
import { f } from '../../utils/functools';
import type { RA } from '../../utils/types';
import { Container, H2 } from '../Atoms';
import { Progress } from '../Atoms';
import { Button } from '../Atoms/Button';
import { uploadFile } from '../Attachments/attachments';
import type { SerializedRecord } from '../DataModel/helperTypes';
import type { SpecifyResource } from '../DataModel/legacyTypes';
import {
deserializeResource,
serializeResource,
} from '../DataModel/serializers';
import { tables } from '../DataModel/tables';
import type {
Attachment,
Spdataset,
SpDataSetAttachment,
} from '../DataModel/types';
import { raise } from '../Errors/Crash';
import { useMenuItem } from '../Header/MenuContext';
import { userInformation } from '../InitialContext/userInformation';
Expand All @@ -42,6 +32,9 @@ import {
ATTACHMENTS_COLUMN,
attachmentsToCell,
BASE_TABLE_NAME,
uploadFiles,
createDataSetAttachments,
saveDataSetAttachments,
} from '../WorkBench/attachmentHelpers';

export function WbImportAttachmentsView(): JSX.Element {
Expand All @@ -65,58 +58,6 @@ export function WbImportAttachmentsView(): JSX.Element {
);
}

function uploadFiles(
files: RA<File>,
handleProgress: (progress: (progress: number | undefined) => number) => void
): RA<Promise<SpecifyResource<Attachment>>> {
return files.map(async (file) =>
uploadFile(file)
.then(async (attachment) =>
attachment === undefined
? Promise.reject(`Upload failed for file ${file.name}`)
: attachment
)
.finally(() =>
handleProgress((progress) =>
typeof progress === 'number' ? progress + 1 : 1
)
)
);
}

async function createDataSetAttachments(
attachments: RA<SpecifyResource<Attachment>>,
dataSet: SpecifyResource<Spdataset>
): Promise<RA<SpecifyResource<SpDataSetAttachment>>> {
return Promise.all(
attachments.map(
(attachment) =>
new tables.SpDataSetAttachment.Resource({
attachment: attachment as never,
spdataset: dataSet.url(),
ordinal: 0,
})
)
);
}

async function saveDataSetAttachments(
dataSetAttachments: RA<SpecifyResource<SpDataSetAttachment>>
): Promise<RA<SpecifyResource<SpDataSetAttachment>>> {
return ajax<RA<SerializedRecord<SpDataSetAttachment>>>(
`/bulk_copy/bulk/${tables.SpDataSetAttachment.name.toLowerCase()}/`,
{
method: 'POST',
headers: { Accept: 'application/json' },
body: dataSetAttachments.map((dataSetAttachment) =>
serializeResource(dataSetAttachment)
),
}
).then(({ data }) =>
data.map((resource) => deserializeResource(serializeResource(resource)))
);
}

function FilesPicked({ files }: { readonly files: RA<File> }): JSX.Element {
const navigate = useNavigate();
const [fileUploadProgress, setFileUploadProgress] = React.useState<
Expand Down
Loading