Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MaikoTan opened this issue Mar 25, 2024 · 2 comments
Open

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

MaikoTan opened this issue Mar 25, 2024 · 2 comments
Labels
bug BUG

Comments

@MaikoTan
Copy link
Member

MaikoTan commented Mar 25, 2024

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 MaikoTan added the bug BUG label Mar 25, 2024
@shigma
Copy link
Member

shigma commented Mar 25, 2024

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

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

@MaikoTan
Copy link
Member Author

MaikoTan commented Mar 26, 2024

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 MaikoTan changed the title Bug(Schema): Computed with Union Not Showing Options Correctly Bug(Schema): Computed with Union Not Showing Branches Correctly Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug BUG
Projects
None yet
Development

No branches or pull requests

2 participants