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

Adapt dataExplorer export for intervention_start_date #2251

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion public/static/locales/en/treemapperAnalytics.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dec": "Dec",
"exportColumnHeaders": {
"hid": "Human Readable ID for a plant location",
"plantDate": "Planted Date",
"interventionStartDate": "Starting date of intervention (e.g. Tree planting date)",
"species": "Name of the species planted",
"treeCount": "",
"geometry": "GeoJson Co-ordinate of the polygon",
Expand Down
2 changes: 1 addition & 1 deletion src/features/common/types/dataExplorer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface ISpeciesPlanted {

export interface IExportData {
hid: string;
plant_date: Date;
intervention_start_date: Date;
species: string;
tree_count: number;
geometry: string;
Expand Down
1 change: 0 additions & 1 deletion src/features/common/types/plantLocation.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export interface PlantLocationBase {
registrationDate: DateString;
/** @deprecated */
plantDate: DateString;
interventionDate: DateString;
interventionStartDate: DateString | null; //should be the same as interventionDate
interventionEndDate: DateString | null;
lastMeasurementDate: DateString | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ export default function PlantLocationDetails({
<div className={styles.singleDetail}>
<div className={styles.detailTitle}>{t('plantingDate')}</div>
<div className={styles.detailValue}>
{formatDate(plantLocation.plantDate)}
{plantLocation.interventionStartDate
? formatDate(plantLocation.interventionStartDate)
: '-'}
</div>
</div>
{(plantLocation.type === 'sample-tree-registration' ||
Expand Down
4 changes: 3 additions & 1 deletion src/features/projects/components/maps/PlantLocations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ export default function PlantLocations(): ReactElement {
};

const getDateDiff = (pl: PlantLocation) => {
if (!pl.interventionStartDate) return null;

const today = new Date();
const plantationDate = new Date(pl.plantDate?.substr(0, 10));
const plantationDate = new Date(pl.interventionStartDate?.slice(0, 10));
const differenceInTime = today.getTime() - plantationDate.getTime();
const differenceInDays = differenceInTime / (1000 * 3600 * 24);
if (differenceInDays < 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export const Export = () => {
description: t('exportColumnHeaders.hid'),
},
{
title: 'plant_date',
description: t('exportColumnHeaders.plantDate'),
title: 'intervention_start_date',
description: t('exportColumnHeaders.interventionStartDate'),
},
{
title: 'species',
Expand Down Expand Up @@ -142,6 +142,7 @@ export const Export = () => {
};

const extractDataToXlsx = (data: IExportData[]) => {
console.log('Data for export:', data[0]);
const worksheet = utils.json_to_sheet(data);
const workbook = utils.book_new();

Expand Down Expand Up @@ -173,6 +174,7 @@ export const Export = () => {
const handleExport = async () => {
if (localProject) {
const res = await makeRequest();
console.log('Data received from API:', res?.data[0]);

if (res) {
const { data } = res;
Expand Down
16 changes: 9 additions & 7 deletions src/features/user/TreeMapper/Import/components/ReviewSubmit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ export default function ReviewSubmit({
{plantLocation.captureMode}
</div>
</div>
<div className={styles.gridItem}>
<div className={styles.gridItemTitle}>
{tTreemapper('plantDate')}
{plantLocation.interventionStartDate !== null && (
<div className={styles.gridItem}>
<div className={styles.gridItemTitle}>
{tTreemapper('plantDate')}
</div>
<div className={styles.gridItemValue}>
{formatDate(plantLocation.interventionStartDate)}
</div>
</div>
<div className={styles.gridItemValue}>
{formatDate(plantLocation.plantDate)}
</div>
</div>
)}
<div className={styles.gridItem}>
<div className={styles.gridItemTitle}>
{tTreemapper('registrationDate')}
Expand Down
18 changes: 0 additions & 18 deletions src/features/user/TreeMapper/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,6 @@ export default function MyTreesMap({
}
};

// const getDateDiff = (pl: PlantLocation) => {
// const today = new Date();
// const plantationDate = new Date(pl.plantDate?.substr(0, 10));
// const differenceInTime = today.getTime() - plantationDate.getTime();
// const differenceInDays = differenceInTime / (1000 * 3600 * 24);
// if (differenceInDays < 1) {
// return t('today');
// } else if (differenceInDays < 2) {
// return t('yesterday');
// } else if (differenceInDays < 30) {
// return t('daysAgo', {
// days: localizedAbbreviatedNumber(i18n.language, differenceInDays, 0),
// });
// } else {
// return null;
// }
// };

const zoomToLocation = (geometry: turf.AllGeoJSON) => {
if (viewport.width && viewport.height && geometry) {
const bbox = turf.bbox(geometry);
Expand Down
12 changes: 8 additions & 4 deletions src/features/user/TreeMapper/components/PlantLocationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,14 @@ export function LocationDetails({
) : (
[]
)}
<div className={styles.singleDetail}>
<p className={styles.title}>{tTreemapper('plantDate')}</p>
<div className={styles.value}>{formatDate(location.plantDate)}</div>
</div>
{location.interventionStartDate !== null && (
<div className={styles.singleDetail}>
<p className={styles.title}>{tTreemapper('plantDate')}</p>
<div className={styles.value}>
{formatDate(location.interventionStartDate)}
</div>
</div>
)}
<div className={styles.singleDetail}>
<p className={styles.title}>{tTreemapper('registrationDate')}</p>
<div className={styles.value}>
Expand Down
Loading