Skip to content

Support multiple datamodels in the same task #2108

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

Merged
merged 176 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
176 commits
Select commit Hold shift + click to select a range
4f3dd1a
started adding new data config
bjosttveit Mar 12, 2024
fcc8107
Merge branch 'main' into multiple-datamodels
bjosttveit Mar 13, 2024
05fd323
generatedatamodelbinding
bjosttveit Mar 13, 2024
a91014e
Merge branch 'main' into multiple-datamodels
bjosttveit Mar 15, 2024
48a12d2
update remaining types and config
bjosttveit Mar 18, 2024
4baa7f7
Merge branch 'main' into multiple-datamodels
bjosttveit Mar 18, 2024
c83a7b9
update formdatawrite++
bjosttveit Mar 20, 2024
ccb69e0
update useSourceOptions
bjosttveit Mar 20, 2024
ba4bf8d
fix cg.dmb to work in all cases
bjosttveit Mar 21, 2024
e0f4d92
proper deprecation-warnings in schema
bjosttveit Mar 21, 2024
6b4df8f
handle action response for multiple data models
bjosttveit Apr 2, 2024
1e9f8a4
add dataType parameter to dataModel expression
bjosttveit Apr 2, 2024
2af755d
fix some low hanging fruit
bjosttveit Apr 2, 2024
1911007
Merge branch 'main' into multiple-datamodels
bjosttveit Apr 3, 2024
831fd73
Merge branch 'main' into multiple-datamodels
bjosttveit Apr 4, 2024
013f214
support multiple data models for invalid data validation
bjosttveit Apr 4, 2024
f46bbe4
added provider for fetching initial data, schema, expr validation con…
bjosttveit Apr 4, 2024
589bb1f
Merge branch 'main' into multiple-datamodels
bjosttveit Apr 5, 2024
8d9cf79
add selectors
bjosttveit Apr 5, 2024
5f209fe
update schema validation to support multiple data models
bjosttveit Apr 5, 2024
d4cffde
update expression validation to support multiple data models
bjosttveit Apr 5, 2024
e384f07
update node validation to work with multiple datamodels
bjosttveit Apr 5, 2024
44744dc
update backend validation to support multiple data models
bjosttveit Apr 8, 2024
3078fef
small fixes
bjosttveit Apr 8, 2024
513e5ed
Merge branch 'main' into multiple-datamodels
bjosttveit Apr 8, 2024
6c52885
proper cleanup
bjosttveit Apr 9, 2024
33d5afa
update 'validating' to check all data models
bjosttveit Apr 9, 2024
579691f
change manualSaveRequested
bjosttveit Apr 9, 2024
c477fe3
maybe ready for first try?
bjosttveit Apr 9, 2024
fa08ff0
fix createStore and other runtime errors
bjosttveit Apr 11, 2024
3434d65
remove check causing import problem
bjosttveit Apr 12, 2024
35a6a0a
fixes
bjosttveit Apr 12, 2024
f800b18
make sure node validation updates when form data changes
bjosttveit Apr 12, 2024
a7bd2cb
fix node validation so it updates properly
bjosttveit Apr 15, 2024
8fe7e3f
fix initial backend validations not being set
bjosttveit Apr 15, 2024
bcf4d85
fix autosave behavior onchangepage race condition
bjosttveit Apr 16, 2024
1f37149
Merge branch 'main' into multiple-datamodels
bjosttveit Apr 16, 2024
ccd0e12
fix flaky datepicker validation test
bjosttveit Apr 16, 2024
634a863
remove todos
bjosttveit Apr 17, 2024
e77d967
fix task validation
bjosttveit Apr 17, 2024
d81943d
renaming and fix LangDataSources type
bjosttveit Apr 17, 2024
036fc68
fix simple todos
bjosttveit Apr 17, 2024
3481d36
error handling in DataModelsProvider
bjosttveit Apr 17, 2024
b37ee98
Merge branch 'main' into multiple-datamodels
bjosttveit Apr 17, 2024
f964446
use lax updateTaskValidations in process next mutation
bjosttveit Apr 17, 2024
dce7b13
fix a bunch of failing tests and errors in test files
bjosttveit Apr 17, 2024
cdd7720
fix more unit tests
bjosttveit Apr 18, 2024
e95e410
fix ErrorReport test
bjosttveit Apr 18, 2024
96ca372
skipping hierarchy test that fails due to stringifying circular object
bjosttveit Apr 19, 2024
e45dd6a
update expression shared test, dataModel expression now supports othe…
bjosttveit Apr 19, 2024
43928a0
update unlock() and fix formdata tests
bjosttveit Apr 19, 2024
25384ce
update SchemaValidation and ExpressionValidation unit tests
bjosttveit Apr 22, 2024
e3aa253
fix type guard
bjosttveit Apr 22, 2024
67dbe84
ignore slow validators on patch validation
bjosttveit Apr 23, 2024
087ccaf
remove erronious }
bjosttveit Apr 23, 2024
47007f6
make sure patch requests send the current language in query
bjosttveit Apr 23, 2024
b7cd81a
Merge branch 'main' into multiple-datamodels
bjosttveit Apr 26, 2024
31d1609
Merge branch 'main' into multiple-datamodels
bjosttveit Apr 26, 2024
89b75ae
update _experimentalSelectAndMap to use the default model
bjosttveit Apr 26, 2024
626e23f
support expressions in query parameters
bjosttveit Apr 29, 2024
5ae35fc
update mutateDataModelBindings to check that dataType matches between…
bjosttveit Apr 30, 2024
b36c203
improve node validation performance
bjosttveit May 2, 2024
6a2a440
fix likert item bindings
bjosttveit May 2, 2024
7061f7c
give feedback when refering to non-existant data types
bjosttveit May 3, 2024
a778f70
add support for queryParameters in ListComponent
bjosttveit May 3, 2024
12ead41
Merge branch 'main' into multiple-datamodels
bjosttveit May 8, 2024
d619a90
Merge branch 'main' into multiple-datamodels
bjosttveit May 13, 2024
df1d44e
Merge branch 'main' into multiple-datamodels
bjosttveit May 16, 2024
e030fd0
Merge branch 'main' into multiple-datamodels
bjosttveit May 16, 2024
914897c
update prefetching and provider ordering
bjosttveit May 16, 2024
d8fccfa
Merge branch 'main' into multiple-datamodels
bjosttveit May 22, 2024
f931136
dont annoy devs with deprecation warning for string datamodelbinding
bjosttveit May 22, 2024
99f1ae5
added cypress tests for data saving
bjosttveit May 23, 2024
09a8137
started adding validation tests
bjosttveit May 23, 2024
ee5e230
added more validation tests
bjosttveit May 23, 2024
1c101ad
added todo
bjosttveit May 23, 2024
17b19dd
Merge branch 'main' into multiple-datamodels
bjosttveit May 23, 2024
d01e611
move formdatawriteprovider after dynamics and rules, these must be lo…
bjosttveit May 23, 2024
0aeb7a8
fix formdata unit test setup
bjosttveit May 23, 2024
ad01f42
make saving tests less flaky
bjosttveit May 24, 2024
3dcaa8e
layout validation
bjosttveit May 24, 2024
87b1ab8
fix has unsaved changes effect
bjosttveit May 24, 2024
8442298
dont validate datamodels that are not for the current task, also disa…
bjosttveit May 24, 2024
9a6b112
woops
bjosttveit May 24, 2024
48110d1
add logic for readonly data models
bjosttveit May 28, 2024
8555479
add more tests and prevent instance being used with stale data
bjosttveit May 28, 2024
ba9355f
completed cypress tests for readonly data models
bjosttveit May 29, 2024
3a414f8
fix race condition where process could proceed before new instance da…
bjosttveit May 29, 2024
092186d
only show mapping as deprecated where we have alternatives
bjosttveit May 29, 2024
5432b62
Merge branch 'main' into multiple-datamodels
bjosttveit Jun 6, 2024
2c41d77
make sure we use the same 'current' layout-set
bjosttveit Jun 7, 2024
a10d828
select less in useIsSaving
bjosttveit Jun 7, 2024
38290a2
remove cleanup on unmount (probably not needed)
bjosttveit Jun 7, 2024
1673dd5
add link to test app in test/README
bjosttveit Jun 7, 2024
1b5ffe6
change the default dataType on dataModel expressions when running exp…
bjosttveit Jun 7, 2024
0a85d45
look for data models in expressions
bjosttveit Jun 7, 2024
3224e1a
object -> unknown
bjosttveit Jun 10, 2024
3f2f3d7
Merge branch 'main' into multiple-datamodels
bjosttveit Jun 13, 2024
0c7a09f
Merge branch 'main' into multiple-datamodels
bjosttveit Jun 13, 2024
0f71e2f
wait for save before using a .then() in cypress
bjosttveit Jun 13, 2024
104b77d
Merge branch 'main' into multiple-datamodels
bjosttveit Jun 18, 2024
232e814
change 'property' -> 'field'
bjosttveit Jun 18, 2024
56095a6
test validations from backend
bjosttveit Jun 20, 2024
56f020b
centralize backend validator states
bjosttveit Jun 21, 2024
7aaaf36
set initial backend validations
bjosttveit Jun 21, 2024
34ee382
identify standard validation with multiple standard validators, one f…
bjosttveit Jun 21, 2024
ed715ac
added new shared expression tests
bjosttveit Jun 24, 2024
0450cbd
Merge branch 'main' into multiple-datamodels
bjosttveit Jun 25, 2024
8881374
use default data type if dataElementId is undefined
bjosttveit Jun 25, 2024
b75ff48
Merge branch 'main' into multiple-datamodels
bjosttveit Jun 26, 2024
b2f1db0
prevent initial validations being set multiple times
bjosttveit Jun 27, 2024
b9f4ca3
Merge branch 'main' into multiple-datamodels
bjosttveit Jun 27, 2024
bb4e613
dont validate on receipt page
bjosttveit Jun 27, 2024
b4d205c
Merge branch 'main' into multiple-datamodels
bjosttveit Jul 22, 2024
a7f62fe
review updates
bjosttveit Jul 23, 2024
31e128a
add more checks
bjosttveit Jul 23, 2024
8583b6d
renaming things
bjosttveit Jul 23, 2024
4e4fc3e
remove unecessary default
bjosttveit Jul 23, 2024
a59b948
Merge branch 'main' into multiple-datamodels
bjosttveit Aug 13, 2024
3e6d8e8
navigate before invalidating appmetadata query
bjosttveit Aug 13, 2024
a76678f
Merge branch 'main' into multiple-datamodels
bjosttveit Aug 19, 2024
e6b3eaa
Merge branch 'main' into multiple-datamodels
bjosttveit Aug 20, 2024
9c95c0f
Merge branch 'main' into multiple-datamodels
bjosttveit Aug 22, 2024
c3fb44e
fix expression validation and some types
bjosttveit Aug 23, 2024
aa41cef
Fixes after merge from main. Preparing to rewrite data model bindings…
Aug 23, 2024
81e8205
Rewriting string dataModelBindings in tests (optimistically, I'm not …
Aug 23, 2024
52b8b11
Quick-and-dirty rewrite of all stringy dataModelBindings to objects
Aug 23, 2024
a1390ef
resolve expr in queryparameters and fix validation loading + cleanup
bjosttveit Aug 23, 2024
ca28c97
cleanup
bjosttveit Aug 23, 2024
2c0e562
Merge branch 'main' into multiple-datamodels
bjosttveit Aug 23, 2024
e9bd421
trying to fix tests
bjosttveit Aug 26, 2024
ecf7044
add null coalessing
bjosttveit Aug 26, 2024
9ec2ad8
Fixing cache key for form data url, removing logging
Aug 26, 2024
fc9afb4
fix non default test
bjosttveit Aug 26, 2024
80382d7
fix language referencing data model
bjosttveit Aug 27, 2024
44d00c9
fix wait for validating to be provided
bjosttveit Aug 27, 2024
1857c7e
fix expression validation tests
bjosttveit Aug 27, 2024
596fb06
Merge branch 'main' into multiple-datamodels
bjosttveit Aug 27, 2024
cc72934
remove prefetching for datamodels provider and fix transpose datamode…
bjosttveit Aug 27, 2024
726ee83
filter non-existing data models and log error instead of rendering error
bjosttveit Aug 28, 2024
7fe7ba1
Throwing a runtime error when the target data model type is not among…
Aug 28, 2024
fd71fb2
implement multi patch
bjosttveit Aug 30, 2024
99447fe
Merge branch 'main' into multiple-datamodels
Aug 30, 2024
1c633ef
Adding a stateful way to test in FormData.test.tsx, fixing locking te…
Aug 30, 2024
f64a5c3
Lint fixes, removing unused variables
Aug 30, 2024
65004f9
Re-implementing formData exporting to Cypress for test to pass
Aug 30, 2024
3b6606c
Fixing the anonymous.ts test, re-implementing support for changes to …
Aug 30, 2024
1b8ec61
Fixing the 'Remove validation message when field disappears' cypress …
Aug 30, 2024
d040846
quickfix initial data loading with stale data, and schema not loading…
bjosttveit Sep 2, 2024
62fc838
fix validation on submit
bjosttveit Sep 2, 2024
303692b
ignore ignoredValdiators in initial validation
bjosttveit Sep 2, 2024
edf43fb
fix isLoadingFormData
bjosttveit Sep 2, 2024
4edc004
quickfix debounce timeout and update multiple datamodel tests for mul…
bjosttveit Sep 2, 2024
616b1e0
Merge branch 'main' into multiple-datamodels
bjosttveit Sep 3, 2024
43d33b6
fix tests after merge
bjosttveit Sep 3, 2024
af82cff
fix some todos
bjosttveit Sep 3, 2024
9677ca1
temporarily disable ignoredValidators
bjosttveit Sep 3, 2024
f9180a6
Merge branch 'main' into multiple-datamodels
Sep 4, 2024
08f1de6
Fixes after merge from main
Sep 4, 2024
1b341f9
Rewriting some assertions to be more robust, accounting for preselect…
Sep 4, 2024
824f8cd
Fixing MapComponent.test.tsx after merge from main
Sep 4, 2024
74b093d
Making test less flaky by verifying the expected number of rows exist…
Sep 4, 2024
cd640a0
Merge branch 'main' into multiple-datamodels
Sep 4, 2024
72003dc
Working around some very aggressive caching in tanstack query that we…
Sep 4, 2024
040e491
Merge branch 'main' into multiple-datamodels
Sep 5, 2024
27600cc
Fixes after merge from main
Sep 5, 2024
e4e3b6a
Merge remote-tracking branch 'origin/multiple-datamodels' into multip…
Sep 5, 2024
743d5fa
Re-fixing the bug that was reproduced in navigation.ts in a way that …
Sep 5, 2024
7e42798
Merge branch 'main' into multiple-datamodels
Sep 5, 2024
2810b1c
Merge remote-tracking branch 'origin/multiple-datamodels' into multip…
Sep 5, 2024
c4a7147
Merge branch 'main' into multiple-datamodels
Sep 6, 2024
c4ff213
Merge branch 'main' into multiple-datamodels
Sep 6, 2024
63ca82c
I never changed the implementation in processChanges() because the in…
Sep 6, 2024
05c6855
Avoiding overwriting the initial data model every time we save (as th…
Sep 6, 2024
3940332
Fixing the unit test after this functionality was improved
Sep 6, 2024
ed09965
Merge branch 'main' into multiple-datamodels
Sep 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion schemas/json/layout/expression.schema.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@
},
"func-dataModel": {
"title": "Data model lookup function",
"description": "This function will look up a value in the data model, using the JSON dot notation for referencing the data model structure. Relative positioning inside repeating groups will be resolved automatically if no positional indexes are specified.",
"description": "This function will look up a value in the data model, using the JSON dot notation for referencing the data model structure. Relative positioning inside repeating groups will be resolved automatically if no positional indexes are specified. The final parameter is optional and specifies the data type to look up.",
"type": "array",
"items": [
{ "const": "dataModel" },
{ "$ref": "#/definitions/string" },
{ "$ref": "#/definitions/string" }
],
"additionalItems": false
Expand Down
2 changes: 0 additions & 2 deletions src/__mocks__/getApplicationMetadataMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export const getIncomingApplicationMetadataMock = (
autoCreate: true,
classRef: 'Altinn.App.Models.Skjema2',
},
taskId: 'Task_0',
maxCount: 1,
minCount: 1,
},
Expand All @@ -60,7 +59,6 @@ export const getIncomingApplicationMetadataMock = (
classRef: 'Altinn.App.Models.Skjema3',
allowAnonymousOnStateless: true,
},
taskId: 'Task_0',
maxCount: 1,
minCount: 1,
},
Expand Down
3 changes: 3 additions & 0 deletions src/__mocks__/getExpressionDataSourcesMock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getApplicationSettingsMock } from 'src/__mocks__/getApplicationSettingsMock';
import { defaultDataTypeMock } from 'src/__mocks__/getLayoutSetsMock';
import { staticUseLanguageForTests } from 'src/features/language/useLanguage';
import type { IInstanceDataSources } from 'src/types/shared';
import type { ExpressionDataSources } from 'src/utils/layout/useExpressionDataSources';
Expand All @@ -13,9 +14,11 @@ export function getExpressionDataSourcesMock(): ExpressionDataSources {
},
optionsSelector: () => ({ isFetching: false, options: [] }),
applicationSettings: getApplicationSettingsMock(),
dataModelNames: [defaultDataTypeMock],
instanceDataSources: {} as IInstanceDataSources | null,
langToolsSelector: () => staticUseLanguageForTests(),
currentLanguage: 'nb',
currentLayoutSet: { id: 'form', dataType: 'data', tasks: ['task1'] },
isHiddenSelector: () => false,
nodeFormDataSelector: (() => ({})) as unknown as NodeFormDataSelector,
nodeDataSelector: () => {
Expand Down
3 changes: 2 additions & 1 deletion src/__mocks__/getFormLayoutGroupMock.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { defaultDataTypeMock } from 'src/__mocks__/getLayoutSetsMock';
import type { CompRepeatingGroupExternal } from 'src/layout/RepeatingGroup/config.generated';

export const getFormLayoutRepeatingGroupMock = (
Expand All @@ -8,7 +9,7 @@ export const getFormLayoutRepeatingGroupMock = (
children: ['field1', 'field2', 'field3', 'field4'],
maxCount: 8,
dataModelBindings: {
group: 'some-group',
group: { dataType: defaultDataTypeMock, field: 'some-group' },
},
...customMock,
});
42 changes: 0 additions & 42 deletions src/__mocks__/getFormLayoutMock.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/__mocks__/getInstanceDataMock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { IInstance } from 'src/types/shared';

export const defaultMockDataElementId = '4f2610c9-911a-46a3-bc2d-5191602193f4';

export function getInstanceDataMock(mutate?: (data: IInstance) => void): IInstance {
const out: IInstance = {
instanceOwner: {
Expand All @@ -10,7 +12,7 @@ export function getInstanceDataMock(mutate?: (data: IInstance) => void): IInstan
created: new Date('2020-01-01').toISOString(),
data: [
{
id: '4f2610c9-911a-46a3-bc2d-5191602193f4',
id: defaultMockDataElementId,
instanceGuid: '91cefc5e-c47b-40ff-a8a4-05971205f783',
dataType: 'test-data-model',
contentType: 'application/xml',
Expand Down
8 changes: 4 additions & 4 deletions src/__mocks__/getLayoutSetsMock.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import type { ILayoutSets } from 'src/layout/common.generated';

export const defaultDataTypeMock = 'test-data-model';
export const statelessDataTypeMock = 'stateless';
export function getLayoutSetsMock(): ILayoutSets {
return {
sets: [
{
id: 'stateless',
dataType: 'stateless',
tasks: ['Task_0'],
dataType: statelessDataTypeMock,
},
{
id: 'stateless-anon',
dataType: 'stateless-anon',
tasks: ['Task_0'],
},
{
id: 'some-data-task',
dataType: 'test-data-model',
dataType: defaultDataTypeMock,
tasks: ['Task_1'],
},
],
Expand Down
3 changes: 2 additions & 1 deletion src/__mocks__/getMultiPageGroupMock.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { defaultDataTypeMock } from 'src/__mocks__/getLayoutSetsMock';
import type { CompRepeatingGroupExternal } from 'src/layout/RepeatingGroup/config.generated';

export const getMultiPageGroupMock = (overrides: Partial<CompRepeatingGroupExternal>): CompRepeatingGroupExternal => ({
id: 'myMultiPageGroup',
type: 'RepeatingGroup',
dataModelBindings: {
group: 'multipageGroup',
group: { dataType: defaultDataTypeMock, field: 'multipageGroup' },
},
maxCount: 2,
edit: {
Expand Down
2 changes: 2 additions & 0 deletions src/codegen/CG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { GenerateArray } from 'src/codegen/dataTypes/GenerateArray';
import { GenerateBoolean } from 'src/codegen/dataTypes/GenerateBoolean';
import { GenerateCommonImport } from 'src/codegen/dataTypes/GenerateCommonImport';
import { GenerateConst } from 'src/codegen/dataTypes/GenerateConst';
import { GenerateDataModelBinding } from 'src/codegen/dataTypes/GenerateDataModelBinding';
import { GenerateEnum } from 'src/codegen/dataTypes/GenerateEnum';
import { GenerateExpressionOr } from 'src/codegen/dataTypes/GenerateExpressionOr';
import { GenerateImportedSymbol } from 'src/codegen/dataTypes/GenerateImportedSymbol';
Expand Down Expand Up @@ -42,6 +43,7 @@ export const CG = {
obj: GenerateObject,
prop: GenerateProperty,
trb: GenerateTextResourceBinding,
dataModelBinding: GenerateDataModelBinding,

// Known values that we have types for elsewhere, or other imported types
common: generateCommonImport,
Expand Down
27 changes: 26 additions & 1 deletion src/codegen/CodeGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export interface JsonSchemaExt<T> {
title: string | undefined;
description: string | undefined;
examples: T[];
deprecated: boolean | undefined;
deprecationWarning: string | undefined;
}

export interface TypeScriptExt {
Expand Down Expand Up @@ -40,20 +42,36 @@ export abstract class CodeGenerator<T> {
title: undefined,
description: undefined,
examples: [],
deprecated: undefined,
deprecationWarning: undefined,
},
typeScript: {},
optional: false,
frozen: false,
};

/**
* Gets the schemas description, and prepends a deprecation warning if the property is deprecated
*/
private getSchemaDescription(): string | undefined {
const description = this.internal.jsonSchema.description;
if (this.internal.jsonSchema.deprecated) {
const deprecationMessage = `**Deprecated**: ${this.internal.jsonSchema.deprecationWarning}`;
return description ? [deprecationMessage, description].join('\n') : deprecationMessage;
}
return description;
}

protected getInternalJsonSchema(): JSONSchema7 {
this.freeze('getInternalJsonSchema');
return {
title: this.internal.jsonSchema.title || this.internal.symbol?.name || undefined,
description: this.internal.jsonSchema.description,
description: this.getSchemaDescription(),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
examples: this.internal.jsonSchema.examples.length ? (this.internal.jsonSchema.examples as any) : undefined,
default: this.internal.optional ? (this.internal.optional.default as JSONSchema7Type) : undefined,
// @ts-expect-error Although not included in JSON schema version 7, this is implemented in more recent versions, and works in VS Code
deprecated: this.internal.jsonSchema.deprecated,
};
}

Expand Down Expand Up @@ -168,6 +186,13 @@ export abstract class MaybeOptionalCodeGenerator<T> extends MaybeSymbolizedCodeG
}

export abstract class DescribableCodeGenerator<T> extends MaybeOptionalCodeGenerator<T> {
setDeprecated(warning: string): this {
this.ensureMutable();
this.internal.jsonSchema.deprecated = true;
this.internal.jsonSchema.deprecationWarning = warning;
return this;
}

setTitle(title: string): this {
this.ensureMutable();
this.internal.jsonSchema.title = title;
Expand Down
110 changes: 73 additions & 37 deletions src/codegen/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,38 +128,61 @@ const common = {
),
),

IDataModelReference: () =>
new CG.obj(
new CG.prop(
'dataType',
new CG.str().setTitle('Data type').setDescription('The name of the datamodel type to reference'),
),
new CG.prop(
'field',
new CG.str().setTitle('Field').setDescription('The path to the property using dot-notation'),
),
),
IRawDataModelBinding: () => new CG.union(new CG.str(), CG.common('IDataModelReference')),

// Data model bindings:
IDataModelBindingsSimple: () =>
new CG.obj(new CG.prop('simpleBinding', new CG.str()))
.setTitle('Data model binding')
.setDescription(
'Describes the location in the data model where the component should store its value(s). A simple ' +
'binding is used for components that only store a single value, usually a string.',
),
IDataModelBindingsOptionsSimple: () =>
new CG.obj(
new CG.prop('simpleBinding', new CG.str()),
new CG.prop('label', new CG.str().optional()),
new CG.prop(
'metadata',
new CG.str()
.optional()
'simpleBinding',
new CG.dataModelBinding()
.setTitle('Data model binding')
.setDescription(
'Describes the location where metadata for the option based component should be stored in the datamodel.',
'Describes the location in the data model where the component should store its value(s). ' +
'A simple binding is used for components that only store a single value, usually a string.',
),
),
)
.setTitle('Data model binding')
.setDescription(
'Describes the location in the data model where the component should store its value(s). A simple ' +
'binding is used for components that only store a single value, usually a string.',
),
IDataModelBindingsOptionsSimple: () =>
new CG.obj(
new CG.prop(
'simpleBinding',
new CG.dataModelBinding()
.setTitle('Data model binding for value')
.setDescription('Describes the location in the data model where the component should store its values.'),
),
new CG.prop(
'label',
new CG.dataModelBinding()
.setTitle('Data model binding for label')
.setDescription('Describes the location in the data model where the component should store its labels')
.optional(),
),
new CG.prop(
'metadata',
new CG.dataModelBinding()
.setTitle('Data model binding for metadata')
.setDescription('Describes the location in the data model where the component should store its metadata')
.optional(),
),
),
IDataModelBindingsLikert: () =>
new CG.obj(
new CG.prop(
'answer',
new CG.str()
.setTitle('Answer')
new CG.dataModelBinding()
.setTitle('Data model binding for answer')
.setDescription(
'Dot notation location for the answers. This must point to a property of the objects inside the ' +
'question array. The answer for each question will be stored in the answer property of the ' +
Expand All @@ -168,25 +191,24 @@ const common = {
),
new CG.prop(
'questions',
new CG.str()
.setTitle('Questions')
new CG.dataModelBinding()
.setTitle('Data model binding for questions')
.setDescription('Dot notation location for a likert structure (array of objects), where the data is stored'),
),
)
.setTitle('Data model binding')
.setDescription(
'Describes the location in the data model where the component should store its value(s). A list binding ' +
'should be pointed to an array structure in the data model, and is used for components that store multiple ' +
'simple values (e.g. a list of strings).',
),
),
IDataModelBindingsList: () =>
new CG.obj(new CG.prop('list', new CG.str()))
.setTitle('Data model binding')
.setDescription(
'Describes the location in the data model where the component should store its value(s). A list binding ' +
'should be pointed to an array structure in the data model, and is used for components that store multiple ' +
'simple values (e.g. a list of strings).',
new CG.obj(
new CG.prop(
'list',
new CG.dataModelBinding()
.setTitle('Data model binding for values')
.setDescription(
'Describes the location in the data model where the component should store its values. A list binding ' +
'should be pointed to an array structure in the data model, and is used for components that store multiple ' +
'simple values (e.g. a list of strings).',
),
),
),

// Text resource bindings:
TRBSummarizable: () =>
Expand Down Expand Up @@ -256,13 +278,22 @@ const common = {
),
IQueryParameters: () =>
new CG.obj()
.additionalProperties(new CG.str())
.additionalProperties(new CG.expr(ExprVal.String))
.setTitle('Query parameters')
.setDescription(
'A mapping of query string parameters to values. Will be appended to the URL when fetching options.',
),
IOptionSource: () =>
new CG.obj(
new CG.prop(
'dataType',
new CG.str()
.setTitle('Data type')
.setDescription(
'The datamodel where the repeating group data is stored. If not specified, the data model defined in the layout-set will be used.',
)
.optional(),
),
new CG.prop(
'group',
new CG.str()
Expand Down Expand Up @@ -318,7 +349,12 @@ const common = {
.setTitle('Dynamic options (fetched from server)')
.setDescription('ID of the option list to fetch from the server'),
),
new CG.prop('mapping', CG.common('IMapping').optional()),
new CG.prop(
'mapping',
CG.common('IMapping')
.optional()
.setDeprecated('Will be removed in the next major version. Use `queryParameters` with expressions instead.'),
),
new CG.prop('queryParameters', CG.common('IQueryParameters').optional()),
new CG.prop(
'options',
Expand Down
Loading
Loading