Skip to content

Conversation

anandtiwary
Copy link
Contributor

@anandtiwary anandtiwary commented Mar 16, 2021

Description

Please include a summary of the change, motivation and context.

  • Fixed tests
  • Adding default select all and clear selected buttons as per the new mocks
  • Fixed a bug where filtered options were not behaving correctly when select option components were added in an async fashion.
  • Removed some dead code

Testing

Please describe the tests that you ran to verify your changes. Please summarize what did you test and what needs to be tested e.g. deployed and tested helm chart locally.

Checklist:

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

Documentation

Make sure that you have documented corresponding changes in this repository or hypertrace docs repo if required.

@anandtiwary anandtiwary requested a review from a team as a code owner March 16, 2021 00:21
@codecov
Copy link

codecov bot commented Mar 16, 2021

Codecov Report

Merging #696 (0c346a9) into main (7c1b320) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #696   +/-   ##
=======================================
  Coverage   85.19%   85.20%           
=======================================
  Files         782      782           
  Lines       16060    16048   -12     
  Branches     2059     2054    -5     
=======================================
- Hits        13683    13674    -9     
+ Misses       2344     2341    -3     
  Partials       33       33           
Impacted Files Coverage Δ
...ponents/src/multi-select/multi-select.component.ts 100.00% <100.00%> (+4.28%) ⬆️
...components/src/multi-select/multi-select.module.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7c1b320...0c346a9. Read the comment docs.

const searchBar = spectator.query('.search-bar', { root: true });
expect(searchBar).toExist();

spectator.triggerEventHandler(SearchBoxComponent, 'valueChange', 'fi');
Copy link
Contributor Author

@anandtiwary anandtiwary Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how these tests worked before. PopoverModule was not added in the shallow test. So the popover content could never get projected.

Also, triggerEventHandler doesn't provide a {root: true} option. Since the search box would be outside the host element's scope, this trigger call just doesn't work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how these tests worked before. PopoverModule was not added in the shallow test.

That's how - it wasn't using the real popover (so those tags are basically ignored), which your test is now. So only the searchbox was mocked as an actual component - but it was never projected. That's also why the root wasn't there before.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also might be able to use read: DebugElement to trigger the event handler since you can't use a selector directly in there.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

<ht-divider *ngIf="this.showAllOptionControl || this.enableSearch"></ht-divider>
<div *ngFor="let item of filteredItems" (click)="this.onSelectionChange(item)" class="multi-select-option">
<ht-divider *ngIf="this.enableSearch" class="divider"></ht-divider>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this could just move inside the enable search ng container

display="${ButtonStyle.Text}"
label="Clear Selected"
(click)="this.onClearSelected()"
></ht-button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we always want the clear/select all? I can't imagine we would in all places, seems better to allow these buttons to be configurable (as they were)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. We had intentionally left these options configurable in the select component. Even for multi select, the UX for a filter usecase with 2 or 3 items would be better without the clutter of clear all / select all options. So, configurable would be better.

SelectComponent has a sample implementation that we could adapt here as well

hypertrace-ui/projects/components/src/select/select.component.ts has an example of how we made it configurable. We could use the same strategy here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo it should be enabled implicitly on certain conditions. For example, we would only show search box and the two buttons when number of options are greater than 5. I would think with an input property we would have to make a similar decision at the usage component level.

Copy link
Contributor Author

@anandtiwary anandtiwary Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combined it with enableSearch option for now. However, it will still be weird if number of options are only a few. So I would say let's remove this property too and we can just enable it based on # of options.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could buy it being implicit, but it still feels to be like it's pre-supposing a specific usage of multiselect. For example, would we want this on places like a table control, where the various selections aren't really related to each other but are more like boolean config options?

Copy link
Contributor Author

@anandtiwary anandtiwary Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could use it there. IMO if there are more options (no matter the option type), search and control buttons should show up. If there are only a few options to show then we don't need these capabilities.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I agree, but I'm certainly fine in deferring making it configurable until we have a spot we want to change the behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, It is already controlled by the input enableSearch. But I do need to turn it off for < 5 options. I can do it from the usage side too (something like enableSearch="{{options.length > 5}}"). What would be your suggestion?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can leave it internal for now. If we need external config of it, let's evaluate once we hit the specific use case.

public justify: MultiSelectJustify = MultiSelectJustify.Left;

@Input()
/** @deprecated */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You removed the actual implementation of this - that's not deprecating, it's breaking. If we're going to break it, might as well remove it (but see other comment about leaving these configurable)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I left it here so that we could talk about it :)

const searchBar = spectator.query('.search-bar', { root: true });
expect(searchBar).toExist();

spectator.triggerEventHandler(SearchBoxComponent, 'valueChange', 'fi');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how these tests worked before. PopoverModule was not added in the shallow test.

That's how - it wasn't using the real popover (so those tags are basically ignored), which your test is now. So only the searchbox was mocked as an actual component - but it was never projected. That's also why the root wasn't there before.

const searchBar = spectator.query('.search-bar', { root: true });
expect(searchBar).toExist();

spectator.triggerEventHandler(SearchBoxComponent, 'valueChange', 'fi');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also might be able to use read: DebugElement to trigger the event handler since you can't use a selector directly in there.

"commitizen": "^4.2.3",
"cz-conventional-changelog": "^3.3.0",
"husky": "^5.1.2",
"husky": "^4.3.8",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this downgrade intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. v5 is not free and requires some additional setup to make it work. So we reverted this change.

display="${ButtonStyle.Text}"
label="Clear Selected"
(click)="this.onClearSelected()"
></ht-button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. We had intentionally left these options configurable in the select component. Even for multi select, the UX for a filter usecase with 2 or 3 items would be better without the clutter of clear all / select all options. So, configurable would be better.

SelectComponent has a sample implementation that we could adapt here as well

hypertrace-ui/projects/components/src/select/select.component.ts has an example of how we made it configurable. We could use the same strategy here.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

displayMode="${SearchBoxDisplayMode.NoBorder}"
></ht-search-box>
<ng-container *ngIf="this.allOptions$ | async as allOptions">
<ng-container *ngIf="allOptions.length > 5">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm so if enable search is disabled, these will never show. If true, it shows when at least 5 options? I thought you were describing that the > 5 rule was the default if enableSearch is unset. Anyway we can go with it and address as use cases pop up.

@github-actions

This comment has been minimized.

@anandtiwary anandtiwary merged commit 44533ab into main Mar 16, 2021
@anandtiwary anandtiwary deleted the multi-select-changes branch March 16, 2021 21:20
@github-actions
Copy link

Unit Test Results

    4 files  ±0  244 suites  ±0   15m 5s ⏱️ -35s
878 tests ±0  878 ✔️ ±0  0 💤 ±0  0 ❌ ±0 
882 runs  ±0  882 ✔️ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 44533ab. ± Comparison against base commit 7c1b320.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants