Skip to content

Commit 226c9df

Browse files
authored
Merge pull request #1988 from IFRCGo/feature/local-unit-status-update
Update status in local unit section
2 parents 38b4f01 + 78f990a commit 226c9df

File tree

17 files changed

+139
-52
lines changed

17 files changed

+139
-52
lines changed

.changeset/blue-insects-show.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"go-web-app": patch
3+
---
4+
5+
Update local units UI
6+
7+
- Add icon for externally managed status
8+
- Relocate status column in local units table
9+
- Improve overall UI

app/src/utils/localUnits.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ export function getFormFields(value: LocalUnitResponse | PartialLocalUnits) {
2323
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2424
modified_by_details,
2525
// eslint-disable-next-line @typescript-eslint/no-unused-vars
26-
is_locked,
27-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2826
status,
2927
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3028
version_id,

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitImportModal/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ function LocalUnitBulkUploadModal(props: Props) {
8989
|| isLocalUnitRegionValidatorByType(countryResponse?.region, localUnitType);
9090

9191
const { response: localUnitsOptions } = useRequest({ url: '/api/v2/local-units-options/' });
92+
9293
const { response: bulkUploadHealthTemplate } = useRequest({
9394
url: '/api/v2/bulk-upload-local-unit/get-bulk-upload-template/',
94-
pathVariables: { bulk_upload_template: 'health_care' },
95+
query: { bulk_upload_template: 'health_care' },
9596
});
97+
9698
const { response: bulkUploadDefaultTemplate } = useRequest({
9799
url: '/api/v2/bulk-upload-local-unit/get-bulk-upload-template/',
98-
pathVariables: { bulk_upload_template: 'local_unit' },
100+
query: { bulk_upload_template: 'local_unit' },
99101
});
100102

101103
const {
@@ -181,7 +183,7 @@ function LocalUnitBulkUploadModal(props: Props) {
181183
onClose={onClose}
182184
headerDescriptionContainerClassName={styles.headerDescriptionContent}
183185
childrenContainerClassName={styles.bulkUploadContent}
184-
headerDescription={importSummaryResponse?.status === BULK_UPLOAD_PENDING
186+
headerDescription={!pending
185187
? strings.modalDescription
186188
: strings.modalImportPendingDescription}
187189
contentViewType="vertical"
@@ -213,6 +215,10 @@ function LocalUnitBulkUploadModal(props: Props) {
213215
error={permissionError}
214216
/>
215217
)}
218+
<NonFieldError
219+
className={styles.nonFieldError}
220+
error={importSummaryResponse?.error_message}
221+
/>
216222
{isNotDefined(importSummaryResponse) && (
217223
<Container
218224
className={styles.uploadSummary}

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitStatus/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import {
22
CheckboxCircleLineIcon,
33
CloseCircleLineIcon,
44
EditCircleLineIcon,
5+
LockLineIcon,
56
} from '@ifrc-go/icons';
67
import { Tooltip } from '@ifrc-go/ui';
78
import { _cs } from '@togglecorp/fujs';
89

910
import {
11+
EXTERNALLY_MANAGED,
1012
PENDING_VALIDATION,
1113
UNVALIDATED,
1214
VALIDATED,
@@ -37,6 +39,7 @@ function LocalUnitStatus(props: LocalUnitStatusProps) {
3739
value === VALIDATED && styles.validated,
3840
value === UNVALIDATED && styles.unvalidated,
3941
value === PENDING_VALIDATION && styles.pendingValidation,
42+
value === EXTERNALLY_MANAGED && styles.externallyManaged,
4043
className,
4144
)}
4245
>
@@ -55,6 +58,11 @@ function LocalUnitStatus(props: LocalUnitStatusProps) {
5558
className={styles.icon}
5659
/>
5760
)}
61+
{value === EXTERNALLY_MANAGED && (
62+
<LockLineIcon
63+
className={styles.icon}
64+
/>
65+
)}
5866
{!compact && valueDisplay}
5967
{compact && valueDisplay && (
6068
<Tooltip

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitStatus/styles.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@
1717
&.pending-validation {
1818
color: var(--go-ui-color-blue);
1919
}
20+
21+
&.externally-managed {
22+
color: var(--go-ui-color-gray-60);
23+
}
2024
}

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitView/i18n.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@
6868
"localUnitViewLocalUnitDeleteButtonLabel": "Delete",
6969
"localUnitViewDoneButtonLabel": "Done",
7070
"localUnitViewRevertButtonLabel": "Revert",
71-
"localUnitViewReasonLabel": "Reason",
7271
"localUnitViewRevertChangesModalHeading": "Revert the Changes",
7372
"localUnitViewRevertChangesContentQuestion": "Are you sure you want to have these changes revert in this project?",
7473
"localUnitViewConfirmChangesModalHeading": "Confirm the Changes",
7574
"localUnitViewConfirmChangesContentQuestion": "Are you sure you want to have these changes in this local unit?",
7675
"localUnitViewNewLocalUnitDescription": "New local unit",
7776
"localUnitViewLatitude": "Latitude",
7877
"localUnitViewLongitude": "Longitude",
78+
"localUnitViewUpdateReason": "Edit reason",
7979
"localUnitViewNoChanges": "No changes found"
8080
}
8181
}

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitView/index.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
} from '../LocalUnitsFormModal/LocalUnitsForm/schema';
3434

3535
import i18n from './i18n.json';
36+
import styles from './styles.module.css';
3637

3738
type VisibilityOptions = NonNullable<GoApiResponse<'/api/v2/global-enums/'>['api_visibility_choices']>[number]
3839
type LocalUnitResponse = NonNullable<GoApiResponse<'/api/v2/local-units/{id}/'>>;
@@ -104,6 +105,15 @@ function LocalUnitView(props: Props) {
104105
emptyMessage={strings.localUnitViewNoChanges}
105106
contentViewType="grid"
106107
numPreferredGridContentColumns={3}
108+
withFooterBorder
109+
footerContent={isDefined(newValue?.update_reason_overview) && (
110+
<TextOutput
111+
valueClassName={styles.updateReasonText}
112+
strongLabel
113+
value={newValue?.update_reason_overview}
114+
label={strings.localUnitViewUpdateReason}
115+
/>
116+
)}
107117
>
108118
<SelectDiffWrapper
109119
showOnlyDiff
@@ -150,6 +160,7 @@ function LocalUnitView(props: Props) {
150160
label={strings.localUnitViewLatitude}
151161
value={newValue?.location_json?.lat}
152162
valueType="number"
163+
maximumFractionDigits={10}
153164
/>
154165
</DiffWrapper>
155166
<DiffWrapper
@@ -163,6 +174,7 @@ function LocalUnitView(props: Props) {
163174
label={strings.localUnitViewLongitude}
164175
value={newValue?.location_json?.lng}
165176
valueType="number"
177+
maximumFractionDigits={10}
166178
/>
167179
</DiffWrapper>
168180
<DiffWrapper
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.update-reason-text {
2+
font-style: italic;
3+
}

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ import {
6565
import { transformObjectError } from '#utils/restRequest/error';
6666

6767
import {
68+
EXTERNALLY_MANAGED,
6869
type ManageResponse,
70+
UNVALIDATED,
6971
VALIDATED,
7072
} from '../../common';
7173
import FormGrid from '../../FormGrid';
@@ -219,8 +221,20 @@ function LocalUnitsForm(props: Props) {
219221
pathVariables: isDefined(localUnitId) ? { id: localUnitId } : undefined,
220222
});
221223

224+
const isLocked = (
225+
isDefined(localUnitDetailsResponse?.status)
226+
&& !(localUnitDetailsResponse.status === VALIDATED)
227+
);
228+
229+
const isNewLocalUnit = localUnitDetailsResponse?.status === UNVALIDATED;
230+
231+
const isExternallyManaged = (localUnitDetailsResponse?.status === EXTERNALLY_MANAGED
232+
|| (isDefined(value.type)
233+
&& isDefined(manageResponse)
234+
&& !!manageResponse[value.type]?.enabled));
235+
222236
const readOnly = readOnlyFromProps
223-
|| localUnitDetailsResponse?.is_locked;
237+
|| isLocked || isExternallyManaged;
224238

225239
const {
226240
response: localUnitsOptions,
@@ -322,22 +336,16 @@ function LocalUnitsForm(props: Props) {
322336
},
323337
});
324338

325-
const isExternallyManaged = useMemo(() => {
326-
if (isDefined(value.type) && isDefined(manageResponse)) {
327-
return manageResponse[value.type]?.enabled;
328-
}
329-
return false;
330-
}, [value.type, manageResponse]);
331-
332339
const hasValidatePermission = isAuthenticated
333340
&& !isExternallyManaged
334341
&& (isSuperUser
335342
|| isLocalUnitGlobalValidatorByType(value.type)
336343
|| isLocalUnitCountryValidatorByType(countryResponse?.id, value.type)
337344
|| isLocalUnitRegionValidatorByType(countryResponse?.region, value.type));
338345

339-
const hasUpdatePermission = isCountryAdmin(countryResponse?.id)
340-
|| hasValidatePermission;
346+
const hasUpdatePermission = (isCountryAdmin(countryResponse?.id)
347+
|| hasValidatePermission)
348+
&& !isExternallyManaged;
341349

342350
const handleFormSubmit = useCallback(
343351
() => {
@@ -392,13 +400,15 @@ function LocalUnitsForm(props: Props) {
392400
localUnitPreviousResponse?.previous_data_details as unknown as LocalUnitResponse | undefined
393401
);
394402

395-
const showChanges = !localUnitDetailsResponse?.is_new_local_unit
396-
&& !!localUnitDetailsResponse?.is_locked
397-
&& isNotDefined(localUnitDetailsResponse.bulk_upload);
403+
const showChanges = !isNewLocalUnit
404+
&& isLocked
405+
&& showValueChanges
406+
&& !isExternallyManaged;
398407

399-
const showViewChanges = !localUnitDetailsResponse?.is_new_local_unit
408+
const showViewChanges = !isNewLocalUnit
400409
&& isDefined(localUnitId)
401-
&& !(localUnitDetailsResponse?.status === VALIDATED);
410+
&& isLocked
411+
&& !isExternallyManaged;
402412

403413
const permissionError = useMemo(() => {
404414
if (isExternallyManaged) {
@@ -446,9 +456,9 @@ function LocalUnitsForm(props: Props) {
446456

447457
return (
448458
<div className={styles.localUnitsForm}>
449-
{isDefined(actionsContainerRef.current) && (
459+
{isDefined(actionsContainerRef.current) && environment !== 'production' && (
450460
<Portal container={actionsContainerRef.current}>
451-
{isDefined(localUnitDetailsResponse) && environment !== 'production' && (
461+
{isDefined(localUnitDetailsResponse) && (
452462
<>
453463
{hasUpdatePermission && (
454464
<Button
@@ -467,7 +477,7 @@ function LocalUnitsForm(props: Props) {
467477
/>
468478
)}
469479
{readOnlyFromProps
470-
&& !localUnitDetailsResponse.is_locked
480+
&& !isLocked
471481
&& hasUpdatePermission && (
472482
<Button
473483
name={undefined}
@@ -541,7 +551,7 @@ function LocalUnitsForm(props: Props) {
541551
onChange={setFieldValue}
542552
keySelector={numericIdSelector}
543553
labelSelector={stringNameSelector}
544-
readOnly={readOnly}
554+
readOnly={readOnlyFromProps || isLocked}
545555
error={error?.type}
546556
nonClearable
547557
/>
@@ -1833,7 +1843,6 @@ function LocalUnitsForm(props: Props) {
18331843
value={updateReason}
18341844
onChange={setUpdateReason}
18351845
/>
1836-
18371846
</LocalUnitViewModal>
18381847
)}
18391848
{showValidateLocalUnitModal

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsMap/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import {
7171
import type { FilterValue } from '../Filters';
7272
import LocalUnitsFormModal from '../LocalUnitsFormModal';
7373
import { TYPE_HEALTH_CARE } from '../LocalUnitsFormModal/LocalUnitsForm/schema';
74+
import LocalUnitStatus from '../LocalUnitStatus';
7475

7576
import i18n from './i18n.json';
7677
import styles from './styles.module.css';
@@ -467,6 +468,7 @@ function LocalUnitsMap(props: Props) {
467468
popupClassName={styles.mapPopup}
468469
coordinates={clickedPointProperties.center}
469470
onCloseButtonClick={handlePointClose}
471+
headingContainerClassName={styles.headingDescription}
470472
heading={(
471473
<Button
472474
name=""
@@ -477,6 +479,12 @@ function LocalUnitsMap(props: Props) {
477479
{localUnitName}
478480
</Button>
479481
)}
482+
headingDescription={(
483+
<LocalUnitStatus
484+
value={localUnitDetail?.status}
485+
valueDisplay={localUnitDetail?.status_details}
486+
/>
487+
)}
480488
contentViewType="vertical"
481489
pending={localUnitDetailPending}
482490
errored={isDefined(localUnitDetailError)}

0 commit comments

Comments
 (0)