Skip to content

Commit 7fabe05

Browse files
committed
Feat: Customize selection input dismiss tag text
1 parent 2216998 commit 7fabe05

File tree

11 files changed

+264
-239
lines changed

11 files changed

+264
-239
lines changed

packages/components/src/components/hds/advanced-table/index.hbs

Lines changed: 205 additions & 203 deletions
Large diffs are not rendered by default.

packages/components/src/components/hds/filter-bar/filter-group/checkbox.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
}}
55
<li class="hds-filter-bar__filter-group__selection-option">
66
<Hds::Form::Checkbox::Field checked={{this.isChecked}} @value={{@value}} {{on "change" this.onChange}} as |F|>
7-
<F.Label>{{yield}}</F.Label>
7+
<F.Label>{{@label}}</F.Label>
88
</Hds::Form::Checkbox::Field>
99
</li>

packages/components/src/components/hds/filter-bar/filter-group/checkbox.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import type { HdsFilterBarFilter } from '../types.ts';
1111
export interface HdsFilterBarFilterGroupCheckboxSignature {
1212
Args: {
1313
value?: string;
14+
label?: string;
1415
keyFilter: HdsFilterBarFilter | undefined;
15-
onChange?: (event: Event) => void;
16+
onChange?: (event: Event, label?: string) => void;
1617
};
1718
Blocks: {
1819
default: [];
@@ -23,9 +24,9 @@ export interface HdsFilterBarFilterGroupCheckboxSignature {
2324
export default class HdsFilterBarFilterGroupCheckbox extends Component<HdsFilterBarFilterGroupCheckboxSignature> {
2425
@action
2526
onChange(event: Event): void {
26-
const { onChange } = this.args;
27+
const { onChange, label } = this.args;
2728
if (onChange && typeof onChange === 'function') {
28-
onChange(event);
29+
onChange(event, label);
2930
}
3031
}
3132

packages/components/src/components/hds/filter-bar/filter-group/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ export default class HdsFilterBarFilterGroup extends Component<HdsFilterBarFilte
113113
}
114114

115115
@action
116-
onSelectionChange(event: Event): void {
116+
onSelectionChange(event: Event, label?: string): void {
117117
const addFilter = (value: unknown): void => {
118118
const newFilter = {
119119
value: value,
120+
label: label,
120121
} as HdsFilterBarGenericFilterData;
121122
if (this.type === 'single-select') {
122123
this.internalFilters = newFilter;

packages/components/src/components/hds/filter-bar/filter-group/radio.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
}}
55
<li class="hds-filter-bar__filter-group__selection-option">
66
<Hds::Form::Radio::Field checked={{this.isChecked}} @value={{@value}} {{on "change" this.onChange}} as |F|>
7-
<F.Label>{{yield}}</F.Label>
7+
<F.Label>{{@label}}</F.Label>
88
</Hds::Form::Radio::Field>
99
</li>

packages/components/src/components/hds/filter-bar/filter-group/radio.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import type { HdsFilterBarFilter } from '../types.ts';
1111
export interface HdsFilterBarFilterGroupRadioSignature {
1212
Args: {
1313
value?: string;
14+
label?: string;
1415
keyFilter: HdsFilterBarFilter | undefined;
15-
onChange?: (event: Event) => void;
16+
onChange?: (event: Event, label?: string) => void;
1617
};
1718
Blocks: {
1819
default: [];
@@ -23,9 +24,9 @@ export interface HdsFilterBarFilterGroupRadioSignature {
2324
export default class HdsFilterBarFilterGroupRadio extends Component<HdsFilterBarFilterGroupRadioSignature> {
2425
@action
2526
onChange(event: Event): void {
26-
const { onChange } = this.args;
27+
const { onChange, label } = this.args;
2728
if (onChange && typeof onChange === 'function') {
28-
onChange(event);
29+
onChange(event, label);
2930
}
3031
}
3132

packages/components/src/components/hds/filter-bar/index.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
{{else if (eq filter.type "multi-select")}}
7474
{{#each (this._filterArrayData filter.data) as |item|}}
7575
<Hds::Tag
76-
@text="{{this._filterKeyText key filter}}: {{item.value}}"
76+
@text="{{this._filterKeyText key filter}}: {{if item.text item.text item.value}}"
7777
@onDismiss={{fn this.onFilterDismiss key item.value}}
7878
/>
7979
{{/each}}

packages/components/src/components/hds/filter-bar/index.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export interface HdsFilterBarSignature {
5151
export default class HdsFilterBar extends Component<HdsFilterBarSignature> {
5252
@service hdsIntl!: HdsIntlService;
5353

54-
@tracked _isExpanded: boolean = false;
54+
@tracked _isExpanded: boolean = this.hasActiveFilters;
5555

5656
get searchValue(): string {
5757
const { filters } = this.args;
@@ -156,19 +156,28 @@ export default class HdsFilterBar extends Component<HdsFilterBarSignature> {
156156
private _filterData = (
157157
data: HdsFilterBarData
158158
): HdsFilterBarGenericFilterData => {
159+
const result = {
160+
value: '',
161+
} as HdsFilterBarGenericFilterData;
159162
if ('value' in data) {
160-
return { value: data.value };
163+
result.value = data.value;
161164
}
162-
return { value: '' };
165+
if ('label' in data) {
166+
result.label = data.label;
167+
}
168+
return result;
163169
};
164170

165171
private _filterText = (filter: HdsFilterBarFilter): string => {
166172
const result = this._filterData(filter.data);
167-
const resultText = result?.value as string;
168-
return resultText ?? '';
173+
const resultLabel = result?.label as string;
174+
const resultValue = result?.value as string;
175+
return resultLabel ?? resultValue;
169176
};
170177

171-
private _filterArrayData = (data: HdsFilterBarData): { value: unknown }[] => {
178+
private _filterArrayData = (
179+
data: HdsFilterBarData
180+
): { value: unknown; text?: string }[] => {
172181
if (isArray(data)) {
173182
return data.map((item) => this._filterData(item));
174183
}

packages/components/src/components/hds/filter-bar/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type HdsFilterBarFilterType = `${HdsFilterBarFilterTypeValues}`;
1818

1919
export interface HdsFilterBarGenericFilterData {
2020
value: unknown;
21+
label?: string;
2122
}
2223

2324
export interface HdsFilterBarNumericalFilterData {

showcase/app/components/mock/app/main/generic-advanced-table.gts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ export default class MockAppMainGenericAdvancedTable extends Component<MockAppMa
857857
as |F|
858858
>
859859
{{#each (get SAMPLE_MODEL_VALUES "name") as |option|}}
860-
<F.Checkbox @value={{option.value}}>{{option.label}}</F.Checkbox>
860+
<F.Checkbox @value={{option.value}} @label={{option.label}} />
861861
{{/each}}
862862
</D.FilterGroup>
863863
<D.FilterGroup
@@ -868,7 +868,7 @@ export default class MockAppMainGenericAdvancedTable extends Component<MockAppMa
868868
as |F|
869869
>
870870
{{#each (get SAMPLE_MODEL_VALUES "project-name") as |option|}}
871-
<F.Checkbox @value={{option.value}}>{{option.label}}</F.Checkbox>
871+
<F.Checkbox @value={{option.value}} @label={{option.label}} />
872872
{{/each}}
873873
</D.FilterGroup>
874874
<D.FilterGroup
@@ -878,7 +878,7 @@ export default class MockAppMainGenericAdvancedTable extends Component<MockAppMa
878878
as |F|
879879
>
880880
{{#each (get SAMPLE_MODEL_VALUES "run-status") as |option|}}
881-
<F.Checkbox @value={{option.value}}>{{option.label}}</F.Checkbox>
881+
<F.Checkbox @value={{option.value}} @label={{option.label}} />
882882
{{/each}}
883883
</D.FilterGroup>
884884
<D.FilterGroup
@@ -888,7 +888,7 @@ export default class MockAppMainGenericAdvancedTable extends Component<MockAppMa
888888
as |F|
889889
>
890890
{{#each (get SAMPLE_MODEL_VALUES "terraform-version") as |option|}}
891-
<F.Radio @value={{option.value}}>{{option.label}}</F.Radio>
891+
<F.Radio @value={{option.value}} @label={{option.label}} />
892892
{{/each}}
893893
</D.FilterGroup>
894894
<D.FilterGroup
@@ -907,6 +907,22 @@ export default class MockAppMainGenericAdvancedTable extends Component<MockAppMa
907907
@type="numerical"
908908
/>
909909
<D.FilterGroup @key="created" @text="Created" @type="date" />
910+
<D.FilterGroup
911+
@key="vcs-repo"
912+
@text="VCS repo"
913+
@type="generic"
914+
as |F|
915+
>
916+
<F.Generic as |G|>
917+
<ShwPlaceholder @text="generic content" @height="100" />
918+
<HdsButton
919+
@text="Add custom filter"
920+
@color="secondary"
921+
@size="small"
922+
{{on "click" (fn G.updateFilter CUSTOM_FILTER)}}
923+
/>
924+
</F.Generic>
925+
</D.FilterGroup>
910926
</F.Dropdown>
911927
</HdsFilterBar>
912928
{{/if}}
@@ -953,9 +969,7 @@ export default class MockAppMainGenericAdvancedTable extends Component<MockAppMa
953969
as |F|
954970
>
955971
{{#each (get SAMPLE_MODEL_VALUES "name") as |option|}}
956-
<F.Checkbox
957-
@value={{option.value}}
958-
>{{option.label}}</F.Checkbox>
972+
<F.Checkbox @value={{option.value}} @label={{option.label}} />
959973
{{/each}}
960974
</D.FilterGroup>
961975
<D.FilterGroup
@@ -966,9 +980,7 @@ export default class MockAppMainGenericAdvancedTable extends Component<MockAppMa
966980
as |F|
967981
>
968982
{{#each (get SAMPLE_MODEL_VALUES "project-name") as |option|}}
969-
<F.Checkbox
970-
@value={{option.value}}
971-
>{{option.label}}</F.Checkbox>
983+
<F.Checkbox @value={{option.value}} @label={{option.label}} />
972984
{{/each}}
973985
</D.FilterGroup>
974986
<D.FilterGroup
@@ -978,9 +990,7 @@ export default class MockAppMainGenericAdvancedTable extends Component<MockAppMa
978990
as |F|
979991
>
980992
{{#each (get SAMPLE_MODEL_VALUES "run-status") as |option|}}
981-
<F.Checkbox
982-
@value={{option.value}}
983-
>{{option.label}}</F.Checkbox>
993+
<F.Checkbox @value={{option.value}} @label={{option.label}} />
984994
{{/each}}
985995
</D.FilterGroup>
986996
<D.FilterGroup
@@ -993,7 +1003,7 @@ export default class MockAppMainGenericAdvancedTable extends Component<MockAppMa
9931003
(get SAMPLE_MODEL_VALUES "terraform-version")
9941004
as |option|
9951005
}}
996-
<F.Radio @value={{option.value}}>{{option.label}}</F.Radio>
1006+
<F.Radio @value={{option.value}} @label={{option.label}} />
9971007
{{/each}}
9981008
</D.FilterGroup>
9991009
<D.FilterGroup

0 commit comments

Comments
 (0)