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

feat(datatrakWeb): RN-1243: resubmit surveys via Datatrak Web #5638

Merged
merged 34 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
fda8b92
WIP
alexd-bes May 13, 2024
6a8058f
Rearrange routes
alexd-bes May 13, 2024
b63f3d3
Ability to resubmit
alexd-bes May 14, 2024
af7fcf0
Ability to upload images in resubmission
alexd-bes May 14, 2024
20e4d54
Success screen
alexd-bes May 14, 2024
5ca9f76
Loading state
alexd-bes May 14, 2024
4f137cc
Disable create new autocomplete abilities in resubmit (temp)
alexd-bes May 14, 2024
b16feb0
tidy ups
alexd-bes May 14, 2024
dc24892
Remove unused import
alexd-bes May 14, 2024
a1484f7
Fix imports
alexd-bes May 14, 2024
2fc2a80
Update SurveyResponsePage.tsx
alexd-bes May 14, 2024
ecd9695
Fix tests
alexd-bes May 14, 2024
79532d8
Update packages/datatrak-web-server/src/routes/SingleSurveyResponseRo…
alexd-bes May 15, 2024
99c064c
feat(adminPanel): RN-1243: Resubmit survey response modal should link…
alexd-bes May 15, 2024
12d308d
Merge branch 'dev' into rn-1243-resubmit-surveys
alexd-bes May 22, 2024
732f1f5
Build fixes
alexd-bes May 22, 2024
1ec1193
Merge branch 'dev' into rn-1243-resubmit-surveys
alexd-bes May 23, 2024
74bd8e8
Merge branch 'dev' into rn-1243-resubmit-surveys
alexd-bes May 23, 2024
455eb49
Merge pull request #5718 from beyondessential/dev
avaek Jun 10, 2024
73e1de7
Apply primary entity answer to resubmit
alexd-bes Jun 10, 2024
6089c63
Fix breaking data_time questions
alexd-bes Jun 10, 2024
a092239
Fix build
alexd-bes Jun 10, 2024
a826d93
Fix survey responses with file uploads
alexd-bes Jun 10, 2024
8d8b169
Display file name for saved file questions and fix remove file value
alexd-bes Jun 10, 2024
a2c5cef
Use dataTime for date questions
alexd-bes Jun 11, 2024
a44fb2c
Merge branch 'dev' into rn-1243-resubmit-surveys
alexd-bes Jun 12, 2024
4efb651
Merge branch 'dev' into rn-1243-resubmit-surveys
alexd-bes Jun 19, 2024
c99d11f
fix permissions
alexd-bes Jun 20, 2024
4384ab4
Merge pull request #5754 from beyondessential/dev
avaek Jul 2, 2024
aa3ab0c
Send timezone through with resubmission
alexd-bes Jul 4, 2024
1366e62
Open up permissions
alexd-bes Jul 8, 2024
8e451a3
Merge branch 'dev' into rn-1243-resubmit-surveys
alexd-bes Jul 9, 2024
79212bf
Merge branch 'dev' into rn-1243-resubmit-surveys
alexd-bes Jul 23, 2024
a193aec
feat(dataTrak): RN-1274: Keep 'outdated' historical survey responses …
rohan-bes Aug 15, 2024
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
1 change: 1 addition & 0 deletions packages/admin-panel/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ REACT_APP_CLIENT_BASIC_AUTH_HEADER=
REACT_APP_VIZ_BUILDER_API_URL=
SKIP_PREFLIGHT_CHECK=
PARSE_LINK_HEADER_MAXLEN=
REACT_APP_DATATRAK_WEB_URL=
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const useEntities = search =>
['entities', search],
async () => {
const endpoint = stringifyQuery(undefined, `entities`, {
columns: JSON.stringify(['name', 'code', 'id']),
columns: JSON.stringify(['name', 'code', 'id', 'country_code']),
filter: JSON.stringify({
name: { comparator: 'ilike', comparisonValue: `%${search}%`, castAs: 'text' },
}),
Expand Down
26 changes: 26 additions & 0 deletions packages/admin-panel/src/api/mutations/useEditSurveyResponse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Tupaia
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/

import { useMutation, useQueryClient } from 'react-query';
import { useApiContext } from '../../utilities/ApiProvider';

export const useEditSurveyResponse = (surveyResponseId, updatedSurveyResponse) => {
const queryClient = useQueryClient();
const api = useApiContext();
return useMutation(
[`surveyResponseEdit`, surveyResponseId, updatedSurveyResponse],
() => {
return api.put(`surveyResponses/${surveyResponseId}`, null, updatedSurveyResponse);
},
{
throwOnError: true,
onSuccess: async () => {
// invalidate the survey response data
await queryClient.invalidateQueries(['surveyResubmitData', surveyResponseId]);
return 'completed';
},
},
);
};

This file was deleted.

2 changes: 1 addition & 1 deletion packages/admin-panel/src/importExport/ExportButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import React from 'react';
import PropTypes from 'prop-types';
import ExportIcon from '@material-ui/icons/GetApp';
import { ExportIcon } from '../icons';
import { makeSubstitutionsInString } from '../utilities';
import { useApiContext } from '../utilities/ApiProvider';
import { ColumnActionButton } from '../table/columnTypes/ColumnActionButton';
Expand Down
33 changes: 19 additions & 14 deletions packages/admin-panel/src/routes/projects/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,6 @@ const DEFAULT_FIELDS = [
maxWidth: 480,
},
},
{
Header: 'Config',
source: 'config',
type: 'jsonTooltip',
editConfig: {
type: 'jsonEditor',
labelTooltip: 'eg. { "tileSets": "osm,satellite,terrain", "permanentRegionLabels": true }',
},
},
{
Header: 'Sort',
source: 'sort_order',
width: 80,
},
];

const CREATE_FIELDS = [
Expand All @@ -101,6 +87,11 @@ const CREATE_FIELDS = [
required: true,
},
...DEFAULT_FIELDS,
{
Header: 'Sort',
source: 'sort_order',
width: 80,
},
];

const EDIT_FIELDS = [
Expand All @@ -111,6 +102,20 @@ const EDIT_FIELDS = [
required: true,
},
...DEFAULT_FIELDS,
{
Header: 'Config',
source: 'config',
type: 'jsonTooltip',
editConfig: {
type: 'jsonEditor',
labelTooltip: 'eg. { "tileSets": "osm,satellite,terrain", "permanentRegionLabels": true }',
},
},
{
Header: 'Sort',
source: 'sort_order',
width: 80,
},
];

const NEW_PROJECT_COLUMNS = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,45 @@
* Tupaia
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/

import React from 'react';
import { getBrowserTimeZone } from '@tupaia/utils';
import moment from 'moment';
import { ApprovalStatus } from '@tupaia/types';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import { SurveyResponsesExportModal } from '../../importExport';
import { getPluralForm } from '../../pages/resources/resourceName';
import { OutdatedFilter } from '../../table/columnTypes/columnFilters';

const RESOURCE_NAME = { singular: 'survey response' };

// Don't include not_required as an editable option because it can lead to
// mis-matches between surveys and survey responses
export const APPROVAL_STATUS_TYPES = Object.values(ApprovalStatus).map(type => ({
label: type,
value: type,
}));
const GREEN = '#47CA80';
const GREY = '#898989';

const Pill = styled.span`
background-color: ${({ $color }) => {
return `${$color}33`; // slightly transparent
}};
border-radius: 1.5rem;
padding: 0.3rem 0.9rem;
color: ${({ $color }) => $color};
.cell-content:has(&) > div {
overflow: visible;
}
`;

const ResponseStatusPill = ({ value }) => {
const text = value ? 'Outdated' : 'Current';
const color = value ? GREY : GREEN;
return <Pill $color={color}>{text}</Pill>;
};

ResponseStatusPill.propTypes = {
value: PropTypes.bool,
};

ResponseStatusPill.defaultProps = {
value: false,
};

const surveyName = {
Header: 'Survey',
Expand Down Expand Up @@ -56,9 +80,13 @@ const dateOfData = {
},
};

const approvalStatus = {
Header: 'Approval status',
source: 'approval_status',
const responseStatus = {
Header: 'Response status',
source: 'outdated',
Filter: OutdatedFilter,
width: 180,
// eslint-disable-next-line react/prop-types
Cell: ({ value }) => <ResponseStatusPill value={value} />,
};

const entityName = {
Expand All @@ -80,7 +108,7 @@ export const SURVEY_RESPONSE_COLUMNS = [
assessorName,
date,
dateOfData,
approvalStatus,
responseStatus,
{
Header: 'Export',
type: 'export',
Expand Down
25 changes: 25 additions & 0 deletions packages/admin-panel/src/routes/surveys/surveys.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { SurveyEditFields } from '../../surveys/SurveyEditFields';
import { QUESTION_FIELDS as BASE_QUESTION_FIELDS } from './questions';
import { EditSurveyPage } from '../../pages/resources';

const { REACT_APP_DATATRAK_WEB_URL } = import.meta.env;

const RESOURCE_NAME = { singular: 'survey' };

const PERIOD_GRANULARITIES = [
Expand Down Expand Up @@ -175,6 +177,16 @@ const SURVEY_COLUMNS = [
SURVEY_FIELDS.project,
SURVEY_FIELDS.name,
SURVEY_FIELDS.code,
{
Header: 'Project ID',
source: 'project.id',
show: false,
},
{
Header: 'countries',
source: 'countryCodes',
show: false,
},
{
Header: 'Permission group',
source: 'permission_group.name',
Expand All @@ -183,6 +195,19 @@ const SURVEY_COLUMNS = [
Header: 'Survey group',
source: 'survey_group.name',
},
{
Header: 'View',
type: 'externalLink',
actionConfig: {
generateUrl: row => {
const { code, countryCodes } = row;
if (!countryCodes || !countryCodes.some(countryCode => !!countryCode)) return null;
const countryCodeToUse = countryCodes.includes('DL') ? 'DL' : countryCodes[0];
return `${REACT_APP_DATATRAK_WEB_URL}/survey/${countryCodeToUse}/${code}/1`;
},
title: 'View in DataTrak',
},
},
{
Header: 'Export',
type: 'export',
Expand Down
Loading