Skip to content

Commit

Permalink
fix(dashboard): bugs related to new passage migration (#516)
Browse files Browse the repository at this point in the history
* fix: loader

* fix: stats

* fix: stats and reports include/exclude dates
  • Loading branch information
arnaudambro authored Mar 23, 2022
1 parent fce1441 commit a05fd7d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
3 changes: 2 additions & 1 deletion dashboard/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules
/build
/build
/src-tauri
1 change: 1 addition & 0 deletions dashboard/src/components/DateRangePickerWithPresets.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ const DateRangePickerWithPresets = ({ period, setPeriod }) => {
onFocusChange={setDatePickerFocused}
disabled={false}
monthFormat="MMMM YYYY"
minimumNights={0}
showClearDates
displayFormat="DD-MM-yyyy"
isOutsideRange={() => null}
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/components/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ const Loader = () => {
response.data.territoryObservations +
response.data.places +
response.data.comments +
response.data.passages +
response.data.reports +
response.data.relsPersonPlace;

Expand Down
2 changes: 0 additions & 2 deletions dashboard/src/scenes/organisation/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ const List = () => {
const [refresh, setRefresh] = useState(true);
const API = useApi();

console.log({ sortBy, sortOrder });

useEffect(() => {
(async () => {
if (!refresh) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const SelectAndCreateCollaboration = ({ values, onChange }) => {
const API = useApi();

const onChangeRequest = (newCollabs) => {
console.log({ newCollabs });
onChange({ currentTarget: { value: newCollabs || [], name: 'collaborations' } });
};

Expand Down
35 changes: 27 additions & 8 deletions dashboard/src/scenes/stats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ import { reportsState } from '../../recoil/reports';
import ExportData from '../data-import-export/ExportData';
import SelectCustom from '../../components/SelectCustom';
import { territoriesState } from '../../recoil/territory';
import { dayjsInstance } from '../../services/date';
import { getIsDayWithinHoursOffsetOfPeriod } from '../../services/date';
import { loadingState, refreshTriggerState } from '../../components/Loader';
import { passagesState } from '../../recoil/passages';

const getDataForPeriod = (data, { startDate, endDate }, filters = []) => {
const getDataForPeriod = (data, { startDate, endDate }, currentTeam, viewAllOrganisationData, { filters = [], field = 'createdAt' } = {}) => {
if (!!filters?.filter((f) => Boolean(f?.value)).length) data = filterData(data, filters);
if (!startDate || !endDate) {
return data;
}
return data.filter((item) => dayjsInstance(item.createdAt).isBetween(startDate, endDate));
const offsetHours = !!viewAllOrganisationData ? 0 : currentTeam?.nightSession ? 12 : 0;

return data.filter((item) =>
getIsDayWithinHoursOffsetOfPeriod(item[field] || item.createdAt, { referenceStartDay: startDate, referenceEndDay: endDate }, offsetHours)
);
};

const tabs = ['Général', 'Accueil', 'Actions', 'Personnes suivies', 'Observations', 'Comptes-rendus'];
Expand Down Expand Up @@ -72,26 +76,41 @@ const Stats = () => {
const persons = getDataForPeriod(
allPersons.filter((e) => viewAllOrganisationData || (e.assignedTeams || []).includes(currentTeam._id)),
period,
filterPersons
currentTeam,
viewAllOrganisationData,
{ filters: filterPersons }
);
const actions = getDataForPeriod(
allActions.filter((e) => viewAllOrganisationData || e.team === currentTeam._id),
period
period,
currentTeam,
viewAllOrganisationData
);
const observations = getDataForPeriod(
allObservations
.filter((e) => viewAllOrganisationData || e.team === currentTeam._id)
.filter((e) => !territory?._id || e.territory === territory._id),
period
period,
currentTeam,
viewAllOrganisationData,
{ field: 'observedAt' }
);
const passages = getDataForPeriod(
allPassages.filter((e) => viewAllOrganisationData || e.team === currentTeam._id),
period
period,
currentTeam,
viewAllOrganisationData,
{ field: 'date' }
);

const reports = getDataForPeriod(
allreports.filter((e) => viewAllOrganisationData || e.team === currentTeam._id),
period
period,
currentTeam,
viewAllOrganisationData,
{ field: 'date' }
);

const reportsServices = reports.map((rep) => (rep.services ? JSON.parse(rep.services) : null)).filter(Boolean);

// Add enabled custom fields in filters.
Expand Down
6 changes: 4 additions & 2 deletions dashboard/src/services/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ export const getIsDayWithinHoursOffsetOfPeriod = (dayToTest, { referenceStartDay
// '[]' includes start and end date
// '[)' includes the start date but excludes the stop
// Source: https://day.js.org/docs/en/plugin/is-between
// we need 'inclusive' to include start of the day
return dayjs(dayToTest).isBetween(startDate, endDate, null, '[]');
// we need '[)' because
// -> the date of reports is at the start of the day
// -> the date of anonymous passages migrated with passages-from-comments-to-table is at the start of the day
return dayjs(dayToTest).isBetween(startDate, endDate, null, '[)');
};

export const dayjsInstance = dayjs;

0 comments on commit a05fd7d

Please sign in to comment.