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(meditrakApp): RN-1361: User type question #5820

Merged
merged 38 commits into from
Aug 8, 2024

Conversation

alexd-bes
Copy link
Contributor

@alexd-bes alexd-bes commented Jul 31, 2024

Issue RN-1361: User type question

Changes:

  • Added user_account and user_entity_permission changes to meditrak_sync_queue
  • Added migrations to backfill data to sync queue
  • Added UserAccount and UserEntityPermission database types to meditrak-app
  • Added UserQuestion to meditrak-app
  • Updated the RealmExplorer menu to scroll so that as more db types get added they can be used

Screenshots:

Screenshot 2024-08-01 at 9 40 00 AM
Screenshot 2024-08-01 at 9 39 37 AM

@@ -33,10 +32,11 @@ function getRecordForSync(models, record, recordType, appVersion) {
}
});

const model = models.getModelForDatabaseRecord(recordType);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is because we can get the correct model more accurately this way (e.g. for user_account database record type that i actually the User model)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good change! Tho tbh it always bothers me when our model names don't match the underlying database tables, the worst one is Facility/clinic! Tho now that we mention it, I'm surprised that table was working here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, because in the meditrak sync queue I was calling these records user_account, what it was doing was looking for a model called UserAccount which doesn't exist

const { parentId, ...restOfData } = data;
const permissionGroupObject = restOfData;
return database.update('PermissionGroup', permissionGroupObject);
return database.update('PermissionGroup', data);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added parentId back here so I can get ancestors of permission groups for the user question

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah if we're making this change, we might need to do a full resync of permission_groups?

Copy link
Collaborator

@rohan-bes rohan-bes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff @alexd-bes taking on this complex ticket. Kinda quite proud that it could be achieved in less than 500 lines of code 🥹

@@ -33,10 +32,11 @@ function getRecordForSync(models, record, recordType, appVersion) {
}
});

const model = models.getModelForDatabaseRecord(recordType);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good change! Tho tbh it always bothers me when our model names don't match the underlying database tables, the worst one is Facility/clinic! Tho now that we mention it, I'm surprised that table was working here?

Comment on lines 24 to 25
// skip internal users
if (internal) return null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on adding the users here and then later on filtering them out in the UserQuestion? I feel it would be a bit unexpected that we sync down internal users, but they don't get written to the client's database.

I also wonder if the rules around internal users might change? For instance it does seem like we might want to allow selecting a user with a bes.au email at some point. If we do want to allow that, then it'd be easier to just change the code and not need to worry about resyncing internal users.

Have we chatted with Georgia about the behaviour of internal users btw?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can do that. Georgia asked for internal users to be excluded (and it does the same on Datatrak Web)

},
};

UserEntityPermission.requiredData = ['userId'];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would entityId and permissionGroupId not also be required here?

