Skip to content

Commit f02ec95

Browse files
aklkvshleewhite
andauthored
Table, KeyValueInputs: adjust types so yielded data is typed (#3150)
Co-authored-by: shleewhite <[email protected]>
1 parent d7c143c commit f02ec95

File tree

14 files changed

+54
-237
lines changed

14 files changed

+54
-237
lines changed

.changeset/loud-readers-sneeze.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@hashicorp/design-system-components": patch
3+
---
4+
5+
<!-- START components/table/table -->
6+
`Table` - Update the model and returned `B.data` to use generic types, so the type of the data is retained.
7+
<!-- END -->
8+
9+
<!-- START components/form/key-value-inputs -->
10+
`KeyValueInputs` - Update the data and returned `R.rowData` to use generic types, so the type of the data is retained.
11+
<!-- END -->

packages/components/src/components/hds/form/key-value-inputs/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ const KEY_VALUE_INPUTS_FIRST_ROW_SELECTOR =
3737
const KEY_VALUE_INPUTS_DELETE_ROW_CONTAINER_SELECTOR =
3838
'.hds-form-key-value-inputs__delete-row-button-container';
3939

40-
export interface HdsFormKeyValueInputsSignature {
40+
export interface HdsFormKeyValueInputsSignature<T = unknown> {
4141
Args: {
42-
data: Array<unknown>;
42+
data: Array<T>;
4343
extraAriaDescribedBy?: string;
4444
isOptional?: boolean;
4545
isRequired?: boolean;
@@ -72,7 +72,7 @@ export interface HdsFormKeyValueInputsSignature {
7272
typeof HdsFormKeyValueInputsDeleteRowButtonComponent,
7373
'onInsert' | 'onRemove' | 'returnFocusTo' | 'rowData' | 'rowIndex'
7474
>;
75-
rowData?: unknown;
75+
rowData?: T;
7676
rowIndex?: number;
7777
},
7878
];
@@ -92,7 +92,9 @@ export interface HdsFormKeyValueInputsSignature {
9292

9393
// @ts-expect-error: decorator function return type 'ClassOf<AriaDescribedBy>' is not assignable to 'typeof HdsFormField'
9494
@ariaDescribedBy
95-
export default class HdsFormKeyValueInputs extends Component<HdsFormKeyValueInputsSignature> {
95+
export default class HdsFormKeyValueInputs<T = unknown> extends Component<
96+
HdsFormKeyValueInputsSignature<T>
97+
> {
9698
private _element!: HTMLFieldSetElement;
9799
@tracked _gridTemplateColumns = '';
98100

packages/components/src/components/hds/table/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const VALIGNMENTS: HdsTableVerticalAlignment[] = Object.values(
4444
);
4545
export const DEFAULT_VALIGN = HdsTableVerticalAlignmentValues.Top;
4646

47-
export interface HdsTableSignature {
47+
export interface HdsTableSignature<T = HdsTableModel> {
4848
Args: {
4949
align?: HdsTableHorizontalAlignment;
5050
caption?: string;
@@ -54,7 +54,7 @@ export interface HdsTableSignature {
5454
isFixedLayout?: boolean;
5555
isSelectable?: boolean;
5656
isStriped?: boolean;
57-
model?: HdsTableModel;
57+
model?: T[];
5858
onSelectionChange?: (selection: HdsTableOnSelectionChangeSignature) => void;
5959
onSort?: (sortBy: string, sortOrder: HdsTableThSortOrder) => void;
6060
selectionAriaLabelSuffix?: string;
@@ -80,7 +80,7 @@ export interface HdsTableSignature {
8080
Td?: ComponentLike<HdsTableTdSignature>;
8181
Tr?: ComponentLike<HdsTableTrSignature>;
8282
Th?: ComponentLike<HdsTableThSignature>;
83-
data?: Record<string, unknown>;
83+
data?: T;
8484
rowIndex?: number;
8585
sortBy?: string;
8686
sortOrder?: HdsTableThSortOrder;
@@ -90,7 +90,9 @@ export interface HdsTableSignature {
9090
Element: HTMLTableElement;
9191
}
9292

93-
export default class HdsTable extends Component<HdsTableSignature> {
93+
export default class HdsTable<T = HdsTableModel> extends Component<
94+
HdsTableSignature<T>
95+
> {
9496
@service hdsIntl!: HdsIntlService;
9597

9698
@tracked sortBy;
@@ -101,7 +103,7 @@ export default class HdsTable extends Component<HdsTableSignature> {
101103
private _selectableRows: HdsTableSelectableRow[] = [];
102104
@tracked private _isSelectAllCheckboxSelected?: boolean = undefined;
103105

104-
constructor(owner: Owner, args: HdsTableSignature['Args']) {
106+
constructor(owner: Owner, args: HdsTableSignature<T>['Args']) {
105107
super(owner, args);
106108
this.sortBy = this.args.sortBy ?? undefined;
107109
this.sortOrder = this.args.sortOrder ?? HdsTableThSortOrderValues.Asc;

showcase/app/components/mock/app/main/generic-form/partials/add-policy.gts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,10 @@ export default class MockAppMainGenericFormPartialsAddPolicy extends Component<M
243243
<R.Field @isRequired={{true}} as |F|>
244244
<F.Label>Tag name</F.Label>
245245
<F.HelperText>Lorem ipsum dolor sit amet.</F.HelperText>
246-
{{! @glint-expect-error }}
247246
<F.TextInput name="key" @value={{R.rowData.name}} />
248247
</R.Field>
249248
<R.Field @isOptional={{true}} as |F|>
250249
<F.Label>Tag description</F.Label>
251-
{{! @glint-expect-error }}
252250
<F.TextInput name="value" @value={{R.rowData.description}} />
253251
</R.Field>
254252
<R.DeleteRowButton />

showcase/app/components/mock/components/form/key-value-inputs/with-dynamic-inputs.gts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -301,56 +301,47 @@ export default class MockComponentsFormKeyValueInputsWithDynamicInputs extends C
301301
>
302302
<option
303303
value=""
304-
{{! @glint-expect-error }}
305304
selected={{if (eq R.rowData.key "") true}}
306305
></option>
307306
<option
308307
value="textinput"
309-
{{! @glint-expect-error }}
310308
selected={{if (eq R.rowData.key "textinput") true}}
311309
>Single line</option>
312310
<option
313311
value="textarea"
314-
{{! @glint-expect-error }}
315312
selected={{if (eq R.rowData.key "textarea") true}}
316313
>Multiline</option>
317314
<option
318315
value="maskedinput"
319-
{{! @glint-expect-error }}
320316
selected={{if (eq R.rowData.key "maskedinput") true}}
321317
>Masked text</option>
322318
<option
323319
value="select"
324-
{{! @glint-expect-error }}
325320
selected={{if (eq R.rowData.key "select") true}}
326321
>Select from list</option>
327322
</F.Select>
328323
</R.Field>
329324

330325
<R.Field as |F|>
331326
<F.Label>Value</F.Label>
332-
{{! @glint-expect-error }}
333327
{{#if (eq R.rowData.key "textarea")}}
334328
<F.Textarea
335329
name="value-{{R.rowIndex}}"
336330
{{! @glint-expect-error }}
337331
@value={{R.rowData.value}}
338332
{{on "input" this.onInputUpdateModel}}
339333
/>
340-
{{! @glint-expect-error }}
341334
{{else if (eq R.rowData.key "maskedinput")}}
342335
<F.MaskedInput
343336
name="value-{{R.rowIndex}}"
344337
{{! @glint-expect-error }}
345338
@value={{R.rowData.value}}
346339
{{on "input" this.onInputUpdateModel}}
347340
/>
348-
{{! @glint-expect-error }}
349341
{{else if (eq R.rowData.key "select")}}
350342
<F.SuperSelectMultiple
351343
name="value-{{R.rowIndex}}"
352344
@options={{SUPERSELECT_OPTIONS}}
353-
{{! @glint-expect-error }}
354345
@selected={{R.rowData.value}}
355346
@onChange={{this.onPowerSelectChangeUpdateModel}}
356347
@ariaLabel="Label"

showcase/app/components/mock/components/form/key-value-inputs/with-validation-and-limit.gts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,28 +324,23 @@ export default class MockComponentsFormKeyValueInputsWithValidationAndLimit exte
324324
<:row as |R|>
325325
<R.Field
326326
@isRequired={{true}}
327-
{{! @glint-expect-error }}
328327
@isInvalid={{if R.rowData.validationMessage true}}
329328
as |F|
330329
>
331330
<F.Label>Tag name</F.Label>
332331
<F.TextInput
333332
name="tag-name-{{R.rowIndex}}"
334-
{{! @glint-expect-error }}
335333
@value={{R.rowData.tag-name}}
336334
{{on "input" this.onInputUpdateModel}}
337335
/>
338-
{{! @glint-expect-error }}
339336
{{#if R.rowData.validationMessage}}
340-
{{! @glint-expect-error }}
341337
<F.Error>{{R.rowData.validationMessage}}</F.Error>
342338
{{/if}}
343339
</R.Field>
344340
<R.Field @isOptional={{true}} as |F|>
345341
<F.Label>Tag description</F.Label>
346342
<F.TextInput
347343
name="tag-description-{{R.rowIndex}}"
348-
{{! @glint-expect-error }}
349344
@value={{R.rowData.tag-description}}
350345
{{on "input" this.onInputUpdateModel}}
351346
/>

showcase/app/routes/page-components/rich-tooltip.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
PLACEMENTS,
1111
ENABLE_COLLISION_DETECTION_OPTIONS,
1212
} from '@hashicorp/design-system-components/modifiers/hds-anchored-position';
13+
import type { HdsBadgeColors } from '@hashicorp/design-system-components/components/hds/badge/types';
14+
import type { HdsIconSignature } from '@hashicorp/design-system-components/components/hds/icon/index';
1315

1416
import type { ModelFrom } from 'showcase/utils/ModelFromRoute';
1517

@@ -18,12 +20,25 @@ export type PageComponentsRichTooltipModel =
1820

1921
type TextAlignOptions = 'left' | 'center' | 'right';
2022

23+
interface DEMO_TABLE_DATA_ITEM {
24+
id: number;
25+
'peer-name': string;
26+
'cluster-partition': string;
27+
'cluster-icon': HdsIconSignature['Args']['name'];
28+
status: {
29+
text: string;
30+
color: HdsBadgeColors;
31+
icon: HdsIconSignature['Args']['name'];
32+
};
33+
tagsCount: number;
34+
}
35+
2136
export default class PageComponentsRichTooltipRoute extends Route {
2237
model() {
2338
// these are used only for presentation purpose in the showcase
2439
const STATES = ['default', 'hover', 'active', 'focus'];
2540

26-
const DEMO_TABLE_DATA = [
41+
const DEMO_TABLE_DATA: DEMO_TABLE_DATA_ITEM[] = [
2742
{
2843
id: 1,
2944
'peer-name': 'cluster-2-partition-2',

showcase/app/templates/page-components/form/key-value-inputs/frameless/demo-in-form.hbs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,8 @@
9191
<F.Label>OS and architecture</F.Label>
9292
<F.Select name="plugin-os">
9393
<option></option>
94-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090 }}
9594
<option selected={{if (eq "darwin - arm64" R.rowData.os) true}}>darwin - arm64</option>
96-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090 }}
9795
<option selected={{if (eq "linux - 386" R.rowData.os) true}}>linux - 386</option>
98-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090 }}
9996
<option selected={{if (eq "windows - amd64" R.rowData.os) true}}>windows - amd64</option>
10097
</F.Select>
10198
</R.Field>

showcase/app/templates/page-components/form/key-value-inputs/frameless/demo-responsiveness-custom-widths.hbs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,18 @@
1919
</:header>
2020

2121
<:row as |R|>
22-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090}}
2322
<R.Field @isInvalid={{(if R.rowData.error true)}} @width="1fr" as |F|>
2423
<F.Label>Key (1fr)</F.Label>
2524
<F.HelperText>The key you enter should be a good key.</F.HelperText>
26-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090}}
2725
<F.TextInput @value={{R.rowData.key}} />
28-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090}}
2926
{{#if R.rowData.error}}
30-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090}}
3127
<F.Error>{{R.rowData.error}}</F.Error>
3228
{{/if}}
3329
</R.Field>
34-
35-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090 }}
3630
<R.Field @isInvalid={{(if R.rowData.error true)}} @width="2fr" as |F|>
3731
<F.Label>Value (2fr)</F.Label>
38-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090}}
3932
<F.Textarea @value={{R.rowData.value}} />
40-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090 }}
4133
{{#if R.rowData.error}}
42-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090 }}
4334
<F.Error>{{R.rowData.error}}</F.Error>
4435
{{/if}}
4536
</R.Field>

showcase/app/templates/page-components/form/key-value-inputs/frameless/demo-responsiveness.hbs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,18 @@
1919
</:header>
2020

2121
<:row as |R|>
22-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090 }}
2322
<R.Field @isInvalid={{(if R.rowData.error true)}} as |F|>
2423
<F.Label>Key</F.Label>
2524
<F.HelperText>The key you enter should be a good key.</F.HelperText>
26-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090 }}
2725
<F.TextInput @value={{R.rowData.key}} />
28-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090 }}
2926
{{#if R.rowData.error}}
30-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090 }}
3127
<F.Error>{{R.rowData.error}}</F.Error>
3228
{{/if}}
3329
</R.Field>
34-
35-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090 }}
3630
<R.Field @isInvalid={{(if R.rowData.error true)}} as |F|>
3731
<F.Label>Value</F.Label>
38-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090 }}
3932
<F.Textarea @value={{R.rowData.value}} />
40-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090 }}
4133
{{#if R.rowData.error}}
42-
{{! @glint-expect-error - https://hashicorp.atlassian.net/browse/HDS-5090 }}
4334
<F.Error>{{R.rowData.error}}</F.Error>
4435
{{/if}}
4536
</R.Field>

0 commit comments

Comments
 (0)