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

add reminders and outcome data in ListSU #95

Merged
merged 5 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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%;
}
237 changes: 214 additions & 23 deletions src/components/ListSU/SUTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@ import SortIcon from "../SortIcon/SortIcon";
import SearchField from "../SearchField/SearchField";
import PaginationNav from "../PaginationNav/PaginationNav";
import SurveyUnitLine from "./SurveyUnitLine";
import OverlayTrigger from "react-bootstrap/OverlayTrigger";
import Tooltip from "react-bootstrap/Tooltip";
import D from "../../i18n";
import Utils from "../../utils/Utils";

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 +35,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 +243,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 +274,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 Down Expand Up @@ -284,6 +398,69 @@ class SUTable extends React.Component {
{D.town}
<SortIcon val="city" sort={sort} />
</th>
{survey.communicationRequestConfiguration && (
RenauxLeaInsee marked this conversation as resolved.
Show resolved Hide resolved
<>
<OverlayTrigger
placement="top"
overlay={<Tooltip>{D.totalReminders}</Tooltip>}
>
<th className="ColTotalReminders">
{D.totalRemindersLabel}
</th>
</OverlayTrigger>
<OverlayTrigger
placement="top"
overlay={<Tooltip>{D.latestReminder}</Tooltip>}
>
<th className="ColLatestReminder">
{D.latestReminderLabel}
</th>
</OverlayTrigger>
<OverlayTrigger
placement="top"
overlay={
<Tooltip>{D.secondLatestReminder}</Tooltip>
}
>
<th className="ColLatestReminder">
{`${D.latestReminderLabel}-1`}
</th>
</OverlayTrigger>
<OverlayTrigger
placement="top"
overlay={<Tooltip>{D.thirdLatestReminder}</Tooltip>}
>
<th className="ColLatestReminder">
{`${D.latestReminderLabel}-2`}
</th>
</OverlayTrigger>
<OverlayTrigger
placement="top"
overlay={
<Tooltip>{D.fourthLatestReminder}</Tooltip>
}
>
<th className="ColLatestReminder">
{`${D.latestReminderLabel}-3`}
</th>
</OverlayTrigger>
<th className="ColContactOutcomeType">
{D.contactOutcomeLabel}
</th>
<OverlayTrigger
placement="top"
overlay={<Tooltip>{D.contactOutcomeDate}</Tooltip>}
>
<th
onClick={handleSortFunct("contactOutcomeDate")}
className="Clickable ColContactOutcomeDate"
>
{D.contactOutcomeDateLabel}
<SortIcon val="contactOutcomeDate" sort={sort} />
</th>
</OverlayTrigger>
</>
)}
<th
onClick={handleSortFunct("state")}
className="Clickable ColState"
Expand All @@ -302,14 +479,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