Skip to content
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

fix: historical sub to pnd and utc date #1516

Merged
merged 6 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public final class Constants {
public static final Integer CLASS_A_SEEDLOT_NUM_MAX = 69999;
public static final String INCOMPLETE_SEEDLOT_STATUS = "INC";
public static final String PENDING_SEEDLOT_STATUS = "PND";
public static final String SUBMITTED_SEEDLOT_STATUS = "SUB";
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public RevisionCountDto saveFormClassA(

SaveSeedlotProgressEntityClassA entityToSave;
// If an entity exist then update the values, otherwise make a new entity.
// The SUB status check is to create a draft for historical Oracle seedlots.
if (optionalEntityToSave.isEmpty()) {
SparLog.info(
"First time saving A-class seedlot progress for seedlot number {}", seedlotNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,18 +591,23 @@ public SeedlotAclassFormDto getAclassSeedlotFormInfo(@NonNull String seedlotNumb
List<SeedlotOrchard> seedlotOrchards =
seedlotOrchardService.getAllSeedlotOrchardBySeedlotNumber(seedlotInfo.getId());

List<SeedlotOrchard> filteredPrimaryOrchard =
seedlotOrchards.stream().filter(so -> so.getIsPrimary()).toList();

String primaryOrchardId =
filteredPrimaryOrchard.isEmpty()
? filteredPrimaryOrchard.get(0).getOrchardId()
: seedlotOrchards.get(0).getOrchardId();

Optional<String> secondaryOrchardId =
seedlotOrchards.size() > 1
? Optional.of(seedlotOrchards.get(1).getOrchardId())
: Optional.empty();
String primaryOrchardId = null;

if (!seedlotOrchards.isEmpty()) {
List<SeedlotOrchard> filteredPrimaryOrchard =
seedlotOrchards.stream().filter(so -> so.getIsPrimary()).toList();

primaryOrchardId =
filteredPrimaryOrchard.isEmpty()
? null
: filteredPrimaryOrchard.get(0).getOrchardId();
}

Optional<String> secondaryOrchardId = Optional.empty();

if (seedlotOrchards.size() > 1 && !seedlotOrchards.get(1).getIsPrimary()) {
secondaryOrchardId = Optional.of(seedlotOrchards.get(1).getOrchardId());
}

SeedlotFormOrchardDto orchardStep =
new SeedlotFormOrchardDto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const InterimReviewRead = () => {
cacheTime: THREE_HALF_HOURS
});

const getFacilityTypeLabel = (interimType: string) => {
if (facilityTypesQuery.data) {
const getFacilityTypeLabel = (interimType: string | null) => {
if (facilityTypesQuery.data && interimType) {
const selectedType = facilityTypesQuery.data.filter((type) => type.code === interimType);
return selectedType[0].label;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const OrchardReviewRead = () => {
<ReadOnlyInput
id="orchard-female-gametic"
label="Female gametic contribution methodology"
value={state.femaleGametic.value.label}
value={state.femaleGametic.value?.label}
showSkeleton={isFetchingData}
/>
</Column>
Expand All @@ -74,7 +74,7 @@ const OrchardReviewRead = () => {
<ReadOnlyInput
id="orchard-male-gametic"
label="Male gametic contribution methodology"
value={state.maleGametic.value.label}
value={state.maleGametic.value?.label}
showSkeleton={isFetchingData}
/>
</Column>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types/SeedlotType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export type InterimFormSubmitType = {
}

export type OrchardFormSubmitType = {
primaryOrchardId: string,
primaryOrchardId: string | null,
secondaryOrchardId: string | null,
femaleGameticMthdCode: string,
maleGameticMthdCode: string,
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/utils/DateUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DateTime as luxon } from 'luxon';
import { PLACE_HOLDER } from '../shared-constants/shared-constants';
import { MONTH_DAY_YEAR, ISO_YEAR_MONTH_DAY_DASH, ISO_YEAR_MONTH_DAY_SLASH } from '../config/DateFormat';
import { MONTH_DAY_YEAR, ISO_YEAR_MONTH_DAY_SLASH, ISO_YEAR_MONTH_DAY_DASH } from '../config/DateFormat';

const DEFAULT_LOCAL_TIMEZONE = 'America/Vancouver';

Expand Down Expand Up @@ -33,7 +33,7 @@ export const utcToIsoSlashStyle = (utcDate: string | null | undefined): string =
if (!utcDate) {
return '';
}
return luxon.fromISO(utcDate, { zone: 'utc' })
return luxon.fromISO(utcDate)
.setZone(DEFAULT_LOCAL_TIMEZONE).toFormat(ISO_YEAR_MONTH_DAY_SLASH);
};

Expand All @@ -44,6 +44,6 @@ export const localDateToUtcFormat = (localDate: string): string | null => {
if (!localDate) {
return null;
}
return luxon.fromFormat(localDate, 'yyyy/MM/dd', { zone: 'America/Vancouver' })
.toUTC().toFormat(ISO_YEAR_MONTH_DAY_DASH);
return luxon.fromFormat(localDate, 'yyyy/MM/dd', { zone: DEFAULT_LOCAL_TIMEZONE })
.startOf('day').toUTC().toFormat(ISO_YEAR_MONTH_DAY_DASH);
};
54 changes: 28 additions & 26 deletions frontend/src/views/Seedlot/ContextContainerClassA/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const initCollectionState = (
},
locationCode: {
id: 'collection-location-code',
value: collectionStepData.collectionLocnCode,
value: collectionStepData.collectionLocnCode ?? '',
isInvalid: false
},
startDate: {
Expand All @@ -90,17 +90,17 @@ export const initCollectionState = (
},
numberOfContainers: {
id: 'collection-num-of-container',
value: String(collectionStepData.noOfContainers),
value: collectionStepData.noOfContainers?.toString() ?? '',
isInvalid: false
},
volumePerContainers: {
id: 'collection-vol-per-container',
value: String(collectionStepData.volPerContainer),
value: collectionStepData.volPerContainer?.toString() ?? '',
isInvalid: false
},
volumeOfCones: {
id: 'collection-vol-of-cones',
value: String(collectionStepData.clctnVolume),
value: collectionStepData.clctnVolume?.toString() ?? '',
isInvalid: false
},
selectedCollectionCodes: {
Expand All @@ -110,7 +110,7 @@ export const initCollectionState = (
},
comments: {
id: 'collection-comments',
value: collectionStepData.seedlotComment,
value: collectionStepData.seedlotComment ?? '',
isInvalid: false
}
});
Expand All @@ -125,14 +125,16 @@ export const initOwnershipState = (
const ownerState = createOwnerTemplate(index, curOwner);

ownerState.ownerAgency.value = defaultAgencyNumber;

ownerState.ownerCode.value = curOwner.ownerLocnCode;
if (methodsOfPayment && fundingSource) {

if (methodsOfPayment && methodsOfPayment.length > 0) {
const payment = methodsOfPayment
.filter((data: MultiOptionsObj) => data.code === curOwner.methodOfPaymentCode)[0];
ownerState.methodOfPayment.value = payment;
}
if (fundingSource && fundingSource.length > 0) {
const fundSource = fundingSource
.filter((data: MultiOptionsObj) => data.code === curOwner.sparFundSrceCode)[0];
ownerState.methodOfPayment.value = payment;
ownerState.fundingSource.value = fundSource;
}
return ownerState;
Expand All @@ -157,7 +159,7 @@ export const initInterimState = (
},
locationCode: {
id: 'interim-location-code',
value: interimStepData.intermStrgLocnCode,
value: interimStepData.intermStrgLocnCode ?? '',
isInvalid: false
},
startDate: {
Expand All @@ -172,12 +174,12 @@ export const initInterimState = (
},
facilityType: {
id: 'storage-facility-type',
value: interimStepData.intermFacilityCode,
value: interimStepData.intermFacilityCode ?? '',
isInvalid: false
},
facilityOtherType: {
id: 'storage-other-type-input',
value: interimStepData.intermOtherFacilityDesc,
value: interimStepData.intermOtherFacilityDesc ?? '',
isInvalid: false
}
});
Expand Down Expand Up @@ -346,7 +348,7 @@ export const initExtractionStorageState = (
},
locationCode: {
id: 'ext-location-code',
value: useTSCExtract ? tscLocationCode : extractionStepData.extractoryLocnCode,
value: useTSCExtract ? tscLocationCode : (extractionStepData.extractoryLocnCode ?? ''),
isInvalid: false
},
startDate: {
Expand All @@ -373,7 +375,7 @@ export const initExtractionStorageState = (
},
locationCode: {
id: 'str-location-code',
value: useTSCStorage ? tscLocationCode : extractionStepData.storageLocnCode,
value: useTSCStorage ? tscLocationCode : (extractionStepData.storageLocnCode ?? ''),
isInvalid: false
},
startDate: {
Expand Down Expand Up @@ -479,28 +481,28 @@ export const verifyCollectionStepCompleteness = (
let isComplete = true;
let idToFocus = '';

if (!collectionData.collectorAgency.value.length) {
if (!collectionData.collectorAgency.value) {
isComplete = false;
idToFocus = collectionData.collectorAgency.id;
} else if (!collectionData.locationCode.value.length) {
} else if (!collectionData.locationCode.value) {
isComplete = false;
idToFocus = collectionData.locationCode.id;
} else if (!collectionData.startDate.value.length) {
} else if (!collectionData.startDate.value) {
isComplete = false;
idToFocus = collectionData.startDate.id;
} else if (!collectionData.endDate.value.length) {
} else if (!collectionData.endDate.value) {
isComplete = false;
idToFocus = collectionData.endDate.id;
} else if (!collectionData.numberOfContainers.value.length) {
} else if (!collectionData.numberOfContainers.value) {
isComplete = false;
idToFocus = collectionData.numberOfContainers.id;
} else if (!collectionData.volumePerContainers.value.length) {
} else if (!collectionData.volumePerContainers.value) {
isComplete = false;
idToFocus = collectionData.volumePerContainers.id;
} else if (!collectionData.volumeOfCones.value.length) {
} else if (!collectionData.volumeOfCones.value) {
isComplete = false;
idToFocus = collectionData.volumeOfCones.id;
} else if (!collectionData.selectedCollectionCodes.value.length) {
} else if (!collectionData.selectedCollectionCodes.value) {
isComplete = false;
// Have to hard code id to focus as they are generated dynamically,
// assuming that there will always be a code 1 in the list of collection methods.
Expand All @@ -525,19 +527,19 @@ export const verifyOwnershipStepCompleteness = (
let idToFocus = '';

for (let i = 0; i < ownershipData.length; i += 1) {
if (!ownershipData[i].ownerAgency.value.length) {
if (!ownershipData[i].ownerAgency.value) {
isComplete = false;
idToFocus = ownershipData[i].ownerAgency.id;
} else if (!ownershipData[i].ownerCode.value.length) {
} else if (!ownershipData[i].ownerCode.value) {
isComplete = false;
idToFocus = ownershipData[i].ownerCode.id;
} else if (!ownershipData[i].ownerPortion.value.length) {
} else if (!ownershipData[i].ownerPortion.value) {
isComplete = false;
idToFocus = ownershipData[i].ownerPortion.id;
} else if (!ownershipData[i].reservedPerc.value.length) {
} else if (!ownershipData[i].reservedPerc.value) {
isComplete = false;
idToFocus = ownershipData[i].reservedPerc.id;
} else if (!ownershipData[i].surplusPerc.value.length) {
} else if (!ownershipData[i].surplusPerc.value) {
isComplete = false;
idToFocus = ownershipData[i].surplusPerc.id;
} else if (
Expand Down
Loading
Loading