hypertrace-ui icon indicating copy to clipboard operation
hypertrace-ui copied to clipboard

fix(stepper): action label not updated

Open adisreyaj opened this issue 2 years ago β€’ 1 comments

😞 Issue

Stepper tab can have custom label for the main action button:

<ht-stepper>
      <ht-stepper-tab label="My Tab" actionButtonLabel="Cool Button">
     	<div> CONTENT </div>
      </ht-stepper-tab>
</ht-stepper>

But if we try to update the actionButtonLabel at a later point based on some condition:

<ht-stepper>
      <ht-stepper-tab label="My Tab" [actionButtonLabel]="condition ? 'Cool Button' : 'Cancel'">
     	<div> CONTENT </div>
      </ht-stepper-tab>
</ht-stepper>

The change is not getting reflected in the stepper because of the current implementation of the logic which gets the label for the button:

<ht-button [label]="this.getActionButtonLabel | htMemoize : stepper.selectedIndex : steps"></ht-button>

Since we use htMemoize the steps value doesn't change.

βš’οΈ Fix

Stepper Tab component exposes a refresh$ observable which emits when any input changes. The new logic for getting label for action button is:

// Know when input changed
const stepsInputChange$ = this.steps$.pipe(
  switchMap(steps => merge(...steps.map(tab => tab.refresh$))),
  startWith(undefined)
);

// Stepper index change
const stepperSelectionChange$ = this.selectionChange.asObservable().pipe(
  map(event => event.selectedIndex),
  startWith(0)
);

this.actionButtonLabel$ = combineLatest([stepperSelectionChange$, this.steps$, stepsInputChange$]).pipe(
  map(([selectedIndex, steps]) => this.getActionButtonLabel(selectedIndex, steps))
);

adisreyaj avatar Mar 02 '23 18:03 adisreyaj

Unit Test Results

βŸβ€„β€ˆβŸβ€„βŸβ€„4 files  Β±0β€‚β€ƒβŸβ€„β€ˆ304 suites  Β±0   24m 11s :stopwatch: + 1m 34s 1β€ˆ090 tests Β±0  1β€ˆ090 :heavy_check_mark: Β±0  0 :zzz: Β±0  0 :x: Β±0  1β€ˆ098 runs  Β±0  1β€ˆ098 :heavy_check_mark: Β±0  0 :zzz: Β±0  0 :x: Β±0 

Results for commit 6b620f45. ± Comparison against base commit 7313bbe6.

github-actions[bot] avatar Mar 02 '23 18:03 github-actions[bot]