Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions frontend/src/components/projectEdit/teamSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,17 @@ export const TeamSelect = () => {
});
};

// Get only ids.
const teamsIds = projectInfo.teams.map((t) => {
return t.teamId;
});

let filteredTeams = teamsData?.teams?.filter((t) => !teamsIds.includes(t.teamId));
let teamList = teamsData?.teams;

if (org !== null) {
filteredTeams = [
teamList = [
{
label: org.name,
options: filteredTeams?.filter((t) => t.organisationId === org.organisationId),
options: teamList?.filter((t) => t.organisationId === org.organisationId),
},
{
label: 'Others',
options: filteredTeams?.filter((t) => t.organisationId !== org.organisationId),
options: teamList?.filter((t) => t.organisationId !== org.organisationId),
},
];
}
Expand Down Expand Up @@ -153,7 +148,7 @@ export const TeamSelect = () => {
classNamePrefix="react-select"
getOptionLabel={(option) => option.name}
getOptionValue={(option) => option.teamId}
options={isTeamsLoading ? [] : filteredTeams}
options={isTeamsLoading ? [] : teamList}
onChange={(value) => handleSelect(value, 'team')}
className="w-40 fl pr2 z-3"
value={teamSelect.team.name !== null ? teamSelect.team : null}
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/views/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,10 @@ export default defineMessages({
defaultMessage:
'{mapping, select, true {Mapping} other {{validation, select, true {Validation} other {}}}} {mapping, select, true {{validation, select, true {and validation} other {}}} other {}} permissions have been set only to team members but no team has been added.',
},
duplicateTeamsAssigned: {
id: 'pages.edit_project.actions.duplicate_teams_assigned',
defaultMessage: 'Same team assigned multiple times for same role',
},
projectEditSection_description: {
id: 'pages.edit_project.sections.description',
defaultMessage: 'Description',
Expand Down
22 changes: 17 additions & 5 deletions frontend/src/views/projectEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,20 @@ export const handleCheckButton = (event, arrayElement) => {

const doesMappingTeamNotExist = (teams, mappingPermission) =>
['TEAMS', 'TEAMS_LEVEL'].includes(mappingPermission) &&
teams.filter((team) => team.role === 'MAPPER').length === 0 &&
teams.filter((team) => team.role === 'VALIDATOR').length === 0 &&
teams.filter((team) => team.role === 'PROJECT_MANAGER').length === 0;
teams.filter((team) => team.role === 'MAPPER').length === 0;

const doesValidationTeamNotExist = (teams, validationPermission) =>
['TEAMS', 'TEAMS_LEVEL'].includes(validationPermission) &&
teams.filter((team) => team.role === 'VALIDATOR').length === 0 &&
teams.filter((team) => team.role === 'PROJECT_MANAGER').length === 0;
teams.filter((team) => team.role === 'VALIDATOR').length === 0;

const doesSameTeamAndRoleExists = (teams) => {
const visited = {};
return teams?.some((team) => {
if (visited[team.teamId] === team.role) return true;
visited[team.teamId] = team.role;
return false;
});
};

export function ProjectEdit() {
const { id } = useParams();
Expand Down Expand Up @@ -164,6 +170,9 @@ export function ProjectEdit() {
) {
missingFields.push({ type: 'noTeamsAssigned' });
}
if (doesSameTeamAndRoleExists(teams)) {
missingFields.push({ type: 'duplicateTeamsAssigned' });
}
// validate name
if (!missingFields?.[0]?.fields?.includes('name')) {
const projectName = defaultLocaleInfo.name;
Expand Down Expand Up @@ -368,6 +377,9 @@ const ErrorTitle = ({ locale, numberOfMissingFields, type, projectInfo }) => {
/>
);
}
if (type === 'duplicateTeamsAssigned') {
return <FormattedMessage {...messages.duplicateTeamsAssigned} />;
}
if (type === 'nameValidationError') {
return (
<FormattedMessage
Expand Down