Skip to content

Commit

Permalink
feat(SupportedDeviceTable): Add excludeIf and includeIf props
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Dec 14, 2023
1 parent 5586460 commit f0b26e6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ interface SupportedDeviceContentProps {
filters: DeviceModelFilters
manufacturers: string[] | null
excludedManufacturers: string[]
includeIf: string[] | null
excludeIf: string[]
}

export function SupportedDeviceContent({
Expand All @@ -23,13 +25,17 @@ export function SupportedDeviceContent({
filters,
manufacturers,
excludedManufacturers,
includeIf,
excludeIf,
}: SupportedDeviceContentProps): JSX.Element | null {
const { deviceModels, isLoading, isError, refetch } = useFilteredDeviceModels(
{
filterValue,
filters,
manufacturers,
excludedManufacturers,
includeIf,
excludeIf,
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const props: ElementProps<SupportedDeviceTableProps> = {
disableFilter: 'boolean',
manufacturers: 'array',
excludedManufacturers: 'array',
includeIf: 'array',
excludeIf: 'array',
}

export { SupportedDeviceTable as Component } from './SupportedDeviceTable.js'
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ export const ExcludeManufacturers: Story = {
),
}

export const IncludeIf: Story = {
render: (props) => (
<SupportedDeviceTable
{...props}
includeIf={[
'software_features.can_remotely_unlock',
'physical_properties.has_physical_key',
]}
/>
),
}

export const ExcludeIf: Story = {
render: (props) => (
<SupportedDeviceTable
{...props}
excludeIf={['software_features.can_remotely_unlock']}
/>
),
}

export const InsideModal: Story = {
render: (props) => {
const [open, toggleOpen] = useToggle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface SupportedDeviceTableProps extends CommonProps {
disableFilter?: boolean
manufacturers?: string[] | null
excludedManufacturers?: string[]
includeIf?: string[] | null
excludeIf?: string[]
}

export const NestedSupportedDeviceTable =
Expand All @@ -24,6 +26,8 @@ export function SupportedDeviceTable({
disableFilter = false,
manufacturers = null,
excludedManufacturers = [],
includeIf = null,
excludeIf = [],
className,
}: SupportedDeviceTableProps = {}): JSX.Element {
useComponentTelemetry('SupportedDeviceTable')
Expand Down Expand Up @@ -59,6 +63,8 @@ export function SupportedDeviceTable({
filters={filters}
manufacturers={manufacturers}
excludedManufacturers={excludedManufacturers}
includeIf={includeIf}
excludeIf={excludeIf}
/>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,29 @@ export interface DeviceModelFilters {
export const useFilteredDeviceModels = ({
filterValue,
filters,
includeIf,
excludeIf,
...manufacturersParams
}: {
filterValue: string
filters: DeviceModelFilters
manufacturers: string[] | null
excludedManufacturers: string[]
includeIf: string[] | null
excludeIf: string[]
}): ReturnType<typeof useDeviceModels> => {
const { manufacturers } = useFilteredManufacturers(manufacturersParams)

const params: UseDeviceModelsParams = {}

if (excludeIf.length > 0) {
params.exclude_if = excludeIf
}

if (includeIf != null) {
params.include_if = includeIf
}

if (filterValue.trim() !== '') {
params.text_search = filterValue.trim()
}
Expand Down

0 comments on commit f0b26e6

Please sign in to comment.