@oneblink/apps-react 5.11.0-beta.1 → 5.11.0-beta.3
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.
@@ -8,9 +8,9 @@ export default function processInjectableOption({ option, submission, formElemen
|
|
8
8
|
taskContext: TaskContext;
|
9
9
|
userProfile: MiscTypes.UserProfile | undefined;
|
10
10
|
}): FormTypes.ChoiceElementOption[];
|
11
|
-
export declare
|
11
|
+
export declare function injectOptionsAcrossAllElements({ submission, ...params }: {
|
12
12
|
elements: FormTypes.FormElement[];
|
13
13
|
submission: SubmissionTypes.S3SubmissionData['submission'];
|
14
14
|
taskContext: TaskContext;
|
15
15
|
userProfile: MiscTypes.UserProfile | undefined;
|
16
|
-
})
|
16
|
+
}): FormTypes.FormElement[];
|
@@ -90,19 +90,54 @@ export default function processInjectableOption({ option, submission, formElemen
|
|
90
90
|
});
|
91
91
|
return generatedOptions;
|
92
92
|
}
|
93
|
-
|
93
|
+
function injectOptionsAcrossEntriesElements({ elements, entries, taskContext, userProfile, }) {
|
94
94
|
return elements.map((e) => {
|
95
|
-
var _a, _b;
|
96
95
|
switch (e.type) {
|
97
|
-
case 'repeatableSet':
|
98
96
|
case 'page':
|
99
|
-
case 'section':
|
97
|
+
case 'section': {
|
98
|
+
return {
|
99
|
+
...e,
|
100
|
+
elements: injectOptionsAcrossEntriesElements({
|
101
|
+
elements: e.elements,
|
102
|
+
entries,
|
103
|
+
taskContext,
|
104
|
+
userProfile,
|
105
|
+
}),
|
106
|
+
};
|
107
|
+
}
|
100
108
|
case 'form': {
|
109
|
+
if (Array.isArray(e.elements)) {
|
110
|
+
return {
|
111
|
+
...e,
|
112
|
+
elements: injectOptionsAcrossEntriesElements({
|
113
|
+
elements: e.elements,
|
114
|
+
entries: entries.reduce((memo, entry) => {
|
115
|
+
if (entry[e.name]) {
|
116
|
+
memo.push(entry[e.name]);
|
117
|
+
}
|
118
|
+
return memo;
|
119
|
+
}, []),
|
120
|
+
taskContext,
|
121
|
+
userProfile,
|
122
|
+
}),
|
123
|
+
};
|
124
|
+
}
|
125
|
+
else {
|
126
|
+
return e;
|
127
|
+
}
|
128
|
+
}
|
129
|
+
case 'repeatableSet': {
|
101
130
|
return {
|
102
131
|
...e,
|
103
|
-
elements:
|
104
|
-
elements:
|
105
|
-
|
132
|
+
elements: injectOptionsAcrossEntriesElements({
|
133
|
+
elements: e.elements,
|
134
|
+
entries: entries.reduce((memo, entry) => {
|
135
|
+
const nestedEntries = entry[e.name];
|
136
|
+
if (Array.isArray(nestedEntries)) {
|
137
|
+
memo.push(...nestedEntries);
|
138
|
+
}
|
139
|
+
return memo;
|
140
|
+
}, []),
|
106
141
|
taskContext,
|
107
142
|
userProfile,
|
108
143
|
}),
|
@@ -113,15 +148,20 @@ export const injectOptionsAcrossAllElements = ({ elements, submission, taskConte
|
|
113
148
|
if (optionsElement) {
|
114
149
|
return {
|
115
150
|
...optionsElement,
|
116
|
-
options:
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
151
|
+
options: entries.reduce((newOptions, submission) => {
|
152
|
+
var _a;
|
153
|
+
(_a = optionsElement.options) === null || _a === void 0 ? void 0 : _a.forEach((o) => {
|
154
|
+
const injected = processInjectableOption({
|
155
|
+
option: o,
|
156
|
+
submission,
|
157
|
+
formElements: elements,
|
158
|
+
taskContext,
|
159
|
+
userProfile,
|
160
|
+
});
|
161
|
+
newOptions.push(...injected.filter((generatedOption) => {
|
162
|
+
return !newOptions.some((addedOption) => addedOption.value === generatedOption.value);
|
163
|
+
}));
|
123
164
|
});
|
124
|
-
newOptions.push(...injected);
|
125
165
|
return newOptions;
|
126
166
|
}, []),
|
127
167
|
};
|
@@ -130,5 +170,16 @@ export const injectOptionsAcrossAllElements = ({ elements, submission, taskConte
|
|
130
170
|
}
|
131
171
|
}
|
132
172
|
});
|
133
|
-
}
|
173
|
+
}
|
174
|
+
export function injectOptionsAcrossAllElements({ submission, ...params }) {
|
175
|
+
// We iterate over entries as an array of submission objects because
|
176
|
+
// child elements of a repeatable set that have injected options
|
177
|
+
// need to include all of the injected options from the same elements
|
178
|
+
// in sibling entries within the set. Otherwise we will not have the
|
179
|
+
// labels for each available option to display the submission.
|
180
|
+
return injectOptionsAcrossEntriesElements({
|
181
|
+
...params,
|
182
|
+
entries: [submission],
|
183
|
+
});
|
184
|
+
}
|
134
185
|
//# sourceMappingURL=injectableOptions.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"injectableOptions.js","sourceRoot":"","sources":["../../src/services/injectableOptions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAA;AAMnC,SAAS,8BAA8B,CAAC,EACtC,MAAM,EACN,UAAU,EACV,YAAY,EACZ,GAAG,MAAM,EAOV;IACC,MAAM,UAAU,GAAwB,IAAI,GAAG,EAAE,CAAA;IAEjD,yCAAyC;IACzC,MAAM,iBAAiB,GAEhB;QACL,GAAG,MAAM;QACT,UAAU;QACV,YAAY;QACZ,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI;QAC7B,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,SAAS;QACvC,iBAAiB,EAAE,MAAM,CAAC,WAAW,CAAC,iBAAiB;QACvD,qBAAqB,EAAE,IAAI;KAC5B,CAAA;IACD,MAAM,EACJ,IAAI,EAAE,KAAK,EACX,yBAAyB,EAAE,gCAAgC,GAC5D,GAAG,mBAAmB,CAAC,mCAAmC,CACzD,MAAM,CAAC,KAAK,EACZ,iBAAiB,CAClB,CAAA;IACD,IAAI,CAAC,gCAAgC,EAAE;QACrC,OAAO,UAAU,CAAA;KAClB;IAED,MAAM,EACJ,IAAI,EAAE,KAAK,EACX,yBAAyB,EAAE,gCAAgC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","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { formElementsService, typeCastService } from '@oneblink/sdk-core'\nimport { localisationService } from '@oneblink/apps'\nimport { v4 as uuidv4 } from 'uuid'\nimport { MiscTypes } from '@oneblink/types'\nimport { TaskContext } from '../hooks/useTaskContext'\n\ntype Option = Pick<FormTypes.ChoiceElementOption, 'value' | 'label'>\n\nfunction processInjectableDynamicOption({\n option,\n submission,\n formElements,\n ...params\n}: {\n option: Option\n submission: SubmissionTypes.S3SubmissionData['submission']\n formElements: FormTypes.FormElement[]\n taskContext: TaskContext\n userProfile: MiscTypes.UserProfile | undefined\n}): Map<string, string> {\n const newOptions: Map<string, string> = new Map()\n\n // Replace root level form element values\n const replaceableParams: Parameters<\n typeof localisationService.replaceInjectablesWithElementValues\n >[1] = {\n ...params,\n submission,\n formElements,\n task: params.taskContext.task,\n taskGroup: params.taskContext.taskGroup,\n taskGroupInstance: params.taskContext.taskGroupInstance,\n excludeNestedElements: true,\n }\n const {\n text: label,\n hadAllInjectablesReplaced: hadAllInjectablesReplacedInLabel,\n } = localisationService.replaceInjectablesWithElementValues(\n option.label,\n replaceableParams,\n )\n if (!hadAllInjectablesReplacedInLabel) {\n return newOptions\n }\n\n const {\n text: value,\n hadAllInjectablesReplaced: hadAllInjectablesReplacedInValue,\n } = localisationService.replaceInjectablesWithElementValues(\n option.value,\n replaceableParams,\n )\n if (!hadAllInjectablesReplacedInValue) {\n return newOptions\n }\n\n // Find nested form elements\n const matches: Map<string, boolean> = new Map()\n formElementsService.matchElementsTagRegex(\n {\n text: label + ' ' + value,\n excludeNestedElements: false,\n },\n ({ elementName }) => {\n const [repeatableSetElementName, ...elementNames] = elementName.split('|')\n matches.set(repeatableSetElementName, !!elementNames.length)\n },\n )\n\n if (matches.size) {\n matches.forEach((hasNestedFormElements, repeatableSetElementName) => {\n if (hasNestedFormElements) {\n // Attempt to create a new option for each entry in the repeatable set.\n const entries = submission?.[repeatableSetElementName]\n if (Array.isArray(entries)) {\n const repeatableSetElement = formElementsService.findFormElement(\n formElements,\n (formElement) => {\n return (\n 'name' in formElement &&\n formElement.name === repeatableSetElementName\n )\n },\n )\n if (\n repeatableSetElement &&\n 'elements' in repeatableSetElement &&\n Array.isArray(repeatableSetElement.elements)\n ) {\n for (const entry of entries) {\n const nestedOptions = processInjectableDynamicOption({\n ...params,\n option: {\n label: label.replaceAll(\n `{ELEMENT:${repeatableSetElementName}|`,\n '{ELEMENT:',\n ),\n value: value.replaceAll(\n `{ELEMENT:${repeatableSetElementName}|`,\n '{ELEMENT:',\n ),\n },\n submission: entry,\n formElements: repeatableSetElement.elements,\n })\n if (nestedOptions.size) {\n nestedOptions.forEach((nestedLabel, nestedValue) => {\n if (!newOptions.has(nestedValue)) {\n newOptions.set(nestedValue, nestedLabel)\n }\n })\n }\n }\n }\n }\n }\n })\n } else {\n newOptions.set(value, label)\n }\n\n return newOptions\n}\n\nexport default function processInjectableOption({\n option,\n submission,\n formElements,\n taskContext,\n userProfile,\n}: {\n option: FormTypes.ChoiceElementOption\n submission: SubmissionTypes.S3SubmissionData['submission']\n formElements: FormTypes.FormElement[]\n taskContext: TaskContext\n userProfile: MiscTypes.UserProfile | undefined\n}): FormTypes.ChoiceElementOption[] {\n const options = processInjectableDynamicOption({\n option,\n submission,\n formElements,\n taskContext,\n userProfile,\n })\n\n const generatedOptions: FormTypes.ChoiceElementOption[] = []\n\n options.forEach((label, value) => {\n generatedOptions.push({\n ...option,\n id: options.size === 1 ? option.id : uuidv4(),\n label,\n value,\n })\n })\n\n return generatedOptions\n}\n\nexport const injectOptionsAcrossAllElements = ({\n elements,\n submission,\n taskContext,\n userProfile,\n}: {\n elements: FormTypes.FormElement[]\n submission: SubmissionTypes.S3SubmissionData['submission']\n taskContext: TaskContext\n userProfile: MiscTypes.UserProfile | undefined\n}): FormTypes.FormElement[] => {\n return elements.map<FormTypes.FormElement>((e) => {\n switch (e.type) {\n case 'repeatableSet':\n case 'page':\n case 'section':\n case 'form': {\n return {\n ...e,\n elements: injectOptionsAcrossAllElements({\n elements: e.elements ?? [],\n submission,\n taskContext,\n userProfile,\n }),\n } as FormTypes.FormElement\n }\n default: {\n const optionsElement = typeCastService.formElements.toOptionsElement(e)\n if (optionsElement) {\n return {\n ...optionsElement,\n options: optionsElement.options?.reduce<\n FormTypes.ChoiceElementOption[]\n >((newOptions, o) => {\n const injected = processInjectableOption({\n option: o,\n submission,\n formElements: elements,\n taskContext,\n userProfile,\n })\n newOptions.push(...injected)\n return newOptions\n }, []),\n }\n }\n return e\n }\n }\n })\n}\n"]}
|
1
|
+
{"version":3,"file":"injectableOptions.js","sourceRoot":"","sources":["../../src/services/injectableOptions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAA;AAMnC,SAAS,8BAA8B,CAAC,EACtC,MAAM,EACN,UAAU,EACV,YAAY,EACZ,GAAG,MAAM,EAOV;IACC,MAAM,UAAU,GAAwB,IAAI,GAAG,EAAE,CAAA;IAEjD,yCAAyC;IACzC,MAAM,iBAAiB,GAEhB;QACL,GAAG,MAAM;QACT,UAAU;QACV,YAAY;QACZ,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI;QAC7B,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,SAAS;QACvC,iBAAiB,EAAE,MAAM,CAAC,WAAW,CAAC,iBAAiB;QACvD,qBAAqB,EAAE,IAAI;KAC5B,CAAA;IACD,MAAM,EACJ,IAAI,EAAE,KAAK,EACX,yBAAyB,EAAE,gCAAgC,GAC5D,GAAG,mBAAmB,CAAC,mCAAmC,CACzD,MAAM,CAAC,KAAK,EACZ,iBAAiB,CAClB,CAAA;IACD,IAAI,CAAC,gCAAgC,EAAE;QACrC,OAAO,UAAU,CAAA;KAClB;IAED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AAO,CAAC,CAAA;aACT;SACF;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,8BAA8B,CAAC,EAC7C,UAAU,EACV,GAAG,MAAM,EAMV;IACC,oEAAoE;IACpE,gEAAgE;IAChE,qEAAqE;IACrE,oEAAoE;IACpE,8DAA8D;IAC9D,OAAO,kCAAkC,CAAC;QACxC,GAAG,MAAM;QACT,OAAO,EAAE,CAAC,UAAU,CAAC;KACtB,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { formElementsService, typeCastService } from '@oneblink/sdk-core'\nimport { localisationService } from '@oneblink/apps'\nimport { v4 as uuidv4 } from 'uuid'\nimport { MiscTypes } from '@oneblink/types'\nimport { TaskContext } from '../hooks/useTaskContext'\n\ntype Option = Pick<FormTypes.ChoiceElementOption, 'value' | 'label'>\n\nfunction processInjectableDynamicOption({\n option,\n submission,\n formElements,\n ...params\n}: {\n option: Option\n submission: SubmissionTypes.S3SubmissionData['submission']\n formElements: FormTypes.FormElement[]\n taskContext: TaskContext\n userProfile: MiscTypes.UserProfile | undefined\n}): Map<string, string> {\n const newOptions: Map<string, string> = new Map()\n\n // Replace root level form element values\n const replaceableParams: Parameters<\n typeof localisationService.replaceInjectablesWithElementValues\n >[1] = {\n ...params,\n submission,\n formElements,\n task: params.taskContext.task,\n taskGroup: params.taskContext.taskGroup,\n taskGroupInstance: params.taskContext.taskGroupInstance,\n excludeNestedElements: true,\n }\n const {\n text: label,\n hadAllInjectablesReplaced: hadAllInjectablesReplacedInLabel,\n } = localisationService.replaceInjectablesWithElementValues(\n option.label,\n replaceableParams,\n )\n if (!hadAllInjectablesReplacedInLabel) {\n return newOptions\n }\n\n const {\n text: value,\n hadAllInjectablesReplaced: hadAllInjectablesReplacedInValue,\n } = localisationService.replaceInjectablesWithElementValues(\n option.value,\n replaceableParams,\n )\n if (!hadAllInjectablesReplacedInValue) {\n return newOptions\n }\n\n // Find nested form elements\n const matches: Map<string, boolean> = new Map()\n formElementsService.matchElementsTagRegex(\n {\n text: label + ' ' + value,\n excludeNestedElements: false,\n },\n ({ elementName }) => {\n const [repeatableSetElementName, ...elementNames] = elementName.split('|')\n matches.set(repeatableSetElementName, !!elementNames.length)\n },\n )\n\n if (matches.size) {\n matches.forEach((hasNestedFormElements, repeatableSetElementName) => {\n if (hasNestedFormElements) {\n // Attempt to create a new option for each entry in the repeatable set.\n const entries = submission?.[repeatableSetElementName]\n if (Array.isArray(entries)) {\n const repeatableSetElement = formElementsService.findFormElement(\n formElements,\n (formElement) => {\n return (\n 'name' in formElement &&\n formElement.name === repeatableSetElementName\n )\n },\n )\n if (\n repeatableSetElement &&\n 'elements' in repeatableSetElement &&\n Array.isArray(repeatableSetElement.elements)\n ) {\n for (const entry of entries) {\n const nestedOptions = processInjectableDynamicOption({\n ...params,\n option: {\n label: label.replaceAll(\n `{ELEMENT:${repeatableSetElementName}|`,\n '{ELEMENT:',\n ),\n value: value.replaceAll(\n `{ELEMENT:${repeatableSetElementName}|`,\n '{ELEMENT:',\n ),\n },\n submission: entry,\n formElements: repeatableSetElement.elements,\n })\n if (nestedOptions.size) {\n nestedOptions.forEach((nestedLabel, nestedValue) => {\n if (!newOptions.has(nestedValue)) {\n newOptions.set(nestedValue, nestedLabel)\n }\n })\n }\n }\n }\n }\n }\n })\n } else {\n newOptions.set(value, label)\n }\n\n return newOptions\n}\n\nexport default function processInjectableOption({\n option,\n submission,\n formElements,\n taskContext,\n userProfile,\n}: {\n option: FormTypes.ChoiceElementOption\n submission: SubmissionTypes.S3SubmissionData['submission']\n formElements: FormTypes.FormElement[]\n taskContext: TaskContext\n userProfile: MiscTypes.UserProfile | undefined\n}): FormTypes.ChoiceElementOption[] {\n const options = processInjectableDynamicOption({\n option,\n submission,\n formElements,\n taskContext,\n userProfile,\n })\n\n const generatedOptions: FormTypes.ChoiceElementOption[] = []\n\n options.forEach((label, value) => {\n generatedOptions.push({\n ...option,\n id: options.size === 1 ? option.id : uuidv4(),\n label,\n value,\n })\n })\n\n return generatedOptions\n}\n\nfunction injectOptionsAcrossEntriesElements({\n elements,\n entries,\n taskContext,\n userProfile,\n}: {\n elements: FormTypes.FormElement[]\n entries: SubmissionTypes.S3SubmissionData['submission'][]\n taskContext: TaskContext\n userProfile: MiscTypes.UserProfile | undefined\n}): FormTypes.FormElement[] {\n return elements.map<FormTypes.FormElement>((e) => {\n switch (e.type) {\n case 'page':\n case 'section': {\n return {\n ...e,\n elements: injectOptionsAcrossEntriesElements({\n elements: e.elements,\n entries,\n taskContext,\n userProfile,\n }),\n }\n }\n case 'form': {\n if (Array.isArray(e.elements)) {\n return {\n ...e,\n elements: injectOptionsAcrossEntriesElements({\n elements: e.elements,\n entries: entries.reduce<\n SubmissionTypes.S3SubmissionData['submission'][]\n >((memo, entry) => {\n if (entry[e.name]) {\n memo.push(\n entry[\n e.name\n ] as SubmissionTypes.S3SubmissionData['submission'],\n )\n }\n return memo\n }, []),\n taskContext,\n userProfile,\n }),\n }\n } else {\n return e\n }\n }\n case 'repeatableSet': {\n return {\n ...e,\n elements: injectOptionsAcrossEntriesElements({\n elements: e.elements,\n entries: entries.reduce<\n SubmissionTypes.S3SubmissionData['submission'][]\n >((memo, entry) => {\n const nestedEntries = entry[e.name]\n if (Array.isArray(nestedEntries)) {\n memo.push(\n ...(nestedEntries as SubmissionTypes.S3SubmissionData['submission'][]),\n )\n }\n return memo\n }, []),\n taskContext,\n userProfile,\n }),\n }\n }\n default: {\n const optionsElement = typeCastService.formElements.toOptionsElement(e)\n if (optionsElement) {\n return {\n ...optionsElement,\n options: entries.reduce<FormTypes.ChoiceElementOption[]>(\n (newOptions, submission) => {\n optionsElement.options?.forEach((o) => {\n const injected = processInjectableOption({\n option: o,\n submission,\n formElements: elements,\n taskContext,\n userProfile,\n })\n\n newOptions.push(\n ...injected.filter((generatedOption) => {\n return !newOptions.some(\n (addedOption) =>\n addedOption.value === generatedOption.value,\n )\n }),\n )\n })\n return newOptions\n },\n [],\n ),\n }\n }\n return e\n }\n }\n })\n}\n\nexport function injectOptionsAcrossAllElements({\n submission,\n ...params\n}: {\n elements: FormTypes.FormElement[]\n submission: SubmissionTypes.S3SubmissionData['submission']\n taskContext: TaskContext\n userProfile: MiscTypes.UserProfile | undefined\n}): FormTypes.FormElement[] {\n // We iterate over entries as an array of submission objects because\n // child elements of a repeatable set that have injected options\n // need to include all of the injected options from the same elements\n // in sibling entries within the set. Otherwise we will not have the\n // labels for each available option to display the submission.\n return injectOptionsAcrossEntriesElements({\n ...params,\n entries: [submission],\n })\n}\n"]}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@oneblink/apps-react",
|
3
3
|
"description": "Helper functions for OneBlink apps in ReactJS.",
|
4
|
-
"version": "5.11.0-beta.
|
4
|
+
"version": "5.11.0-beta.3",
|
5
5
|
"author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
|
6
6
|
"bugs": {
|
7
7
|
"url": "https://github.com/oneblink/apps-react/issues"
|
@@ -11,7 +11,7 @@
|
|
11
11
|
"@emotion/react": "^11.11.3",
|
12
12
|
"@emotion/styled": "^11.11.0",
|
13
13
|
"@mui/icons-material": "^5.15.6",
|
14
|
-
"@oneblink/sdk-core": "^6.0.0-beta.
|
14
|
+
"@oneblink/sdk-core": "^6.0.0-beta.3",
|
15
15
|
"@react-google-maps/api": "2.19.2",
|
16
16
|
"blueimp-load-image": "^5.16.0",
|
17
17
|
"bulma": "^0.9.4",
|