Skip to content

Commit

Permalink
Merge branch 'main' into custom-upload-url
Browse files Browse the repository at this point in the history
  • Loading branch information
danphilibin authored Jul 29, 2022
2 parents 2969330 + fc6f820 commit d4340c8
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/classes/IOClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ export class IOClient {
number: this.createIOMethod('INPUT_NUMBER'),
email: this.createIOMethod('INPUT_EMAIL'),
richText: this.createIOMethod('INPUT_RICH_TEXT'),
date: this.createIOMethod('INPUT_DATE', { componentDef: date }),
time: this.createIOMethod('INPUT_TIME'),
datetime: this.createIOMethod('INPUT_DATETIME', {
componentDef: datetime,
}),
},
select: {
single: this.createIOMethod('SELECT_SINGLE', {
Expand Down Expand Up @@ -449,11 +454,6 @@ export class IOClient {
propsRequired: true,
componentDef: spreadsheet,
}),
date: this.createIOMethod('INPUT_DATE', { componentDef: date }),
time: this.createIOMethod('INPUT_TIME'),
datetime: this.createIOMethod('INPUT_DATETIME', {
componentDef: datetime,
}),
input: {
file: this.createIOMethod('UPLOAD_FILE', {
componentDef: file(this.logger),
Expand Down
4 changes: 0 additions & 4 deletions src/classes/IOComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,6 @@ export default class IOComponent<MethodName extends T_IO_METHOD_NAMES> {
return this.instance
}

setOptional(optional: boolean) {
this.instance.isOptional = optional
}

get label() {
return this.instance.label
}
Expand Down
3 changes: 3 additions & 0 deletions src/components/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ export default function search<Result = any>({
onSearch,
initialResults = [],
renderResult,
disabled = false,
...rest
}: {
placeholder?: string
helpText?: string
disabled?: boolean
initialResults?: Result[]
renderResult: (result: Result) => RenderResultDef
onSearch: (query: string) => Promise<Result[]>
Expand Down Expand Up @@ -58,6 +60,7 @@ export default function search<Result = any>({
const props: T_IO_PROPS<'SEARCH'> = {
...rest,
results: renderResults(initialResults),
disabled,
}

return {
Expand Down
70 changes: 67 additions & 3 deletions src/examples/basic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,70 @@ const interval = new Interval({
logLevel: 'debug',
endpoint: 'ws://localhost:3000/websocket',
actions: {
disabled_inputs: async io => {
await io.group([
io.display.heading('Here are a bunch of disabled inputs'),
io.input.text('Text input', {
disabled: true,
placeholder: 'Text goes here',
}),
io.experimental.datetime('Date & time', { disabled: true }),
io.input.boolean('Boolean input', { disabled: true }),
io.select.single('Select something', {
options: [1, 2, 3],
disabled: true,
}),
io.input.number('Number input', {
disabled: true,
}),
io.input.email('Email input', { disabled: true }),
io.input.richText('Rich text input', { disabled: true }),
io.search('Search for a user', {
disabled: true,
renderResult: user => ({
label: user.name,
description: user.email,
}),
onSearch: async query => {
return [
{
name: 'John Doe',
email: '[email protected]',
},
]
},
}),
io.select.multiple('Select multiple of something', {
options: [1, 2, 3],
disabled: true,
}),
io.select.table('Select from table', {
data: [
{
album: 'Exile on Main Street',
artist: 'The Rolling Stones',
year: 1972,
},
{
artist: 'Michael Jackson',
album: 'Thriller',
year: 1982,
},
{
album: 'Enter the Wu-Tang (36 Chambers)',
artist: 'Wu-Tang Clan',
year: 1993,
},
],
disabled: true,
}),
io.experimental.date('Date input', { disabled: true }),
io.experimental.time('Time input', { disabled: true }),
io.experimental.input.file('File input', { disabled: true }),
])

return 'Done!'
},
'long-return-string': async io => {
return {
date: new Date(),
Expand Down Expand Up @@ -313,7 +377,7 @@ const interval = new Interval({
},
dates: async io => {
const [date, time, datetime] = await io.group([
io.experimental.date('Enter a date', {
io.input.date('Enter a date', {
min: {
year: 2020,
month: 1,
Expand All @@ -325,7 +389,7 @@ const interval = new Interval({
day: 30,
},
}),
io.experimental.time('Enter a time', {
io.input.time('Enter a time', {
min: {
hour: 8,
minute: 30,
Expand All @@ -335,7 +399,7 @@ const interval = new Interval({
minute: 0,
},
}),
io.experimental.datetime('Enter a datetime', {
io.input.datetime('Enter a datetime', {
defaultValue: new Date(),
min: new Date(),
}),
Expand Down
13 changes: 13 additions & 0 deletions src/ioSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export const ioSchema = {
lines: z.optional(z.number()),
minLength: z.optional(z.number().int().positive()),
maxLength: z.optional(z.number().int().positive()),
disabled: z.optional(z.boolean().default(false)),
}),
state: z.null(),
returns: z.string(),
Expand All @@ -259,6 +260,7 @@ export const ioSchema = {
helpText: z.optional(z.string()),
placeholder: z.optional(z.string()),
defaultValue: z.optional(z.string()),
disabled: z.optional(z.boolean().default(false)),
}),
state: z.null(),
returns: z.string(),
Expand All @@ -273,6 +275,7 @@ export const ioSchema = {
defaultValue: z.optional(z.number()),
decimals: z.optional(z.number().positive().int()),
currency: z.optional(currencyCode),
disabled: z.optional(z.boolean().default(false)),
}),
state: z.null(),
returns: z.number(),
Expand All @@ -281,6 +284,7 @@ export const ioSchema = {
props: z.object({
helpText: z.optional(z.string()),
defaultValue: z.boolean().default(false),
disabled: z.optional(z.boolean().default(false)),
}),
state: z.null(),
returns: z.boolean(),
Expand All @@ -290,6 +294,7 @@ export const ioSchema = {
helpText: z.optional(z.string()),
placeholder: z.optional(z.string()),
defaultValue: z.optional(z.string()),
disabled: z.optional(z.boolean().default(false)),
}),
state: z.null(),
returns: z.string(),
Expand All @@ -300,6 +305,7 @@ export const ioSchema = {
defaultValue: z.optional(dateObject),
min: z.optional(dateObject),
max: z.optional(dateObject),
disabled: z.optional(z.boolean().default(false)),
}),
state: z.null(),
returns: dateObject,
Expand All @@ -310,6 +316,7 @@ export const ioSchema = {
defaultValue: z.optional(timeObject),
min: z.optional(timeObject),
max: z.optional(timeObject),
disabled: z.optional(z.boolean().default(false)),
}),
state: z.null(),
returns: timeObject,
Expand All @@ -320,6 +327,7 @@ export const ioSchema = {
defaultValue: z.optional(dateTimeObject),
min: z.optional(dateTimeObject),
max: z.optional(dateTimeObject),
disabled: z.optional(z.boolean().default(false)),
}),
state: z.null(),
returns: dateTimeObject,
Expand All @@ -339,6 +347,7 @@ export const ioSchema = {
allowedExtensions: z.array(z.string()).optional(),
uploadUrl: z.string().nullish().optional(),
downloadUrl: z.string().nullish().optional(),
disabled: z.optional(z.boolean().default(false)),
}),
state: z.object({
name: z.string(),
Expand All @@ -364,6 +373,7 @@ export const ioSchema = {
),
placeholder: z.optional(z.string()),
helpText: z.optional(z.string()),
disabled: z.optional(z.boolean().default(false)),
}),
state: z.object({ queryTerm: z.string() }),
returns: z.string(),
Expand All @@ -383,6 +393,7 @@ export const ioSchema = {
data: z.array(internalTableRow),
minSelections: z.optional(z.number().int().min(0)),
maxSelections: z.optional(z.number().positive().int()),
disabled: z.optional(z.boolean().default(false)),
}),
state: z.null(),
returns: z.array(internalTableRow),
Expand All @@ -393,6 +404,7 @@ export const ioSchema = {
helpText: z.optional(z.string()),
defaultValue: z.optional(richSelectOption),
searchable: z.optional(z.boolean()),
disabled: z.optional(z.boolean().default(false)),
}),
state: z.object({ queryTerm: z.string() }),
returns: richSelectOption,
Expand All @@ -406,6 +418,7 @@ export const ioSchema = {
.default([] as z.infer<typeof labelValue>[]),
minSelections: z.optional(z.number().int().min(0)),
maxSelections: z.optional(z.number().positive().int()),
disabled: z.optional(z.boolean().default(false)),
}),
state: z.null(),
returns: z.array(labelValue),
Expand Down

0 comments on commit d4340c8

Please sign in to comment.