pict-section-form 1.3.15 → 1.3.16

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 (47) hide show
  1. package/docs/Providers.md +12 -7
  2. package/docs/_sidebar.md +2 -0
  3. package/docs/input_providers/016-facet-filter.md +106 -0
  4. package/docs/input_providers/README.md +1 -0
  5. package/example_applications/README.md +6 -0
  6. package/example_applications/facet_filter/.quackage.json +9 -0
  7. package/example_applications/facet_filter/Facet-Filter-Application.js +210 -0
  8. package/example_applications/facet_filter/Facet-Filter-Server.js +233 -0
  9. package/example_applications/facet_filter/Facet-Filter-Smoke-Runner.js +101 -0
  10. package/example_applications/facet_filter/FacetFilterData.json +44 -0
  11. package/example_applications/facet_filter/README-FacetFilter.md +70 -0
  12. package/example_applications/facet_filter/html/Facet-Filter-Smoke.js +128 -0
  13. package/example_applications/facet_filter/html/index.html +74 -0
  14. package/example_applications/facet_filter/package.json +27 -0
  15. package/example_applications/nested_distill_sandbox/Sandbox-Driver-Headlight.js +17 -0
  16. package/example_applications/nested_distill_sandbox/Sandbox-Driver.js +369 -0
  17. package/example_applications/nested_distill_sandbox/Sandbox-Runner.js +372 -0
  18. package/example_applications/nested_distill_sandbox/approaches/A1-tabular-trigger-group.js +67 -0
  19. package/example_applications/nested_distill_sandbox/approaches/A3-crossmap-selectoptionsrefresh.js +61 -0
  20. package/example_applications/nested_distill_sandbox/approaches/A4-graph-solvers-flat-list.js +53 -0
  21. package/example_applications/nested_distill_sandbox/approaches/A5-facet-filter.js +75 -0
  22. package/example_applications/nested_distill_sandbox/approaches/A5b-facet-filter-symmetric.js +15 -0
  23. package/example_applications/nested_distill_sandbox/approaches/A5h-facet-filter-headlight-picker.js +15 -0
  24. package/example_applications/nested_distill_sandbox/approaches/R0-original-jmf-manifest-headlight.js +27 -0
  25. package/example_applications/nested_distill_sandbox/approaches/R1-real-jmf-manifest-headlight.js +136 -0
  26. package/example_applications/nested_distill_sandbox/approaches/_Common.js +344 -0
  27. package/example_applications/nested_distill_sandbox/approaches/_Scenarios.js +262 -0
  28. package/package.json +1 -1
  29. package/source/providers/Pict-Provider-DynamicSolver.js +2 -0
  30. package/source/providers/Pict-Provider-ListDistilling.js +266 -1
  31. package/source/providers/Pict-Provider-MetaLists.js +16 -2
  32. package/source/providers/inputs/Pict-Provider-Input-FacetFilter.js +232 -0
  33. package/source/providers/inputs/Pict-Provider-Input-Select.js +41 -1
  34. package/source/views/Pict-View-Form-Metacontroller.js +5 -3
  35. package/test/Pict-Provider-ListDistilling-Facet_tests.js +375 -0
  36. package/test/PictSectionForm-Injection-Conformance_tests.js +11 -0
  37. package/test/fixtures/injection/Injection-Fixture-Cases.js +1 -0
  38. package/test/fixtures/injection/Injection-Fixture-Manifest.json +15 -0
  39. package/types/source/providers/Pict-Provider-DynamicSolver.d.ts.map +1 -1
  40. package/types/source/providers/Pict-Provider-ListDistilling.d.ts +90 -1
  41. package/types/source/providers/Pict-Provider-ListDistilling.d.ts.map +1 -1
  42. package/types/source/providers/Pict-Provider-MetaLists.d.ts.map +1 -1
  43. package/types/source/providers/inputs/Pict-Provider-Input-FacetFilter.d.ts +103 -0
  44. package/types/source/providers/inputs/Pict-Provider-Input-FacetFilter.d.ts.map +1 -0
  45. package/types/source/providers/inputs/Pict-Provider-Input-Select.d.ts +12 -0
  46. package/types/source/providers/inputs/Pict-Provider-Input-Select.d.ts.map +1 -1
  47. package/types/source/views/Pict-View-Form-Metacontroller.d.ts.map +1 -1
