Skip to content

Commit

Permalink
Add defaultPageSize to display.table and select.table
Browse files Browse the repository at this point in the history
Haven't yet added a UI for the end user to change the page size.
`Infinity` actually just works out of the box!
  • Loading branch information
jacobmischka committed Aug 24, 2022
1 parent fd2a56e commit 7aca3da
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
55 changes: 32 additions & 23 deletions src/examples/basic/selectFromTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,35 @@ export const table_custom: IntervalActionHandler = async io => {
'zip',
].map(f => ({ label: f, value: f }))

const [rowsCount, fields, tableType, orientation] = await io.group([
io.input.number('Number of rows', { defaultValue: 50 }),
io.select.multiple('Fields', {
options: options,
defaultValue: options,
}),
io.select.single('Table type', {
options: [
{ label: 'Display', value: 'display' },
{ label: 'Select', value: 'select' },
],
defaultValue: { label: 'Select', value: 'select' },
}),
io.select.single('Orientation', {
options: [
{ label: 'Horizontal', value: 'horizontal' },
{ label: 'Vertical', value: 'vertical' },
],
defaultValue: { label: 'Select', value: 'select' },
helpText:
'Warning: Vertical orientation is not supported for select tables; it will be ignored',
}),
])
const [rowsCount, fields, tableType, orientation, defaultPageSize] =
await io.group([
io.input.number('Number of rows', { defaultValue: 50 }),
io.select.multiple('Fields', {
options: options,
defaultValue: options,
}),
io.select.single('Table type', {
options: [
{ label: 'Display', value: 'display' },
{ label: 'Select', value: 'select' },
],
defaultValue: { label: 'Select', value: 'select' },
}),
io.select.single('Orientation', {
options: [
{ label: 'Horizontal', value: 'horizontal' },
{ label: 'Vertical', value: 'vertical' },
],
defaultValue: { label: 'Horizontal', value: 'horizontal' },
helpText:
'Warning: Vertical orientation is not supported for select tables; it will be ignored',
}),
io.input
.number('Default page size', {
defaultValue: 20,
})
.optional(),
])

const rows: { [key: string]: any }[] = []
for (let i = 0; i < rowsCount; i++) {
Expand Down Expand Up @@ -179,12 +185,14 @@ export const table_custom: IntervalActionHandler = async io => {
await io.display.table('Table', {
data: rows,
orientation: orientation.value as 'horizontal' | 'vertical',
defaultPageSize,
})
} else {
const [selections] = await io.select.table('Select a person', {
data: rows,
minSelections: 1,
maxSelections: 3,
defaultPageSize,
})
await io.display.object('Selected', { data: selections })
}
Expand Down Expand Up @@ -258,6 +266,7 @@ export const table_custom_columns: IntervalActionHandler = async io => {
],
minSelections: 1,
maxSelections: 2,
defaultPageSize: Infinity,
})
.optional()

Expand Down
2 changes: 2 additions & 0 deletions src/ioSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ export const ioSchema = {
helpText: z.optional(z.string()),
columns: z.optional(z.array(internalTableColumn)),
data: z.array(internalTableRow),
defaultPageSize: z.number().optional(),
minSelections: z.optional(z.number().int().min(0)),
maxSelections: z.optional(z.number().positive().int()),
disabled: z.optional(z.boolean().default(false)),
Expand Down Expand Up @@ -498,6 +499,7 @@ export const ioSchema = {
columns: z.optional(z.array(internalTableColumn)),
data: z.array(internalTableRow),
orientation: z.enum(['vertical', 'horizontal']).default('horizontal'),
defaultPageSize: z.number().optional(),
}),
state: z.null(),
returns: z.null(),
Expand Down

0 comments on commit 7aca3da

Please sign in to comment.