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

fix(person): personselect should now clear on setting selectedPerson … #1650

Merged
merged 1 commit into from
Nov 20, 2024
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
13 changes: 13 additions & 0 deletions .changeset/two-carrots-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@equinor/fusion-wc-person": patch
---

### Changes in `PersonSelectController`

- Renamed the `attrSelectPerson` method to `attrSelectedPerson`.
- Updated the `attrSelectedPerson` method to clear `selectedIds` when `select` is null or an empty string and `selectedIds` size is greater than zero.
- Added logic to clear previous selections when the `selectedPerson` property changes.

### Changes in `PersonSelectElement`

- Updated the `updated` method to call `attrSelectedPerson` instead of `attrSelectPerson`.
12 changes: 10 additions & 2 deletions packages/person/src/components/select/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,20 @@ export class PersonSelectController implements ReactiveController {
* Resolve personInfo task from selectedPerson property.
* Runs on host updated when property is changed
*/
public attrSelectPerson(select: string | null | undefined) {
/* Do not trigger task if undefined or null */
public attrSelectedPerson(select: string | null | undefined) {
if ((select === null || select === '') && this.selectedIds.size) {
this.clear();
return;
}

/* Do not trigger task if undefined */
if (!select) {
return;
}

// clear previous selections since property has changed
this.selectedIds.clear();

/* Trigger PersonInfo task with upn or azureId */
if (select.match('@')) {
this.#host.upn = select;
Expand Down
2 changes: 1 addition & 1 deletion packages/person/src/components/select/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class PersonSelectElement

updated(props: Map<string, string | null | undefined>) {
if (props.has('selectedPerson')) {
this.controllers.element.attrSelectPerson(
this.controllers.element.attrSelectedPerson(
this.selectedPerson?.upn ?? this.selectedPerson?.azureId ?? (this.selectedPerson as null | undefined),
);
}
Expand Down