Skip to content

Commit

Permalink
Once again allow action prop in SDK, plan to deprecate soon
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobmischka committed Oct 27, 2022
1 parent d898ad7 commit 5879518
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/classes/IntervalClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
ActionResultSchema,
IOFunctionReturnType,
IO_RESPONSE,
LinkProps,
LegacyLinkProps,
T_IO_RENDER_INPUT,
T_IO_RESPONSE,
} from '../ioSchema'
Expand Down Expand Up @@ -1041,7 +1041,7 @@ export default class IntervalClient {
})
},
}),
redirect: (props: LinkProps) =>
redirect: (props: LegacyLinkProps) =>
this.#sendRedirect(transactionId, props),
}

Expand Down Expand Up @@ -1301,7 +1301,7 @@ export default class IntervalClient {
})
}

async #sendRedirect(transactionId: string, props: LinkProps) {
async #sendRedirect(transactionId: string, props: LegacyLinkProps) {
const response = await this.#send('SEND_REDIRECT', {
transactionId,
...props,
Expand Down
6 changes: 6 additions & 0 deletions src/components/displayLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export default function displayLink(
route: string
params?: SerializableRecord
}
// deprecated in favor of `route`
// TODO: Add TS deprecated flag soon
| {
action: string
params?: SerializableRecord
}
)
) {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const hello_app = new Page({
rowMenuItems: () => [
{
label: 'Hello',
route: 'hello_app/hello_world',
action: 'hello_app/hello_world',
},
],
}),
Expand Down
10 changes: 2 additions & 8 deletions src/internalRpcSchema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { z } from 'zod'
import {
deserializableRecord,
legacyLinkSchema,
linkSchema,
serializableRecord,
} from './ioSchema'
Expand Down Expand Up @@ -257,14 +258,7 @@ export const wsServerSchema = {
z.object({
transactionId: z.string(),
}),
z.union([
linkSchema,
// deprecated in favor of `route` from linkSchema
z.object({
action: z.string(),
params: serializableRecord.optional(),
}),
])
legacyLinkSchema
),
returns: z.boolean(),
},
Expand Down
18 changes: 12 additions & 6 deletions src/ioSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,17 @@ export const linkSchema = z.union([

export type LinkProps = z.infer<typeof linkSchema>

// TODO: Remove soon
export const legacyLinkSchema = z.union([
linkSchema,
z.object({
action: z.string(),
params: serializableRecord.optional(),
}),
])

export type LegacyLinkProps = z.infer<typeof legacyLinkSchema>

export const internalTableRow = z.object({
key: z.string(),
data: tableRow,
Expand Down Expand Up @@ -397,12 +408,7 @@ const DISPLAY_SCHEMA = {
z.object({
href: z.string(),
}),
// deprecated in favor of `route` in linkSchema
z.object({
action: z.string(),
params: serializableRecord.optional(),
}),
linkSchema,
legacyLinkSchema,
])
),
state: z.null(),
Expand Down
16 changes: 15 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
serializableRecord,
ImageSize,
SerializableRecord,
LegacyLinkProps,
} from './ioSchema'
import type { HostSchema } from './internalRpcSchema'
import type { IOClient, IOClientRenderValidator } from './classes/IOClient'
Expand Down Expand Up @@ -218,7 +219,7 @@ export type ActionLogFn = (...args: any[]) => Promise<void>

export type NotifyFn = (config: NotifyConfig) => Promise<void>

export type RedirectFn = (props: LinkProps) => Promise<void>
export type RedirectFn = (props: LegacyLinkProps) => Promise<void>

export type ResponseHandlerFn = (fn: T_IO_RESPONSE) => void

Expand Down Expand Up @@ -304,6 +305,13 @@ export type MenuItem = {
params?: SerializableRecord
disabled?: boolean
}
// Deprecated in favor of `route`
// TODO: Add TS deprecation soon
| {
action: string
params?: SerializableRecord
disabled?: boolean
}
| {
url: string
disabled?: boolean
Expand All @@ -317,6 +325,9 @@ export type ButtonItem = {
theme?: 'primary' | 'secondary' | 'danger'
} & (
| { route: string; params?: SerializableRecord; disabled?: boolean }
// Deprecated in favor of `route`
// TODO: Add TS deprecation soon
| { action: string; params?: SerializableRecord; disabled?: boolean }
| { url: string; disabled?: boolean }
| { disabled: true }
)
Expand Down Expand Up @@ -344,6 +355,9 @@ export type TableColumnResult =
} & ({ url: string } | { buffer: Buffer })
url?: string
route?: string
// Deprecated in favor of `route`
// TODO: Add TS deprecation soon
action?: string
params?: z.infer<typeof serializableRecord>
}
| TableCellValue
Expand Down

0 comments on commit 5879518

Please sign in to comment.