@@ -0,0 +1,262 @@
1
+ /*
2
+ The user stories every approach is scored on. An approach declares which behaviours it claims
3
+ (pCapabilities); a check for a behaviour it does not claim is reported as [known], not [fail].
4
+ */
5
+
6
+ const libCommon = require('./_Common.js');
7
+
8
+ const SUMMARY_ADDRESS = `${libCommon.MARSHAL_ROOT}.FormulaData.AggregateBlendGsb`;
9
+
10
+ /**
11
+ * @param {Record<string, any>} pFixtures
12
+ * @param {Record<string, boolean>} pCapabilities
13
+ * @param {Array<string>} pSelectColumns
14
+ * @return {Array<Record<string, any>>}
15
+ */
16
+ function scenarios(pFixtures, pCapabilities, pSelectColumns)
17
+ {
18
+ const tmpCan = (pKey) => (pCapabilities[pKey] === false) ? false : undefined;
19
+ const tmpState = pFixtures.StateGraph;
20
+ const tmpAllPits = libCommon.distinctStrings(tmpState.map((pRow) => pRow.PitNumber));
21
+ const tmpProductA = pFixtures.UniquePitProduct;
22
+ const tmpProductB = pFixtures.ProductElsewhere;
23
+ const tmpProductC = tmpState.find((pRow) => (pRow.Gsb !== undefined) && (pRow.IDProduct !== tmpProductA.IDProduct) && (pRow.IDProduct !== tmpProductB.IDProduct) && (pRow.Site !== tmpProductA.Site) && (pRow.Site !== tmpProductB.Site));
24
+ const tmpHasSelect = (pColumn) => pSelectColumns.indexOf(pColumn) >= 0;
25
+ const fRowMatches = (pRow, pProduct) => pRow && (String(pRow.Data.Material) === String(pProduct.IDProduct)) && (pRow.Data.Site === pProduct.Site) && (String(pRow.Data.PitNumber) === String(pProduct.PitNumber)) && ((pProduct.Gsb === undefined) ? ((pRow.Data.Gsb === undefined) || (pRow.Data.Gsb === '')) : (Number(pRow.Data.Gsb) === Number(pProduct.Gsb)));
26
+ const fSummaryHas = (pSnapshot, pProduct) => (pProduct.Gsb === undefined) || (String(pSnapshot.Probe[SUMMARY_ADDRESS] || '').split(',').indexOf(String(pProduct.Gsb)) >= 0);
27
+ const fIntegrity = (pResults, pGraph) => libCommon.integrityChecks(pResults, pGraph, pSelectColumns, tmpCan('Integrity'));
28
+
29
+ const tmpScenarios = [];
30
+
31
+ tmpScenarios.push(
32
+ {
33
+ Name: 'product-first',
34
+ Script:
35
+ [
36
+ { Action: 'choose', Row: 1, Column: 'Material', Value: String(tmpProductB.IDProduct), SettleMs: 0, Label: 'choose product' },
37
+ { Action: 'snapshot', Label: 'immediate' },
38
+ { Action: 'wait', Ms: 600 },
39
+ { Action: 'snapshot', Label: 'settled' },
40
+ ],
41
+ checks: (pResults, pFixtures2, pGraph) =>
42
+ {
43
+ const tmpImmediate = libCommon.snapshot(pResults, 'immediate');
44
+ const tmpSettled = libCommon.snapshot(pResults, 'settled');
45
+ return (
46
+ [
47
+ libCommon.check('choosing a product fills its Site, Pit and Gsb into that row', fRowMatches(tmpSettled.Rows[1], tmpProductB), tmpSettled.Rows[1].Data, tmpCan('AutofillFromProduct')),
48
+ libCommon.check('the fill is in place in the same solve (no lag)', fRowMatches(tmpImmediate.Rows[1], tmpProductB), tmpImmediate.Rows[1].Data, tmpCan('NoLag')),
49
+ libCommon.check('the form-level summary sees the new row values in the same solve', fSummaryHas(tmpImmediate, tmpProductB), tmpImmediate.Probe, tmpCan('NoLag')),
50
+ libCommon.check('the summary is right once settled', fSummaryHas(tmpSettled, tmpProductB), tmpSettled.Probe, tmpCan('AutofillFromProduct')),
51
+ libCommon.check('other rows are untouched', [ 0, 2, 3 ].every((pIndex) => !tmpSettled.Rows[pIndex].Data.Material && !tmpSettled.Rows[pIndex].Data.Site), [ 0, 2, 3 ].map((pIndex) => tmpSettled.Rows[pIndex].Data), tmpCan('RowIsolation')),
52
+ ].concat(fIntegrity(pResults, pGraph)));
53
+ }
54
+ });
55
+
56
+ if (tmpHasSelect('Site'))
57
+ {
58
+ tmpScenarios.push(
59
+ {
60
+ Name: 'site-first',
61
+ Script:
62
+ [
63
+ { Action: 'choose', Row: 0, Column: 'Site', Value: pFixtures.MultiPitSite, Label: 'choose site' },
64
+ { Action: 'snapshot', Label: 'site' },
65
+ { Action: 'choose', Row: 0, Column: 'PitNumber', Value: pFixtures.UniquePit, Label: 'choose pit' },
66
+ { Action: 'snapshot', Label: 'pit' },
67
+ ],
68
+ checks: (pResults, pFixtures2, pGraph) =>
69
+ {
70
+ const tmpSite = libCommon.snapshot(pResults, 'site');
71
+ const tmpPit = libCommon.snapshot(pResults, 'pit');
72
+ const tmpProductsAtSite = libCommon.matching(tmpState, { Site: pFixtures.MultiPitSite }).map((pRow) => pRow.IDProduct);
73
+ return (
74
+ [
75
+ libCommon.check('the Pit list narrows to the pits at the chosen Site', libCommon.sameSet(tmpSite.Rows[0].Options.PitNumber, pFixtures.PitsOfMultiPitSite), { Offered: tmpSite.Rows[0].Options.PitNumber, Expected: pFixtures.PitsOfMultiPitSite }, tmpCan('NarrowByRow')),
76
+ libCommon.check('the Product list narrows to the products at the chosen Site', libCommon.sameSet(tmpSite.Rows[0].Options.Material, tmpProductsAtSite), { Offered: (tmpSite.Rows[0].Options.Material || []).length, Expected: tmpProductsAtSite.length }, tmpCan('NarrowByRow')),
77
+ libCommon.check('another row\'s Pit list is not narrowed by this row', libCommon.sameSet(tmpSite.Rows[1].Options.PitNumber, tmpAllPits), { Offered: (tmpSite.Rows[1].Options.PitNumber || []).length, Expected: tmpAllPits.length }, tmpCan('RowIsolation')),
78
+ libCommon.check('a Pit with exactly one product at that Site fills the product', fRowMatches(tmpPit.Rows[0], tmpProductA), tmpPit.Rows[0].Data, tmpCan('AutofillUnique')),
79
+ libCommon.check('the summary sees the filled product in the same solve', fSummaryHas(tmpPit, tmpProductA), tmpPit.Probe, tmpCan('AutofillUnique')),
80
+ ].concat(fIntegrity(pResults, pGraph)));
81
+ }
82
+ });
83
+ }
84
+
85
+ if (tmpHasSelect('Site') && pFixtures.MultiProductPit)
86
+ {
87
+ tmpScenarios.push(
88
+ {
89
+ Name: 'pit-with-several-products',
90
+ Script:
91
+ [
92
+ { Action: 'choose', Row: 2, Column: 'PitNumber', Value: pFixtures.MultiProductPit, Label: 'choose pit' },
93
+ { Action: 'snapshot', Label: 'pit' },
94
+ ],
95
+ checks: (pResults, pFixtures2, pGraph) =>
96
+ {
97
+ const tmpPit = libCommon.snapshot(pResults, 'pit');
98
+ const tmpProducts = libCommon.matching(tmpState, { PitNumber: pFixtures.MultiProductPit });
99
+ const tmpSites = libCommon.distinctStrings(tmpProducts.map((pRow) => pRow.Site));
100
+ return (
101
+ [
102
+ libCommon.check('an ambiguous Pit leaves the product blank', !tmpPit.Rows[2].Data.Material, tmpPit.Rows[2].Data, tmpCan('AutofillUnique')),
103
+ libCommon.check('the Product list narrows to that Pit\'s products', libCommon.sameSet(tmpPit.Rows[2].Options.Material, tmpProducts.map((pRow) => pRow.IDProduct)), { Offered: (tmpPit.Rows[2].Options.Material || []).length, Expected: tmpProducts.length }, tmpCan('NarrowByRow')),
104
+ libCommon.check((tmpSites.length === 1) ? 'a Pit found at exactly one Site fills the Site' : 'a Pit found at several Sites leaves the Site blank', (tmpSites.length === 1) ? (tmpPit.Rows[2].Data.Site === tmpSites[0]) : !tmpPit.Rows[2].Data.Site, tmpPit.Rows[2].Data, tmpCan('AutofillUnique')),
105
+ ].concat(fIntegrity(pResults, pGraph)));
106
+ }
107
+ });
108
+ }
109
+
110
+ tmpScenarios.push(
111
+ {
112
+ Name: 'change-site-after-product',
113
+ Script: tmpHasSelect('Site') ?
114
+ [
115
+ { Action: 'choose', Row: 0, Column: 'Material', Value: String(tmpProductA.IDProduct), Label: 'choose product' },
116
+ { Action: 'wait', Ms: 400 },
117
+ { Action: 'choose', Row: 0, Column: 'Site', Value: pFixtures.OtherSite, Label: 'change site' },
118
+ { Action: 'wait', Ms: 400 },
119
+ { Action: 'snapshot', Label: 'changed' },
120
+ ] :
121
+ [
122
+ { Action: 'choose', Row: 0, Column: 'Material', Value: String(tmpProductA.IDProduct), Label: 'choose product' },
123
+ { Action: 'wait', Ms: 400 },
124
+ { Action: 'choose', Row: 0, Column: 'Material', Value: String(tmpProductB.IDProduct), Label: 'change product' },
125
+ { Action: 'wait', Ms: 400 },
126
+ { Action: 'snapshot', Label: 'changed' },
127
+ ],
128
+ checks: (pResults, pFixtures2, pGraph) =>
129
+ {
130
+ const tmpChanged = libCommon.snapshot(pResults, 'changed');
131
+ const tmpRow = tmpChanged.Rows[0].Data;
132
+ const tmpChecks = [];
133
+ if (tmpHasSelect('Site'))
134
+ {
135
+ tmpChecks.push(libCommon.check('changing the Site keeps the new Site and drops the product that is not there', (tmpRow.Site === pFixtures.OtherSite) && (!tmpRow.Material || (libCommon.matching(tmpState, { Site: tmpRow.Site, IDProduct: tmpRow.Material }).length > 0)), tmpRow, tmpCan('ClearOnChange')));
136
+ }
137
+ else
138
+ {
139
+ tmpChecks.push(libCommon.check('changing the product re-derives Site, Pit and Gsb', fRowMatches(tmpChanged.Rows[0], tmpProductB), tmpRow, tmpCan('AutofillFromProduct')));
140
+ }
141
+ return tmpChecks.concat(fIntegrity(pResults, pGraph));
142
+ }
143
+ });
144
+
145
+ tmpScenarios.push(
146
+ {
147
+ Name: 'delete-row',
148
+ Script:
149
+ [
150
+ { Action: 'addRow' },
151
+ { Action: 'wait', Ms: 100 },
152
+ { Action: 'choose', Row: 0, Column: 'Material', Value: String(tmpProductA.IDProduct) },
153
+ { Action: 'wait', Ms: 400 },
154
+ { Action: 'choose', Row: 1, Column: 'Material', Value: String(tmpProductB.IDProduct) },
155
+ { Action: 'wait', Ms: 400 },
156
+ { Action: 'choose', Row: 2, Column: 'Material', Value: String(tmpProductC.IDProduct) },
157
+ { Action: 'wait', Ms: 400 },
158
+ { Action: 'deleteRow', Row: 0 },
159
+ { Action: 'wait', Ms: 200 },
160
+ { Action: 'snapshot', Label: 'deleted' },
161
+ { Action: 'choose', Row: 2, Column: 'Material', Value: String(tmpProductA.IDProduct), Label: 'choose after delete' },
162
+ { Action: 'wait', Ms: 600 },
163
+ { Action: 'snapshot', Label: 'after' },
164
+ ],
165
+ checks: (pResults, pFixtures2, pGraph) =>
166
+ {
167
+ const tmpDeleted = libCommon.snapshot(pResults, 'deleted');
168
+ const tmpAfter = libCommon.snapshot(pResults, 'after');
169
+ return (
170
+ [
171
+ libCommon.check('rows shift up intact after a delete', fRowMatches(tmpDeleted.Rows[0], tmpProductB) && fRowMatches(tmpDeleted.Rows[1], tmpProductC), tmpDeleted.Rows.map((pRow) => pRow.Data), tmpCan('AutofillFromProduct')),
172
+ libCommon.check('a pick after the delete fills the row it was made in', fRowMatches(tmpAfter.Rows[2], tmpProductA), tmpAfter.Rows[2].Data, tmpCan('RowIdentity')),
173
+ libCommon.check('...and leaves the other rows alone', fRowMatches(tmpAfter.Rows[0], tmpProductB) && fRowMatches(tmpAfter.Rows[1], tmpProductC), [ tmpAfter.Rows[0].Data, tmpAfter.Rows[1].Data ], tmpCan('RowIdentity')),
174
+ ].concat(fIntegrity(pResults, pGraph)));
175
+ }
176
+ });
177
+
178
+ if (pFixtures.ExpiredProduct)
179
+ {
180
+ const tmpExpired = pFixtures.ExpiredProduct;
181
+ const tmpSavedRows =
182
+ [
183
+ { Material: String(tmpExpired.IDProduct), Site: tmpExpired.Metadata.Current.Site, PitNumber: tmpExpired.Metadata.PitNumber, BlendPct: '40.0', Gsb: '2.500', DesignYear: 2019 },
184
+ { Material: String(tmpProductB.IDProduct), Site: tmpProductB.Site, PitNumber: tmpProductB.PitNumber, BlendPct: '60.0' },
185
+ {}, {},
186
+ ];
187
+ tmpScenarios.push(
188
+ {
189
+ Name: 'saved-document-with-expired-product',
190
+ AppData: libCommon.appData(tmpSavedRows),
191
+ Script:
192
+ [
193
+ { Action: 'snapshot', Label: 'opened' },
194
+ { Action: 'choose', Row: 2, Column: 'Material', Value: String(tmpProductA.IDProduct), Label: 'edit another row' },
195
+ { Action: 'wait', Ms: 600 },
196
+ { Action: 'snapshot', Label: 'edited' },
197
+ ],
198
+ checks: (pResults, pFixtures2, pGraph) =>
199
+ {
200
+ const tmpOpened = libCommon.snapshot(pResults, 'opened');
201
+ const tmpEdited = libCommon.snapshot(pResults, 'edited');
202
+ const tmpRow = tmpEdited.Rows[0];
203
+ return (
204
+ [
205
+ libCommon.check('the expired product still shows on the saved row', !tmpHasSelect('Material') || (String(tmpOpened.Rows[0].Shown.Material) === String(tmpExpired.IDProduct)), tmpOpened.Rows[0], tmpCan('SavedValues')),
206
+ libCommon.check('the saved row keeps its product, Site and Pit after other edits', (String(tmpRow.Data.Material) === String(tmpExpired.IDProduct)) && (tmpRow.Data.Site === tmpExpired.Metadata.Current.Site), tmpRow.Data, tmpCan('SavedValues')),
207
+ libCommon.check('values carried at save time are kept, not re-derived from today\'s catalog', (String(tmpRow.Data.Gsb) === '2.500') && (String(tmpRow.Data.DesignYear) === '2019'), tmpRow.Data, tmpCan('SnapshotCarry')),
208
+ ].concat(fIntegrity(pResults, pGraph)));
209
+ }
210
+ });
211
+ }
212
+
213
+ tmpScenarios.push(
214
+ {
215
+ Name: 'clear-product',
216
+ Script:
217
+ [
218
+ { Action: 'choose', Row: 0, Column: 'Material', Value: String(tmpProductA.IDProduct) },
219
+ { Action: 'wait', Ms: 400 },
220
+ { Action: 'choose', Row: 0, Column: 'Material', Value: '', Label: 'clear product' },
221
+ { Action: 'wait', Ms: 400 },
222
+ { Action: 'snapshot', Label: 'cleared' },
223
+ ],
224
+ checks: (pResults, pFixtures2, pGraph) =>
225
+ {
226
+ const tmpRow = libCommon.snapshot(pResults, 'cleared').Rows[0].Data;
227
+ return (
228
+ [
229
+ libCommon.check('a cleared product stays cleared', !tmpRow.Material, tmpRow, tmpCan('Clear')),
230
+ libCommon.check('...and its carried values go with it', !tmpRow.Gsb && !tmpRow.DesignYear && !tmpRow.Producer, tmpRow, tmpCan('Clear')),
231
+ ].concat(fIntegrity(pResults, pGraph)));
232
+ }
233
+ });
234
+
235
+ tmpScenarios.push(
236
+ {
237
+ Name: 'add-row',
238
+ Script:
239
+ [
240
+ { Action: 'addRow' },
241
+ { Action: 'wait', Ms: 200 },
242
+ { Action: 'snapshot', Label: 'added' },
243
+ { Action: 'choose', Row: 4, Column: 'Material', Value: String(tmpProductB.IDProduct) },
244
+ { Action: 'wait', Ms: 600 },
245
+ { Action: 'snapshot', Label: 'filled' },
246
+ ],
247
+ checks: (pResults, pFixtures2, pGraph) =>
248
+ {
249
+ const tmpAdded = libCommon.snapshot(pResults, 'added');
250
+ const tmpFilled = libCommon.snapshot(pResults, 'filled');
251
+ return (
252
+ [
253
+ libCommon.check('a new row offers the state\'s products', (tmpAdded.Rows[4] && (tmpAdded.Rows[4].Options.Material || []).length) >= tmpState.length, tmpAdded.Rows[4] && (tmpAdded.Rows[4].Options.Material || []).length, tmpCan('AddRow')),
254
+ libCommon.check('a new row fills like any other', fRowMatches(tmpFilled.Rows[4], tmpProductB), tmpFilled.Rows[4] && tmpFilled.Rows[4].Data, tmpCan('AddRow')),
255
+ ].concat(fIntegrity(pResults, pGraph)));
256
+ }
257
+ });
258
+
259
+ return tmpScenarios;
260
+ }
261
+
262
+ module.exports = { scenarios, SUMMARY_ADDRESS };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pict-section-form",
3
- "version": "1.3.15",
3
+ "version": "1.3.16",
4
4
  "description": "Pict dynamic forms",
