Skip to content

Commit

Permalink
fix: fix map center point when no org unit
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikmv committed Dec 9, 2024
1 parent 0a9847d commit 3274b43
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
7 changes: 5 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-12-08T13:28:49.327Z\n"
"PO-Revision-Date: 2024-12-08T13:28:49.327Z\n"
"POT-Creation-Date: 2024-12-09T14:19:09.122Z\n"
"PO-Revision-Date: 2024-12-09T14:19:09.122Z\n"

msgid "Choose one or more dates..."
msgstr "Choose one or more dates..."
Expand Down Expand Up @@ -1270,6 +1270,9 @@ msgstr "organisation unit could not be retrieved. Please try again later."
msgid "Saving to {{stageName}} for {{programName}} in {{orgUnitName}}"
msgstr "Saving to {{stageName}} for {{programName}} in {{orgUnitName}}"

msgid "Saving to {{stageName}} for {{programName}}"
msgstr "Saving to {{stageName}} for {{programName}}"

msgid "program or stage is invalid"
msgstr "program or stage is invalid"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ const convertToClientCoordinates = ({ coordinates, type }: { coordinates: any[],

const getCenterPoint = (InnerComponent: ComponentType<any>) => (props: Object) => {
const { orgUnit, ...passOnProps } = props;
const [orgUnitKey, setOrgUnitKey] = useState(orgUnit?.id);
if (!orgUnit || !orgUnit.id) {
return <InnerComponent {...passOnProps} center={DEFAULT_CENTER} onOpenMap={() => {}} />;
}
const [orgUnitKey, setOrgUnitKey] = useState(orgUnit.id);
const [shouldFetch, setShouldFetch] = useState(false);
const queryKey = ['organisationUnit', 'geometry', orgUnitKey];
const queryFn = {
Expand All @@ -28,8 +31,8 @@ const getCenterPoint = (InnerComponent: ComponentType<any>) => (props: Object) =
},
};
const queryOptions = useMemo(
() => ({ enabled: Boolean(orgUnit?.id) && shouldFetch }),
[shouldFetch, orgUnit?.id],
() => ({ enabled: Boolean(orgUnit.id) && shouldFetch }),
[shouldFetch, orgUnit.id],
);
const { data } = useApiMetadataQuery<any>(queryKey, queryFn, queryOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import type { Props } from './savingText.types';
export const SavingText = ({ orgUnitName, stageName, programName }: Props) => (
<InfoIconText>
<span>
{i18n.t('Saving to {{stageName}} for {{programName}} in {{orgUnitName}}',
{ orgUnitName, stageName, programName, interpolation: { escapeValue: false } })}
{orgUnitName
? i18n.t('Saving to {{stageName}} for {{programName}} in {{orgUnitName}}',
{ orgUnitName, stageName, programName, interpolation: { escapeValue: false } })
: i18n.t('Saving to {{stageName}} for {{programName}}',
{ stageName, programName, interpolation: { escapeValue: false } })}
</span>
</InfoIconText>
);
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const WidgetEventSchedulePlain = ({
setScheduledOrgUnit(undefined);
};


return (
<Widget
noncollapsible
Expand All @@ -73,23 +72,20 @@ const WidgetEventSchedulePlain = ({
dataTest="schedule-section"
sectionName={i18n.t('Schedule info')}
>
<div className={classes.test}>
<ScheduleOrgUnit
orgUnit={orgUnit}
onSelectOrgUnit={onSelectOrgUnit}
onDeselectOrgUnit={onDeselectOrgUnit}
{...passOnProps}
/>
<ScheduleDate
programId={programId}
stageId={stageId}
orgUnit={orgUnit}
scheduleDate={scheduleDate}
serverSuggestedScheduleDate={serverSuggestedScheduleDate}
{...passOnProps}
/>
</div>

<ScheduleOrgUnit
orgUnit={orgUnit}
onSelectOrgUnit={onSelectOrgUnit}
onDeselectOrgUnit={onDeselectOrgUnit}
{...passOnProps}
/>
<ScheduleDate
programId={programId}
stageId={stageId}
orgUnit={orgUnit}
scheduleDate={scheduleDate}
serverSuggestedScheduleDate={serverSuggestedScheduleDate}
{...passOnProps}
/>
</DataSection>
{programCategory && <DataSection
dataTest="category-options-section"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,14 @@ export const WidgetEventSchedule = ({
const { programStageScheduleConfig } = useScheduleConfigFromProgramStage(stageId);
const { programConfig } = useScheduleConfigFromProgram(programId);
const suggestedScheduleDate = useDetermineSuggestedScheduleDate({
programStageScheduleConfig,
programConfig,
initialScheduleDate,
...passOnProps,
programStageScheduleConfig, programConfig, initialScheduleDate, ...passOnProps,
});
const orgUnit = useOrgUnitNameWithAncestors(initialOrgUnitId);
const orgUnitInitial = initialOrgUnitId && orgUnit?.displayName
? { id: initialOrgUnitId, name: orgUnit.displayName } : undefined;
const orgUnitData = useOrgUnitNameWithAncestors(initialOrgUnitId);
const orgUnit = initialOrgUnitId && orgUnitData
? { id: initialOrgUnitId, name: orgUnitData.displayName } : undefined;
const { currentUser, noteId } = useNoteDetails();
const [scheduleDate, setScheduleDate] = useState('');
const [scheduledOrgUnit, setScheduledOrgUnit] = useState(orgUnitInitial);
const [scheduledOrgUnit, setScheduledOrgUnit] = useState(orgUnit);
const convertFn = pipe(convertFormToClient, convertClientToServer);
const serverScheduleDate = convertFn(scheduleDate, dataElementTypes.DATE);
const serverSuggestedScheduleDate = convertFn(suggestedScheduleDate, dataElementTypes.DATE);
Expand All @@ -66,9 +63,7 @@ export const WidgetEventSchedule = ({
const [categoryOptionsError, setCategoryOptionsError] = useState();
const { programCategory } = useCategoryCombinations(programId);
useEffect(() => {
if (!scheduleDate && suggestedScheduleDate) {
setScheduleDate(suggestedScheduleDate);
}
if (!scheduleDate && suggestedScheduleDate) { setScheduleDate(suggestedScheduleDate); }
}, [suggestedScheduleDate, scheduleDate]);

useEffect(() => {
Expand Down

0 comments on commit 3274b43

Please sign in to comment.