generated from EyeSeeTea/dhis2-app-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fixes in incident management team builder page #36
Merged
bhavananarayanan
merged 13 commits into
development
from
fix/incident-management-team-fixes
Nov 11, 2024
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c8f2ceb
Allow bulk deletion, fix search, expand by default, fixed multiple in…
anagperal 4339973
Fix infinity loop
anagperal eb378dc
Update translations
anagperal 3ab4619
Add contacts table and improve code
anagperal 1a2434b
Add translations
anagperal 86f5d7f
Merge branch 'fix/local-timezone' into fix/incident-management-team-f…
anagperal aefc6bd
Improve code
anagperal d58492b
Change button label
anagperal 7a907d7
Do not allow to delete teamRoles if it's parent and all children are …
anagperal 3dd5b41
Flatten team when searching
anagperal adc486e
Do not allow child be in the team hierarchy with itself as parent
anagperal c235383
Improve UI
anagperal 368eb3e
Solve infinite loop when reload page
anagperal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ import { Id } from "../../../domain/entities/Ref"; | |
import { IncidentManagementTeamRepository } from "../../../domain/repositories/IncidentManagementTeamRepository"; | ||
import { Maybe } from "../../../utils/ts-utils"; | ||
import { FutureData } from "../../api-futures"; | ||
import { INCIDENT_MANAGER_ROLE } from "../consts/IncidentManagementTeamBuilderConstants"; | ||
|
||
export class IncidentManagementTeamTestRepository implements IncidentManagementTeamRepository { | ||
get( | ||
|
@@ -26,38 +25,10 @@ export class IncidentManagementTeamTestRepository implements IncidentManagementT | |
return Future.success(undefined); | ||
} | ||
|
||
deleteIncidentManagementTeamMemberRole( | ||
_teamMemberRole: TeamRole, | ||
_incidentManagementTeamMember: TeamMember, | ||
deleteIncidentManagementTeamMemberRoles( | ||
_diseaseOutbreakId: Id, | ||
_roles: Role[] | ||
_incidentManagementTeamRoleIds: Id[] | ||
): FutureData<void> { | ||
return Future.success(undefined); | ||
} | ||
|
||
getIncidentManagementTeamMember( | ||
username: Id, | ||
_diseaseOutbreakId: Id, | ||
_roles: Role[] | ||
): FutureData<TeamMember> { | ||
const teamMember: TeamMember = new TeamMember({ | ||
id: username, | ||
username: username, | ||
name: `Team Member Name ${username}`, | ||
email: `[email protected]`, | ||
phone: `121-1234`, | ||
teamRoles: [ | ||
{ | ||
id: "role", | ||
name: "role", | ||
roleId: INCIDENT_MANAGER_ROLE, | ||
reportsToUsername: "reportsToUsername", | ||
}, | ||
], | ||
status: "Available", | ||
photo: new URL("https://www.example.com"), | ||
workPosition: "workPosition", | ||
}); | ||
return Future.success(teamMember); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 62 additions & 1 deletion
63
src/domain/entities/incident-management-team/IncidentManagementTeam.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,71 @@ | ||
import { Maybe } from "../../../utils/ts-utils"; | ||
import { TEAM_ROLE_FIELD_ID } from "../../../webapp/pages/form-page/incident-management-team-member-assignment/mapIncidentManagementTeamMemberToInitialFormState"; | ||
import { Struct } from "../generic/Struct"; | ||
import { ValidationError } from "../ValidationError"; | ||
import { TeamMember } from "./TeamMember"; | ||
|
||
interface IncidentManagementTeamAttrs { | ||
lastUpdated: Maybe<Date>; | ||
teamHierarchy: TeamMember[]; | ||
} | ||
|
||
export class IncidentManagementTeam extends Struct<IncidentManagementTeamAttrs>() {} | ||
export class IncidentManagementTeam extends Struct<IncidentManagementTeamAttrs>() { | ||
static validateNotCyclicalDependency( | ||
teamMember: string | undefined, | ||
reportsToUsername: string | undefined, | ||
currentIncidentManagementTeamHierarchy: TeamMember[], | ||
property: string | ||
): ValidationError[] { | ||
const descendantsUsernamesByParentUsername = getAllDescendantsUsernamesByParentUsername( | ||
currentIncidentManagementTeamHierarchy | ||
); | ||
|
||
const descendantsFromTeamMember = | ||
descendantsUsernamesByParentUsername.get(teamMember ?? "") ?? []; | ||
|
||
const isCyclicalDependency = descendantsFromTeamMember.includes(reportsToUsername ?? ""); | ||
|
||
return property === TEAM_ROLE_FIELD_ID || !isCyclicalDependency | ||
? [] | ||
: [ | ||
{ | ||
property: property, | ||
value: "", | ||
errors: ["cannot_create_cyclycal_dependency"], | ||
}, | ||
]; | ||
} | ||
} | ||
|
||
function getAllDescendantsUsernamesByParentUsername( | ||
teamMembers: TeamMember[] | ||
): Map<string, string[]> { | ||
const initialMap = teamMembers.reduce((acc, member) => { | ||
const entries = (member.teamRoles ?? []).map(role => ({ | ||
parentUsername: role.reportsToUsername ?? "PARENT_ROOT", | ||
username: member.username, | ||
})); | ||
|
||
return entries.reduce((mapAcc, { parentUsername, username }) => { | ||
return mapAcc.set(parentUsername, [...(mapAcc.get(parentUsername) ?? []), username]); | ||
}, acc); | ||
}, new Map<string, string[]>()); | ||
|
||
const getDescendantUsernames = ( | ||
parent: string, | ||
processedParents = new Set<string>() | ||
): string[] => { | ||
if (processedParents.has(parent)) return []; | ||
processedParents.add(parent); | ||
|
||
return (initialMap.get(parent) ?? []).flatMap(username => [ | ||
username, | ||
...getDescendantUsernames(username, processedParents), | ||
]); | ||
}; | ||
|
||
return Array.from(initialMap.keys()).reduce((descendantsMap, parent) => { | ||
descendantsMap.set(parent, getDescendantUsernames(parent)); | ||
return descendantsMap; | ||
}, new Map<string, string[]>()); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!