Skip to content

Commit

Permalink
ezqms-729: fix teamspaces
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
  • Loading branch information
lexiv0re committed May 4, 2024
1 parent 1c9c368 commit 74e66c0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
let isColorSelected = false
let members: Ref<Account>[] =
teamspace?.members !== undefined ? hierarchy.clone(teamspace.members) : [getCurrentAccount()._id]
const owners: Ref<Account>[] =
let owners: Ref<Account>[] =
teamspace?.owners !== undefined ? hierarchy.clone(teamspace.owners) : [getCurrentAccount()._id]
let rolesAssignment: RolesAssignment = {}
Expand Down Expand Up @@ -117,6 +117,7 @@
description,
private: isPrivate,
members,
owners,
archived: false,
icon,
color
Expand Down Expand Up @@ -155,6 +156,16 @@
}
}
}
if (teamspaceData.owners?.length !== teamspace?.owners?.length) {
update.owners = teamspaceData.owners
} else {
for (const owner of teamspaceData.owners ?? []) {
if (teamspace.owners?.findIndex((p) => p === owner) === -1) {
update.owners = teamspaceData.owners
break
}
}
}
if (Object.keys(update).length > 0) {
await client.update(teamspace, update)
Expand Down Expand Up @@ -217,6 +228,13 @@
$: roles = (spaceType?.$lookup?.roles ?? []) as Role[]
function handleOwnersChanged (newOwners: Ref<Account>[]): void {
owners = newOwners
const newMembersSet = new Set([...members, ...newOwners])
members = Array.from(newMembersSet)
}
function handleMembersChanged (newMembers: Ref<Account>[]): void {
// If a member was removed we need to remove it from any roles assignments as well
const newMembersSet = new Set(newMembers)
Expand All @@ -239,16 +257,21 @@
rolesAssignment[roleId] = newMembers
}
$: canSave =
name.trim().length > 0 &&
!(members.length === 0 && isPrivate) &&
typeId !== undefined &&
spaceType?.targetClass !== undefined &&
owners.length > 0 &&
(!isPrivate || owners.some((o) => members.includes(o)))
</script>

<Card
label={isNew ? documentRes.string.NewTeamspace : documentRes.string.EditTeamspace}
okLabel={isNew ? presentation.string.Create : presentation.string.Save}
okAction={handleSave}
canSave={name.trim().length > 0 &&
!(members.length === 0 && isPrivate) &&
typeId !== undefined &&
spaceType?.targetClass !== undefined}
{canSave}
accentHeader
width={'medium'}
gap={'gapV-6'}
Expand Down Expand Up @@ -326,21 +349,18 @@
/>
</div>

{#if !isNew}
<div class="antiGrid-row">
<div class="antiGrid-row__header">
<Label label={core.string.Owners} />
</div>
<AccountArrayEditor
value={owners}
label={core.string.Owners}
onChange={undefined}
readonly={true}
kind={'regular'}
size={'large'}
/>
<div class="antiGrid-row">
<div class="antiGrid-row__header">
<Label label={core.string.Owners} />
</div>
{/if}
<AccountArrayEditor
value={owners}
label={core.string.Owners}
onChange={handleOwnersChanged}
kind={'regular'}
size={'large'}
/>
</div>

<div class="antiGrid-row">
<div class="antiGrid-row__header withDesciption">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
if (projectData.owners?.length !== project?.owners?.length) {
update.owners = projectData.owners
} else {
for (const owner of projectData?.owners || []) {
for (const owner of projectData.owners || []) {
if (project.owners?.findIndex((p) => p === owner) === -1) {
update.owners = projectData.owners
break
Expand Down

0 comments on commit 74e66c0

Please sign in to comment.