Skip to content

Commit d4f41f9

Browse files
authored
feat(SupportedDeviceTable): Add excludeIf and includeIf props (#575)
* feat(SupportedDeviceTable): Add excludeIf and includeIf props * Add UPSTREAM note
1 parent 2b7c9ce commit d4f41f9

File tree

5 files changed

+60
-8
lines changed

5 files changed

+60
-8
lines changed

src/lib/seam/components/SupportedDeviceTable/SupportedDeviceContent.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ interface SupportedDeviceContentProps {
1515
filters: DeviceModelFilters
1616
manufacturers: string[] | null
1717
excludedManufacturers: string[]
18+
includeIf: string[] | null
19+
excludeIf: string[]
1820
}
1921

2022
export function SupportedDeviceContent({
@@ -23,13 +25,17 @@ export function SupportedDeviceContent({
2325
filters,
2426
manufacturers,
2527
excludedManufacturers,
28+
includeIf,
29+
excludeIf,
2630
}: SupportedDeviceContentProps): JSX.Element | null {
2731
const { deviceModels, isLoading, isError, refetch } = useFilteredDeviceModels(
2832
{
2933
filterValue,
3034
filters,
3135
manufacturers,
3236
excludedManufacturers,
37+
includeIf,
38+
excludeIf,
3339
}
3440
)
3541

src/lib/seam/components/SupportedDeviceTable/SupportedDeviceTable.element.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export const props: ElementProps<SupportedDeviceTableProps> = {
88
disableFilter: 'boolean',
99
manufacturers: 'array',
1010
excludedManufacturers: 'array',
11+
includeIf: 'array',
12+
excludeIf: 'array',
1113
}
1214

1315
export { SupportedDeviceTable as Component } from './SupportedDeviceTable.js'

src/lib/seam/components/SupportedDeviceTable/SupportedDeviceTable.stories.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,27 @@ export const ExcludeManufacturers: Story = {
5050
),
5151
}
5252

53+
export const IncludeIf: Story = {
54+
render: (props) => (
55+
<SupportedDeviceTable
56+
{...props}
57+
includeIf={[
58+
'software_features.can_remotely_unlock',
59+
'physical_properties.has_physical_key',
60+
]}
61+
/>
62+
),
63+
}
64+
65+
export const ExcludeIf: Story = {
66+
render: (props) => (
67+
<SupportedDeviceTable
68+
{...props}
69+
excludeIf={['software_features.can_remotely_unlock']}
70+
/>
71+
),
72+
}
73+
5374
export const InsideModal: Story = {
5475
render: (props) => {
5576
const [open, toggleOpen] = useToggle()

src/lib/seam/components/SupportedDeviceTable/SupportedDeviceTable.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export interface SupportedDeviceTableProps extends CommonProps {
1515
disableFilter?: boolean
1616
manufacturers?: string[] | null
1717
excludedManufacturers?: string[]
18+
includeIf?: string[] | null
19+
excludeIf?: string[]
1820
}
1921

2022
export const NestedSupportedDeviceTable =
@@ -24,6 +26,8 @@ export function SupportedDeviceTable({
2426
disableFilter = false,
2527
manufacturers = null,
2628
excludedManufacturers = [],
29+
includeIf = null,
30+
excludeIf = [],
2731
className,
2832
}: SupportedDeviceTableProps = {}): JSX.Element {
2933
useComponentTelemetry('SupportedDeviceTable')
@@ -59,6 +63,8 @@ export function SupportedDeviceTable({
5963
filters={filters}
6064
manufacturers={manufacturers}
6165
excludedManufacturers={excludedManufacturers}
66+
includeIf={includeIf}
67+
excludeIf={excludeIf}
6268
/>
6369
</div>
6470
)

src/lib/seam/components/SupportedDeviceTable/use-filtered-device-models.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,30 @@ export interface DeviceModelFilters {
1313
export const useFilteredDeviceModels = ({
1414
filterValue,
1515
filters,
16+
includeIf,
17+
excludeIf,
1618
...manufacturersParams
1719
}: {
1820
filterValue: string
1921
filters: DeviceModelFilters
2022
manufacturers: string[] | null
2123
excludedManufacturers: string[]
24+
includeIf: string[] | null
25+
excludeIf: string[]
2226
}): ReturnType<typeof useDeviceModels> => {
2327
const { manufacturers } = useFilteredManufacturers(manufacturersParams)
2428

2529
const params: UseDeviceModelsParams = {}
2630

31+
if (excludeIf.length > 0) {
32+
params.exclude_if = excludeIf
33+
}
34+
35+
// UPSTREAM: API does not parse zero-length arrays correctly.
36+
if (includeIf != null && includeIf.length > 0) {
37+
params.include_if = includeIf
38+
}
39+
2740
if (filterValue.trim() !== '') {
2841
params.text_search = filterValue.trim()
2942
}
@@ -50,13 +63,17 @@ export const useFilteredDeviceModels = ({
5063

5164
return {
5265
...rest,
53-
deviceModels: deviceModels?.filter(
54-
(deviceModel) =>
55-
manufacturers?.some(
56-
(manufacturer) =>
57-
deviceModel.manufacturer.manufacturer_id ===
58-
manufacturer.manufacturer_id
59-
)
60-
),
66+
deviceModels:
67+
// UPSTREAM: API does not parse zero-length arrays correctly.
68+
includeIf?.length === 0
69+
? []
70+
: deviceModels?.filter(
71+
(deviceModel) =>
72+
manufacturers?.some(
73+
(manufacturer) =>
74+
deviceModel.manufacturer.manufacturer_id ===
75+
manufacturer.manufacturer_id
76+
)
77+
),
6178
}
6279
}

0 commit comments

Comments
 (0)