Skip to content

Commit

Permalink
Merge branch 'main' into fix/1704-seedlots-not-updating-bv-values-cor…
Browse files Browse the repository at this point in the history
…rectly
  • Loading branch information
mgaseta authored Nov 19, 2024
2 parents e56d781 + 9017ecd commit 6b6da44
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,4 @@ schemaspy/output
# local testing
*.bat

oracle-api/config
oracle-api/config
1 change: 1 addition & 0 deletions frontend/src/components/ClientAndCodeInput/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type ClientAndCodeInputProps = {
readOnly?: boolean,
maxInputColSize?: number,
checkBoxInput?: BooleanInputType
shouldSelectDefaultValue?: boolean
}

export default ClientAndCodeInputProps;
27 changes: 17 additions & 10 deletions frontend/src/components/ClientAndCodeInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import './styles.scss';
const ClientAndCodeInput = ({
checkboxId, clientInput, locationCodeInput, textConfig, defaultClientNumber,
defaultLocCode, setClientAndCode, readOnly, showCheckbox, maxInputColSize,
checkBoxInput
checkBoxInput, shouldSelectDefaultValue = false
}: ClientAndCodeInputProps) => {
const getIsDefaultVal = () => (
checkBoxInput === undefined
Expand All @@ -38,9 +38,16 @@ const ClientAndCodeInput = ({
const clientInputRef = useRef<HTMLInputElement>(null);
const locCodeInputRef = useRef<HTMLInputElement>(null);
const [isDefault, setIsDefault] = useState<boolean>(
() => getIsDefaultVal()
!shouldSelectDefaultValue ? false : () => getIsDefaultVal()
);

const [isChecked, setIsChecked] = useState<boolean>(() => {
if (!shouldSelectDefaultValue) {
return false;
}
return checkBoxInput ? checkBoxInput.value : isDefault;
});

const [showClientValidationStatus, setShowClientValidationStatus] = useState<boolean>(true);

const [showLocCodeValidationStatus, setShowLocCodeValidationStatus] = useState<boolean>(false);
Expand All @@ -60,7 +67,9 @@ const ClientAndCodeInput = ({
useEffect(() => {
const areValsDefault = getIsDefaultVal();

setIsDefault(areValsDefault);
if (shouldSelectDefaultValue) {
setIsDefault(areValsDefault);
}

// Do not show validation status if isDefault is true
if (areValsDefault) {
Expand Down Expand Up @@ -223,10 +232,8 @@ const ClientAndCodeInput = ({
}
: undefined
);

if (!checkBoxInput) {
setIsDefault(checked);
}
setIsDefault(checked);
setIsChecked(checked);
};

const [openAgnTooltip, setOpenAgnTooltip] = useState<boolean>(false);
Expand Down Expand Up @@ -343,7 +350,7 @@ const ClientAndCodeInput = ({
name={textConfig.useDefaultCheckbox.name}
labelText={textConfig.useDefaultCheckbox.labelText}
readOnly={readOnly}
checked={checkBoxInput ? checkBoxInput.value : isDefault}
checked={isChecked}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
handleDefaultCheckBox(e.target.checked);
}}
Expand All @@ -363,7 +370,7 @@ const ClientAndCodeInput = ({
id={clientInput.id}
autoCapitalize="on"
labelText={textConfig.agencyInput.titleText}
defaultValue={forestClientQuery.data?.acronym}
defaultValue={shouldSelectDefaultValue ? forestClientQuery.data?.acronym : ''}
helperText={
(readOnly || (showCheckbox && isDefault))
? null
Expand Down Expand Up @@ -406,7 +413,7 @@ const ClientAndCodeInput = ({
id={locationCodeInput.id}
ref={locCodeInputRef}
name={textConfig.locationCode.name}
defaultValue={locationCodeInput.value}
defaultValue={shouldSelectDefaultValue ? locationCodeInput.value : ''}
type="number"
maxCount={LOCATION_CODE_LIMIT}
enableCounter
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/LotApplicantAndInfoForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const LotApplicantAndInfoForm = ({
}
readOnly={isEdit}
maxInputColSize={6}
shouldSelectDefaultValue
/>
<Row className="agency-email-row">
<Column sm={4} md={8} lg={16} xlg={12}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ export const fieldsConfig = {
},
volumePerContainers: {
name: 'volumePerContainers',
labelText: 'Volume per Containers (HI)',
labelText: 'Volume per containers (hl)',
invalidText: 'Invalid entry. Number must be between 0 and 10,000 and up to 3 decimal places.'
},
volumeOfCones: {
name: 'volumeOfCones',
labelText: 'Volume of Cones (HI)',
labelText: 'Volume of cones (hl)',
invalidText: 'Number has more than 3 decimals.',
helperText: 'This value must be the "Volume per container" X "Number of containers".',
warnText: 'The total volume of cones does not equal, please note that this value must be the "Volume per container" x "Number of containers"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -929,15 +929,11 @@ export const isMissingSecondaryOrchard = (orchardStepData: OrchardForm): boolean
* Check if orchards selections are valid.
*/
export const areOrchardsValid = (orchardStepData: OrchardForm): boolean => {
let isValid = true;
const { orchards } = orchardStepData;

if (!orchards.primaryOrchard.value.code) {
isValid = false;
}
if (isMissingSecondaryOrchard(orchardStepData)) {
isValid = false;
return false;
}

return isValid;
return true;
};
6 changes: 3 additions & 3 deletions frontend/src/types/SeedlotType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ export type CollectionFormSubmitType = {
collectionLocnCode: string,
collectionStartDate: string,
collectionEndDate: string,
noOfContainers: number,
volPerContainer: number,
clctnVolume: number,
noOfContainers: string,
volPerContainer: string,
clctnVolume: string,
seedlotComment: string,
coneCollectionMethodCodes: Array<number>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ export const emptyCollectionStep: CollectionFormSubmitType = {
collectionLocnCode: '',
collectionStartDate: '',
collectionEndDate: '',
noOfContainers: 1,
volPerContainer: 1,
clctnVolume: 1,
noOfContainers: '',
volPerContainer: '',
clctnVolume: '',
seedlotComment: '',
coneCollectionMethodCodes: []
};
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/views/Seedlot/ContextContainerClassA/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,9 +852,9 @@ export const convertCollection = (collectionData: CollectionForm): CollectionFor
// Assume the date values are present as validation has occurred before payload is generated
collectionStartDate: localDateToUtcFormat(collectionData.startDate.value)!,
collectionEndDate: localDateToUtcFormat(collectionData.endDate.value)!,
noOfContainers: +collectionData.numberOfContainers.value,
volPerContainer: +collectionData.volumePerContainers.value,
clctnVolume: +collectionData.volumeOfCones.value,
noOfContainers: `${+collectionData.numberOfContainers.value}`,
volPerContainer: `${+collectionData.volumePerContainers.value}`,
clctnVolume: `${+collectionData.volumeOfCones.value}`,
seedlotComment: collectionData.comments.value,
coneCollectionMethodCodes: collectionData
.selectedCollectionCodes.value.map((code) => parseInt(code, 10))
Expand Down

0 comments on commit 6b6da44

Please sign in to comment.