From 186b7c1372584216a386d64c201e7ddaca87e3e6 Mon Sep 17 00:00:00 2001 From: Jacob Mischka Date: Tue, 12 Jul 2022 10:00:19 -0500 Subject: [PATCH 1/3] Enforce io.select defaultValue being in provided options If not the case, log a warning in the console and discard the provided value (if `select.multiple`, discard the entire `defaultValue` array instead of filtering). To unify the `defaultValue` logic on our frontend, only use it when determining the initial results array in TransactionUI, and use the resulting `props.value` in each IO component's component. Closes #669 --- src/classes/IOClient.ts | 12 ++++- src/components/selectMultiple.ts | 78 ++++++++++++++++++-------------- src/components/selectSingle.ts | 76 +++++++++++++++++-------------- src/examples/basic/index.ts | 14 ++++++ src/ioSchema.ts | 4 ++ 5 files changed, 115 insertions(+), 69 deletions(-) diff --git a/src/classes/IOClient.ts b/src/classes/IOClient.ts index a8848b8..aa85057 100644 --- a/src/classes/IOClient.ts +++ b/src/classes/IOClient.ts @@ -338,8 +338,16 @@ export class IOClient { richText: this.createIOMethod('INPUT_RICH_TEXT'), }, select: { - single: this.createIOMethod('SELECT_SINGLE', true, selectSingle), - multiple: this.createIOMethod('SELECT_MULTIPLE', true, selectMultiple), + single: this.createIOMethod( + 'SELECT_SINGLE', + true, + selectSingle(this.logger) + ), + multiple: this.createIOMethod( + 'SELECT_MULTIPLE', + true, + selectMultiple(this.logger) + ), table: this.createIOMethod( 'SELECT_TABLE', true, diff --git a/src/components/selectMultiple.ts b/src/components/selectMultiple.ts index abd82a2..794be70 100644 --- a/src/components/selectMultiple.ts +++ b/src/components/selectMultiple.ts @@ -1,5 +1,6 @@ import { z } from 'zod' import { T_IO_PROPS, T_IO_RETURNS, labelValue } from '../ioSchema' +import Logger from '../classes/Logger' type SelectMultipleProps