koishi icon indicating copy to clipboard operation
koishi copied to clipboard

Bug(Schema): Computed with Union Not Showing Branches Correctly

Open MaikoTan opened this issue 10 months ago • 2 comments

Describe the bug

Computed schema with union schema behaves weird currently.

Also some are not visible in production mode.

  • union()
  • computed(number()) ❌ branches ✅ save config
  • computed(union()) ✅ resolve options ❌ branches ✅ save config
  • computed(union([const(), const()]) ✅ resolve options ❌ branches ✅ save config
  • computed(union([const(), const(), object()]) ✅ resolve options ❌ branches ✅ save config
  • computed(union()).role('radio') ✅ resolve options ❌ branches ✅ save config
  • computed(union([const(), const()]).role('radio') ✅ resolve options ❌ branches ✅ save config

Steps to reproduce

export interface Config {
  testNormal: 'one' | 'two'
  testComputedNumber: Computed<number>
  testComputed: Computed<'one' | 'two'>
  testComputedUnionConst: Computed<'one' | 'two'>
  testComputedUnionConstWithCustom: Computed<'one' | 'two' | { value: number }>
  testComputedRadio: Computed<'one' | 'two'>
  testComputedUnionConstRadio: Computed<'one' | 'two'>
}

export const Config: Schema<Config> = Schema.object({
  testNormal: Schema.union(['one', 'two']).default('one'),
  testComputedNumber: Schema.computed(Schema.number()).default(1),
  testComputed: Schema.computed(Schema.union(['one', 'two'])).default('one'),
  testComputedUnionConst: Schema.computed(Schema.union([Schema.const('one'), Schema.const('two')])).default('one'),
  testComputedUnionConstWithCustom: Schema.computed(
    Schema.union([Schema.const('one'), Schema.const('two'), Schema.object({ value: Schema.number() })]),
  ).default('one'),
  testComputedRadio: Schema.computed(Schema.union(['one', 'two']).role('radio')).default('one'),
  testComputedUnionConstRadio: Schema.computed(
    Schema.union([Schema.const('one'), Schema.const('two')]).role('radio'),
  ).default('one'),
})

Or see this repo instead

Expected behaviour

Able to resolve options and save config correctly.

Screenshots

Dev Mode

image

Prod Mode

image

Versions

  • OS: Arch Linux 6.8.1-arch1-1
  • Platform: Sandbox
  • Node version: v21.7.1
  • Koishi version: v4.17.2

Additional context

No response

MaikoTan avatar Mar 25 '24 03:03 MaikoTan

computed(union()).role('radio')

It should be computed(union().role('radio')). Actually computed itself is a role.

shigma avatar Mar 25 '24 19:03 shigma

computed(union()).role('radio')

It should be computed(union().role('radio')). Actually computed itself is a role.

Okay I have updated the examples and:

  • .default(value) on .computed() is not correctly shown on the configuration page
  • All computed schemata are not allowing to select branches (not very sure, but I didn't see any relating buttons)

image

MaikoTan avatar Mar 26 '24 03:03 MaikoTan