Skip to content

Commit

Permalink
Merge pull request #1084 from IFRCGo/feature/presentation-mode-local-…
Browse files Browse the repository at this point in the history
…unit

Presentation Mode in Local unit map
  • Loading branch information
frozenhelium authored May 23, 2024
2 parents b560773 + 5a1ae43 commit c544e98
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/old-mirrors-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"go-web-app": patch
---

Add presentation mode in local units map
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"failedMessage": "Failed to add local unit",
"updateMessage": "Local unit updated successfully!",
"updateFailedMessage": "Failed to update local unit",
"healthCareDetails": "Health care details",
"subtype": "Sub-type",
"subtypeDescription": "(e.g. hospital)",
"englishLabel": "English",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ function LocalUnitsForm(props: Props) {
</Container>
{value.type === TYPE_HEALTH_CARE && (
<Container
heading="Health care details"
heading={strings.healthCareDetails}
withHeaderBorder
contentViewType="vertical"
childrenContainerClassName={styles.healthCareDetailsContent}
Expand Down Expand Up @@ -982,22 +982,22 @@ function LocalUnitsForm(props: Props) {
error={healthFormError?.other_profiles}
/>
</LocalUnitInputSection>
<LocalUnitInputSection
title={strings.commentsNS}
numPreferredColumns={1}
>
<TextArea
name="feedback"
value={value.health?.feedback}
onChange={onHealthFieldChange}
readOnly={readOnly}
error={getErrorString(
healthFormError?.feedback,
)}
/>
</LocalUnitInputSection>
</Container>
)}
<Container
heading={strings.commentsNS}
withHeaderBorder
>
<TextArea
name="feedback"
value={value.health?.feedback}
onChange={onHealthFieldChange}
readOnly={readOnly}
error={getErrorString(
healthFormError?.feedback,
)}
/>
</Container>
</Container>
{!readOnly
&& isDefined(submitButtonContainerRef)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const schema: LocalUnitsFormSchema = {
required: true,
},
date_of_data: { required: true },
source_loc: {},
source_en: {},
address_en: {
validations: [lengthSmallerThanCondition(200)],
Expand Down Expand Up @@ -153,11 +154,12 @@ const schema: LocalUnitsFormSchema = {
},
hospital_type: {},
specialized_medical_beyond_primary_level: { required: true },
primary_health_care_center: {},
other_services: {
validations: [lengthSmallerThanCondition(200)],
},
blood_services: { required: true },
professional_training_facilities: { forceValue: [] },
professional_training_facilities: { defaultValue: [] },
general_medical_services: { required: true },
speciality: {
validations: [lengthSmallerThanCondition(200)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"localUnitLocalUnitType": "Local Unit Type",
"localUnitHealthFacilityType": "Health Facility Type",
"localUnitLegendHealthCareTitle": "Health Care Local Units",
"presentationModeButton":"Presentation Mode",
"localUnitDetailEmail": "Email"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import react, { useMemo } from 'react';
import { useOutletContext } from 'react-router-dom';
import {
ArtboardLineIcon,
LocationIcon,
MailIcon,
} from '@ifrc-go/icons';
import {
Button,
Container,
LegendItem,
List,
Expand Down Expand Up @@ -99,7 +101,16 @@ function emailKeySelector(email: string) {
return email;
}

function LocalUnitsMap() {
interface Props {
onPresentationModeButtonClick?: () => void;
presentationMode?: boolean;
}

function LocalUnitsMap(props: Props) {
const {
onPresentationModeButtonClick,
presentationMode = false,
} = props;
const { countryResponse } = useOutletContext<CountryOutletContext>();

const {
Expand Down Expand Up @@ -347,7 +358,7 @@ function LocalUnitsMap() {
className={styles.localUnitsMap}
contentViewType="vertical"
withGridViewInFilter
filters={(
filters={!presentationMode && (
<Filters
value={rawFilter}
setFieldValue={setFilterField}
Expand Down Expand Up @@ -468,6 +479,17 @@ function LocalUnitsMap() {
</MapPopup>
)}
</BaseMap>
{onPresentationModeButtonClick && !presentationMode && (
<Button
className={styles.presentationModeButton}
name={undefined}
icons={<ArtboardLineIcon />}
onClick={onPresentationModeButtonClick}
variant="secondary"
>
{strings.presentationModeButton}
</Button>
)}
{hasContactDetails && (
<Container
className={styles.contactDetail}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
.map-container-with-contact-details {
position: relative;

.presentation-mode-button {
position: absolute;
top: var(--go-ui-spacing-md);
left: var(--go-ui-spacing-md);
}

.map-container {
height: 45rem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@ function LocalUnitsTableActions(props: Props) {
type="button"
name={localUnitId}
onClick={setShowLocalUnitViewModalTrue}
disabled={!hasValidatePermission}
>
{strings.localUnitsView}
</DropdownMenuItem>
<DropdownMenuItem
type="button"
name={localUnitId}
onClick={setShowLocalUnitEditModalTrue}
disabled={!hasValidatePermission}
>
{strings.localUnitsEdit}
</DropdownMenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"localUnitDetailType": "Type",
"localUnitsMapView": "Map view",
"localUnitsListView": "List view",
"addLocalUnitLabel": "Add a Local Unit"
"addLocalUnitLabel": "Add a Local Unit",
"closePresentationLabel": "Close"
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import {
useCallback,
useEffect,
useRef,
useState,
} from 'react';
import { useOutletContext } from 'react-router-dom';
import { CloseLineIcon } from '@ifrc-go/icons';
import {
Button,
Container,
IconButton,
Tab,
TabList,
TabPanel,
Expand All @@ -15,7 +19,11 @@ import {
useBooleanState,
useTranslation,
} from '@ifrc-go/ui/hooks';
import { _cs } from '@togglecorp/fujs';
import {
_cs,
isDefined,
isNotDefined,
} from '@togglecorp/fujs';

import useAuth from '#hooks/domain/useAuth';
import usePermissions from '#hooks/domain/usePermissions';
Expand All @@ -41,15 +49,36 @@ function NationalSocietyLocalUnits(props: Props) {
const { isAuthenticated } = useAuth();
const { countryResponse } = useOutletContext<CountryOutletContext>();
const { isSuperUser, isCountryAdmin } = usePermissions();
const containerRef = useRef<HTMLDivElement>(null);

// NOTE: key is used to refresh the page when local unit data is updated
const [localUnitUpdateKey, setLocalUnitUpdateKey] = useState(0);
const [
presentationMode,
setFullScreenMode,
] = useState(false);

const [showAddEditModal, {
setTrue: setShowAddEditModalTrue,
setFalse: setShowAddEditModalFalse,
}] = useBooleanState(false);

const handleFullScreenChange = useCallback(() => {
setFullScreenMode(isDefined(document.fullscreenElement));
}, [setFullScreenMode]);

const handleFullScreenToggleClick = useCallback(() => {
if (isNotDefined(containerRef.current)) {
return;
}
const { current: viewerContainer } = containerRef;
if (!presentationMode && isDefined(viewerContainer?.requestFullscreen)) {
viewerContainer?.requestFullscreen();
} else if (presentationMode && isDefined(document.exitFullscreen)) {
document.exitFullscreen();
}
}, [presentationMode]);

const handleLocalUnitFormModalClose = useCallback(
() => {
setShowAddEditModalFalse();
Expand All @@ -62,6 +91,14 @@ function NationalSocietyLocalUnits(props: Props) {

const hasAddLocalUnitPermission = isCountryAdmin(countryResponse?.id) || isSuperUser;

useEffect(() => {
document.addEventListener('fullscreenchange', handleFullScreenChange);

return (() => {
document.removeEventListener('fullscreenchange', handleFullScreenChange);
});
}, [handleFullScreenChange]);

return (
<Tabs
onChange={setActiveTab}
Expand Down Expand Up @@ -91,9 +128,27 @@ function NationalSocietyLocalUnits(props: Props) {
)}
>
<TabPanel name="map">
<LocalUnitsMap
key={localUnitUpdateKey}
/>
<Container
className={_cs(presentationMode && styles.presentationMode)}
containerRef={containerRef}
actions={presentationMode && (
<IconButton
name={undefined}
onClick={handleFullScreenToggleClick}
title={strings.closePresentationLabel}
variant="secondary"
ariaLabel={strings.closePresentationLabel}
>
<CloseLineIcon />
</IconButton>
)}
>
<LocalUnitsMap
key={localUnitUpdateKey}
onPresentationModeButtonClick={handleFullScreenToggleClick}
presentationMode={presentationMode}
/>
</Container>
</TabPanel>
<TabPanel name="table">
<LocalUnitsTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@
align-items: flex-end;
}

.presentation-mode {
background-color: var(--go-ui-color-background);
padding: var(--go-ui-spacing-2xl);
width: 96vw;
}
}

0 comments on commit c544e98

Please sign in to comment.