-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent from carrying preps in interaction during cloning #4905
base: production
Are you sure you want to change the base?
Conversation
const interactionTablesWithPreps = [ | ||
'Disposal', | ||
'Loan', | ||
'Gift', | ||
'ExchangeIn', | ||
'ExchangeOut', | ||
'Borrow', | ||
] as const; | ||
type InteractionTable = typeof interactionTablesWithPreps[number]; | ||
const interactionTablesPrepsFieldName: RR<InteractionTable, string> = { | ||
Disposal: 'disposalPreparations', | ||
Loan: 'loanPreparations', | ||
Gift: 'giftPreparations', | ||
ExchangeOut: 'exchangeOutPreps', | ||
ExchangeIn: 'exchangeInPreps', | ||
Borrow: 'borrowPreparations', | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need to hardcode this list?
imagine someone adding a new table - how would they know that this place in the code might need to be modified before the table is added or else a bug is introduced???
that is why you should avoid hardcoding things and creating edge cases where possible - instead compute things on the fly
could you please dynamically construct it on the fly (i.e if field name is a relationship to the Preparations table, then don't clone it)
the only exception to computing things on the fly is when doing so is computationally expensive - but in those cases, you should add a test case that will do the computation to make sure the hardcoded list is not out of date with the dynamically computed list
(i.e front-end stores a hardcoed list of all the permission policies that sp7 back-end defines so as not to have to fetch those from the back-end on each app load - yet, when in development, it will make sure that the hardcoded list stored on the front-end matches exactly what back-end provides)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at the changes made in #4805: there is code to get the main Interaction tables which have preparations:
specify7/specifyweb/frontend/js_src/lib/components/Interactions/helpers.ts
Lines 20 to 26 in 5638811
export type InteractionWithPreps = Tables[ExtractInteraction< | |
AnyInteractionPreparation['tableName'] | |
>]; | |
export const interactionsWithPrepTables: RestrictedTuple< | |
InteractionWithPreps['tableName'] | |
> = ['Disposal', 'ExchangeIn', 'ExchangeOut', 'Gift', 'Loan']; |
This code relies on a dynamically generated type which already exists on the frontend called AnyInteractionPreparation
:
specify7/specifyweb/frontend/js_src/lib/components/DataModel/helperTypes.ts
Lines 58 to 69 in 3fb636e
export type AnyInteractionPreparation = Extract< | |
ValueOf<Tables>, | |
{ | |
readonly fields: { | |
readonly quantity: number | null; | |
}; | |
} & { | |
readonly toOneIndependent: { | |
readonly preparation: Preparation | null; | |
}; | |
} | |
>; |
#4805 also has examples of using/getting the relationship from Interaction -> InteractionPreparation:
specify7/specifyweb/frontend/js_src/lib/components/Interactions/PrepDialog.tsx
Lines 234 to 241 in 5638811
const preparationRelationship = defined( | |
interaction.specifyTable.relationships.find((relationship) => | |
interactionPrepTables.includes( | |
(relationship.relatedTable as SpecifyTable<AnyInteractionPreparation>) | |
.name | |
) | |
) | |
); |
const uniqueFields = getUniqueFields(table); | ||
if ( | ||
interactionTablesWithPreps.includes(table.name as InteractionTable) && | ||
cloneAll |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you sure this logic should apply only in the cloneAll
cases?
it seems like it should apply in !cloneAll
case too...
NOTES: |
Fixes #4012
Checklist
and self-explanatory (or properly documented)
Testing instructions