5
5
  "main": "source/Pict-Section-Form.js",
6
6
  "directories": {
@@ -20,6 +20,7 @@ const libInputTemplatedEntityLookup = require('./inputs/Pict-Provider-Input-Temp
20
20
  const libInputChart = require('./inputs/Pict-Provider-Input-Chart.js');
21
21
  const libInputTabularTriggerGroup = require('./inputs/Pict-Provider-Input-TabularTriggerGroup.js');
22
22
  const libInputObjectEditor = require('./inputs/Pict-Provider-Input-ObjectEditor.js');
23
+ const libInputFacetFilter = require('./inputs/Pict-Provider-Input-FacetFilter.js');
23
24
 
24
25
  /** @type {Record<string, any>} */
25
26
  const _DefaultProviderConfiguration = (
@@ -84,6 +85,7 @@ class PictDynamicSolver extends libPictProvider
84
85
  this.pict.addProviderSingleton('Pict-Input-Chart', libInputChart.default_configuration, libInputChart);
85
86
  this.pict.addProviderSingleton('Pict-Input-TabularTriggerGroup', libInputTabularTriggerGroup.default_configuration, libInputTabularTriggerGroup);
86
87
  this.pict.addProviderSingleton('Pict-Input-ObjectEditor', libInputObjectEditor.default_configuration, libInputObjectEditor);
88
+ this.pict.addProviderSingleton('Pict-Input-FacetFilter', libInputFacetFilter.default_configuration, libInputFacetFilter);
87
89
  }
88
90
 
89
91
  logSolveOutcome(pSolveOutcome)
@@ -81,9 +81,10 @@ class PictListDistilling extends libPictProvider
81
81
  * @param {Object} pView - The pict view the list is within
82
82
  * @param {*} pInput - The input within the dynamic forms view
83
83
  * @param {*} pList - The raw list of options to filter
84
+ * @param {number} [pRowIndex] - The tabular row the list is for; Facet rules read sibling values from this row
84
85
  * @returns
85
86
  */
86
- filterList(pView, pInput, pList)
87
+ filterList(pView, pInput, pList, pRowIndex)
87
88
  {
88
89
  // The list is expected to be an array of objects with "id" and "text" properties. This is because of Select2.
89
90
  if (typeof(pInput) != 'object')
@@ -107,6 +108,9 @@ class PictListDistilling extends libPictProvider
107
108
  return pList;
108
109
  }
109
110
 
111
+ // Facet rules resolve to a set of allowed values once per list build rather than once per option.
112
+ const tmpFacetAllowedValues = tmpFilterRules.map((pRule) => (pRule && (pRule.FilterType === 'Facet')) ? this.getFacetOfferedValues(pView, pInput, pRule, pRowIndex) : null);
113
+
110
114
  // Make a copy of the incoming list of options
111
115
  let tmpFilteredList = pList.slice(0);
112
116
  // We walk backwards so we can remove items from the end without breaking this loop.
@@ -295,6 +299,13 @@ class PictListDistilling extends libPictProvider
295
299
 
296
300
  break;
297
301
 
302
+ case 'Facet':
303
+ if (tmpFacetAllowedValues[i] && !tmpFacetAllowedValues[i].has(String(tmpComparisonValue)))
304
+ {
305
+ tmpEntryAllowed = false;
306
+ }
307
+ break;
308
+
298
309
  default:
299
310
  // See if there is a provider for it
300
311
  let tmpProvider = this.pict.providers[tmpFilterRule.FilterType];
@@ -318,6 +329,260 @@ class PictListDistilling extends libPictProvider
318
329
 
319
330
  return tmpFilteredList;
320
331
  }
332
+
333
+ /**
334
+ * @param {Record<string, any>} pInput
335
+ * @return {Record<string, any>|null} the input's Facet rule, if it has one
336
+ */
337
+ getFacetRule(pInput)
338
+ {
339
+ const tmpRules = pInput && pInput.PictForm && pInput.PictForm.ListFilterRules;
340
+ if (!Array.isArray(tmpRules))
341
+ {
342
+ return null;
343
+ }
344
+ return tmpRules.find((pRule) => pRule && (pRule.FilterType === 'Facet')) || null;
345
+ }
346
+
347
+ /**
348
+ * @param {Object} pView
349
+ * @param {Record<string, any>} pRule
350
+ * @return {Array<any>} the join list a Facet rule distills, as an array
351
+ */
352
+ getFacetJoinList(pView, pRule)
353
+ {
354
+ let tmpJoinList;
355
+ if (pRule.JoinListAddressGlobal)
356
+ {
357
+ const tmpAddressSpace = { Fable: this.pict, Pict: this.pict, AppData: this.pict.AppData, Bundle: this.pict.Bundle, View: pView };
358
+ tmpJoinList = this.pict.manifest.getValueAtAddress(tmpAddressSpace, pRule.JoinListAddress);
359
+ }
360
+ else
361
+ {
362
+ tmpJoinList = pView.getValueByHash(pRule.JoinListAddress);
363
+ }
364
+ if (Array.isArray(tmpJoinList))
365
+ {
366
+ return tmpJoinList;
367
+ }
368
+ if (tmpJoinList && (typeof(tmpJoinList) === 'object'))
369
+ {
370
+ return Object.values(tmpJoinList);
371
+ }
372
+ return [];
373
+ }
374
+
375
+ /**
376
+ * Every input that shares a Facet rule's join list with pInput, in the same tabular row (or the same
377
+ * view, outside a table), with the value it currently holds. pInput itself is included.
378
+ *
379
+ * @param {Object} pView
380
+ * @param {Record<string, any>} pInput
381
+ * @param {number} [pRowIndex]
382
+ * @return {Array<{ Input: Record<string, any>, Rule: Record<string, any>, Value: any }>}
383
+ */
384
+ getFacetSiblings(pView, pInput, pRowIndex)
385
+ {
386
+ const tmpRule = this.getFacetRule(pInput);
387
+ if (!tmpRule)
388
+ {
389
+ return [];
390
+ }
391
+ const tmpSiblings = [];
392
+ const fAdd = (pSiblingInput, fGetValue) =>
393
+ {
394
+ const tmpSiblingRule = this.getFacetRule(pSiblingInput);
395
+ if (tmpSiblingRule && (tmpSiblingRule.JoinListAddress === tmpRule.JoinListAddress))
396
+ {
397
+ tmpSiblings.push({ Input: pSiblingInput, Rule: tmpSiblingRule, Value: fGetValue(pSiblingInput) });
398
+ }
399
+ };
400
+ const tmpIsTabular = (typeof(pRowIndex) === 'number') || ((typeof(pRowIndex) === 'string') && (pRowIndex !== ''));
401
+ if (tmpIsTabular)
402
+ {
403
+ const tmpGroupIndex = pInput.PictForm.GroupIndex;
404
+ const tmpGroup = pView.getGroup(tmpGroupIndex);
405
+ const tmpRecord = pView.getTabularRecordData(tmpGroupIndex, pRowIndex) || {};
406
+ const tmpAddresses = (tmpGroup && tmpGroup.supportingManifest) ? tmpGroup.supportingManifest.elementAddresses : [];
407
+ for (let i = 0; i < tmpAddresses.length; i++)
408
+ {
409
+ const tmpSiblingInput = pView.getTabularRecordInput(tmpGroupIndex, i);
410
+ if (tmpSiblingInput)
411
+ {
412
+ fAdd(tmpSiblingInput, (pSibling) => tmpGroup.supportingManifest.getValueByHash(tmpRecord, pSibling.DataAddress || tmpAddresses[i]));
413
+ }
414
+ }
415
+ return tmpSiblings;
416
+ }
417
+ const tmpDescriptors = (pView.sectionManifest && pView.sectionManifest.elementDescriptors) ? pView.sectionManifest.elementDescriptors : {};
418
+ for (const tmpAddress of Object.keys(tmpDescriptors))
419
+ {
420
+ const tmpSiblingInput = tmpDescriptors[tmpAddress];
421
+ if (tmpSiblingInput && tmpSiblingInput.PictForm && !tmpSiblingInput.IsTabular)
422
+ {
423
+ fAdd(tmpSiblingInput, (pSibling) => pView.getValueByHash(pSibling.Hash));
424
+ }
425
+ }
426
+ return tmpSiblings;
427
+ }
428
+
429
+ /**
430
+ * @param {any} pValue
431
+ * @return {boolean}
432
+ */
433
+ isEmptyFacetValue(pValue)
434
+ {
435
+ return (pValue === undefined) || (pValue === null) || (pValue === '');
436
+ }
437
+
438
+ /**
439
+ * The values a Facet rule's dropdown offers: the allowed values (narrowed per the rule's NarrowBy), plus
440
+ * the input's own current value unless KeepCurrentValue is false, so a filter never hides what the row
441
+ * already stores (a saved choice that has since fallen out of scope still shows).
442
+ *
443
+ * @param {Object} pView
444
+ * @param {Record<string, any>} pInput
445
+ * @param {Record<string, any>} pRule - the input's Facet rule
446
+ * @param {number} [pRowIndex]
447
+ * @return {Set<string>}
448
+ */
449
+ getFacetOfferedValues(pView, pInput, pRule, pRowIndex)
450
+ {
451
+ const tmpSiblings = this.getFacetSiblings(pView, pInput, pRowIndex);
452
+ const tmpOffered = this.getFacetAllowedValues(pView, pInput, pRule, pRowIndex, tmpSiblings, pRule.NarrowBy);
453
+ const tmpSelf = tmpSiblings.find((pSibling) => pSibling.Input === pInput);
454
+ if ((pRule.KeepCurrentValue !== false) && tmpSelf && !this.isEmptyFacetValue(tmpSelf.Value))
455
+ {
456
+ tmpOffered.add(String(tmpSelf.Value));
457
+ }
458
+ return tmpOffered;
459
+ }
460
+
461
+ /**
462
+ * @param {any} pJoinValue - the value on the join record
463
+ * @param {string} pOperator - EQ (default), NE, LT, LE, GT or GE
464
+ * @param {string} pValue - the constraint value
465
+ * @return {boolean}
466
+ */
467
+ compareFacetValue(pJoinValue, pOperator, pValue)
468
+ {
469
+ if (!pOperator || (pOperator === 'EQ'))
470
+ {
471
+ return String(pJoinValue) === pValue;
472
+ }
473
+ if (pOperator === 'NE')
474
+ {
475
+ return String(pJoinValue) !== pValue;
476
+ }
477
+ if (this.isEmptyFacetValue(pJoinValue))
478
+ {
479
+ return false;
480
+ }
481
+ // Numbers compare as numbers; anything else compares as text, and a bare YYYY-MM-DD compares against
482
+ // only the date part of an ISO timestamp so a record dated that day is on the day, not after it.
483
+ const tmpNumeric = (pJoinValue !== '') && (pValue !== '') && !isNaN(Number(pJoinValue)) && !isNaN(Number(pValue));
484
+ let tmpLeft = tmpNumeric ? Number(pJoinValue) : String(pJoinValue);
485
+ if (!tmpNumeric && /^\d{4}-\d{2}-\d{2}$/.test(pValue) && /^\d{4}-\d{2}-\d{2}T/.test(tmpLeft))
486
+ {
487
+ tmpLeft = tmpLeft.substring(0, 10);
488
+ }
489
+ const tmpRight = tmpNumeric ? Number(pValue) : pValue;
490
+ switch (pOperator)
491
+ {
492
+ case 'LT':
493
+ return tmpLeft < tmpRight;
494
+ case 'LE':
495
+ return tmpLeft <= tmpRight;
496
+ case 'GT':
497
+ return tmpLeft > tmpRight;
498
+ case 'GE':
499
+ return tmpLeft >= tmpRight;
500
+ default:
501
+ this.log.warn(`Facet constraint operator [${pOperator}] is not supported; the constraint is ignored.`);
502
+ return true;
503
+ }
504
+ }
505
+
506
+ /**
507
+ * The values a Facet rule's input may hold, given what its siblings hold: the distinct
508
+ * JoinListValueAddress values of the join records that agree with every constraining non-empty sibling
509
+ * value and every explicit facet. Empty siblings do not constrain.
510
+ *
511
+ * pNarrowBy picks the constraining siblings: 'All' (default) is every sibling; 'Preceding' is only the
512
+ * siblings before this input (column order in a table), so a list offers every value its upstream
513
+ * choices allow and picking one never needs a downstream value cleared first.
514
+ *
515
+ * @param {Object} pView
516
+ * @param {Record<string, any>} pInput
517
+ * @param {Record<string, any>} pRule - the input's Facet rule
518
+ * @param {number} [pRowIndex]
519
+ * @param {Array<{ Input: Record<string, any>, Rule: Record<string, any>, Value: any }>} [pSiblings] - precomputed siblings (values may be overridden by the caller)
520
+ * @param {string} [pNarrowBy] - 'All' or 'Preceding'
521
+ * @return {Set<string>}
522
+ */
523
+ getFacetAllowedValues(pView, pInput, pRule, pRowIndex, pSiblings, pNarrowBy)
524
+ {
525
+ const tmpAllowed = new Set();
526
+ for (const tmpJoinRecord of this.getFacetMatchingRecords(pView, pInput, pRule, pRowIndex, pSiblings, pNarrowBy))
527
+ {
528
+ const tmpCandidate = this.pict.manifest.getValueAtAddress(tmpJoinRecord, pRule.JoinListValueAddress);
529
+ if (!this.isEmptyFacetValue(tmpCandidate))
530
+ {
531
+ tmpAllowed.add(String(tmpCandidate));
532
+ }
533
+ }
534
+ return tmpAllowed;
535
+ }
536
+
537
+ /**
538
+ * The join records that agree with every constraining non-empty sibling value and every explicit facet;
539
+ * see getFacetAllowedValues for pNarrowBy. pInput's own value does not constrain.
540
+ *
541
+ * @param {Object} pView
542
+ * @param {Record<string, any>} pInput
543
+ * @param {Record<string, any>} pRule - the input's Facet rule
544
+ * @param {number} [pRowIndex]
545
+ * @param {Array<{ Input: Record<string, any>, Rule: Record<string, any>, Value: any }>} [pSiblings]
546
+ * @param {string} [pNarrowBy] - 'All' or 'Preceding'
547
+ * @return {Array<Record<string, any>>}
548
+ */
549
+ getFacetMatchingRecords(pView, pInput, pRule, pRowIndex, pSiblings, pNarrowBy)
550
+ {
551
+ const tmpConstraints = [];
552
+ const tmpSiblings = pSiblings || this.getFacetSiblings(pView, pInput, pRowIndex);
553
+ const tmpOwnIndex = tmpSiblings.findIndex((pSibling) => pSibling.Input === pInput);
554
+ for (let i = 0; i < tmpSiblings.length; i++)
555
+ {
556
+ const tmpSibling = tmpSiblings[i];
557
+ if ((pNarrowBy === 'Preceding') && (tmpOwnIndex >= 0) && (i > tmpOwnIndex))
558
+ {
559
+ continue;
560
+ }
561
+ if ((tmpSibling.Input !== pInput) && !this.isEmptyFacetValue(tmpSibling.Value))
562
+ {
563
+ tmpConstraints.push({ Address: tmpSibling.Rule.JoinListValueAddress, Value: String(tmpSibling.Value) });
564
+ }
565
+ }
566
+ for (const tmpFacet of (Array.isArray(pRule.Facets) ? pRule.Facets : []))
567
+ {
568
+ const tmpValue = ('ValueAddress' in tmpFacet) ? pView.getValueByHash(tmpFacet.ValueAddress) : tmpFacet.Value;
569
+ if (!this.isEmptyFacetValue(tmpValue))
570
+ {
571
+ tmpConstraints.push({ Address: tmpFacet.JoinListValueAddress, Value: String(tmpValue), Operator: tmpFacet.Operator });
572
+ }
573
+ }
574
+ return this.getFacetJoinList(pView, pRule).filter((pJoinRecord) =>
575
+ {
576
+ for (const tmpConstraint of tmpConstraints)
577
+ {
578
+ if (!this.compareFacetValue(this.pict.manifest.getValueAtAddress(pJoinRecord, tmpConstraint.Address), tmpConstraint.Operator, tmpConstraint.Value))
579
+ {
580
+ return false;
581
+ }
582
+ }
583
+ return true;
584
+ });
585
+ }
321
586
  }
