@genesislcap/foundation-forms 14.25.0 → 14.25.1-alpha-3c26bb7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +665 -16
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -1,15 +1,38 @@
1
- # Genesis Foundation Forms
1
+ # Foundation Forms
2
2
 
3
3
  [![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org/)
4
4
  [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](https://www.typescriptlang.org/)
5
5
 
6
- `foundation-forms` is a library for efficiently building complex forms at scale
7
-
8
6
  ### [API Docs](./docs/api/index.md)
9
7
 
10
- ## General usage
8
+ `foundation-forms` is a library for efficiently building complex forms and filters at scale.
9
+
10
+ Foundation forms is defined by using two schemata:
11
+
12
+ - `resourceName`/`jsonSchema` defines the underlying data to be shown in the UI (objects, properties, and their types).
13
+ - `uiSchema` defines how this data is rendered as a form, e.g. the order of controls, their visibility, and the layout.
14
+
15
+ ## Forms
16
+
17
+ ### Basic install
18
+
19
+ To enable this module in your application, follow the steps below.
20
+
21
+ 1. Add `@genesislcap/foundation-forms` as a dependency in your **package.json** file. Whenever you change the dependencies of your project, ensure you run the `$ npm run bootstrap` command again. You can find more information in the [package.json basics](../../../web/basics/package-json-basics/) page.
22
+
23
+ ```javascript
24
+ {
25
+ ...
26
+ "dependencies": {
27
+ "@genesislcap/foundation-forms": "latest"
28
+ },
29
+ ...
30
+ }
31
+ ```
11
32
 
12
- 1. *Register components*
33
+ ### General usage
34
+
35
+ #### 1. Register components
13
36
 
14
37
  ```ts
15
38
  import { Form } from '@genesislcap/foundation-forms';
@@ -18,39 +41,665 @@ Form
18
41
  ...
19
42
  ```
20
43
 
21
- 2. *Add component to the template*
44
+ #### 2. Add component to the template
45
+
22
46
  ```html
23
47
  <foundation-form resourceName="EVENT_TRADE_INSERT"></foundation-form>
24
48
  ```
25
49
 
26
- This should generate working form based on the JSON schema for that endpoint.
27
- DevTools console will output autogenerated UI schema that you can use to configure the form
50
+ This should generate working form based on the `JSON schema` for that endpoint.
51
+ DevTools console will output autogenerated `UI schema` that you can use to configure the form
52
+
53
+ #### 3. Configure form using UI schema
28
54
 
29
- 3. *Configure form using UI schema*
30
55
  ```ts
31
56
  const sampleUISchema = {
57
+ type: "VerticalLayout",
58
+ elements: [
59
+ {
60
+ type: "Control",
61
+ scope: "#/properties/QUANTITY",
62
+ label: "Quantity",
63
+ },
64
+ {
65
+ type: "Control",
66
+ scope: "#/properties/SIDE",
67
+ label: "Side",
68
+ },
69
+ ],
70
+ };
71
+ ```
72
+
73
+ ```html
74
+ <foundation-form resourceName="EVENT_TRADE_INSERT" :uischema=${() => sampleUISchema}></foundation-form>
75
+ ```
76
+
77
+ #### 4. Configure form using JSON schema (optional)
78
+
79
+ Alternatively to providing `resourceName` you can hardcode the `JSON schema` on the client.
80
+
81
+ ```ts
82
+ const sampleJsonSchema = {
83
+ type: 'object',
84
+ properties: {
85
+ ISSUER_NAME: {
86
+ type: 'string',
87
+ minLength: 3,
88
+ description: 'kotlin.String',
89
+ },
90
+ PRICE: {
91
+ type: 'number',
92
+ description: 'kotlin.Double',
93
+ },
94
+ MAIN_CONTACT: {
95
+ type: 'string',
96
+ pattern: '^[\\+]?[(]?[0-9]{3}[)]?[-\\s\\.]?[0-9]{3}[-\\s\\.]?[0-9]{4,6}$',
97
+ description: 'kotlin.String',
98
+ },
99
+ PASSWORD: {
100
+ type: 'string',
101
+ description: 'kotlin.String',
102
+ },
103
+ },
104
+ additionalProperties: false,
105
+ required: ['ISSUER_NAME', 'MAIN_CONTACT'],
106
+ };
107
+ ```
108
+
109
+ ```ts
110
+ const sampleUiSchema = {
32
111
  type: 'VerticalLayout',
33
112
  elements: [
34
113
  {
35
114
  type: 'Control',
36
- scope: '#/properties/QUANTITY',
37
- label: 'Quantity',
115
+ label: 'Issuer Name',
116
+ scope: '#/properties/ISSUER_NAME',
117
+ },
118
+ {
119
+ type: 'Control',
120
+ label: 'Phone',
121
+ scope: '#/properties/MAIN_CONTACT',
122
+ },
123
+ {
124
+ type: 'Control',
125
+ label: 'Price',
126
+ scope: '#/properties/PRICE',
127
+ },
128
+ {
129
+ type: 'Control',
130
+ scope: '#/properties/COUNTERPARTY',
131
+ options: {
132
+ allOptionsResourceName: 'COUNTERPARTY',
133
+ valueField: 'COUNTERPARTY_ID',
134
+ labelField: 'COUNTERPARTY_ID',
135
+ datasourceConfig: {
136
+ request: {
137
+ COUNTERPARTY_ID: 'ACME',
138
+ },
139
+ },
140
+ },
38
141
  },
39
142
  {
40
143
  type: 'Control',
41
- scope: '#/properties/SIDE',
42
- label: 'Side',
144
+ label: 'Password',
145
+ scope: '#/properties/PASSWORD',
146
+ options: {
147
+ isPassword: true,
148
+ },
43
149
  },
44
150
  ],
45
151
  };
152
+ ```
153
+
154
+ ```html
155
+ <foundation-form :jsonSchema=${() => sampleJsonSchema} :uischema=${() => sampleUISchema}></foundation-form>
156
+ ```
157
+
158
+ :::info
159
+ Use this when you want to avoid fetching metadata from the server but be aware that it could get out of sync if metadata changes on the server.
160
+ :::
161
+
162
+ #### 5. Pre-fill forms with data (optional)
163
+
164
+ Use the `data` attribute, which allows you to pre-fill the form with ready-made information.
46
165
 
166
+ ```ts
167
+ const sampleData = {
168
+ ISSUER_NAME: 'Some Issuer',
169
+ INVIS: 'Invisible value!',
170
+ USER: 'JohnDoe',
171
+ };
47
172
  ```
173
+
48
174
  ```html
49
- <foundation-form resourceName="EVENT_TRADE_INSERT" :uischema=${() => sampleUISchema}></foundation-form>
175
+ <foundation-form resourceName="EVENT_TRADE_INSERT" :uischema=${() => sampleUISchema} :data=${() => sampleData}></foundation-form>
176
+ ```
177
+
178
+ ## Filters
179
+
180
+ ### Basic install
181
+
182
+ To enable this module in your application, follow the steps below.
183
+
184
+ 1. Add `@genesislcap/foundation-forms` as a dependency in your **package.json** file. Whenever you change the dependencies of your project, ensure you run the `$ npm run bootstrap` command again. You can find more information in the [package.json basics](../../../web/basics/package-json-basics/) page.
185
+
186
+ ```javascript
187
+ {
188
+ ...
189
+ "dependencies": {
190
+ "@genesislcap/foundation-forms": "latest"
191
+ },
192
+ ...
193
+ }
194
+ ```
195
+
196
+ ### General usage
197
+
198
+ #### 1. Register components
199
+
200
+ ```ts
201
+ import { Filters } from '@genesislcap/foundation-forms';
202
+ ...
203
+ Filters
204
+ ...
50
205
  ```
51
-
52
206
 
207
+ #### 2. Add component to the template
208
+
209
+ ```html
210
+ <foundation-filters resourceName="ALL_TRADES"></foundation-filters>
211
+ ```
212
+
213
+ This should generate working form based on the `JSON schema` for that endpoint.
214
+ DevTools console will output autogenerated `UI schema` that you can use to configure the filters
215
+
216
+ #### 3. Configure form using UI schema
217
+
218
+ ```ts
219
+ const sampleUISchema = {
220
+ type: "VerticalLayout",
221
+ elements: [
222
+ {
223
+ type: "Control",
224
+ scope: "#/properties/QUANTITY",
225
+ label: "Quantity",
226
+ },
227
+ {
228
+ type: "Control",
229
+ scope: "#/properties/SIDE",
230
+ label: "Side",
231
+ },
232
+ ],
233
+ };
234
+ ```
235
+
236
+ ```html
237
+ <foundation-filters resourceName="ALL_TRADES" :uischema=${() => sampleUISchema}></foundation-filters>
238
+ ```
239
+
240
+ #### 4. Configure form using JSON schema (optional)
241
+
242
+ Alternatively to providing `resourceName` you can hardcode the `JSON schema` on the client.
243
+
244
+ ```ts
245
+ const sampleJsonSchema = {
246
+ type: 'object',
247
+ properties: {
248
+ INSTRUMENT_ID: {
249
+ type: 'string',
250
+ minLength: 3,
251
+ description: 'kotlin.String',
252
+ },
253
+ QUANTITY: {
254
+ type: 'number',
255
+ description: 'kotlin.Double',
256
+ },
257
+ },
258
+ };
259
+ ```
260
+
261
+ ```ts
262
+ const sampleUiSchema = {
263
+ type: 'VerticalLayout',
264
+ elements: [
265
+ {
266
+ type: 'Control',
267
+ label: 'Instrument ID',
268
+ scope: '#/properties/INSTRUMENT_ID',
269
+ },
270
+ {
271
+ type: 'Control',
272
+ label: 'Quantity',
273
+ scope: '#/properties/QUANTITY',
274
+ },
275
+ ],
276
+ };
277
+ ```
278
+
279
+ ```html
280
+ <foundation-filters :jsonSchema=${() => sampleJsonSchema} :uischema=${() => sampleUISchema}></foundation-filters>
281
+ ```
282
+
283
+ :::info
284
+ Use this when you want to avoid fetching metadata from the server but be aware that it could get out of sync if metadata changes on the server.
285
+ :::
286
+
287
+ #### 5. An example of synchronizing values with datasource criteria
288
+
289
+ ```html
290
+ <zero-card>
291
+ <foundation-filters
292
+ resourceName="ALL_USERS"
293
+ :value=${sync((x) => x.allUsersfilters)}>
294
+ </foundation-filters>
295
+ </zero-card>
296
+ <zero-grid-pro>
297
+ <grid-pro-genesis-datasource
298
+ resource-name="ALL_USERS"
299
+ criteria=${(x) => x.allUsersfilters}
300
+ ></grid-pro-genesis-datasource>
301
+ </zero-grid-pro>
302
+ ```
303
+
304
+
305
+ ## Advanced customization
306
+
307
+ ### Default layout renderers and examples
308
+
309
+ #### 1. Vertical Layout
310
+
311
+ This is the default layout that is defined if no `uiSchema` is specified. Arranges our control elements vertically.
312
+
313
+ ```ts
314
+ const VerticalUISchema = {
315
+ type: 'VerticalLayout',
316
+ elements: [
317
+ ...
318
+ ],
319
+ };
320
+ ```
321
+
322
+ #### 2. Vertical Layout - Two columns
323
+
324
+ Arranges our control elements in 2 columns vertically
325
+
326
+ ```ts
327
+ const VerticalColumnsUISchema = {
328
+ type: 'LayoutVertical2Columns',
329
+ elements: [
330
+ ...
331
+ ],
332
+ };
333
+ ```
334
+
335
+ #### 3. Horizontal Layout
336
+
337
+ Arranges our control elements horizontally
338
+
339
+ ```ts
340
+ const horizontalUISchema = {
341
+ type: 'HorizontalLayout',
342
+ elements: [
343
+ ...
344
+ ],
345
+ };
346
+ ```
347
+
348
+ #### 4. Array Layout
349
+
350
+ Array Layout allows you to create a dynamic form with the ability to add, for example, multiple users.
351
+
352
+ It is more complicated when it comes to customization because it needs proper `jsonSchema` and `uiSchema`.
353
+
354
+ ```ts
355
+ const arrayUISchema = {
356
+ type: "VerticalLayout",
357
+ elements: [
358
+ {
359
+ type: "array",
360
+ scope: "#/properties/users",
361
+ options: {
362
+ childUiSchema: {
363
+ type: "HorizontalLayout",
364
+ elements: [
365
+ {
366
+ type: "Control",
367
+ scope: "#/properties/firstname",
368
+ label: "First Name",
369
+ },
370
+ {
371
+ type: "Control",
372
+ scope: "#/properties/lastname",
373
+ label: "Last Name",
374
+ },
375
+ {
376
+ type: "Control",
377
+ scope: "#/properties/email",
378
+ label: "Email",
379
+ },
380
+ ],
381
+ },
382
+ },
383
+ },
384
+ ],
385
+ };
386
+ ```
387
+
388
+ ```ts
389
+ const arrayJsonSchema = {
390
+ type: "object",
391
+ properties: {
392
+ users: {
393
+ type: "array",
394
+ items: {
395
+ type: "object",
396
+ title: "Users",
397
+ properties: {
398
+ firstname: {
399
+ type: "string",
400
+ },
401
+ lastname: {
402
+ type: "string",
403
+ },
404
+ email: {
405
+ type: "string",
406
+ format: "email",
407
+ },
408
+ },
409
+ },
410
+ },
411
+ },
412
+ };
413
+ ```
414
+
415
+ #### 5. Categorization Layout
416
+
417
+ Categorization layout allows you to create more complex forms that can be divided into appropriate categories, for example: personal information and address - which will be in separate tabs.
418
+
419
+ ```ts
420
+ const categoryUISchema = {
421
+ type: "Categorization",
422
+ elements: [
423
+ {
424
+ type: "Category",
425
+ scope: "#/properties/basic",
426
+ label: "Personal information",
427
+ options: {
428
+ childElements: [
429
+ {
430
+ type: "HorizontalLayout",
431
+ elements: [
432
+ {
433
+ type: "Control",
434
+ scope: "#/properties/firstName",
435
+ },
436
+ {
437
+ type: "Control",
438
+ scope: "#/properties/secondName",
439
+ },
440
+ ],
441
+ },
442
+ ],
443
+ },
444
+ },
445
+ {
446
+ type: "Category",
447
+ label: "Address",
448
+ scope: "#/properties/address",
449
+ options: {
450
+ childElements: [
451
+ {
452
+ type: "HorizontalLayout",
453
+ elements: [
454
+ {
455
+ type: "Control",
456
+ scope: "#/properties/address/properties/street",
457
+ },
458
+ {
459
+ type: "Control",
460
+ scope: "#/properties/address/properties/streetNumber",
461
+ },
462
+ ],
463
+ },
464
+ ],
465
+ },
466
+ },
467
+ ],
468
+ };
469
+ ```
470
+
471
+ #### 6. Group Layout
472
+
473
+ Group layout similarly to categorization layout divides forms, but this time into groups. They are visible on the same tab, but they are separated from each other by their own labels.
474
+
475
+ ```ts
476
+ const groupUISchema = {
477
+ type: "VerticalLayout",
478
+ elements: [
479
+ {
480
+ type: "Group",
481
+ label: "Person",
482
+ scope: "#/properties/person",
483
+ options: {
484
+ childElements: [
485
+ {
486
+ type: "LayoutVertical2Columns",
487
+ elements: [
488
+ {
489
+ type: "Control",
490
+ label: "First Name",
491
+ scope: "#/properties/person/properties/firstName",
492
+ },
493
+ {
494
+ type: "Control",
495
+ scope: "#/properties/person/properties/lastName",
496
+ },
497
+ ],
498
+ },
499
+ ],
500
+ },
501
+ },
502
+ {
503
+ type: "Group",
504
+ label: "Address",
505
+ scope: "#/properties/address/",
506
+ options: {
507
+ childElements: [
508
+ {
509
+ type: "VerticalLayout",
510
+ elements: [
511
+ {
512
+ type: "Control",
513
+ scope: "#/properties/person/properties/shippingAddress",
514
+ },
515
+ {
516
+ type: "Control",
517
+ scope: "#/properties/address/properties/street",
518
+ },
519
+ ],
520
+ },
521
+ ],
522
+ },
523
+ },
524
+ ],
525
+ };
526
+ ```
527
+
528
+ ### Default control renderers and examples
529
+
530
+ Most renderers are defined directly in the `jsonSchema` that comes from the server, but there are also those that we can add via `uiSchema`.
531
+
532
+ #### 1. String Renderer
533
+
534
+ The default renderer that will create a `text-field`.
535
+
536
+ ```ts
537
+ const stringJsonSchema = {
538
+ type: "object",
539
+ properties: {
540
+ ISSUER_NAME: {
541
+ type: "string",
542
+ minLength: 3,
543
+ description: "kotlin.String",
544
+ },
545
+ USER: {
546
+ type: "string",
547
+ description: "kotlin.String",
548
+ },
549
+ MAIN_CONTACT: {
550
+ type: "string",
551
+ pattern: "^[\\+]?[(]?[0-9]{3}[)]?[-\\s\\.]?[0-9]{3}[-\\s\\.]?[0-9]{4,6}$",
552
+ description: "kotlin.String",
553
+ },
554
+ },
555
+ };
556
+ ```
557
+
558
+ #### 2. Number Renderer
559
+
560
+ The number renderer that will create a `number-field`.
561
+
562
+ ```ts
563
+ const numberJsonSchema = {
564
+ type: "object",
565
+ properties: {
566
+ PRICE: {
567
+ type: "number",
568
+ description: "kotlin.Double",
569
+ },
570
+ },
571
+ };
572
+ ```
573
+
574
+ #### 3. Boolean Renderer
575
+
576
+ The boolean renderer that will create a `checkbox-field`.
577
+
578
+ ```ts
579
+ const booleanJsonSchema = {
580
+ type: "object",
581
+ properties: {
582
+ vegetarian: {
583
+ type: "boolean",
584
+ },
585
+ },
586
+ };
587
+ ```
588
+
589
+ #### 4. Connected Multiselect Renderer
590
+
591
+ The boolean renderer that will create a `multiselect` component with options from datasource.
592
+
593
+ ```ts
594
+ const connectedMultiselectUISchema = {
595
+ type: "HorizontalLayout",
596
+ elements: [
597
+ {
598
+ type: 'Control',
599
+ label: 'Rights',
600
+ scope: '#/properties/RIGHT_CODES',
601
+ options: {
602
+ allOptionsResourceName: 'RIGHT',
603
+ valueField: 'CODE',
604
+ labelField: 'CODE',
605
+ },
606
+ },
607
+ {
608
+ type: 'Control',
609
+ label: 'Users',
610
+ scope: '#/properties/USER_NAMES',
611
+ options: {
612
+ allOptionsResourceName: 'USER',
613
+ valueField: 'USER_NAME',
614
+ labelField: 'USER_NAME',
615
+ },
616
+ },
617
+ ],
618
+ };
619
+ ```
620
+
621
+ #### 5. Connected Select Renderer
622
+
623
+ The boolean renderer that will create a `select` component with options.
624
+
625
+ ```ts
626
+ const connectedSelectUISchema = {
627
+ type: "HorizontalLayout",
628
+ elements: [
629
+ {
630
+ type: "Control",
631
+ scope: "#/properties/COUNTERPARTY_ID",
632
+ options: {
633
+ data: CounterpartyOptions,
634
+ valueField: "value",
635
+ labelField: "name",
636
+ },
637
+ label: "Counterparty",
638
+ },
639
+ {
640
+ type: "Control",
641
+ scope: "#/properties/INSTRUMENT_ID",
642
+ options: {
643
+ data: InstrumentOptions,
644
+ valueField: "value",
645
+ labelField: "name",
646
+ },
647
+ label: "Instrument",
648
+ },
649
+ ],
650
+ };
651
+ ```
652
+
653
+ #### 6. Date Renderer
654
+
655
+ The date renderer that will create a `date-field`.
656
+
657
+ ```ts
658
+ const dateJsonSchema = {
659
+ type: "object",
660
+ properties: {
661
+ tradeDate: {
662
+ type: "string",
663
+ description: "org.joda.time.DateTime",
664
+ },
665
+ },
666
+ };
667
+ ```
668
+
669
+ ### Specific renderers for filters and examples
670
+
671
+ #### 1. Filter Date Renderer
672
+
673
+ The filter date renderer that will create a two `date-fields` with minimum and maximum value.
674
+
675
+ ```ts
676
+ const dateJsonSchema = {
677
+ type: "object",
678
+ properties: {
679
+ tradeDate: {
680
+ type: "string",
681
+ description: "org.joda.time.DateTime",
682
+ },
683
+ },
684
+ };
685
+ ```
686
+
687
+ #### 2. Filter Number Renderer
688
+
689
+ The filter number renderer that will create a two `number-fields` with minimum and maximum value.
690
+
691
+ ```ts
692
+ const numberJsonSchema = {
693
+ type: "object",
694
+ properties: {
695
+ PRICE: {
696
+ type: "number",
697
+ description: "kotlin.Double",
698
+ },
699
+ },
700
+ };
701
+ ```
53
702
 
54
703
  ## License
55
704
 
56
- Note: this project provides front end dependencies and uses licensed components listed in the next section, thus licenses for those components are required during development. Contact [Genesis Global](https://genesis.global/contact-us/) for more details.
705
+ Note: this project provides front end dependencies and uses licensed components listed in the next section, thus licenses for those components are required during development. Contact [Genesis Global](https://genesis.global/contact-us/) for more details.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/foundation-forms",
3
3
  "description": "Genesis Foundation Forms",
4
- "version": "14.25.0",
4
+ "version": "14.25.1-alpha-3c26bb7.0",
5
5
  "sideEffects": false,
6
6
  "license": "SEE LICENSE IN license.txt",
7
7
  "main": "dist/esm/index.js",
@@ -43,8 +43,8 @@
43
43
  "test:unit:watch": "watchlist src test -- npm run test:unit"
44
44
  },
45
45
  "devDependencies": {
46
- "@genesislcap/foundation-testing": "^14.25.0",
47
- "@genesislcap/genx": "^14.25.0",
46
+ "@genesislcap/foundation-testing": "14.25.1-alpha-3c26bb7.0",
47
+ "@genesislcap/genx": "14.25.1-alpha-3c26bb7.0",
48
48
  "@playwright/test": "^1.18.1",
49
49
  "@types/json-schema": "^7.0.11",
50
50
  "@types/ua-parser-js": "^0.7.36",
@@ -59,9 +59,9 @@
59
59
  "watchlist": "^0.3.1"
60
60
  },
61
61
  "dependencies": {
62
- "@genesislcap/foundation-comms": "^14.25.0",
63
- "@genesislcap/foundation-criteria": "^14.25.0",
64
- "@genesislcap/foundation-utils": "^14.25.0",
62
+ "@genesislcap/foundation-comms": "14.25.1-alpha-3c26bb7.0",
63
+ "@genesislcap/foundation-criteria": "14.25.1-alpha-3c26bb7.0",
64
+ "@genesislcap/foundation-utils": "14.25.1-alpha-3c26bb7.0",
65
65
  "@jsonforms/core": "^3.0.0",
66
66
  "@microsoft/fast-components": "^2.21.3",
67
67
  "@microsoft/fast-element": "^1.7.0",
@@ -82,5 +82,5 @@
82
82
  "access": "public"
83
83
  },
84
84
  "customElements": "dist/custom-elements.json",
85
- "gitHead": "ee636dcc509e1cd2ab564462cb147819e7043154"
85
+ "gitHead": "b6c823b4ea994c87daea91aee563858162469ebd"
86
86
  }