Skip to content

Commit

Permalink
WAITP-1475: survey project mapping (#5190)
Browse files Browse the repository at this point in the history
* Waitp 1368 datatrak web fe setup (#4875)

* Added skeleton datatrak-server package

* Added datatrak-server to CI/CD

* wip datatrak front end app

* Added api-client to datatrak-server

* Added /projects route to datatrak-server

* disable eslint and re-install dependencies

* Added /entities route to datatrak-server

* add base views and downgrade react

* Update api.js

* Disabled frozen-lockfile

* Reverted yarn.lock

* Re-enabled frozen lockfile

* Add datatrak to CI/CD

* Added /surveys and /surveyScreenComponents routes

* Re-enabled exports of ui-components

* Switched to using pre-existing build and start scripts for datatrak

* add base form components

* Fix datatrak build

* format data to screens

* Got login working

* Added extra fields to FetchSurveyScreenComponents

* Got project and country selection working

* Upated yarn.lock

* Got survey selection working

* Got Survey page working

* screen steps

* add template styling

* add admin route

* Switched to using .env var for server url

* add logout

* Fixed up FetchUserRoute

* Add submitSurveyResponse route

* labels

* Add entity question

* add entity question to screen

* survey submit

* Update yarn.lock

* Update package.json

* remove anything not from fe

* Merge branch 'dev' into datatrak-hackathon

* Remove unused files

* Add initial fetch example

* Update README.md

* Revert change

* Remove unneeded change

* Add back in datatrak-app

* Add .env.example

* Update files

* Remove unnecessary code

* Fixes

* Test remove server setup

* Remove test step

* WAITP-1368: Basic page layout (#4890)

* basic page layout

* styles

* use theme colours

---------

Co-authored-by: Rohan Port <rohan@beyondessential.com.au>
Co-authored-by: Tom Caiger <caigertom@gmail.com>

* WAITP-1367 DataTrak Server (#4902)

* WAITP-1367 Add datatrak_session table to db

* WAITP-1367 Add request type for datatrak user request

* WAITP-1367 Add datatrak-server package

* WAITP-1367 Regenerate yarn.lock

* WAITP-1367 Fix minor copy-paste errors

* WAITP-1367 Add datatrak_session to ignored tables for hooks

* WAITP-1367 Add datatrak-server to server startup script in datatrak-web

* WAITP-1367 Add datatrak-server to CI/CD scripts

* WAITP-1367 Reduce layer count in dockerfile

* WAITP-1367 Regenerate types

* WAITP-1367 Regnerate types (again)

* WAITP-1367 Fixup clashing exports

* WAITP-1367 Rebalance test batching

* WAITP-1367: Rename datatrak-server to datatrak-web-server (#4904)

* find and replace

* rename package

* Update tupaia-ci-cd.Dockerfile

* update types

* Generate types

* Revert "Generate types"

This reverts commit 6fbbec6.

* WAITP-1277 datatrak-web login form part 1 (#4899)

* Setup reusable login form

* Working login

* User menu

* Fix versions

* Comments and tidy ups

* Fix build issue

* Add verify email view

* Update loginForm.stories.js

* FIx export

* Fix storybook

* Fixes

* Fix route names

* Update private routes and fix build

* Fix type errors

* Fix types

* Generate types

* Revert "Generate types"

This reverts commit de0fb64.

* Create private route

---------

Co-authored-by: Tom Caiger <caigertom@gmail.com>

* WAITP-1377 register page (#4903)

* Setup reusable login form

* Working login

* User menu

* Fix versions

* Comments and tidy ups

* Fix build issue

* Add verify email view

* Update loginForm.stories.js

* FIx export

* Update storybook

* Fix storybook

* Add pages to datatrak-web and mobile styling

* Fixes

* Fix route names

* Update private routes and fix build

* Fix height

* Fix type errors

* Fix types

* Generate types

* Revert "Generate types"

This reverts commit de0fb64.

* Create private route

* Fix build

* Fix casing

* Fix build error

---------

Co-authored-by: Tom Caiger <caigertom@gmail.com>

* WAITP-1379: select survey (#4925)

* Initial landing page

* Working survey select

* Fix type errors

* WAITP-1411: Setup datatrak survey screens (#4920)

* Setup reusable login form

* Working login

* User menu

* Fix versions

* Comments and tidy ups

* Fix build issue

* Add verify email view

* Update loginForm.stories.js

* FIx export

* Fix storybook

* Fixes

* Fix route names

* survey screens

* save form data

* routes

* Update Routes.tsx

* fix types

* scrren layout

* refactor context

* tidy up css

* resolve conflicts

* Update merge

* Update useSurveyScreenComponents.tsx

---------

Co-authored-by: acdunham <alex@beyondessential.com.au>

* Fix circular types error

* Fix route

* Test types generate

* revert generate changes

---------

Co-authored-by: Tom Caiger <caigertom@gmail.com>

* Waitp 1417 top progress bar (#4923)

* Started on progress bar commit

* added more styling and changed logic

* designed logic for progress bar

* fixed progress bar colour

* fixed pr

* ready for retest

* Added to survey page

* cleaned a few things

---------

Co-authored-by: acdunham <alex@beyondessential.com.au>

* WAITP-1345: core question types (#4930)

* Text question

* Binary and radio questions

* Update types

* ƒix option parsing

* Date question

* Update question number logic

* Instruction question

* Update index.ts

* Handle review screen

* Fix date styles

* Update text field width

* Update line height

* Add types

* remove question number for now

* Checkbox question and styling

* Checkbox question

* Add comment

* DateTimeQuestion

* Add controller around all questions

* Add in question number

* Reorder imports

* Handle more than 26 questions on a screen

* Update casing.ts

* Fix imports

* Fixes and generate types

* Fix merge and question number logic

* Fix props

* yarn generate

* yarn generate

* WAITP-1428: datatrak design updates (#4949)

* Auth updates part 1

* Auth view

* Survey screen

* Tooltip buttons

* Use theme variable

* Update theme variable for primary text

* Auth layout

* Move styles into common form files

* Fix layout padding

* Update layout

* Update SurveySelectPage.tsx

---------

Co-authored-by: Tom Caiger <caigertom@gmail.com>

* Waitp 1414 code generator hints (#4944)

* Setup reusable login form

* Working login

* User menu

* Fix versions

* Comments and tidy ups

* Fix build issue

* Add verify email view

* Update loginForm.stories.js

* FIx export

* Fix storybook

* Fixes

* Fix route names

* survey screens

* save form data

* routes

* Update Routes.tsx

* Initial landing page

* fix types

* scrren layout

* refactor context

* Working survey select

* tidy up css

* resolve conflicts

* Fix type errors

* Update merge

* Update useSurveyScreenComponents.tsx

* work in progress

* need testing

* quick fix

* styling commit

* few pr changes

* changed folder locations

* fixed imports and exports

---------

Co-authored-by: acdunham <alex@beyondessential.com.au>
Co-authored-by: Tom Caiger <caigertom@gmail.com>

* WAITP-1346: Survey contents menu (#4958)

* Working menu

* Remove unused import

* Fixes

* WAITP-1350: Cancel survey workflow (#4964)

* WAITP-1327: Geolocate question type (#4917)

* WIP on geolocation question

* Pushing to remote for pairing

* updates to map pin drop functionality and ui

* tidying up unused imports and redundant components

* Fixes part 1

* Updates

* Fixes

---------

Co-authored-by: wduncker <wduncker@LAPTOP-AFVENG10>
Co-authored-by: acdunham <alex@beyondessential.com.au>

* Waitp 1427 survey submit success screen (#4965)

* almost done with routes

* sorted, does need cleaning up

* survey success commit

* Tidy up files

* Fix merge issues

* Fixes

* Fix types

* remove questions url

* Fix types

---------

Co-authored-by: acdunham <alex@beyondessential.com.au>

* update ci cd with datatrak web

* add stub test

* WAITP-1407: Datatrak project select (#4950)

* project select modal

* save project id for a user

* fix types

* Update ProjectSelectPage.tsx

* edit project

* Update ProjectSelectPage.tsx

* Update ProjectSelectModal.tsx

* custom icons

* pr changes

* request access styles

* request access on click

* update types

* WAITP-1439: Survey review screen (#4985)

* almost done with routes

* sorted, does need cleaning up

* survey success commit

* Tidy up files

* Fix merge issues

* Review screen

* Initial mutation

* Tidy up files

* Fixes

* Update SurveyLayout.tsx

---------

Co-authored-by: Chao Xin Nhin <chaon@missionreadyhq.com>
Co-authored-by: Tom Caiger <caigertom@gmail.com>

* WAITP-1410: Request project access (#4997)

* Working request access

* Add access requested icon to project list

* Add 'EditUserForMe' endpoint

* Remove all countries requested view

* Refactor select list

* Fix on select issue

* Don't have onClick if is not a button

* Generate types

* Fixes

* Update types

* WAITP-1429: Autocomplete question (#5010)

* WIP

* Finish styling and get working

* Update styles

* Update font size

* Update hover colour

* Update packages/datatrak-web/src/features/Questions/AutocompleteQuestion.tsx

Co-authored-by: Tom Caiger <caigertom@gmail.com>

---------

Co-authored-by: Tom Caiger <caigertom@gmail.com>

* WAITP-1413: Datatrak Web Entity Question (#4996)

* setup entities question

* searching

* debounce

* styles

* close button

* sorting search results

* update filters

* remove old entity route

* fix filters

* fix types

* Update EntityList.js

* Update EntitiesRoute.ts

* refactor to match new list component

* Update useUser.ts

* add mock api with msw (#5019)

* WAITP-1437 toast messages (#5015)

* Toast messages

* Remove buttons from landing page

* Apply error handling by default

* Fixes

* Fix build errors and merge conflicts

* Fix error

* Fix broken test

* WAITP-1407: Add support for user preferences to user accounts (#5023)

* migration

* saving user preferences

* add validation to edit user endpoint

* fix tests

* WAITP-1431: Select country (#5026)

* Generate types

* migration

* Working country display

* WIP

* saving user preferences

* Add country name to survey toolbar

* Add country to entity search

* add validation to edit user endpoint

* Clean up and add comments

* Plumb in saving country

* Generate types

* Update schemas.ts

* Fixes

* Reorganise files

* Fix build errors

---------

Co-authored-by: Tom Caiger <caigertom@gmail.com>

* WAITP-1423: Primary entity question (#5027)

* Toast messages

* Remove buttons from landing page

* Apply error handling by default

* Generate types

* migration

* Working country display

* WIP

* saving user preferences

* Fixes

* Fix build errors and merge conflicts

* Add country name to survey toolbar

* setup submit

* Add country to entity search

* add validation to edit user endpoint

* Clean up and add comments

* Plumb in saving country

* move mocks

* primary entity handling

* Generate types

* Update schemas.ts

* attributes filter

* use country data

* Fixes

* Reorganise files

* Fix build errors

* update survey data key

---------

Co-authored-by: acdunham <alex@beyondessential.com.au>

* WAITP-1369 Setup datatrak deployment (#5031)

* WAITP-1369 Add datatrak to servers.conf and subdomain suffixes

* WAITP-1369 Regenerate types

* WAITP-1369 Regen yarn.lock

* WAITP-1369 Fixup entity-server test

* WAITP-1369 Fixup usage of entity request type

* WAITP-1369 Remove broken include

* WAITP-1369 Regen types

* WAITP-1369 Fixup unit test

* Update tsconfig-build for datatrak-web-server

* no-issue-dedupe-react-router-dom

* WAITP-1349: Survey submit (#5032)

* Working survey submit

* Only show repeat survey button when canRepeat is true

* Fix todos

* Add loader

* Add coconut notification

* Tidy up

* Fix variable names

* Fix types

* Reorder imports

* Fix build error

* No issue: add test runner to datatrak-web (#5034)

* setup test runner

* add example survey

* change import meta to process env

* update survey test

* Update survey.test.tsx

* WAITP-1429: Autocomplete add and filtering of options (#5040)

* Enable create new option and filter options

* Tidy up code

* Add tests for autocomplete question

* Update AutocompleteQuestion.test.tsx

* Add survey submit tests

* Update packages/datatrak-web/src/__tests__/features/Questions/AutocompleteQuestion.test.tsx

Co-authored-by: Tom Caiger <caigertom@gmail.com>

* Fix types

---------

Co-authored-by: Tom Caiger <caigertom@gmail.com>

* WAITP-1416: Visibility criteria (#5044)

* WIP visibility criteria

* Working survey visibility criteria

* Generate types

* Add tests

* Redirect user if survey screen is not visible

* Reset invisible answers

* Handle when value is not an array

* Remove only from test

* Fix tests

* WAITP-1440: Mobile styling (#5042)

* WIP mobile styling

* WIP

* Fix project button styling

* Fix types

* Mobile app prompt

* Fix dashboard button styling

* WAITP-1347: Validation criteria (#5047)

* WIP visibility criteria

* Working survey visibility criteria

* Generate types

* Add tests

* Redirect user if survey screen is not visible

* Reset invisible answers

* Handle when value is not an array

* Remove only from test

* Fix tests

* Working validation

* Working validation

* Fix autocomplete styling

* Fix autocomplete issue

* Extract getRules function

* Fix typo

* No issue: Update survey screen fetching (#5050)

* Update get surveys endpoint

* Change to using surveys endpoint

* Fix types and visible question logic

* Remove old route

* Fix types and tests

* Generate types

* WAITP-1424: Entity question upserts (#5045)

* Enable create new option and filter options

* Tidy up code

* add filter prop

* Add tests for autocomplete question

* Update AutocompleteQuestion.test.tsx

* Add survey submit tests

* Submit Survey route

* Update useSubmitSurvey.ts

* add entities upserted

* update test suite

* fix bad merge

* update types

* set country in upsert entity

* Update schemas.ts

* fix up types

* fix tests

* fix schema

* fix tests

* wip refactor form submission

* move tests to server

* generate schemas

* fix entity test

* Update render.tsx

* Update useSubmitSurvey.test.ts

* Update render.tsx

* reuse survey request types

* Update schemas.ts

* fix question types

* fix types

* Update schemas.ts

* optional screen id

---------

Co-authored-by: acdunham <alex@beyondessential.com.au>

* WAITP-1430: condition question (#5049)

* WIP visibility criteria

* Working survey visibility criteria

* Generate types

* Add tests

* Redirect user if survey screen is not visible

* Reset invisible answers

* Handle when value is not an array

* Remove only from test

* Fix tests

* Conditional questions working

* Get question fully updating

* Generate types

* Add tests and update types

* Update survey.json

* Fix types and build

* Fix tests

* Fix tests and build

* WAITP-1453: UI updates (#5052)

* Handle location errors

* Fix redirect issue for requesting access

* Add tooltip delay

* Add delay on mobile devices

* Tidy tooltip props code

* Update popovers

* Update header heights

* Update number field width

* Make text inputs multiline when text wraps

* Make radio labels full width

* Clip side menu item length

* Center instruction only screens

* Remove horizontal centering

* Hide placeholder in review screen

* Update survey icons

* Remove unused import

* Fix build errors

* Fixes

* Fix errors

* WAITP-1412: Arithmetic question (#5054)

* WIP visibility criteria

* Working survey visibility criteria

* Generate types

* Add tests

* Redirect user if survey screen is not visible

* Reset invisible answers

* Handle when value is not an array

* Remove only from test

* Fix tests

* Conditional questions working

* Get question fully updating

* Generate types

* Add tests and update types

* Update survey.json

* Fix types and build

* Fix tests

* Initial logic and separate out context

* Working arithmetic question

* Fix tests and build

* Generate types

* Fix types

* Add tests

* Add handling for custom display text

* WAITP-1276: Forgot password (#5056)

* Add forgot passowrd view

* Working form

* Add stories

* Fix build

* Set height on forgot password screen

* Reset success screen

* Reorder imports

* WAITP-1345:Core question updates (#5066)

* Allow color to be set on radio options

* Get help text working

* Update SurveyQuestionGroup.tsx

* Update types

* WAITP-1349: Fix DataTrak survey submit (#5078)

* Update surveyResponse.js

* Update surveyResponse.js

* WAITP-1454: design updates (#5079)

* Update hover state for primary buttons

* New validation

* Update text area focus styles

* Update project button font weight

* Update checkbox colour

* Remove menu list item hover

* Text sizing and close menu on click

* Update landing page display sizing

* Fix geolocate accuracy

* Update validation types

* Fix build

* Fix autocomplete filter

* PR fixes

* Alphabetize survey results

* Update sorting

* WAITP-1454: Fix sorting of surveys (#5080)

* Update hover state for primary buttons

* New validation

* Update text area focus styles

* Update project button font weight

* Update checkbox colour

* Remove menu list item hover

* Text sizing and close menu on click

* Update landing page display sizing

* Fix geolocate accuracy

* Update validation types

* Fix build

* Fix autocomplete filter

* PR fixes

* Alphabetize survey results

* Update sorting

* Fix sorting in folders

* Update FE sorting

* tile component

* Revert "tile component"

This reverts commit 7b612fb.

* WAITP-1454: UI changes (#5089)

* tile component

* Show modal when exiting survey via home button

* Remove unused imports

* Stop menu re-rendering on change of survey screen

* Update button disabled state

* Fix build errors

* Fix tests

* Close side menu on screen change on mobile

* clean up code from another branch

* Update LandingPage.tsx

---------

Co-authored-by: Tom Caiger <caigertom@gmail.com>

* WAITP-1377 Forward signup route to web config server (#5090)

* WAITP-1377 Forward signup route to web config server

* WAITP-1377 Fixup lint

* WAITP-1449: QR code generator (#5086)

* WIP visibility criteria

* Working survey visibility criteria

* Generate types

* Add tests

* Redirect user if survey screen is not visible

* Reset invisible answers

* Handle when value is not an array

* Remove only from test

* Fix tests

* Conditional questions working

* Get question fully updating

* Generate types

* Add tests and update types

* Update survey.json

* Fix types and build

* Fix tests

* Initial logic and separate out context

* Working arithmetic question

* Fix tests and build

* Generate types

* Fix types

* Add tests

* WIP

* WIP

* WIP

* WIP

* Working qr code

* Fix types

* Update test

* Fix tests

* PR fixes

* WAITP-1415: Photo upload question (#5099)

* WIP

* Use built in functionality

* Add comment

* Fix build errors

* no-issue-fix-types-after-merge

* WAITP-1357: Datatrak dashboard survey responses (#5091)

* Update LandingPage.tsx

* update landing page

* data fetching layer

* fix console errors

* re organise landing page

* tooltips

* style tweaks

* update landing page layout

* horizontal scroll

* page limit

* WAITP-1461: Datatrak design feedback (#5109)

* Update LandingPage.tsx

* update landing page

* data fetching layer

* fix console errors

* re organise landing page

* tooltips

* style tweaks

* update landing page layout

* horizontal scroll

* page limit

* project select page

* menu ux

* Update useSubmitSurvey.ts

* gps question

* Update index.html

* Update ProjectsRoute.ts

* theming

* Update mui.d.ts

* Update useSubmitSurvey.test.ts

* Update theme.ts

* Update SurveySelectPage.tsx

* Update SurveySelectPage.tsx

* Update useValidationResolver.ts (#5128)

* WAITP-1412: fix arithmetic questions

* one time login flow (#5138)

* WAITP-1354: Leaderboard (#5132)

* no-issue: Add @tupaia/server-utils package (#5121)

* RN-1060: (task) Moved sendEmail to @tupaia/server-utils (#5126)

* RN-1060: (task) Added dashboards/:project/:entity/:dashboard/export route to tupaia-web (#5125)

* WAITP-1354: Leaderboard

* Update copyright

* Update internal email

* Update email filter

* Fix response type

* Update packages/datatrak-web/src/features/Leaderboard/LeaderboardTable.tsx

Co-authored-by: Tom Caiger <caigertom@gmail.com>

* Update background variable

* Update branch name validation script (#5136)

* Update to use new leaderboard model

* Revert "Merge branch 'dev' into waitp-1354-leaderboard"

This reverts commit c2acdbe, reversing
changes made to 747f182.

* Fix types

* Update packages/database/src/modelClasses/SurveyResponse.js

Co-authored-by: Rohan Port <59544282+rohan-bes@users.noreply.github.com>

* PR fixes

* Fix error

---------

Co-authored-by: Rohan Port <59544282+rohan-bes@users.noreply.github.com>
Co-authored-by: Tom Caiger <caigertom@gmail.com>
Co-authored-by: Ethan McQuarrie <69437175+EMcQ-BES@users.noreply.github.com>

* WAITP-1356: recent surveys (#5113)

* Update LandingPage.tsx

* update landing page

* data fetching layer

* fix console errors

* re organise landing page

* tooltips

* style tweaks

* update landing page layout

* horizontal scroll

* page limit

* Frontend layout

* Working request

* Refetch recent surveys on submit

* Fix recent survey request and styling

* Use grid and update heading element

* Remove unnecessary css

* PR fixes

---------

Co-authored-by: Tom Caiger <caigertom@gmail.com>

* WAITP-1469: account delete (#5134)

* WIP

* Account deletion

* Update component for section

* Update modals

* Remove forced open state

* Fix types

* fix build error

* Update packages/datatrak-web/src/api/mutations/useEditUser.ts

Co-authored-by: Tom Caiger <caigertom@gmail.com>

* Update packages/datatrak-web/src/api/mutations/useEditUser.ts

Co-authored-by: Tom Caiger <caigertom@gmail.com>

* Change format

* fix bad merge

* return zeros for rewards

---------

Co-authored-by: Tom Caiger <caigertom@gmail.com>

* WAITP-1330: File upload question type (#5100)

* WIP

* Use built in functionality

* Add comment

* Fix build errors

* Working file upload

* Fix build

* Remove unused vars

* Update format of file upload answers

* Update schemas.ts

* Update processSurveyResponse.test.ts

* Update upsertAnswers.js

---------

Co-authored-by: Tom Caiger <caigertom@gmail.com>

* WAITP-1424: Datatrak PrimaryEntity question fix (#5144)

* fix rewards types

* update primary entity question name

* WIP

* Fix success screen layout

* Fix date change issue

* Fix error styling

* Working activity feed

* Tidy ups

* WAITP-1427: Fix survey cancelling (#5148)

* Update CancelSurveyModal.tsx

* tidy up landing page

* fix console errors

* No issue: Only generate QR code when createNew is true

* No issue: Fix tests

* Remove permission group and country from admin panel feed items

* No issue: Fix recent survey layout

* Working pinned posts

* No issue: Login redirect (#5151)

* Redirect to route on login or project select

* Formatting

* Always show user on leaderboard

* WAITP-1478 Single survey response endpoint (#5153)

* WAITP-1478 Add types definition for RecentSurveyResponseRoute

* WAITP-1478 Regen types

* WAITP-1478 Add route for RecentSurveyResponse

* WAITP-1478 Fixup export

* WAITP-1478 Update url

* WAITP-1478 Regen types

* WAITP-1478 Update survey response answers to map by question_id

* WAITP-1478 Rename RecentSurveyResponse to SingleSurveyResponse

* WAITP-1478 Rename files

* Fix PR

* Generate types

* Fix styling

* Update Button.tsx

* Fixes

* WAITP-1452: Datatrak-web refactor survey context (#5156)

* Update useLogin.ts

* refactor survey context to be at survey level

* Create migration

* Update types

* Responsive styling (#5158)

* Responsive styling

* Fix padding on mobile

* Handle project id in queries

* Filter user rewards by project id

* Update queries to have projectId as optional param

* Fix bindings

* Update SurveyResponse.js

* Add project column to admin panel

* WAITP-1452: Recent survey response page (#5157)

* WAITP-1478 Add types definition for RecentSurveyResponseRoute

* WAITP-1478 Regen types

* WAITP-1478 Add route for RecentSurveyResponse

* WAITP-1478 Fixup export

* WAITP-1478 Update url

* WAITP-1478 Regen types

* useSurveyResponse

* survey review screen

* wip set default values

* set up route

* Update useLogin.ts

* refactor survey context to be at survey level

* remove bad merge

* survey data

* basic working setup

* remove debug changes

* split out paginator

* put page back in survey layout

* refactor layout components

* Update index.ts

* Update SurveyContext.tsx

* Update SurveyReviewSection.tsx

---------

Co-authored-by: Ethan McQuarrie <ethan@beyondessential.com.au>

* Update 20231112212117-AddProjectIdToSurveys-modifies-schema.js

* Add index to migration

* Fix migration

* Fix typo

* Cap survey name length at 50 characters

* WAITP-1490: Datatrak current user context (#5170)

* add current user context

* add error display

* rename context

* WAITP-1431: Fix survey select filter (#5177)

* Update SurveysRoute.ts

* remove tsx extentions

* Update SurveysRoute.ts

* WAITP-1387: Add survey project field (#5172)

* Responsive styling of dashboard leaderboard (#5173)

* Responsive styling of dashboard leaderboard

* Fix type error

* Survey not found error handling (#5160)

* Survey not found error handling

* Reorder imports

* Updates to route

* Fix types

* Remove unused imports

* Error page rename

* Rename page

* no-issue: Fix `location.state` null (#5179)

* extract useFromLocation

* extract `useFromLocation` to own file and use

* WAITP-1474: Update success illustration on DataTrak (#5159)

* generify high-five graphic filename

* update submission success graphic

* define margins along block/inline axes

See https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_flow_layout/Block_and_inline_layout_in_normal_flow

* success screen fix horizontal overflow

* define survey success image dimen with `rem`

* relabel button ‘Close’ → ‘Return to dashboard’

* Fix package error

* Fix autocomplete validation issue

* Create migration for surveys to project mapping

* WAITP-1431: Update datatrak survey url with country code (#5182)

* add Single Entity Route

* use country url to submit

* fix tests

* make TupaiaWebEntityRequest re-usable

* Update SingleEntityRoute.ts

* update recent surveys and responses routes

* handle recent survey submissions

* Update SurveyResponsesSection.tsx

* update country id in survey page

* remove unused code

* Update processSurveyResponse.test.ts

* Update queries

* Update preferred project on survey load

* Update queries and FE to handle project ids, and add migration for project creation

* Add toast to tell user project has been updated

* Remove unused import

* Remove unused import

* Update projectSurveyMappings.json

* Filter out new empty projects from Tupaia Web frontend

* Fix merge issues

* Update mappings

* Add new projects

* WAITP-1480: survey duplication (#5193)

* Make migration

* Update migration

* Update migration

* Remove survey responses when migrating down

* Update GETSurveyResponses.test.js

---------

Co-authored-by: Rohan Port <rohan@beyondessential.com.au>
Co-authored-by: Tom Caiger <caigertom@gmail.com>
Co-authored-by: Ethan McQuarrie <69437175+EMcQ-BES@users.noreply.github.com>
Co-authored-by: Chao Xin Nhin <122791168+chaoxinnhin@users.noreply.github.com>
Co-authored-by: Wilhelmus Duncker <122330202+WDuncker@users.noreply.github.com>
Co-authored-by: wduncker <wduncker@LAPTOP-AFVENG10>
Co-authored-by: Chao Xin Nhin <chaon@missionreadyhq.com>
Co-authored-by: Ethan McQuarrie <ethan@beyondessential.com.au>
Co-authored-by: Rohan Port <59544282+rohan-bes@users.noreply.github.com>
Co-authored-by: Jasper Lai <33956381+jaskfla@users.noreply.github.com>
Co-authored-by: RajneelR <132311480+RajneelR@users.noreply.github.com>
  • Loading branch information
12 people authored Nov 30, 2023
1 parent 5622a5f commit 71f93db
Show file tree
Hide file tree
Showing 24 changed files with 2,969 additions and 75 deletions.
4 changes: 2 additions & 2 deletions packages/api-client/src/connections/WebConfigApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class WebConfigApi extends BaseApi {
public async fetchMeasureData(mapOverlayCode: string, query?: QueryParameters | null) {
return this.connection.get('measureData', { ...query, mapOverlayCode });
}
public async fetchProjects() {
return this.connection.get('projects');
public async fetchProjects(query?: QueryParameters | null) {
return this.connection.get('projects', query);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type AccessPolicyObject = Record<string, string[]>;

export type EmptyObject = Record<string, never>;

export type QueryParameters = Record<string, string>;
export type QueryParameters = Record<string, string | boolean>;

export interface AuthHandler {
getAuthHeader: () => Promise<string>;
Expand Down
5 changes: 2 additions & 3 deletions packages/central-server/src/social/getRewardsForUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ export const getRewardsForUser = async (database, userId, projectId = '') => {
JOIN survey on survey.id=survey_id
WHERE user_id = ?
-- If there is no projectId specified, return all survey_responses. eg. on meditrak-app
-- TODO: remove the null project_id check once all surveys have been migrated to have a project_id
${projectId ? 'AND (project_id = ? OR project_id IS NULL)' : ''}
GROUP BY user_id;
${projectId ? 'AND project_id = ?' : ''}
GROUP BY user_id;
`,
// Need to make sure the number of replacements matches the number of ? in the query
projectId ? [userId, projectId] : [userId],
Expand Down
68 changes: 32 additions & 36 deletions packages/central-server/src/tests/apiV2/GETSurveyResponses.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,41 +69,37 @@ describe('Permissions checker for GETSurveyResponses', async () => {
},
]);

const [
vanuatuAdminBuild,
laosAdminBuild,
vanuatuDonorBuild,
laosDonorBuild,
] = await buildAndInsertSurveyResponses(models, [
{
id: vanuatuAdminResponseId,
surveyCode: 'TEST_SURVEY_1',
entityCode: vanuatuEntity.code,
data_time: '2020-01-31T09:00:00',
answers: [],
},
{
id: laosAdminResponseId,
surveyCode: 'TEST_SURVEY_1',
entityCode: laosEntity.code,
data_time: '2020-01-31T09:00:00',
answers: [],
},
{
id: vanuatuDonorResponseId,
surveyCode: 'TEST_SURVEY_2',
entityCode: vanuatuEntity.code,
data_time: '2020-01-31T09:00:00',
answers: [],
},
{
id: laosDonorResponseId,
surveyCode: 'TEST_SURVEY_2',
entityCode: laosEntity.code,
data_time: '2020-01-31T09:00:00',
answers: [],
},
]);
const [vanuatuAdminBuild, laosAdminBuild, vanuatuDonorBuild, laosDonorBuild] =
await buildAndInsertSurveyResponses(models, [
{
id: vanuatuAdminResponseId,
surveyCode: 'TEST_SURVEY_1',
entityCode: vanuatuEntity.code,
data_time: '2020-01-31T09:00:00',
answers: [],
},
{
id: laosAdminResponseId,
surveyCode: 'TEST_SURVEY_1',
entityCode: laosEntity.code,
data_time: '2020-01-31T09:00:00',
answers: [],
},
{
id: vanuatuDonorResponseId,
surveyCode: 'TEST_SURVEY_2',
entityCode: vanuatuEntity.code,
data_time: '2020-01-31T09:00:00',
answers: [],
},
{
id: laosDonorResponseId,
surveyCode: 'TEST_SURVEY_2',
entityCode: laosEntity.code,
data_time: '2020-01-31T09:00:00',
answers: [],
},
]);

laosAdminResponseId = laosAdminBuild.surveyResponse.id;
laosDonorResponseId = laosDonorBuild.surveyResponse.id;
Expand Down Expand Up @@ -220,7 +216,7 @@ describe('Permissions checker for GETSurveyResponses', async () => {
const projectId = 'testId';
// The test data doesn't have project ids, but still want to make sure that it handles the param and returns the correct rewards
const rewards = await getRewardsForUser(app.database, userId, projectId);
expect(rewards.coconuts).to.equal('4');
expect(rewards.coconuts).to.equal(0);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
'use strict';

import projectsToAdd from './migrationData/20231119225952-AddNewSurveyProjects/projectsToAdd.json';
import { codeToId, insertObject, generateId, findSingleRecord, deleteObject } from '../utilities';

var dbm;
var type;
var seed;

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function (options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
};

const createProject = async (db, project) => {
const { name, code, permissionGroup, countryCode, description } = project;

// create project entity
await insertObject(db, 'entity', {
id: generateId(),
code,
parent_id: await codeToId(db, 'entity', 'World'),
name,
type: 'project',
});
const entityHierarchyId = generateId();

// create project entity hierarchy
await insertObject(db, 'entity_hierarchy', {
id: entityHierarchyId,
name: code,
canonical_types: '{}',
});

// create project entity relation between project and country
await insertObject(db, 'entity_relation', {
id: generateId(),
parent_id: await codeToId(db, 'entity', code),
child_id: await codeToId(db, 'entity', countryCode),
entity_hierarchy_id: entityHierarchyId,
});

// create project dashboard
await insertObject(db, 'dashboard', {
id: generateId(),
code: `${code}_project`,
name: 'General',
root_entity_code: countryCode,
sort_order: 1,
});

// create project entry
await insertObject(db, 'project', {
id: generateId(),
code,
description,
sort_order: 15,
image_url: '',
default_measure: '126',
permission_groups: '{Public}',
logo_url: '',
entity_id: await codeToId(db, 'entity', code),
entity_hierarchy_id: entityHierarchyId,
});
};

const hierarchyNameToId = async (db, name) => {
const record = await db.runSql(`SELECT id FROM entity_hierarchy WHERE name = '${name}'`);
return record?.rows[0].id;
};

const removeProject = async (db, project) => {
const { code } = project;
const hierarchyId = await hierarchyNameToId(db, code);

await db.runSql(`DELETE FROM dashboard WHERE code = '${code}_project'`);
await db.runSql(`DELETE FROM project WHERE code = '${code}'`);
await db.runSql(`DELETE FROM entity_relation WHERE entity_hierarchy_id = '${hierarchyId}'`);
await db.runSql(`DELETE FROM entity_hierarchy WHERE name = '${code}'`);
await db.runSql(`DELETE FROM entity WHERE code = '${code}'`);
};

exports.up = function (db) {
return Promise.all(projectsToAdd.map(project => createProject(db, project)));
};

exports.down = function (db) {
return Promise.all(projectsToAdd.map(project => removeProject(db, project)));
};

exports._meta = {
version: 1,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
'use strict';

import projectSurveyMap from './migrationData/20231119234449-AddProjectIdToSurveys/projectSurveyMappings.json';

var dbm;
var type;
var seed;

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function (options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
};

const getProjects = async db => {
const projects = await db.runSql(`
SELECT id, code FROM project where code IN (${projectSurveyMap
.map(item => `'${item.projectCode}'`)
.join(',')});
`);
return projects.rows;
};

exports.up = async function (db) {
// get the projects in the projectSurveyMap
const projects = await getProjects(db);

// get the surveys in the projectSurveyMap
const existingSurveys = await db.runSql(`
SELECT id, code, project_id FROM survey where code IN (${projectSurveyMap
.map(item => `'${item.surveyCode}'`)
.join(',')});
`);

const dbUpdates = projectSurveyMap.reduce((acc, item) => {
// get the project and survey for each item in the projectSurveyMap
const project = projects.find(projectRow => projectRow.code === item.projectCode);
const survey = existingSurveys.rows.find(surveyRow => surveyRow.code === item.surveyCode);

// if either the project or survey is missing, skip this item
if (!project || !survey) return acc;

// return the update query for the survey
return [...acc, `UPDATE survey SET project_id = '${project.id}' WHERE id = '${survey.id}';`];
}, []);

// do the updates
await Promise.all(dbUpdates.map(item => db.runSql(item)));
};

exports.down = async function (db) {
const projects = await getProjects(db);
const existingSurveys = await db.runSql(`
SELECT id, code, project_id FROM survey where code IN (${projectSurveyMap
.map(item => `'${item.surveyCode}'`)
.join(',')});
`);

const dbChanges = projectSurveyMap.reduce((acc, item) => {
// get the project and survey for each item in the projectSurveyMap
const project = projects.find(projectRow => projectRow.code === item.projectCode);
const survey = existingSurveys.rows.find(surveyRow => surveyRow.code === item.surveyCode);

// if either the project or survey is missing, skip this item
// also if the survey doesn't belong to the project, skip this item, as it means it has been updated some other way
if (!project || !survey || survey.project_id !== project.id) return acc;

// return the update query for the survey
return [...acc, `UPDATE survey SET project_id = NULL WHERE id = '${survey.id}';`];
}, []);

await Promise.all(dbChanges.map(item => db.runSql(item)));
};

exports._meta = {
version: 1,
};
Loading

0 comments on commit 71f93db

Please sign in to comment.