Skip to content

Commit

Permalink
add schema enums (#1013)
Browse files Browse the repository at this point in the history
  • Loading branch information
sceuick authored Aug 21, 2024
1 parent 34fc2a0 commit 914dc62
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
22 changes: 18 additions & 4 deletions web/shared/JsonSchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ export const JsonSchema: Component<{
return { name: value, disabled: f.disabled, type: f.type }
}
if (field === 'disabled') return { name: f.name, disabled: !value, type: f.type }
if (field === 'enum') {
return {
name: f.name,
disabled: f.disabled,
type: {
...f.type,
enum: (value || '')
.split(',')
.map((t: string) => t.trim())
.filter((v: string) => !!v),
},
}
}

return {
name: f.name,
Expand Down Expand Up @@ -147,6 +160,7 @@ const SchemaField: Component<{
{ label: 'Boolean', value: 'bool' },
{ label: 'String', value: 'string' },
{ label: 'Number', value: 'integer' },
{ label: 'Enum', value: 'enum' },
]}
fieldName={`${props.index}.type`}
value={props.def.type}
Expand Down Expand Up @@ -223,7 +237,7 @@ const SchemaField: Component<{

<div
class="flex w-full gap-2"
classList={{ hidden: !props.def.valid && type() !== 'string' }}
classList={{ hidden: !props.def.valid && type() !== 'string' && type() !== 'enum' }}
>
<Show when={type() === 'string'}>
<TextInput
Expand All @@ -233,12 +247,12 @@ const SchemaField: Component<{
value={(props.def as any).maxLength}
/>
</Show>
<Show when={props.validate && type() === 'enum'}>
<Show when={type() === 'enum'}>
<TextInput
fieldName={`${props.index}.valid`}
fieldName={`${props.index}.enum`}
placeholder="(Optional) Allowed values - comma seperated"
parentClass="w-1/2"
value={props.def.valid}
value={(props.def as any).enum?.join(', ')}
/>
</Show>
<Show when={props.validate && type() === 'bool'}>
Expand Down
13 changes: 11 additions & 2 deletions web/shared/Slot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { getPagePlatform, getWidthPlatform, useEffect, useResizeObserver } from
import { getUserSubscriptionTier, wait } from '/common/util'
import { createDebounce } from './util'

const win: any = window

window.googletag = window.googletag || { cmd: [] }
window.ezstandalone = window.ezstandalone || { cmd: [] }
window.fusetag = window.fusetag || { que: [] }
Expand Down Expand Up @@ -99,7 +101,13 @@ const Slot: Component<{

const tier = createMemo(() => {
if (!user.user) return
return getUserSubscriptionTier(user.user, user.tiers)
const subtier = getUserSubscriptionTier(user.user, user.tiers)

if (subtier?.tier.disableSlots) {
win.enableSticky = undefined
}

return subtier
})

const id = createMemo(() => {
Expand Down Expand Up @@ -525,7 +533,6 @@ function toPixels(size: string) {
return {}
}

const win: any = window
win.getSlotById = getSlotById

export function getSlotById(id: string) {
Expand Down Expand Up @@ -704,6 +711,8 @@ const [invokeFuse] = createDebounce(() => {
if (!status) return
const ids = Array.from(FuseIds.values())
console.log(`[fuse] init ${ids}`)
const win: any = window
win.enableSticky = true
window.fusetag.que.push(() => {
window.fusetag.pageInit({ blockingFuseIds: ids })
})
Expand Down

0 comments on commit 914dc62

Please sign in to comment.