Skip to content

Commit

Permalink
Merge pull request #3659 from specify/issue-2135-b
Browse files Browse the repository at this point in the history
Allow to add preparations in loan form
  • Loading branch information
CarolineDenis authored Jul 3, 2023
2 parents b0b15f7 + ef72f0b commit 4ad26fd
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 255 deletions.

This file was deleted.

54 changes: 11 additions & 43 deletions specifyweb/frontend/js_src/lib/components/FormCells/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { ReadOnlyContext, SearchDialogContext } from '../Core/Contexts';
import type { AnySchema } from '../DataModel/helperTypes';
import type { SpecifyResource } from '../DataModel/legacyTypes';
import { resourceOn } from '../DataModel/resource';
import type { Collection } from '../DataModel/specifyTable';
import { tables } from '../DataModel/tables';
import { softFail } from '../Errors/Crash';
import { fetchPathAsString } from '../Formatters/formatters';
Expand All @@ -25,8 +24,6 @@ import { SpecifyForm } from '../Forms/SpecifyForm';
import { SubView } from '../Forms/SubView';
import { propsToFormMode } from '../Forms/useViewDefinition';
import { TableIcon } from '../Molecules/TableIcon';
import { relationshipIsToMany } from '../WbPlanView/mappingHelpers';
import { FormTableInteraction } from './FormTableInteraction';

const cellRenderers: {
readonly [KEY in keyof CellTypes]: (props: {
Expand Down Expand Up @@ -147,54 +144,25 @@ const cellRenderers: {
false
);

const [interactionCollection] = useAsyncState<
Collection<AnySchema> | false
>(
React.useCallback(
async () =>
typeof relationship === 'object' &&
relationshipIsToMany(relationship) &&
typeof data?.resource === 'object' &&
[
'LoanPreparation',
'GiftPreparation',
'DisposalPreparation',
].includes(relationship.relatedTable.name)
? data?.resource.rgetCollection(relationship.name)
: false,
[relationship, data?.resource]
),
false
);
if (
relationship === undefined ||
data?.resource === undefined ||
interactionCollection === undefined ||
actualFormType === undefined
)
return null;

return (
<ReadOnlyContext.Provider value={isReadOnly}>
{interactionCollection === false || actualFormType === 'form' ? (
<SubView
formType={actualFormType}
icon={icon}
isButton={isButton}
parentFormType={parentFormType}
parentResource={data.resource}
relationship={relationship}
sortField={sortField}
viewName={viewName}
/>
) : (
<FormTableInteraction
collection={interactionCollection}
dialog={false}
sortField={sortField}
onClose={f.never}
onDelete={undefined}
/>
)}
<SubView
formType={actualFormType}
icon={icon}
isButton={isButton}
parentFormType={parentFormType}
parentResource={data.resource}
relationship={relationship}
sortField={sortField}
viewName={viewName}
/>
</ReadOnlyContext.Provider>
);
},
Expand Down
Loading

0 comments on commit 4ad26fd

Please sign in to comment.