Skip to content

Commit

Permalink
fix(person): personselect should now clear on setting selectedPerson …
Browse files Browse the repository at this point in the history
…to null
  • Loading branch information
eikeland committed Nov 19, 2024
1 parent 0f03d02 commit 25727c9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
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) {

Check warning on line 58 in packages/person/src/components/select/controller.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/person/src/components/select/controller.ts#L58

[prettier/prettier] Replace `select·===·''·&&·this.selectedIds.size` with `(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

0 comments on commit 25727c9

Please sign in to comment.