Skip to content

Commit

Permalink
add reminders and outcome data in ListSU (#95)
Browse files Browse the repository at this point in the history
* add reminders and outcome data in ListSU

* remove useless traduction

* rework functions to get reminders

* refacto SUTable component

* rework SUTableHeader component
  • Loading branch information
RenauxLeaInsee authored Jan 16, 2024
1 parent cbc41ca commit 0481354
Show file tree
Hide file tree
Showing 16 changed files with 524 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5172,7 +5172,7 @@ exports[`Select another survey 1`] = `
<div
data-testid="Redirect-surveyInfos"
>
{"survey":{"allSurveys":[{"id":"vqs2021x00","label":"Everyday life and health survey 2021","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000},{"id":"simpsons2020x00","label":"Survey on the Simpsons tv show 2020","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000}],"id":"simpsons2020x00","label":"Survey on the Simpsons tv show 2020","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000},"surveyInfo":{"id":"simpsons2020x00","label":"Survey on the Simpsons tv show 2020","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000}}
{"survey":{"allSurveys":[{"id":"vqs2021x00","label":"Everyday life and health survey 2021","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000},{"id":"simpsons2020x00","label":"Survey on the Simpsons tv show 2020","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000}],"id":"simpsons2020x00","label":"Survey on the Simpsons tv show 2020","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000,"communicationRequestConfiguration":false},"surveyInfo":{"id":"simpsons2020x00","label":"Survey on the Simpsons tv show 2020","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000}}
</div>
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19915,15 +19915,15 @@ exports[`Select another survey (by interviewer) 1`] = `
<div
data-testid="Redirect-survey"
>
{"allSurveys":[{"id":"vqs2021x00","label":"Everyday life and health survey 2021","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000},{"id":"simpsons2020x00","label":"Survey on the Simpsons tv show 2020","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000}],"id":"simpsons2020x00","label":"Survey on the Simpsons tv show 2020","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000}
{"allSurveys":[{"id":"vqs2021x00","label":"Everyday life and health survey 2021","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000},{"id":"simpsons2020x00","label":"Survey on the Simpsons tv show 2020","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000}],"id":"simpsons2020x00","label":"Survey on the Simpsons tv show 2020","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000,"communicationRequestConfiguration":false}
</div>
`;

exports[`Select another survey (by site) 1`] = `
<div
data-testid="Redirect-survey"
>
{"allSurveys":[{"id":"vqs2021x00","label":"Everyday life and health survey 2021","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000},{"id":"simpsons2020x00","label":"Survey on the Simpsons tv show 2020","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000}],"id":"simpsons2020x00","label":"Survey on the Simpsons tv show 2020","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000}
{"allSurveys":[{"id":"vqs2021x00","label":"Everyday life and health survey 2021","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000},{"id":"simpsons2020x00","label":"Survey on the Simpsons tv show 2020","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000}],"id":"simpsons2020x00","label":"Survey on the Simpsons tv show 2020","managementStartDate":1576801000000,"interviewerStartDate":1575937000000,"identificationPhaseStartDate":1577233000000,"collectionStartDate":1577837800000,"collectionEndDate":1640996200000,"endDate":1641514600000,"communicationRequestConfiguration":false}
</div>
`;

Expand Down
27 changes: 22 additions & 5 deletions src/components/ListSU/ListSU.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,41 @@
}

#SUTable .ColId {
width: 15%;
width: 6%;
}
#SUTable .ColInterviewer {
width: 20%;
width: 15%;
}

#SUTable .ColSsech {
width: 11%;
width: 4%;
}

#SUTable .ColDepartement {
width: 13%;
width: 6%;
}

#SUTable .ColCity {
width: 20%;
width: 15%;
}

#SUTable .ColState {
width: 13%;
}

#SUTable .ColTotalReminders {
width: 3%;
min-width: 3rem;
}

#SUTable .ColLatestReminder {
width: 7%;
}

#SUTable .ColContactOutcomeType {
width: 10%;
}

#SUTable .ColContactOutcomeDate {
width: 5%;
}
232 changes: 165 additions & 67 deletions src/components/ListSU/SUTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@ import Spinner from "react-bootstrap/Spinner";
import Card from "react-bootstrap/Card";
import Modal from "react-bootstrap/Modal";
import Form from "react-bootstrap/Form";
import SortIcon from "../SortIcon/SortIcon";
import SearchField from "../SearchField/SearchField";
import PaginationNav from "../PaginationNav/PaginationNav";
import SurveyUnitLine from "./SurveyUnitLine";
import D from "../../i18n";
import Utils from "../../utils/Utils";
import { SUTableHeader } from "./SUTableHeader";
import { SUTableHeaderParameters } from "./SUTableHeaderParameters";

function makeTableForExport(data) {
const header = [
const getInitiatedDate = (reminder) =>
reminder.status.find((status) => status.status === "INITIATED")?.date ?? 0;

const orderReminders = (reminders) => {
reminders.sort((a, b) => getInitiatedDate(b) - getInitiatedDate(a));
};

function makeTableForExport(data, communicationRequestConfiguration) {
const headerTitle = [
[
D.identifier,
D.interviewer,
Expand All @@ -25,17 +34,118 @@ function makeTableForExport(data) {
],
];

return header.concat(
data.map((line) => [
line.id,
line.interviewer,
line.idep,
line.ssech,
line.departement?.substring(0, 2),
line.city,
line.state,
])
);
if (communicationRequestConfiguration) {
let maxReminders = 0;

headerTitle[0].splice(headerTitle[0].length - 1, 0, D.totalReminders);

data.forEach((survey) => {
const length =
survey.communicationRequests?.filter(
(request) =>
request.emiter === "INTERVIEWER" && request.type === "REMINDER"
)?.length ?? 0;
length > maxReminders && (maxReminders = length);
});

maxReminders !== 0 &&
headerTitle[0].splice(
headerTitle[0].length - 1,
0,
Array.from(new Array(maxReminders)).reduce((previous) => {
return [
...previous,
D.reminderMediumExportLabel,
D.reminderReasonExportLabel,
D.reminderDateExportLabel,
];
}, [])
);

headerTitle[0].splice(
headerTitle[0].length - 1,
0,
D.contactOutcomeLabel,
D.contactOutcomeDateLabel
);
}

const header = headerTitle;

return communicationRequestConfiguration
? header.concat(
data.map((line) => {
const reminders =
line.communicationRequests?.filter(
(request) =>
request.emiter === "INTERVIEWER" && request.type === "REMINDER"
) ?? [];
orderReminders(reminders);

const reminderInformationsToExport = reminders.reduce(
(previous, current) => {
const initiatedStatus = current.status.find(
(status) => status.status === "INITIATED"
);
return [
...previous,
D[current.medium?.toLowerCase()] ?? "",
D[current.reason?.toLowerCase()] ?? "",
Utils.convertToDateString(new Date(initiatedStatus.date)),
];
},
[]
);

return reminders.length !== 0
? [
line.id,
line.interviewer,
line.idep,
line.ssech,
line.departement?.substring(0, 2),
line.city,
reminders.length,
[...reminderInformationsToExport],
line.contactOutcome?.type ? D[line.contactOutcome.type] : "",
line.contactOutcome?.date
? Utils.convertToDateString(
new Date(line.contactOutcome.date)
)
: "",
line.state,
]
: [
line.id,
line.interviewer,
line.idep,
line.ssech,
line.departement?.substring(0, 2),
line.city,
reminders.length,
line.contactOutcome?.type ? D[line.contactOutcome.type] : "",
line.contactOutcome?.date
? Utils.convertToDateString(
new Date(line.contactOutcome.date)
)
: "",
line.state,
];
})
)
: header.concat(
data.map((line) => {
return [
line.id,
line.interviewer,
line.idep,
line.ssech,
line.departement?.substring(0, 2),
line.city,
line.state,
];
})
);
}

class SUTable extends React.Component {
Expand Down Expand Up @@ -132,7 +242,10 @@ class SUTable extends React.Component {
const title = `${fileLabel}_${new Date()
.toLocaleDateString()
.replace(/\//g, "")}.csv`.replace(/ /g, "_");
const table = makeTableForExport(data);
const table = makeTableForExport(
data,
survey.communicationRequestConfiguration
);
const csvContent = `data:text/csv;charset=utf-8,\ufeff${table
.map((e) => e.join(";"))
.join("\n")}`;
Expand Down Expand Up @@ -160,7 +273,7 @@ class SUTable extends React.Component {
}

render() {
const { data, sort, handleSort, isLoading } = this.props;
const { data, sort, handleSort, isLoading, survey } = this.props;
const fieldsToSearch = ["city", "interviewer", "id", "state"];
const {
pagination,
Expand All @@ -178,6 +291,12 @@ class SUTable extends React.Component {
handleSort(property);
};
}

const parameters = SUTableHeaderParameters.filter(
(parameter) =>
parameter.isAlwaysVisible || survey.communicationRequestConfiguration
);

return (
<Card className="ViewCard">
<Card.Title className="PageTitle">
Expand Down Expand Up @@ -248,49 +367,14 @@ class SUTable extends React.Component {
onChange={(e) => this.handleCheckAll(e)}
/>
</th>
<th
onClick={handleSortFunct("id")}
className="Clickable ColId"
>
{D.identifier}
<SortIcon val="id" sort={sort} />
</th>
<th
data-testid="TableHeader_interviewer_name"
onClick={handleSortFunct("interviewer")}
className="Clickable ColInterviewer"
>
{D.interviewer}
<SortIcon val="interviewer" sort={sort} />
</th>
<th
onClick={handleSortFunct("ssech")}
className="Clickable ColSsech"
>
{D.ssech}
<SortIcon val="ssech" sort={sort} />
</th>
<th
onClick={handleSortFunct("departement")}
className="Clickable ColDepartement"
>
{D.department}
<SortIcon val="departement" sort={sort} />
</th>
<th
onClick={handleSortFunct("city")}
className="Clickable ColCity"
>
{D.town}
<SortIcon val="city" sort={sort} />
</th>
<th
onClick={handleSortFunct("state")}
className="Clickable ColState"
>
{D.state}
<SortIcon val="state" sort={sort} />
</th>
{parameters.map((parameters) => (
<SUTableHeader
{...parameters}
handleSortFunction={handleSortFunct}
sort={sort}
key={parameters.label}
/>
))}
</tr>
</thead>
<tbody>
Expand All @@ -302,14 +386,28 @@ class SUTable extends React.Component {
displayedLines.length
)
)
.map((line) => (
<SurveyUnitLine
key={line.id}
lineData={line}
isChecked={checkboxArray[line.id]}
updateFunc={() => toggleCheckBox(line.id)}
/>
))}
.map((line) => {
const reminders =
line.communicationRequests?.filter(
(request) =>
request.emiter === "INTERVIEWER" &&
request.type === "REMINDER"
) ?? [];

orderReminders(reminders);

return (
<SurveyUnitLine
key={line.id}
lineData={{ ...line, remindersByOrder: reminders }}
isChecked={checkboxArray[line.id]}
updateFunc={() => toggleCheckBox(line.id)}
communicationRequestConfiguration={
survey.communicationRequestConfiguration
}
/>
);
})}
</tbody>
</Table>
<div className="tableOptionsWrapper">
Expand Down
Loading

0 comments on commit 0481354

Please sign in to comment.