From ddf135da42e5d81ce2c44fb501eb1418f0089871 Mon Sep 17 00:00:00 2001 From: Dan Philibin Date: Sat, 13 Aug 2022 23:25:27 +0000 Subject: [PATCH 01/11] define tableRowAction schema --- src/ioSchema.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/ioSchema.ts b/src/ioSchema.ts index e811fa8..7929168 100644 --- a/src/ioSchema.ts +++ b/src/ioSchema.ts @@ -143,6 +143,24 @@ export const tableRow = z // If no columns specified, we'll just serialize any nested objects. .or(z.object({}).passthrough()) +export const tableRowAction = z.intersection( + z.object({ + label: z.string(), + disabled: z.boolean().optional(), + }), + z.union([ + z.object({ + action: z.string(), + params: serializableRecord.optional(), + }), + z.object({ + url: z.string(), + }), + ]) +) + +export type TableRowAction = z.infer + export const newInternalTableRow = z.object({ key: z.string(), data: tableRow, From 32836b072031253482b889cbbf84a14d59526385 Mon Sep 17 00:00:00 2001 From: Dan Philibin Date: Sat, 13 Aug 2022 23:26:45 +0000 Subject: [PATCH 02/11] add actions to serializer & components --- src/components/table.ts | 9 ++++++--- src/ioSchema.ts | 1 + src/utils/table.ts | 9 ++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/components/table.ts b/src/components/table.ts index ad2d7d2..ff6fdeb 100644 --- a/src/components/table.ts +++ b/src/components/table.ts @@ -6,6 +6,7 @@ import { newInternalTableRow, T_IO_RETURNS, serializableRecord, + tableRowAction, } from '../ioSchema' import { columnsBuilder, tableRowSerializer } from '../utils/table' import Logger from '../classes/Logger' @@ -38,6 +39,7 @@ export function selectTable(logger: Logger) { props: Omit, 'data' | 'columns'> & { data: Row[] columns?: (Column | string)[] + actions?: (row: Row) => z.infer[] } ) { type DataList = typeof props['data'] @@ -47,7 +49,7 @@ export function selectTable(logger: Logger) { ) const data = props.data.map((row, idx) => - tableRowSerializer(idx, row, columns) + tableRowSerializer(idx, row, columns, props.actions) ) return { @@ -66,10 +68,11 @@ export function selectTable(logger: Logger) { } export function displayTable(logger: Logger) { - return function displayTable( + return function displayTable = any>( props: Omit, 'data' | 'columns'> & { data: Row[] columns?: (Column | string)[] + actions?: (row: Row) => z.infer[] } ) { const columns = columnsBuilder(props, column => @@ -77,7 +80,7 @@ export function displayTable(logger: Logger) { ) const data = props.data.map((row, idx) => - tableRowSerializer(idx, row, columns) + tableRowSerializer(idx, row, columns, props.actions) ) return { diff --git a/src/ioSchema.ts b/src/ioSchema.ts index 7929168..c34c3dc 100644 --- a/src/ioSchema.ts +++ b/src/ioSchema.ts @@ -164,6 +164,7 @@ export type TableRowAction = z.infer export const newInternalTableRow = z.object({ key: z.string(), data: tableRow, + actions: z.array(tableRowAction).optional(), }) export const internalTableRow = z.union([newInternalTableRow, tableRow]) diff --git a/src/utils/table.ts b/src/utils/table.ts index a746aef..8217574 100644 --- a/src/utils/table.ts +++ b/src/utils/table.ts @@ -3,6 +3,7 @@ import { internalTableColumn, tableRow, internalTableRow, + tableRowAction, } from '../ioSchema' import { z } from 'zod' import Logger from '../classes/Logger' @@ -55,10 +56,11 @@ export function columnsWithoutRender( /** * Applies cell renderers to a row. */ -export function tableRowSerializer( +export function tableRowSerializer>( idx: number, - row: z.infer, - columns: z.infer[] + row: T, + columns: z.infer[], + actions?: (row: T) => z.infer[] ): z.infer { const key = idx.toString() @@ -81,5 +83,6 @@ export function tableRowSerializer( return { key, data: finalRow, + actions: actions ? actions(row) : undefined, } } From dd9280b6c4d4b7751f53206f962cb23fccaddeb7 Mon Sep 17 00:00:00 2001 From: Dan Philibin Date: Sat, 13 Aug 2022 23:50:05 +0000 Subject: [PATCH 03/11] support disabled items without a click action --- src/ioSchema.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ioSchema.ts b/src/ioSchema.ts index c34c3dc..3931c50 100644 --- a/src/ioSchema.ts +++ b/src/ioSchema.ts @@ -146,15 +146,19 @@ export const tableRow = z export const tableRowAction = z.intersection( z.object({ label: z.string(), - disabled: z.boolean().optional(), }), z.union([ z.object({ action: z.string(), params: serializableRecord.optional(), + disabled: z.boolean().optional(), }), z.object({ url: z.string(), + disabled: z.boolean().optional(), + }), + z.object({ + disabled: z.literal(true), }), ]) ) From c3e83724ddf18ac78f791bc4cb47ce82af5c7bd6 Mon Sep 17 00:00:00 2001 From: Dan Philibin Date: Sat, 13 Aug 2022 23:50:11 +0000 Subject: [PATCH 04/11] add example --- src/examples/basic/index.ts | 2 ++ src/examples/basic/selectFromTable.ts | 36 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/examples/basic/index.ts b/src/examples/basic/index.ts index ada0fce..5aab4f2 100644 --- a/src/examples/basic/index.ts +++ b/src/examples/basic/index.ts @@ -10,6 +10,7 @@ import { table_basic, table_custom_columns, table_custom, + table_actions, } from './selectFromTable' import unauthorized from './unauthorized' import './ghostHost' @@ -201,6 +202,7 @@ const interval = new Interval({ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sit amet quam in lorem sagittis accumsan malesuada nec mauris. Nulla cursus dolor id augue sodales, et consequat elit mattis. Suspendisse nec sollicitudin ex. Pellentesque laoreet nulla nec malesuada consequat. Donec blandit leo id tincidunt tristique. Mauris vehicula metus sed ex bibendum, nec bibendum urna tincidunt. Curabitur porttitor euismod velit sed interdum. Suspendisse at dapibus eros. Vestibulum varius, est vel luctus pellentesque, risus lorem ullamcorper est, a ullamcorper metus dolor eget neque. Donec sit amet nulla tempus, fringilla magna eu, bibendum tortor. Nam pulvinar diam id vehicula posuere. Praesent non turpis et nibh dictum suscipit non nec ante. Phasellus vulputate egestas nisl a dapibus. Duis augue lorem, mattis auctor condimentum a, convallis sed elit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Pellentesque bibendum, magna vel pharetra fermentum, eros mi vulputate enim, in consectetur est quam quis felis.', } }, + table_actions, table_basic, table_custom, table_custom_columns, diff --git a/src/examples/basic/selectFromTable.ts b/src/examples/basic/selectFromTable.ts index 14306d7..eee5157 100644 --- a/src/examples/basic/selectFromTable.ts +++ b/src/examples/basic/selectFromTable.ts @@ -64,6 +64,42 @@ export const table_basic: IntervalActionHandler = async io => { await io.display.object('Selected', { data: selections }) } +export const table_actions: IntervalActionHandler = async io => { + const simpleCharges = charges.map((ch, idx) => ({ + id: idx, + name: ch.name, + email: faker.internet.email(), + amount: ch.amount, + })) + + const selections = await io.display.table('Charges', { + data: simpleCharges, + actions: row => [ + { + label: 'Edit', + action: 'edit_user', + params: { email: row.email }, + }, + { + label: 'View in CRM', + url: 'https://interval.com/', + // disabled: true, + }, + { + label: 'Disabled item', + disabled: true, + }, + { + label: 'Delete', + action: 'delete', + params: { id: row.id }, + }, + ], + }) + + await io.display.object('Selected', { data: selections }) +} + export const table_custom: IntervalActionHandler = async io => { const options = [ 'id', From e9296091ee5e3100e41f51c2406f72746e7cfb7d Mon Sep 17 00:00:00 2001 From: Dan Philibin Date: Mon, 15 Aug 2022 18:51:07 +0000 Subject: [PATCH 05/11] WIP - sticky menus --- src/examples/basic/selectFromTable.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/examples/basic/selectFromTable.ts b/src/examples/basic/selectFromTable.ts index eee5157..e7e79f4 100644 --- a/src/examples/basic/selectFromTable.ts +++ b/src/examples/basic/selectFromTable.ts @@ -70,6 +70,11 @@ export const table_actions: IntervalActionHandler = async io => { name: ch.name, email: faker.internet.email(), amount: ch.amount, + address1: faker.address.streetAddress(), + address2: faker.address.secondaryAddress(), + city: faker.address.city(), + state: faker.address.state(), + zip: faker.address.zipCode(), })) const selections = await io.display.table('Charges', { From 1c95e45d48a238fd3a528a5106923a737b3e0b4f Mon Sep 17 00:00:00 2001 From: Dan Philibin Date: Tue, 16 Aug 2022 19:35:00 +0000 Subject: [PATCH 06/11] add theme and onClick props --- src/components/table.ts | 4 ++-- src/ioSchema.ts | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/table.ts b/src/components/table.ts index ff6fdeb..58975b8 100644 --- a/src/components/table.ts +++ b/src/components/table.ts @@ -39,7 +39,7 @@ export function selectTable(logger: Logger) { props: Omit, 'data' | 'columns'> & { data: Row[] columns?: (Column | string)[] - actions?: (row: Row) => z.infer[] + actions?: (row: Row) => z.infer>[] } ) { type DataList = typeof props['data'] @@ -72,7 +72,7 @@ export function displayTable(logger: Logger) { props: Omit, 'data' | 'columns'> & { data: Row[] columns?: (Column | string)[] - actions?: (row: Row) => z.infer[] + actions?: (row: Row) => z.infer>[] } ) { const columns = columnsBuilder(props, column => diff --git a/src/ioSchema.ts b/src/ioSchema.ts index 3931c50..44e4e1c 100644 --- a/src/ioSchema.ts +++ b/src/ioSchema.ts @@ -146,6 +146,7 @@ export const tableRow = z export const tableRowAction = z.intersection( z.object({ label: z.string(), + theme: z.enum(['default', 'danger']).default('default'), }), z.union([ z.object({ @@ -160,6 +161,12 @@ export const tableRowAction = z.intersection( z.object({ disabled: z.literal(true), }), + // TODO: we Omit this in the component type, but it's included here so the imported type + // works well on the frontend. is there a better way to do this? + z.object({ + onClick: z.function().returns(z.void()), + disabled: z.boolean().optional(), + }), ]) ) From 1f3212e94834258f669b7ab8c5a7534c5c9d73fd Mon Sep 17 00:00:00 2001 From: Dan Philibin Date: Tue, 16 Aug 2022 20:37:57 +0000 Subject: [PATCH 07/11] rename "actions" to "menus" `actions` seems confusing given that "action" is a first-class item in Interval --- src/components/table.ts | 10 +++++----- src/examples/basic/selectFromTable.ts | 16 +--------------- src/ioSchema.ts | 8 ++++---- src/utils/table.ts | 6 +++--- 4 files changed, 13 insertions(+), 27 deletions(-) diff --git a/src/components/table.ts b/src/components/table.ts index 58975b8..e1027b9 100644 --- a/src/components/table.ts +++ b/src/components/table.ts @@ -6,7 +6,7 @@ import { newInternalTableRow, T_IO_RETURNS, serializableRecord, - tableRowAction, + tableRowMenuItem, } from '../ioSchema' import { columnsBuilder, tableRowSerializer } from '../utils/table' import Logger from '../classes/Logger' @@ -39,7 +39,7 @@ export function selectTable(logger: Logger) { props: Omit, 'data' | 'columns'> & { data: Row[] columns?: (Column | string)[] - actions?: (row: Row) => z.infer>[] + menus?: (row: Row) => z.infer>[] } ) { type DataList = typeof props['data'] @@ -49,7 +49,7 @@ export function selectTable(logger: Logger) { ) const data = props.data.map((row, idx) => - tableRowSerializer(idx, row, columns, props.actions) + tableRowSerializer(idx, row, columns, props.menus) ) return { @@ -72,7 +72,7 @@ export function displayTable(logger: Logger) { props: Omit, 'data' | 'columns'> & { data: Row[] columns?: (Column | string)[] - actions?: (row: Row) => z.infer>[] + menus?: (row: Row) => z.infer>[] } ) { const columns = columnsBuilder(props, column => @@ -80,7 +80,7 @@ export function displayTable(logger: Logger) { ) const data = props.data.map((row, idx) => - tableRowSerializer(idx, row, columns, props.actions) + tableRowSerializer(idx, row, columns, props.menus) ) return { diff --git a/src/examples/basic/selectFromTable.ts b/src/examples/basic/selectFromTable.ts index e7e79f4..3db4c05 100644 --- a/src/examples/basic/selectFromTable.ts +++ b/src/examples/basic/selectFromTable.ts @@ -79,26 +79,12 @@ export const table_actions: IntervalActionHandler = async io => { const selections = await io.display.table('Charges', { data: simpleCharges, - actions: row => [ + menus: row => [ { label: 'Edit', action: 'edit_user', params: { email: row.email }, }, - { - label: 'View in CRM', - url: 'https://interval.com/', - // disabled: true, - }, - { - label: 'Disabled item', - disabled: true, - }, - { - label: 'Delete', - action: 'delete', - params: { id: row.id }, - }, ], }) diff --git a/src/ioSchema.ts b/src/ioSchema.ts index 44e4e1c..1848099 100644 --- a/src/ioSchema.ts +++ b/src/ioSchema.ts @@ -143,10 +143,10 @@ export const tableRow = z // If no columns specified, we'll just serialize any nested objects. .or(z.object({}).passthrough()) -export const tableRowAction = z.intersection( +export const tableRowMenuItem = z.intersection( z.object({ label: z.string(), - theme: z.enum(['default', 'danger']).default('default'), + theme: z.enum(['default', 'danger']).default('default').optional(), }), z.union([ z.object({ @@ -170,12 +170,12 @@ export const tableRowAction = z.intersection( ]) ) -export type TableRowAction = z.infer +export type TableRowMenuItem = z.infer export const newInternalTableRow = z.object({ key: z.string(), data: tableRow, - actions: z.array(tableRowAction).optional(), + menu: z.array(tableRowMenuItem).optional(), }) export const internalTableRow = z.union([newInternalTableRow, tableRow]) diff --git a/src/utils/table.ts b/src/utils/table.ts index 8217574..86d14f1 100644 --- a/src/utils/table.ts +++ b/src/utils/table.ts @@ -3,7 +3,7 @@ import { internalTableColumn, tableRow, internalTableRow, - tableRowAction, + tableRowMenuItem, } from '../ioSchema' import { z } from 'zod' import Logger from '../classes/Logger' @@ -60,7 +60,7 @@ export function tableRowSerializer>( idx: number, row: T, columns: z.infer[], - actions?: (row: T) => z.infer[] + menus?: (row: T) => z.infer[] ): z.infer { const key = idx.toString() @@ -83,6 +83,6 @@ export function tableRowSerializer>( return { key, data: finalRow, - actions: actions ? actions(row) : undefined, + menu: menus ? menus(row) : undefined, } } From d23f31fb982c8ff0c3dc5bc5fbfd2ec490e45380 Mon Sep 17 00:00:00 2001 From: Dan Philibin Date: Tue, 16 Aug 2022 21:31:36 +0000 Subject: [PATCH 08/11] clean up types --- src/components/table.ts | 4 ++-- src/ioSchema.ts | 8 -------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/components/table.ts b/src/components/table.ts index e1027b9..ec6f72b 100644 --- a/src/components/table.ts +++ b/src/components/table.ts @@ -39,7 +39,7 @@ export function selectTable(logger: Logger) { props: Omit, 'data' | 'columns'> & { data: Row[] columns?: (Column | string)[] - menus?: (row: Row) => z.infer>[] + menus?: (row: Row) => z.infer[] } ) { type DataList = typeof props['data'] @@ -72,7 +72,7 @@ export function displayTable(logger: Logger) { props: Omit, 'data' | 'columns'> & { data: Row[] columns?: (Column | string)[] - menus?: (row: Row) => z.infer>[] + menus?: (row: Row) => z.infer[] } ) { const columns = columnsBuilder(props, column => diff --git a/src/ioSchema.ts b/src/ioSchema.ts index 1848099..9d44067 100644 --- a/src/ioSchema.ts +++ b/src/ioSchema.ts @@ -161,17 +161,9 @@ export const tableRowMenuItem = z.intersection( z.object({ disabled: z.literal(true), }), - // TODO: we Omit this in the component type, but it's included here so the imported type - // works well on the frontend. is there a better way to do this? - z.object({ - onClick: z.function().returns(z.void()), - disabled: z.boolean().optional(), - }), ]) ) -export type TableRowMenuItem = z.infer - export const newInternalTableRow = z.object({ key: z.string(), data: tableRow, From 928e143092a73c497c8075ffc87fd0509d4d536a Mon Sep 17 00:00:00 2001 From: Dan Philibin Date: Wed, 17 Aug 2022 02:37:10 +0000 Subject: [PATCH 09/11] tableRowMenuItem -> dropdownMenuItem This already maps to `DropdownMenuItem` on the frontend, and I also imagine we'll use the same API for menus in other locations. --- src/components/table.ts | 6 +++--- src/ioSchema.ts | 4 ++-- src/utils/table.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/table.ts b/src/components/table.ts index ec6f72b..2d97533 100644 --- a/src/components/table.ts +++ b/src/components/table.ts @@ -6,7 +6,7 @@ import { newInternalTableRow, T_IO_RETURNS, serializableRecord, - tableRowMenuItem, + dropdownMenuItem, } from '../ioSchema' import { columnsBuilder, tableRowSerializer } from '../utils/table' import Logger from '../classes/Logger' @@ -39,7 +39,7 @@ export function selectTable(logger: Logger) { props: Omit, 'data' | 'columns'> & { data: Row[] columns?: (Column | string)[] - menus?: (row: Row) => z.infer[] + menus?: (row: Row) => z.infer[] } ) { type DataList = typeof props['data'] @@ -72,7 +72,7 @@ export function displayTable(logger: Logger) { props: Omit, 'data' | 'columns'> & { data: Row[] columns?: (Column | string)[] - menus?: (row: Row) => z.infer[] + menus?: (row: Row) => z.infer[] } ) { const columns = columnsBuilder(props, column => diff --git a/src/ioSchema.ts b/src/ioSchema.ts index 9d44067..01c9d20 100644 --- a/src/ioSchema.ts +++ b/src/ioSchema.ts @@ -143,7 +143,7 @@ export const tableRow = z // If no columns specified, we'll just serialize any nested objects. .or(z.object({}).passthrough()) -export const tableRowMenuItem = z.intersection( +export const dropdownMenuItem = z.intersection( z.object({ label: z.string(), theme: z.enum(['default', 'danger']).default('default').optional(), @@ -167,7 +167,7 @@ export const tableRowMenuItem = z.intersection( export const newInternalTableRow = z.object({ key: z.string(), data: tableRow, - menu: z.array(tableRowMenuItem).optional(), + menu: z.array(dropdownMenuItem).optional(), }) export const internalTableRow = z.union([newInternalTableRow, tableRow]) diff --git a/src/utils/table.ts b/src/utils/table.ts index 86d14f1..89e0677 100644 --- a/src/utils/table.ts +++ b/src/utils/table.ts @@ -3,7 +3,7 @@ import { internalTableColumn, tableRow, internalTableRow, - tableRowMenuItem, + dropdownMenuItem, } from '../ioSchema' import { z } from 'zod' import Logger from '../classes/Logger' @@ -60,7 +60,7 @@ export function tableRowSerializer>( idx: number, row: T, columns: z.infer[], - menus?: (row: T) => z.infer[] + menus?: (row: T) => z.infer[] ): z.infer { const key = idx.toString() From d0a886411cf1bbe08aaba2a6948a4627fdaac80c Mon Sep 17 00:00:00 2001 From: Dan Philibin Date: Wed, 17 Aug 2022 17:03:43 +0000 Subject: [PATCH 10/11] rename menus -> rowMenuItems --- src/components/table.ts | 10 +++++----- src/examples/basic/selectFromTable.ts | 2 +- src/ioSchema.ts | 4 ++-- src/utils/table.ts | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/table.ts b/src/components/table.ts index 2d97533..4bfde47 100644 --- a/src/components/table.ts +++ b/src/components/table.ts @@ -6,7 +6,7 @@ import { newInternalTableRow, T_IO_RETURNS, serializableRecord, - dropdownMenuItem, + menuItem, } from '../ioSchema' import { columnsBuilder, tableRowSerializer } from '../utils/table' import Logger from '../classes/Logger' @@ -39,7 +39,7 @@ export function selectTable(logger: Logger) { props: Omit, 'data' | 'columns'> & { data: Row[] columns?: (Column | string)[] - menus?: (row: Row) => z.infer[] + rowMenuItems?: (row: Row) => z.infer[] } ) { type DataList = typeof props['data'] @@ -49,7 +49,7 @@ export function selectTable(logger: Logger) { ) const data = props.data.map((row, idx) => - tableRowSerializer(idx, row, columns, props.menus) + tableRowSerializer(idx, row, columns, props.rowMenuItems) ) return { @@ -72,7 +72,7 @@ export function displayTable(logger: Logger) { props: Omit, 'data' | 'columns'> & { data: Row[] columns?: (Column | string)[] - menus?: (row: Row) => z.infer[] + rowMenuItems?: (row: Row) => z.infer[] } ) { const columns = columnsBuilder(props, column => @@ -80,7 +80,7 @@ export function displayTable(logger: Logger) { ) const data = props.data.map((row, idx) => - tableRowSerializer(idx, row, columns, props.menus) + tableRowSerializer(idx, row, columns, props.rowMenuItems) ) return { diff --git a/src/examples/basic/selectFromTable.ts b/src/examples/basic/selectFromTable.ts index 3db4c05..1367bf0 100644 --- a/src/examples/basic/selectFromTable.ts +++ b/src/examples/basic/selectFromTable.ts @@ -79,7 +79,7 @@ export const table_actions: IntervalActionHandler = async io => { const selections = await io.display.table('Charges', { data: simpleCharges, - menus: row => [ + rowMenuItems: row => [ { label: 'Edit', action: 'edit_user', diff --git a/src/ioSchema.ts b/src/ioSchema.ts index 01c9d20..fd9393f 100644 --- a/src/ioSchema.ts +++ b/src/ioSchema.ts @@ -143,7 +143,7 @@ export const tableRow = z // If no columns specified, we'll just serialize any nested objects. .or(z.object({}).passthrough()) -export const dropdownMenuItem = z.intersection( +export const menuItem = z.intersection( z.object({ label: z.string(), theme: z.enum(['default', 'danger']).default('default').optional(), @@ -167,7 +167,7 @@ export const dropdownMenuItem = z.intersection( export const newInternalTableRow = z.object({ key: z.string(), data: tableRow, - menu: z.array(dropdownMenuItem).optional(), + menu: z.array(menuItem).optional(), }) export const internalTableRow = z.union([newInternalTableRow, tableRow]) diff --git a/src/utils/table.ts b/src/utils/table.ts index 89e0677..21c19ae 100644 --- a/src/utils/table.ts +++ b/src/utils/table.ts @@ -3,7 +3,7 @@ import { internalTableColumn, tableRow, internalTableRow, - dropdownMenuItem, + menuItem, } from '../ioSchema' import { z } from 'zod' import Logger from '../classes/Logger' @@ -60,7 +60,7 @@ export function tableRowSerializer>( idx: number, row: T, columns: z.infer[], - menus?: (row: T) => z.infer[] + menuBuilder?: (row: T) => z.infer[] ): z.infer { const key = idx.toString() @@ -83,6 +83,6 @@ export function tableRowSerializer>( return { key, data: finalRow, - menu: menus ? menus(row) : undefined, + menu: menuBuilder ? menuBuilder(row) : undefined, } } From d52fd65c1ec903659ed6fb7a716fe9f04e23af77 Mon Sep 17 00:00:00 2001 From: Dan Philibin Date: Wed, 17 Aug 2022 17:25:51 +0000 Subject: [PATCH 11/11] remove newInternalTableRow --- src/components/table.ts | 4 ++-- src/ioSchema.ts | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/components/table.ts b/src/components/table.ts index 4bfde47..3fffe71 100644 --- a/src/components/table.ts +++ b/src/components/table.ts @@ -3,7 +3,7 @@ import { T_IO_PROPS, tableColumn, tableRow, - newInternalTableRow, + internalTableRow, T_IO_RETURNS, serializableRecord, menuItem, @@ -56,7 +56,7 @@ export function selectTable(logger: Logger) { props: { ...props, data, columns }, getValue(response: T_IO_RETURNS<'SELECT_TABLE'>) { const indices = response.map(row => - Number((row as z.infer).key) + Number((row as z.infer).key) ) const rows = props.data.filter((_, idx) => indices.includes(idx)) diff --git a/src/ioSchema.ts b/src/ioSchema.ts index fd9393f..49d44e1 100644 --- a/src/ioSchema.ts +++ b/src/ioSchema.ts @@ -164,14 +164,12 @@ export const menuItem = z.intersection( ]) ) -export const newInternalTableRow = z.object({ +export const internalTableRow = z.object({ key: z.string(), data: tableRow, menu: z.array(menuItem).optional(), }) -export const internalTableRow = z.union([newInternalTableRow, tableRow]) - export const tableColumn = z.object({ label: z.string(), renderCell: z