Skip to content

Commit 4d629ea

Browse files
committed
[playground] Add OneOfDefaults sample
1 parent 3b025ef commit 4d629ea

File tree

3 files changed

+225
-0
lines changed

3 files changed

+225
-0
lines changed

.changeset/good-ties-play.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"playground": patch
3+
---
4+
5+
Add `OneOfDefaults` sample

apps/playground/src/samples/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import errorSchema from "./errorSchema";
2727
import defaults from "./defaults";
2828
import options from "./options";
2929
import ifThenElse from "./ifThenElse";
30+
import oneOfDefaults from './one-of-defaults'
3031
import type { Sample } from "./Sample";
3132

3233
const blank: Sample = { status: "perfect", schema: {}, uiSchema: {}, formData: {} };
@@ -62,4 +63,5 @@ export const samples = Object.freeze({
6263
Nullable: nullable,
6364
ErrorSchema: errorSchema,
6465
Defaults: defaults,
66+
OneOfDefaults: oneOfDefaults,
6567
} satisfies Record<string, Sample>);
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
import type { Schema, UiSchemaRoot } from "@sjsf/form";
2+
import type { Sample } from "./Sample";
3+
4+
enum TransformPreset {
5+
Default = "Default",
6+
Manual = "Manual",
7+
}
8+
9+
enum OutputFormat {
10+
HTML = "HTML",
11+
XLSX = "XLSX",
12+
ASCII = "ASCII",
13+
}
14+
15+
enum ASCIITableFormat {
16+
MySQL = "MySql",
17+
MarkdownLike = "Markdown Like",
18+
}
19+
20+
const schema: Schema = {
21+
type: "object",
22+
title: "Options",
23+
properties: {
24+
preset: {
25+
title: "Preset",
26+
type: "string",
27+
enum: Object.values(TransformPreset),
28+
default: TransformPreset.Default,
29+
},
30+
transform: {
31+
title: "Transform",
32+
description: "Apply a transformation to the output data",
33+
type: "boolean",
34+
default: false,
35+
},
36+
format: {
37+
title: "Output format",
38+
type: "string",
39+
enum: Object.values(OutputFormat),
40+
default: OutputFormat.HTML,
41+
},
42+
paginate: {
43+
title: "Paginate",
44+
description:
45+
"Partitioning the input data (object or array) into pages by their keys",
46+
type: "boolean",
47+
default: false,
48+
},
49+
createOnOpen: {
50+
type: "boolean",
51+
title: "Create on open",
52+
description: "Creating a table when opening a share link",
53+
default: true,
54+
},
55+
},
56+
required: ["preset", "format"],
57+
dependencies: {
58+
preset: {
59+
oneOf: [
60+
{
61+
properties: {
62+
preset: {
63+
const: TransformPreset.Default,
64+
},
65+
},
66+
},
67+
{
68+
properties: {
69+
preset: {
70+
const: TransformPreset.Manual,
71+
},
72+
collapseIndexes: {
73+
title: "Combine nested indexes",
74+
description:
75+
"Combines hierarchical indexes into one cell (1.1, 1.2, ...)",
76+
type: "boolean",
77+
default: true,
78+
},
79+
joinPrimitiveArrayValues: {
80+
title: "Combine simple values",
81+
description:
82+
"Combines the values of an array of primitives into one cell (separated by ',')",
83+
type: "boolean",
84+
default: true,
85+
},
86+
combineArraysOfObjects: {
87+
title: "Combine objects",
88+
description: "Combine arrays of objects into a single object",
89+
type: "boolean",
90+
default: false,
91+
},
92+
stabilizeOrderOfPropertiesInArraysOfObjects: {
93+
title: "Stabilize order of properties",
94+
description:
95+
"Stabilizing the order in which properties are displayed for arrays of objects",
96+
type: "boolean",
97+
default: true,
98+
},
99+
proportionalSizeAdjustmentThreshold: {
100+
title: "Proportional size adjustment threshold",
101+
description:
102+
"Specifies the threshold to which the value (height, width) can be increased for a proportional increase. The default is 1 (by 100%).",
103+
type: "number",
104+
minimum: 0,
105+
default: 1,
106+
},
107+
cornerCellValue: {
108+
title: "Corner cell value",
109+
description: "The value of the corner cell.",
110+
type: "string",
111+
default: "№",
112+
},
113+
},
114+
required: ["proportionalSizeAdjustmentThreshold"],
115+
},
116+
],
117+
},
118+
transform: {
119+
oneOf: [
120+
{
121+
properties: {
122+
transform: {
123+
const: false,
124+
},
125+
},
126+
},
127+
{
128+
properties: {
129+
transform: {
130+
const: true,
131+
},
132+
horizontalReflect: {
133+
type: "boolean",
134+
title: "Reflect horizontally",
135+
default: false,
136+
},
137+
verticalReflect: {
138+
type: "boolean",
139+
title: "Reflect vertically",
140+
default: false,
141+
},
142+
transpose: {
143+
type: "boolean",
144+
title: "Transpose",
145+
default: false,
146+
},
147+
},
148+
},
149+
],
150+
},
151+
format: {
152+
oneOf: [
153+
{
154+
properties: {
155+
format: {
156+
const: OutputFormat.HTML,
157+
},
158+
},
159+
},
160+
{
161+
properties: {
162+
format: {
163+
const: OutputFormat.XLSX,
164+
},
165+
},
166+
},
167+
{
168+
properties: {
169+
format: {
170+
const: OutputFormat.ASCII,
171+
},
172+
asciiFormat: {
173+
type: "string",
174+
title: "ASCII table format",
175+
enum: Object.values(ASCIITableFormat),
176+
default: ASCIITableFormat.MySQL,
177+
},
178+
},
179+
},
180+
],
181+
},
182+
},
183+
};
184+
185+
const uiSchema: UiSchemaRoot = {
186+
"ui:options": {
187+
order: [
188+
"preset",
189+
"collapseIndexes",
190+
"joinPrimitiveArrayValues",
191+
"combineArraysOfObjects",
192+
"stabilizeOrderOfPropertiesInArraysOfObjects",
193+
"proportionalSizeAdjustmentThreshold",
194+
"cornerCellValue",
195+
"transform",
196+
"horizontalReflect",
197+
"verticalReflect",
198+
"transpose",
199+
"format",
200+
"asciiFormat",
201+
"paginate",
202+
"createOnOpen",
203+
],
204+
},
205+
};
206+
207+
export default {
208+
status: "broken",
209+
schema,
210+
uiSchema,
211+
formData: {
212+
preset: TransformPreset.Default,
213+
transform: false,
214+
format: OutputFormat.HTML,
215+
paginate: false,
216+
createOnOpen: true,
217+
},
218+
} satisfies Sample;

0 commit comments

Comments
 (0)