Comment on lines +49 to +55
// Resync all users so that the new user entity permission structure comes through
10: async (synchroniser, setProgressMessage) => {
await resyncRecordTypes(synchroniser, setProgressMessage, ['user_account']);
},
11: async (synchroniser, setProgressMessage) => {
await resyncRecordTypes(synchroniser, setProgressMessage, ['user_entity_permission']);
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooohhh I didn't know we could do this! This is awesome, it means we don't have to force users to do a full resync when we add those models, just syncing down the new data 😄 Great stuff!

@@ -139,7 +139,8 @@ class AutocompleteComponent extends PureComponent {
data={options}
onEndReached={this.onEndReached}
onEndReachedThreshold={endReachedOffset}
keyExtractor={item => item}
// add an index here to make sure all options are unique
keyExtractor={(item, i) => `${item}-${i}`}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

const { parentId, ...restOfData } = data;
const permissionGroupObject = restOfData;
return database.update('PermissionGroup', permissionGroupObject);
return database.update('PermissionGroup', data);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah if we're making this change, we might need to do a full resync of permission_groups?


const userIds = userEntityPermissionEntries.map(entry => entry.userId);

if (!userIds.length) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!userIds.length) {
if (userIds.length === 0) {

Extremely nitpicky and kinda personal, but js falsy behaviour has been bothering me a little lately so I've been leaning towards this. Totally optional


const handleSelectOption = option => {
const newSelectedUser = users.find(user => user.name === option);
onSelectUser(newSelectedUser?.id ?? null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onSelectUser(newSelectedUser?.id ?? null);
if (!newSelectedUser) {
throw new Error(`Cannot find user in database: ${option}`);
}
onSelectUser(newSelectedUser.id);

This feels like it would never fail, but on the chance it does it feels like it'd be better to fail explicitly than silently 👍

Btw I guess we just don't handle multiple users with the same name huh? Guess that's fine but might be worth mentioning to Georgia

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking in the database, it does seem like we have quite a number of duplicate names:

select first_name || ' ' || last_name, count(*) from user_account ua group by first_name || ' ' || last_name order by count desc

I'm fairly certain almost all of these would be the same person just with multiple emails. However, I worry that things might not work for those users as there might be multiple entries in the dropdown for them and they'd only be able to select one...

Maybe lets chat with Georgia and workout if this is a data cleanup job? But we might also need to sync down emails and show them if the user has multiple accounts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, good point. I think there is a task with the Maui team at the moment to cleanup test users in the db

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this probably will still work - it will save the userId but this is just checking for the value to display as 'selected', but won't actually impact the saved value. Duplicate names is always going to be an issue, unfortunately, since there could be multiple 'John Smiths', but unless we show the email address, I'm not sure what we can do to fix that

.map(
(id, i) =>
// the timestamp is incremented by i to ensure that each record has a unique timestamp
`('${generateId()}', 'update', 'user_account', '${id}', ${timestamp + i})`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`('${generateId()}', 'update', 'user_account', '${id}', ${timestamp + i})`,
`('${generateId()}', 'update', 'user_account', '${id}', ${getSyncQueueChangeTime(i)})`,

We have this getSyncQueueChangeTime function in the tsutils package that we use when inserting records into the meditrak_sync_queue which we should probably use here. Tbh it doesn't differ much from what you're doing just that it divides the index by 1000 so that it's a decimal

}
return restOfRecord;
},
minAppVersion: '1.14.142',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
minAppVersion: '1.14.142',
minAppVersion: '1.14.143',

Might be worth bumping the version as part of this ticket too. If we did accidentally release this without a version bump it would create a few problemos 😅

Copy link
Collaborator

@rohan-bes rohan-bes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change 🙏 Looks good!

@alexd-bes alexd-bes merged commit a739614 into epic-tasks Aug 8, 2024
44 checks passed
@alexd-bes alexd-bes deleted the rn-1361-user-app-question branch August 8, 2024 02:12
alexd-bes added a commit that referenced this pull request Sep 16, 2024
* No data display

* Fix tests

* Reorganise files

* tweaks

* Add loading state

* Exclude tasks from ios

* tweaks

* Types fix

* Make due date nullable

* Rename repeat_schedule field

* Tweaks

* Fix tests

* Revert "Fix tests"

This reverts commit 0e566d3.

* Fix tests

* Fix validation rules

* Link status and assignee name to records at the model level

* Generate types

* Fix types and apply new field names

* Get tasks filters working

* Fix pagination

* Fix build

* refactor(adminPanel): RN-1336: Move modal into ui-components (#5765)

* Move modal to ui-components

* Fix build

* Reorder import

* Enable popover portal

* feat(datatrakWeb): RN-1336: Create a task workflow (#5763)

* Create button

* Move modal to ui-components

* Move country selector to features folder

* Update country selector exports/imports

* Update tupaia-pin.svg

* Country selector on modal

* Move survey selector to features

* Move types

* Update survey list component to take care of fetching

* Survey selector

* Move entity selector to features

* Fix types

* Entity selector

* Styling entity selector

* Due date

* WIP

* WIP

* assignee input

* Add loading state and save user id

* Styling repeat scheduler

* Comments placholder

* Styling

* WIP

* Create task route

* Create task workflow

* Clear form when modal is reopened

* Update schemas.ts

* remove unused import

* Handle reset

* Fix datatrak tests

* Fix central server tests

* Move modal to ui-components

* Remove unused import

* Remove duplicate file

* Fix build

* Fix tests

* Update packages/central-server/src/apiV2/utilities/constructNewRecordValidationRules.js

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

* Fix error messages

* Handle search term in the BE

* Fix timezone issue

* Fix date formatting of filter

* remove unused variable

* Fix casing

* Default to showing countries if no primary entity question

* Update AssigneeInput.tsx

* Show loader when loading project and countries

* Fix copy

* Exclude internal users

* Fix types

* Change colour of icon in entity list

---------

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

* feat(datatrakWeb): RN-1338: Mark tasks as completed when survey responses are submitted (#5766)

* Create migration for created_at column

* Create change handler

* fix(types):Update schemas.ts

* feat(datatrakWeb): RN-1358: Assign tasks from dashboard (#5770)

* Create button

* Move modal to ui-components

* Move country selector to features folder

* Update country selector exports/imports

* Update tupaia-pin.svg

* Country selector on modal

* Move survey selector to features

* Move types

* Update survey list component to take care of fetching

* Survey selector

* Move entity selector to features

* Fix types

* Entity selector

* Styling entity selector

* Due date

* WIP

* WIP

* assignee input

* Add loading state and save user id

* Styling repeat scheduler

* Comments placholder

* Styling

* WIP

* Create task route

* Create task workflow

* Clear form when modal is reopened

* Update schemas.ts

* remove unused import

* Handle reset

* Fix datatrak tests

* Fix central server tests

* Move modal to ui-components

* Remove unused import

* Remove duplicate file

* Fix build

* Fix tests

* Update packages/central-server/src/apiV2/utilities/constructNewRecordValidationRules.js

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

* Fix error messages

* Handle search term in the BE

* WIP

* WIP

* Assignee Id modal

* Working assignee

* remove unused property

* Fix timezone issue

* Fix date formatting of filter

* remove unused variable

* Remove unused variable

* Fix casing

* Default to showing countries if no primary entity question

* Update AssigneeInput.tsx

* Show loader when loading project and countries

* Fix copy

* Exclude internal users

* Fix types

* Change colour of icon in entity list

* Fix modal button types

* Fix types

---------

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

* feat(datatrakWeb): RN-1314: add return to tasks button on success screen (#5747)

* add back to tasks button

* use useFromLocation

* update types

* Update SurveySuccessScreen.tsx

* save task endpoint

* save task mutation

* task cancel modal

* update types

* pass from location into useSubmitSurveyResponse

* remove SaveTaskRequest

* Update TasksTable.tsx

* refactor action button

* fix(datatrakWeb): Fix table height

* tweak(datatrakWeb): Use full month name in repeat schedule options

* fix(datatrakWeb): Handle errors when loading creating task modal

* fix(datatrakWeb): Hide actions on completed and cancelled tasks

* tweak(datatrakWeb): Update repeating schedule input to be matching autocomplete

* fix(datatrakWeb): Change select list focus styling slightly

* fix(datatrakWeb): Fix UTC date issue

* fix(datatrakWeb): fix focus styles on select filter

* fix(datatrakWeb): Fix type error

* tweak(datatrakWeb): Change text on complete task button

* fix(datatrakWeb): remove redundant file

* fix(datatrakWeb): Fix assignee autocomplete

* tweak(datatrakWeb): Navigate user to project select screen on 403 entities error

* feat(datatrak): RN-1343: Task dashboard filter settings (#5757)

* add back to tasks button

* use useFromLocation

* update types

* Update SurveySuccessScreen.tsx

* save task endpoint

* save task mutation

* task cancel modal

* update types

* pass from location into useSubmitSurveyResponse

* build ui

* set up filtering

* testing filters

* Update useTasks.ts

* fix front end

* filtering with cookies

* update cookie handling

* clean up types

* refactor tasks route

* handle invalidFilterValues

* Create TaskRoute.test.ts

* sort by status

* clear cookies on logout

* Delete SaveTaskRoute.ts

* renaming

* tweak(datatrakWeb): Make search fuzzy always

* tweak(datatrakWeb): RN-1358: Assign task modal changes (#5784)

* Update design for assign modal

* Update schemas.ts

* PR fixes

* Update taskFilterSettings.ts

* Update ActionButton.tsx

* feat(datatrakWeb): RN-1329: Task details view (#5783)

* Create button

* Move modal to ui-components

* Move country selector to features folder

* Update country selector exports/imports

* Update tupaia-pin.svg

* Country selector on modal

* Move survey selector to features

* Move types

* Update survey list component to take care of fetching

* Survey selector

* Move entity selector to features

* Fix types

* Entity selector

* Styling entity selector

* Due date

* WIP

* WIP

* assignee input

* Add loading state and save user id

* Styling repeat scheduler

* Comments placholder

* Styling

* WIP

* Create task route

* Create task workflow

* Clear form when modal is reopened

* Update schemas.ts

* remove unused import

* Handle reset

* Fix datatrak tests

* Fix central server tests

* Move modal to ui-components

* Remove unused import

* Remove duplicate file

* Fix build

* Fix tests

* Update packages/central-server/src/apiV2/utilities/constructNewRecordValidationRules.js

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

* Fix error messages

* Handle search term in the BE

* WIP

* WIP

* Assignee Id modal

* Working assignee

* remove unused property

* Fix timezone issue

* Fix date formatting of filter

* remove unused variable

* Remove unused variable

* Fix casing

* Default to showing countries if no primary entity question

* Update AssigneeInput.tsx

* Show loader when loading project and countries

* Fix copy

* Exclude internal users

* Fix types

* Change colour of icon in entity list

* Link to details page

* Fix modal button types

* Fix types

* Update handling of columns

* get task route

* WIP

* Link to survey for incomplete tasks

* Handle unloaded task

* Task metadata section

* Fix merge issue

* WIP

* Update schemas.ts

* feat(datatrakWeb): RN-1358: Assign tasks from dashboard (#5770)

* Create button

* Move modal to ui-components

* Move country selector to features folder

* Update country selector exports/imports

* Update tupaia-pin.svg

* Country selector on modal

* Move survey selector to features

* Move types

* Update survey list component to take care of fetching

* Survey selector

* Move entity selector to features

* Fix types

* Entity selector

* Styling entity selector

* Due date

* WIP

* WIP

* assignee input

* Add loading state and save user id

* Styling repeat scheduler

* Comments placholder

* Styling

* WIP

* Create task route

* Create task workflow

* Clear form when modal is reopened

* Update schemas.ts

* remove unused import

* Handle reset

* Fix datatrak tests

* Fix central server tests

* Move modal to ui-components

* Remove unused import

* Remove duplicate file

* Fix build

* Fix tests

* Update packages/central-server/src/apiV2/utilities/constructNewRecordValidationRules.js

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

* Fix error messages

* Handle search term in the BE

* WIP

* WIP

* Assignee Id modal

* Working assignee

* remove unused property

* Fix timezone issue

* Fix date formatting of filter

* remove unused variable

* Remove unused variable

* Fix casing

* Default to showing countries if no primary entity question

* Update AssigneeInput.tsx

* Show loader when loading project and countries

* Fix copy

* Exclude internal users

* Fix types

* Change colour of icon in entity list

* Fix modal button types

* Fix types

---------

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

* Fix merge error

* Fix styles and types

* Styling

* Fix multi re-render

* Comments placeholder

* Add buttons

* Submit changes

* Clear changes

* Fix merge issues

* Disable inputs when task is completed or cancelled

* responsive styling

* Add cancel menu

* Generate types

* Fix loading styling

* Remove unused var

* Handle onSuccess of edit task

* PR fixes

* PR fixes

* Remove form provider

---------

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

* fix tasks button

* removeTaskFilterSetting on logout

* fix(datatrakWeb): Make 'unassigned' searchable

* fix(datatrakWeb): Fix task row links

* fix(datatrakWeb): Fix task styling

* tweak(datatrakWeb): Tweak styling of task details view

* fix(adminPanel): Fix merge

* Fix build

* feat(datatrak): RN-1314: Auto populate entity question (#5793)

* set primary entity

* survey response

* Update SurveyResponsePage.tsx

* feat(datatrak): RN-1313: My tasks section (#5776)

* add tasks section

* create task tile

* NoTasksSection

* styling

* styling landing page

* styling

* Update TaskTile.tsx

* pr changes

* styling

* responsive styles

* Update useTasks.ts

* fix use tasks

* Update TasksRoute.ts

* Update TaskTile.tsx

* Update SurveyScreen.tsx

* Fix build

* tweak(datatrakWeb): RN-1339: Move survey response page into modal (#5786)

* Create button

* Move modal to ui-components

* Move country selector to features folder

* Update country selector exports/imports

* Update tupaia-pin.svg

* Country selector on modal

* Move survey selector to features

* Move types

* Update survey list component to take care of fetching

* Survey selector

* Move entity selector to features

* Fix types

* Entity selector

* Styling entity selector

* Due date

* WIP

* WIP

* assignee input

* Add loading state and save user id

* Styling repeat scheduler

* Comments placholder

* Styling

* WIP

* Create task route

* Create task workflow

* Clear form when modal is reopened

* Update schemas.ts

* remove unused import

* Handle reset

* Fix datatrak tests

* Fix central server tests

* Move modal to ui-components

* Remove unused import

* Remove duplicate file

* Fix build

* Fix tests

* Update packages/central-server/src/apiV2/utilities/constructNewRecordValidationRules.js

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

* Fix error messages

* Handle search term in the BE

* WIP

* WIP

* Assignee Id modal

* Working assignee

* remove unused property

* Fix timezone issue

* Fix date formatting of filter

* remove unused variable

* Remove unused variable

* Fix casing

* Default to showing countries if no primary entity question

* Update AssigneeInput.tsx

* Show loader when loading project and countries

* Fix copy

* Exclude internal users

* Fix types

* Change colour of icon in entity list

* Link to details page

* Fix modal button types

* Fix types

* Update handling of columns

* get task route

* WIP

* Link to survey for incomplete tasks

* Handle unloaded task

* Task metadata section

* Fix merge issue

* WIP

* Update schemas.ts

* feat(datatrakWeb): RN-1358: Assign tasks from dashboard (#5770)

* Create button

* Move modal to ui-components

* Move country selector to features folder

* Update country selector exports/imports

* Update tupaia-pin.svg

* Country selector on modal

* Move survey selector to features

* Move types

* Update survey list component to take care of fetching

* Survey selector

* Move entity selector to features

* Fix types

* Entity selector

* Styling entity selector

* Due date

* WIP

* WIP

* assignee input

* Add loading state and save user id

* Styling repeat scheduler

* Comments placholder

* Styling

* WIP

* Create task route

* Create task workflow

* Clear form when modal is reopened

* Update schemas.ts

* remove unused import

* Handle reset

* Fix datatrak tests

* Fix central server tests

* Move modal to ui-components

* Remove unused import

* Remove duplicate file

* Fix build

* Fix tests

* Update packages/central-server/src/apiV2/utilities/constructNewRecordValidationRules.js

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

* Fix error messages

* Handle search term in the BE

* WIP

* WIP

* Assignee Id modal

* Working assignee

* remove unused property

* Fix timezone issue

* Fix date formatting of filter

* remove unused variable

* Remove unused variable

* Fix casing

* Default to showing countries if no primary entity question

* Update AssigneeInput.tsx

* Show loader when loading project and countries

* Fix copy

* Exclude internal users

* Fix types

* Change colour of icon in entity list

* Fix modal button types

* Fix types

---------

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

* Fix merge error

* Fix styles and types

* Styling

* Fix multi re-render

* Comments placeholder

* Add buttons

* Submit changes

* Clear changes

* Fix merge issues

* Disable inputs when task is completed or cancelled

* responsive styling

* Add cancel menu

* Generate types

* Fix loading styling

* Remove unused var

* Handle onSuccess of edit task

* Display modal

* Survey response modal

* Handle isResponseScreen flag

* Error handling

* Error handling

* Fix tests

* Remove country and survey code from url

* Fix imports

* feat(datatrakWeb): RN-1339: Link survey responses to tasks (#5788)

* Create survey_response_id column

* Update change handler

* Update TaskCompletionHandler.js

* Fix type

* feat(datatrakWeb): RN-1339: View completed survey response from task (#5789)

* Create survey_response_id column

* Update change handler

* View completed survey

* Error handling

* Fix comment

* fix tasks button

* removeTaskFilterSetting on logout

* PR fixes

---------

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

* Fix build

---------

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

* feat(datatrak): RN-1357: Task created toast message (#5798)

Update useCreateTask.ts

Co-authored-by: alexd-bes <129009580+alexd-bes@users.noreply.github.com>

* feat(datatrakWeb): RN-1381: Add new question types (#5807)

* Add User and Task question types

* Add question config types

* Update types

* Update types

* Fix surveyCode type

* feat(datatrak): RN-1364: Completing of repeat tasks (#5802)

* Create button

* Move modal to ui-components

* Move country selector to features folder

* Update country selector exports/imports

* Update tupaia-pin.svg

* Country selector on modal

* Move survey selector to features

* Move types

* Update survey list component to take care of fetching

* Survey selector

* Move entity selector to features

* Fix types

* Entity selector

* Styling entity selector

* Due date

* WIP

* WIP

* assignee input

* Add loading state and save user id

* Styling repeat scheduler

* Comments placholder

* Styling

* WIP

* Create task route

* Create task workflow

* Clear form when modal is reopened

* Update schemas.ts

* remove unused import

* Handle reset

* Fix datatrak tests

* Fix central server tests

* Move modal to ui-components

* Remove unused import

* Remove duplicate file

* Fix build

* Fix tests

* Update packages/central-server/src/apiV2/utilities/constructNewRecordValidationRules.js

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

* Fix error messages

* Handle search term in the BE

* WIP

* WIP

* Assignee Id modal

* Working assignee

* remove unused property

* Fix timezone issue

* Fix date formatting of filter

* remove unused variable

* Remove unused variable

* Fix casing

* Default to showing countries if no primary entity question

* Update AssigneeInput.tsx

* Show loader when loading project and countries

* Fix copy

* Exclude internal users

* Fix types

* Change colour of icon in entity list

* Link to details page

* Fix modal button types

* Fix types

* Update handling of columns

* get task route

* WIP

* Link to survey for incomplete tasks

* Handle unloaded task

* Task metadata section

* Fix merge issue

* WIP

* Update schemas.ts

* feat(datatrakWeb): RN-1358: Assign tasks from dashboard (#5770)

* Create button

* Move modal to ui-components

* Move country selector to features folder

* Update country selector exports/imports

* Update tupaia-pin.svg

* Country selector on modal

* Move survey selector to features

* Move types

* Update survey list component to take care of fetching

* Survey selector

* Move entity selector to features

* Fix types

* Entity selector

* Styling entity selector

* Due date

* WIP

* WIP

* assignee input

* Add loading state and save user id

* Styling repeat scheduler

* Comments placholder

* Styling

* WIP

* Create task route

* Create task workflow

* Clear form when modal is reopened

* Update schemas.ts

* remove unused import

* Handle reset

* Fix datatrak tests

* Fix central server tests

* Move modal to ui-components

* Remove unused import

* Remove duplicate file

* Fix build

* Fix tests

* Update packages/central-server/src/apiV2/utilities/constructNewRecordValidationRules.js

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

* Fix error messages

* Handle search term in the BE

* WIP

* WIP

* Assignee Id modal

* Working assignee

* remove unused property

* Fix timezone issue

* Fix date formatting of filter

* remove unused variable

* Remove unused variable

* Fix casing

* Default to showing countries if no primary entity question

* Update AssigneeInput.tsx

* Show loader when loading project and countries

* Fix copy

* Exclude internal users

* Fix types

* Change colour of icon in entity list

* Fix modal button types

* Fix types

---------

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

* Fix merge error

* Fix styles and types

* Styling

* Fix multi re-render

* Comments placeholder

* Add buttons

* Submit changes

* Clear changes

* Fix merge issues

* Disable inputs when task is completed or cancelled

* responsive styling

* Add cancel menu

* Generate types

* Fix loading styling

* Remove unused var

* Handle onSuccess of edit task

* Display modal

* Survey response modal

* Handle isResponseScreen flag

* Error handling

* Error handling

* Fix tests

* Remove country and survey code from url

* Fix imports

* feat(datatrakWeb): RN-1339: Link survey responses to tasks (#5788)

* Create survey_response_id column

* Update change handler

* Update TaskCompletionHandler.js

* Fix type

* feat(datatrakWeb): RN-1339: View completed survey response from task (#5789)

* Create survey_response_id column

* Update change handler

* View completed survey

* Error handling

* Fix comment

* fix tasks button

* removeTaskFilterSetting on logout

* PR fixes

---------

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

* Update TaskCompletionHandler.test.js

* handle repeatSchedule tasks

* set up duplicate test

* clean up PR

* allow null repeating tasks

---------

Co-authored-by: alexd-bes <129009580+alexd-bes@users.noreply.github.com>

* feat(datatrakWeb): RN-1331: Task comments setup (#5800)

* Create task comment table and generate types

* Create Model

* WIP

* WIP

* Working endpoints

* Generate types

* Fix test

* Update 20240719015050-AddTaskCommentsTable-modifies-schema.js

* Remove task comments endpoints

* Revert "Remove task comments endpoints"

This reverts commit 498b1be.

* Fix revert

* feat(datatrakWeb): RN-1331: Task comments UI (#5801)

* Create task with comments

* View comments on task details

* Allow create comment on edit task

* Display comments count on table

* Show comment count on tasks tile on landing page

* Fix up types

* Order comments descending

* Update schemas.ts

* Move comment adding to central server

* Update schemas.ts

* Fix types

* build fixes

* Revert "Remove task comments endpoints"

This reverts commit 498b1be.

* Remove task comment create endpoint as no longer needed

* Fix merge errors

* Fix build

* feat(datatrakWeb): RN-1391: Generate system comments for tasks (#5806)

* Create task comment table and generate types

* Create Model

* WIP

* WIP

* Working endpoints

* Generate types

* Fix test

* Create task with comments

* Update 20240719015050-AddTaskCommentsTable-modifies-schema.js

* View comments on task details

* Allow create comment on edit task

* Display comments count on table

* Show comment count on tasks tile on landing page

* Fix up types

* Order comments descending

* Update schemas.ts

* addTaskComment on model

* Generate comment on edit task

* Generate comments on create of task

* Generate system message on task completion

* Syetm task styling

* Handle editing a task with just a comment

* Move comment handling to central server

* Move comment adding to central server

* Update schemas.ts

* Fix types

* Remove task comments endpoints

* build fixes

* Add comments

* Revert "Remove task comments endpoints"

This reverts commit 498b1be.

* Remove task comment create endpoint as no longer needed

* Revert "Remove task comments endpoints"

This reverts commit 498b1be.

* Fix revert

* Handle recurring task comments

* feat(datatrakWeb): RN-1331: Task comments UI (#5801)

* Create task with comments

* View comments on task details

* Allow create comment on edit task

* Display comments count on table

* Show comment count on tasks tile on landing page

* Fix up types

* Order comments descending

* Update schemas.ts

* Move comment adding to central server

* Update schemas.ts

* Fix types

* build fixes

* Revert "Remove task comments endpoints"

This reverts commit 498b1be.

* Remove task comment create endpoint as no longer needed

* Fix import order

* PR changes

* Fix change handler tests

* Update TasksRoute.ts

* Update taskFilterSettings.ts

* feat(adminPanel): RN-1381: Ability to import task and user questions in surveys (#5813)

* Add User and Task question types

* Add question config types

* Update types

* Update types

* Fix surveyCode type

* WIP

* Ability to import config

* WIP

* User permission group validation

* Add comment

* Handle exporting of questions

* Hide the task question always

* Handle BES admin users

* Handle multiple task questions

* rename entityCode to entityId

* Generate types

* Update SurveyContext.tsx

* Update TaskCompletionHandler.js

* feat(datatrakWeb): RN-1362: Datatrak Web User question type (#5815)

* New endpoint

* Question

* Add tests

* Generate types

* PR fixes

* feat(datatrak) RN-1340: Cancel task modal design update (#5819)

update modal design

* fix merge conflicts

* tweak(datatrakWeb): Update tooltip on tasks dashboard

* feat(datatrak): RN-1373: Task question (#5809)

* task creation handler

* get answers for task questions

* handle saving string values

* Update TaskCreationHandler.test.js

* Update surveyScreenComponent.ts

* move change handler to central server

* move helpers to central server

* handle primary entity question

* generate types

* clean up

* Update TaskCreationHandler.js

* move back to database

* fix fe tests

* handle success message

* handle should_create_task

* fix tests

* fix tests

* remove test code

* update types

* refactor

* Update getTaskQuestionField.ts

* remove toast message

* hide task questions on the server side

* Update SurveyRoute.ts

* remove survey_response_id

* fix tests

* update types

* test multiple task questions

* update types

* Update schemas.ts

* tweak(datatrakWeb): RN-1331: Update to task details/comments (#5823)

* WIP

* UI comments

* Remove comment handling on edit task

* Create task comment endpoint

* Link to task from landing page, and back button

* CHange back icon

* Update tests

* Don't navigate back on successful task save

* Remove double default values

* feat(datatrak): RN-1314: Handle task completion when submitting a survey (#5826)

* handle task completion inline

* update task completion handling

* Clean up

* Update index.js

* update comments

* pr review tweaks

* fix handle completion

* Update TaskDetailsPage.tsx

* feat(meditrakApp): RN-1361: User type question (#5820)

* Add User and Task question types

* Add question config types

* Update types

* Update types

* Fix surveyCode type

* WIP

* Ability to import config

* WIP

* User permission group validation

* Add comment

* Handle exporting of questions

* Hide the task question always

* Handle BES admin users

* Handle multiple task questions

* rename entityCode to entityId

* Generate types

* Add sync configs

* Update permissions based sync queue for user entity permissions

* Add user entity permissions to sync queue

* Sync user accounts

* User account syncing

* Make realm explorer scroll

* Fix permissions based sync queue for user entity permissions

* Add database type for user entity permission

* Make separate user account model

* Working question

* Fix user model usage

* Working question with permission groups

* Update schema.jsx

* add comments

* Handle filtering and pagination

* Use permission group id instead of name

* Update filtering

* PR fixes

* Add internal field to users

* fix shouldCreateTask

* Update TaskCreationHandler.js

* Display parent entity name next to entity name

* Update task details buttons

* Generate types

* Reset pagination on filter change

* fix(datatrakWeb): Fix permissions on tasks

* feat(tasks): RN-1372: Email templating (#5830)

* Working template setup

* v1

* Generic template working

* Request country access

* Delete account request

* Rename templates

* Password reset template

* Verify email

* Permission granted email

* email after timeout

* dashboard subscription emails

* Handle no template name

* Make subfolder for content

* Update pagination no records text

* Fix tests

* feat(datatrak): RN-1330: View initial request for a task (#5832)

* add initial_request_id and modal

* remove unused useSurveyResponseWithForm

* Update useSurveyResponseWithForm.ts

* Update TaskDetails.tsx

* update types

* Update TaskDetails.tsx

* fix tests

* feat(datatrakWeb): RN-1337: Send emails to assignee of tasks (#5834)

* Working template setup

* v1

* Generic template working

* Request country access

* Delete account request

* Rename templates

* Password reset template

* Verify email

* Permission granted email

* email after timeout

* dashboard subscription emails

* Handle no template name

* Make subfolder for content

* Add email template

* WIP

* Add env

* Update configureEnv.js

* Working email handler

* Tests

* Remove log

* Remove duplicate model

* Add trigger creation in runPostMigration

* Allow assignee question to be empty or non-mandatory

* Fix tests

* Revert to starts with search

* Fix tests

* Fix comment details colour

* Don't email assignees when completed repeating tasks are created

* Fix tests

* Update LandingPage.tsx

* tweak(datatrakWeb): RN-1417: save parent task to completed repeating tasks (#5840)

* Ad column to tasks table

* Handle completion of repeating tasks

* feat(datatrak): RN-1398: Setup task scheduler (#5841)

* setup scheduled task

* set up email template

* update script

* clean up

* PR suggestions

* Update ScheduledTask.js

* Basic responsive styling

* Task header back button

* Layout tidy ups

* Remove warning log

* Scroll tidying

* Generate types

* Merge fixes

* Fix build

* tweak emails

* tweak(datatrakWeb): RN-1400: save task due date in unix time (#5838)

* Change due date to be number

* Working time zone saving

* Save dates

* Working filters

* Fix tests

* Task creation handler tests

* database tests

* Central server tests

* Fix merge conflict error

* handle timezones

* Fix tests

* Handle creating tasks in timezone

* Set ms to be 0

* Fix tests

* Add task route test

* Update packages/datatrak-web-server/src/routes/TasksRoute.ts

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

* Make custom column selector for due dates

* Update due date field

* build fixes

* Build fixes

---------

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

* Make survey success direct to tasks where applicable

* add a default sort

* Fix user question

* Filter surveys by permission group and country

* Handle when no permissions for country

* fix(datatrakWeb): Limit entity results to 100 (#5847)

Fix(datatrakWeb): Limit entity results to 100

* Update SurveyContext.tsx

* Show all users for public surveys

* Fix font weights

* Convert permission groupI ID to name when exporting survey

* Handle assignee lists and search

* Generate types

* feat(datatrakWeb): RN-1341: Repeating tasks (#5844)

* WIP rrule

* Working rrule utils

* Add generic rrule handler

* frequency enum

* types

* handle repeat schedule in task changes

* Create and edit repeating tasks

* Handle system comments

* Creating and editing with comments

* WIP

* Update filtering

* disable sort by repeat frequency

* Add next occurrence handler

* Apply due date to completed tasks

* Handle bugs

* Update tests

* Update yarn.lock

* Mark due date of tasks

* Comments and tidy ups

* Use timestamp for due date

* Fix tests

* add comments

* Move getRepeatScheduleOptions

* Remove duplicate identifier

* Allow removing of repeat schedule

* feat(datatrak): RN-1314: Auto fill primary entity questions for a survey (#5853)

* useEntityAncestors

* entityAncestors

* clean up

* refactoring

* refactor getEntityQuestionAncestorAnswers

* refactor usePrimaryEntityLocation

* autofill in survey context

* add test

* Update usePrimaryEntityQuestionAutoFill.ts

* Update schemas.ts

* fix test

* Repeating task fixes

* Reset tasks pagination to 0 when filter checkbox value changes

* Handle overdue tasks with no assignee

* styling tidy ups

* Handle multiline task comments

* Add entity name to modals

* Fix user question re-renders

* Update task entities on survey response edit

* tweak(datatrakWeb): RN-1391: Update system comments handling (#5859)

* Task comment changes

* Tidy ups

* Update Task.js

* interceptor for creating tasks

* Editing tidyups

* central server tests

* Task tests

* Merge fixes

* Comment fix

* build fixes

* Fix type error

* Display entity parent name on survey response modals

* Fix user question values disappearing

* Fix user not showing in survey response

* Display 'user deleted' message for deleted message

* Remove review section headings

* Generate types

* Update SurveyReviewSection.tsx

* Amend db migration for meditrak sync queue

* Tidy up migration

* Handle exporting of answers for user questions

* Admin panel user question fixes

* Check for user config being allowed access to the survey

* Should validate that surveyCode is set

* Add validation for task config question types and multi field validation errors

* Update TaskConfigValidator.js

* Update task assignee question validation

* Don't remove instruction questions on survey review screens

* Undo change with multiple config being validated at once

* Update importSurveyQuestions.js

* Remove unused import

* Handle user question names with special characters

* Use locale for datepicker

* feat(datatrakWeb): RN-1374: Task Metrics (#5860)

* task metrics

* types update

* Update useCreateTask.ts

* review changes

* review updates

* update to MUI breakpoints

* Review updates

* Update TaskCompletionHandler.js

* tasks section responsive styles

* Update SurveyContext.tsx

* Complete tasks based on survey response end time

* Create permissions based sync queue on first startup

* Handle survey responses with no parent name

* Make use of util for survey review screen

* tweak(datatrakWeb): RN-1374: Dashboard Metrics Updates (#5864)

* task metrics

* types update

* Update useCreateTask.ts

* review changes

* review updates

* update to MUI breakpoints

* Review updates

* Update TaskCompletionHandler.js

* updates

* Update permissions based sync handler on startup

* Allow removal of repeat schedule

* Handle db migrations error

* Fix types

* Remove unused var

* Test

* Update index.js

* fix(datatrak): RN-1330: Fix logout request cache clearing (#5865)

* Update Tile.tsx

* wip

* cleanup

* Update TaskTile.tsx

* tweak(datatrakWeb): RN-1374: Dashboard Metrics Updates (#5866)

* task metrics

* types update

* Update useCreateTask.ts

* review changes

* review updates

* update to MUI breakpoints

* Review updates

* Update TaskCompletionHandler.js

* updates

* Rounding up completion rate

* Update SingleSurveyResponseRoute.ts

* Update getDbMigrator.js

* Fix error on due date updater

* Fix broken deployment

* Wrap sync queue handler in feature flag checker

* Update scheduledTask.js

* Allow past due dates in some cases

* Fix env vars

* fix task link

* Update usePrimaryEntityQuestionAutoFill.ts

* Update TaskTile.tsx

* Handle user changes

* Update TaskOverdueChecker.js

* remove due date from overdue email

* Remove due date from assignee emails

* fix(datatrak): Fix survey autofill loading (#5883)

* add loading

* Update TaskOverdueChecker.js

* overdue email comment

* Update schemas.ts

* Update yarn.lock

* Regenerate types

* Fix build

* Fix apostrophe and single quote search

* Fix build

* Fix random 0

* Sort filtered users

* Sync all user entity permissions by country, instead of by country and permission group

* Update TaskComment.js

* Force a full resync on update to version 26

* TEST

* Update version

* fix(datatrak): RN-1314: Update autofilling entity when completing a task (#5893)

move primary entity code to url params

* TEST

* Fix react-query updates

* Fix ordering of keys

* Update migration

* Keep survey search on page change

* handle loading state

* Use isSuccess instead of loading state for use effect

* Fix loading race conditions

* Disable backdating of tasks

---------

Co-authored-by: Tom Caiger <caigertom@gmail.com>
Co-authored-by: Salman <114740396+hrazasalman@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants