Skip to content

Commit 45c17ae

Browse files
committed
Open interaction dialog when adding prep in ExchangeOut
Fixes #922
1 parent 58ab2b2 commit 45c17ae

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

specifyweb/frontend/js_src/lib/components/FormSliders/IntegratedRecordSelector.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { useAllSaveBlockers } from '../DataModel/saveBlockers';
1515
import type { Collection } from '../DataModel/specifyTable';
1616
import type {
1717
DisposalPreparation,
18+
ExchangeOutPrep,
1819
GiftPreparation,
1920
LoanPreparation,
2021
} from '../DataModel/types';
@@ -101,9 +102,12 @@ export function IntegratedRecordSelector({
101102
typeof relationship === 'object' &&
102103
relationshipIsToMany(relationship) &&
103104
typeof collection.related === 'object' &&
104-
['LoanPreparation', 'GiftPreparation', 'DisposalPreparation'].includes(
105-
relationship.relatedTable.name
106-
);
105+
[
106+
'LoanPreparation',
107+
'GiftPreparation',
108+
'DisposalPreparation',
109+
'ExchangeOutPrep',
110+
].includes(relationship.relatedTable.name);
107111

108112
const [isDialogOpen, handleOpenDialog, handleCloseDialog] = useBooleanState();
109113

@@ -148,7 +152,10 @@ export function IntegratedRecordSelector({
148152
actionTable={collection.related.specifyTable}
149153
itemCollection={
150154
collection as Collection<
151-
DisposalPreparation | GiftPreparation | LoanPreparation
155+
| DisposalPreparation
156+
| GiftPreparation
157+
| LoanPreparation
158+
| ExchangeOutPrep
152159
>
153160
}
154161
onClose={handleCloseDialog}

specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import type { Collection, SpecifyTable } from '../DataModel/specifyTable';
3232
import { tables } from '../DataModel/tables';
3333
import type {
3434
DisposalPreparation,
35+
ExchangeOutPrep,
3536
Gift,
3637
GiftPreparation,
3738
LoanPreparation,
@@ -58,7 +59,7 @@ export function InteractionDialog({
5859
readonly actionTable: SpecifyTable;
5960
readonly isLoanReturn?: boolean;
6061
readonly itemCollection?: Collection<
61-
DisposalPreparation | GiftPreparation | LoanPreparation
62+
DisposalPreparation | GiftPreparation | LoanPreparation | ExchangeOutPrep
6263
>;
6364
}): JSX.Element {
6465
const itemTable = isLoanReturn ? tables.Loan : tables.CollectionObject;

specifyweb/frontend/js_src/lib/components/Interactions/InteractionsDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export const interactionWorkflowTables: Partial<
3434
Loan: 'CollectionObject',
3535
Gift: 'CollectionObject',
3636
Disposal: 'CollectionObject',
37+
ExchangeOut: 'Preparation',
3738
/*
38-
* ExchangeOut: 'Preparation',
3939
* InfoRequest: 'CollectionObject',
4040
*/
4141
};

specifyweb/frontend/js_src/lib/components/Interactions/PrepDialog.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import { strictGetTable, tables } from '../DataModel/tables';
2121
import type {
2222
Disposal,
2323
DisposalPreparation,
24+
ExchangeOut,
25+
ExchangeOutPrep,
2426
Gift,
2527
GiftPreparation,
2628
Loan,
@@ -38,9 +40,9 @@ export function PrepDialog({
3840
}: {
3941
readonly onClose: () => void;
4042
readonly preparations: RA<PreparationData>;
41-
readonly table: SpecifyTable<Disposal | Gift | Loan>;
43+
readonly table: SpecifyTable<Disposal | Gift | Loan | ExchangeOut>;
4244
readonly itemCollection?: Collection<
43-
DisposalPreparation | GiftPreparation | LoanPreparation
45+
DisposalPreparation | GiftPreparation | LoanPreparation | ExchangeOutPrep
4446
>;
4547
}): JSX.Element {
4648
const preparations = React.useMemo(() => {
@@ -152,10 +154,15 @@ export function PrepDialog({
152154
<Form
153155
id={id('form')}
154156
onSubmit={(): void => {
155-
const itemTable = strictGetTable(
156-
`${table.name}Preparation`
157-
) as SpecifyTable<
158-
DisposalPreparation | GiftPreparation | LoanPreparation
157+
const tableName =
158+
table.name === 'ExchangeOut'
159+
? `${table.name}Prep`
160+
: `${table.name}Preparation`;
161+
const itemTable = strictGetTable(tableName) as SpecifyTable<
162+
| DisposalPreparation
163+
| GiftPreparation
164+
| LoanPreparation
165+
| ExchangeOutPrep
159166
>;
160167
const items = filterArray(
161168
preparations.map((preparation, index) => {
@@ -192,6 +199,10 @@ export function PrepDialog({
192199
'disposalPreparations',
193200
items as RA<SpecifyResource<DisposalPreparation>>
194201
);
202+
toTable(interaction, 'ExchangeOut')?.set(
203+
'exchangeOutPreps',
204+
items as RA<SpecifyResource<ExchangeOutPrep>>
205+
);
195206
navigate(getResourceViewUrl(table.name, undefined), {
196207
state: {
197208
type: 'RecordSet',

0 commit comments

Comments
 (0)