Skip to content

Commit 90819f3

Browse files
authored
Merge pull request #4047 from LiteFarmOrg/LF-5170/List_the_locations_on_the_readonly_view
LF-5170: List the locations on the readonly view
2 parents e7e2a23 + 9bf6c88 commit 90819f3

4 files changed

Lines changed: 89 additions & 3 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2026 LiteFarm.org
3+
* This file is part of LiteFarm.
4+
*
5+
* LiteFarm is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* LiteFarm is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details, see <<https://www.gnu.org/licenses/>.>
14+
*/
15+
16+
import { useTranslation } from 'react-i18next';
17+
import clsx from 'clsx';
18+
import { Location } from '../../../types';
19+
import styles from './styles.module.scss';
20+
import navStyles from '@navStyles';
21+
22+
interface LocationListProps {
23+
locations: Location[];
24+
isTransplantTask: boolean;
25+
selectedLocationIds?: Location['location_id'][];
26+
}
27+
28+
export default function LocationList({
29+
locations,
30+
isTransplantTask,
31+
selectedLocationIds,
32+
}: LocationListProps) {
33+
const { t } = useTranslation();
34+
35+
if (!locations?.length) {
36+
return null;
37+
}
38+
39+
if (isTransplantTask) {
40+
const transplantLocation = locations.find(
41+
({ location_id }) => location_id === selectedLocationIds?.[0],
42+
);
43+
// When transplanting to the same location, currentLocation becomes transplantLocation
44+
const currentLocation =
45+
locations.find(({ location_id }) => location_id !== selectedLocationIds?.[0]) ||
46+
transplantLocation;
47+
48+
return (
49+
<ul className={clsx(styles.locationList, navStyles.showWhenOffline)}>
50+
<li>
51+
{t('TASK.CURRENT')}: {currentLocation?.name}
52+
</li>
53+
<li>
54+
{t('TASK.TRANSPLANT')}: {transplantLocation?.name}
55+
</li>
56+
</ul>
57+
);
58+
}
59+
60+
return (
61+
<ul className={clsx(styles.locationList, navStyles.showWhenOffline)}>
62+
{locations.map((location) => {
63+
return <li key={location.location_id}>{location.name}</li>;
64+
})}
65+
</ul>
66+
);
67+
}

packages/webapp/src/components/Task/TaskReadOnly/index.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import PureDocumentTile from '../../../containers/Documents/DocumentTile';
6969
import PureDocumentTileContainer from '../../../containers/Documents/DocumentTile/DocumentTileContainer';
7070
import RevisionPrompt from '../RevisionPrompt';
7171
import RevisionInfoText from '../../RevisionInfoText';
72+
import LocationList from './LocationList';
7273

7374
export default function PureTaskReadOnly({
7475
onGoBack,
@@ -163,9 +164,9 @@ export default function PureTaskReadOnly({
163164
const isCurrent = !isCompleted && !isAbandoned;
164165
const taskStatus = getTaskStatus(task);
165166
const isRevised = !!task.revision_date;
167+
const isTransplantTask = isTaskType(taskType, 'TRANSPLANT_TASK');
166168

167-
const showTaskNotes =
168-
!isTaskType(taskType, 'PLANT_TASK') && !isTaskType(taskType, 'TRANSPLANT_TASK');
169+
const showTaskNotes = !isTaskType(taskType, 'PLANT_TASK') && !isTransplantTask;
169170

170171
const [showTaskAssignModal, setShowTaskAssignModal] = useState(false);
171172
const [showDueDateModal, setShowDueDateModal] = useState(false);
@@ -300,7 +301,12 @@ export default function PureTaskReadOnly({
300301
{showLocations ? (
301302
<>
302303
<Semibold className={styles.taskLocationsTitle}>{t('TASK.LOCATIONS')}</Semibold>
303-
{isTaskType(taskType, 'TRANSPLANT_TASK') && (
304+
<LocationList
305+
isTransplantTask={isTransplantTask}
306+
locations={task.locations}
307+
selectedLocationIds={task.selectedLocationIds}
308+
/>
309+
{isTransplantTask && (
304310
<TransplantLocationLabel
305311
locations={task.locations}
306312
selectedLocationId={task.selectedLocationIds[0]}

packages/webapp/src/components/Task/TaskReadOnly/styles.module.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,8 @@
143143
font-style: italic;
144144
padding-top: 12px;
145145
}
146+
147+
.locationList {
148+
margin-bottom: 20px;
149+
list-style-position: inside;
150+
}

packages/webapp/src/containers/Navigation/styles.module.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,13 @@
3232
.hideWhenOffline {
3333
display: none;
3434
}
35+
36+
.showWhenOffline {
37+
display: block;
38+
}
39+
}
40+
41+
.showWhenOffline {
42+
display: none;
3543
}
3644
}

0 commit comments

Comments
 (0)