Skip to content

Commit 87b3cbb

Browse files
committed
fix(create-view-link): added logic for uncheck
1 parent 3dd4150 commit 87b3cbb

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

src/app/features/project/contributors/components/create-view-link-dialog/create-view-link-dialog.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
} @else {
3535
<div class="flex flex-column gap-2">
3636
@for (item of componentsList(); track item.id) {
37-
<osf-component-checkbox-item [item]="item" (checkboxChange)="onCheckboxChange()" />
37+
<osf-component-checkbox-item [item]="item" (checkboxChange)="onCheckboxChange(item)" />
3838
}
3939
</div>
4040
}

src/app/features/project/contributors/components/create-view-link-dialog/create-view-link-dialog.component.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,19 @@ export class CreateViewLinkDialogComponent implements OnInit {
7979
}
8080
}
8181

82-
onCheckboxChange(): void {
83-
this.componentsList.update((items) =>
84-
items.map((item) => ({
82+
onCheckboxChange(changedItem: ViewOnlyLinkComponentItem): void {
83+
this.componentsList.update((items) => {
84+
let updatedItems = [...items];
85+
86+
if (!changedItem.checked) {
87+
updatedItems = this.uncheckChildren(changedItem.id, updatedItems);
88+
}
89+
90+
return updatedItems.map((item) => ({
8591
...item,
86-
disabled: item.isCurrentResource ? item.disabled : !this.isParentChecked(item, items),
87-
}))
88-
);
92+
disabled: item.isCurrentResource ? item.disabled : !this.isParentChecked(item, updatedItems),
93+
}));
94+
});
8995
}
9096

9197
addLink(): void {
@@ -111,6 +117,23 @@ export class CreateViewLinkDialogComponent implements OnInit {
111117
return parent?.checked ?? true;
112118
}
113119

120+
private uncheckChildren(parentId: string, items: ViewOnlyLinkComponentItem[]): ViewOnlyLinkComponentItem[] {
121+
let updatedItems = items.map((item) => {
122+
if (item.parentId === parentId) {
123+
return { ...item, checked: false };
124+
}
125+
return item;
126+
});
127+
128+
const directChildren = updatedItems.filter((item) => item.parentId === parentId);
129+
130+
for (const child of directChildren) {
131+
updatedItems = this.uncheckChildren(child.id, updatedItems);
132+
}
133+
134+
return updatedItems;
135+
}
136+
114137
private buildLinkData(
115138
selectedIds: string[],
116139
rootProjectId: string,

0 commit comments

Comments
 (0)