322
587
 
323
588
  module.exports = PictListDistilling;
@@ -191,8 +191,17 @@ class PictMetalist extends libPictProvider
191
191
  return false;
192
192
  }
193
193
 
194
- // Now try to fetch the list data
195
- let tmpListData = this.pict.providers.DataBroker.getValueByHash(pListObject.ListSourceAddress);
194
+ // Now try to fetch the list data; a global source reads application state rather than the form data.
195
+ let tmpListData;
196
+ if (pListObject.ListSourceAddressGlobal)
197
+ {
198
+ const tmpAddressSpace = { Fable: this.pict, Pict: this.pict, AppData: this.pict.AppData, Bundle: this.pict.Bundle };
199
+ tmpListData = this.pict.manifest.getValueAtAddress(tmpAddressSpace, pListObject.ListSourceAddress);
200
+ }
201
+ else
202
+ {
203
+ tmpListData = this.pict.providers.DataBroker.getValueByHash(pListObject.ListSourceAddress);
204
+ }
196
205
  if (!tmpListData)
197
206
  {
198
207
  //this.log.warn(`Dynamic MetaList Provider [${this.UUID}]::[${this.Hash}] failed to fetch the list data for PickList [${pListObject.Hash}]. Skipping.`);
@@ -215,6 +224,11 @@ class PictMetalist extends libPictProvider
215
224
 
216
225
  if (!tmpTextString || !tmpIDString)
217
226
  {
227
+ // A list over an optional field (SkipEmpty) expects records without it.
228
+ if (pListObject.SkipEmpty)
229
+ {
230
+ continue;
231
+ }
218
232
  this.log.error(`Dynamic MetaList Provider [${this.UUID}]::[${this.Hash}] failed to generate the Text or ID for PickList [${pListObject.Hash}]. Skipping.`);
219
233
  // this.log.error(`Dynamic MetaList Provider [${this.UUID}]::[${this.Hash}] failed to generate the Text or ID for PickList [${pListObject.Hash}]. Skipping.`, {"Text": tmpTextString, "ID": tmpIDString, "Entry": tmpListEntry});
220
234
  continue;