From 7aca3da3f8c3d4455fb37c5be941a1878bfb452b Mon Sep 17 00:00:00 2001 From: Jacob Mischka Date: Wed, 24 Aug 2022 14:59:41 -0500 Subject: [PATCH] Add defaultPageSize to display.table and select.table Haven't yet added a UI for the end user to change the page size. `Infinity` actually just works out of the box! --- src/examples/basic/selectFromTable.ts | 55 ++++++++++++++++----------- src/ioSchema.ts | 2 + 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/examples/basic/selectFromTable.ts b/src/examples/basic/selectFromTable.ts index 1367bf0..3787a4f 100644 --- a/src/examples/basic/selectFromTable.ts +++ b/src/examples/basic/selectFromTable.ts @@ -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++) { @@ -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 }) } @@ -258,6 +266,7 @@ export const table_custom_columns: IntervalActionHandler = async io => { ], minSelections: 1, maxSelections: 2, + defaultPageSize: Infinity, }) .optional() diff --git a/src/ioSchema.ts b/src/ioSchema.ts index 49d44e1..46ef530 100644 --- a/src/ioSchema.ts +++ b/src/ioSchema.ts @@ -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)), @@ -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(),