pict-section-form 1.3.7 → 1.3.8
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.
- package/example_applications/README.md +8 -0
- package/example_applications/section_visibility/.quackage.json +9 -0
- package/example_applications/section_visibility/ProductData.json +21 -0
- package/example_applications/section_visibility/README-SectionVisibility.md +43 -0
- package/example_applications/section_visibility/Section-Visibility-Application.js +201 -0
- package/example_applications/section_visibility/html/index.html +73 -0
- package/example_applications/section_visibility/package.json +34 -0
- package/package.json +1 -1
- package/source/providers/Pict-Provider-DynamicFormSolverBehaviors.js +242 -1
- package/source/views/Pict-View-DynamicForm.js +10 -0
- package/test/Pict-Provider-DynamicFormSolverBehaviors-GroupRender_tests.js +99 -0
- package/test/PictSectionForm-Tabular-Features_tests.js +219 -0
|
@@ -44,6 +44,13 @@ A more complex tabular form example that uses the fruit data again
|
|
|
44
44
|
and performs mathematical solves across each row, and aggregation
|
|
45
45
|
functions down. Single file, all configuration, no code.
|
|
46
46
|
|
|
47
|
+
### Section Visibility
|
|
48
|
+
|
|
49
|
+
A regression harness for solver-driven section and group visibility. Renaming
|
|
50
|
+
a product re-renders every table whose columns are generated from it; the hide
|
|
51
|
+
class lives on an element that render regenerates, so it used to be dropped.
|
|
52
|
+
Single file, all configuration.
|
|
53
|
+
|
|
47
54
|
## Advanced
|
|
48
55
|
|
|
49
56
|
### Postcard
|
|
@@ -66,6 +73,7 @@ gradebook
|
|
|
66
73
|
manifest_testbed
|
|
67
74
|
manyfest_editor
|
|
68
75
|
postcard_example
|
|
76
|
+
section_visibility
|
|
69
77
|
simple_form
|
|
70
78
|
simple_table
|
|
71
79
|
simple_table_from_object
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Workflow":
|
|
3
|
+
{
|
|
4
|
+
"ShowGradation": 0
|
|
5
|
+
},
|
|
6
|
+
|
|
7
|
+
"Products":
|
|
8
|
+
[
|
|
9
|
+
{ "IDProduct": 1, "ProductName": "Limestone 3/4\"" },
|
|
10
|
+
{ "IDProduct": 2, "ProductName": "Natural Sand" },
|
|
11
|
+
{ "IDProduct": 3, "ProductName": "RAP" }
|
|
12
|
+
],
|
|
13
|
+
|
|
14
|
+
"Gradation":
|
|
15
|
+
[
|
|
16
|
+
{ "SieveSize": "1/2\"", "Passing": { "1": 100, "2": 100, "3": 98 } },
|
|
17
|
+
{ "SieveSize": "#4", "Passing": { "1": 42, "2": 96, "3": 71 } },
|
|
18
|
+
{ "SieveSize": "#8", "Passing": { "1": 22, "2": 84, "3": 55 } },
|
|
19
|
+
{ "SieveSize": "#200", "Passing": { "1": 1.8, "2": 4.2, "3": 6.1 } }
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Section Visibility
|
|
2
|
+
|
|
3
|
+
A regression harness for solver-driven section and group visibility surviving a re-render.
|
|
4
|
+
|
|
5
|
+
## What it demonstrates
|
|
6
|
+
|
|
7
|
+
`setsectionvisibility` and `setgroupvisibility` apply a CSS class to `#SECTION-<formID>` and
|
|
8
|
+
`#GROUP-<formID>-<hash>`. Both of those elements are emitted **by the section template**, so a
|
|
9
|
+
`render()` repaints them carrying only their manifest `CSSClass` — and the hide is silently dropped.
|
|
10
|
+
|
|
11
|
+
Nothing used to put it back. Solvers run in the SOLVE phase; the renders that destroy the class
|
|
12
|
+
happen later in the MARSHAL, so a hidden section stayed wrongly visible until some later solve
|
|
13
|
+
happened to run. Adding another `SetSectionVisibility` call in a PostSolver does not help — that is
|
|
14
|
+
still solve-phase, still before the render.
|
|
15
|
+
|
|
16
|
+
The `Average Gradation` table here generates one column per `Products` row, labeled from that row's
|
|
17
|
+
name. Renaming a product is a **label-only** change: the column set is identical, so the Tabular
|
|
18
|
+
layout takes its `namesChanged` path — a `render()` with no template rebuild. That render is what
|
|
19
|
+
destroys the hide.
|
|
20
|
+
|
|
21
|
+
## Reproducing
|
|
22
|
+
|
|
23
|
+
```shell
|
|
24
|
+
npx quack examples
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
1. On load, `Average Gradation` is hidden (`Show Gradation` unchecked).
|
|
28
|
+
2. Rename a product in `Aggregate Products` and tab out.
|
|
29
|
+
3. Before the fix the section reappears with the box still unchecked. After it, the section stays
|
|
30
|
+
hidden and its headers still relabel — tick the box to see the updated column names.
|
|
31
|
+
|
|
32
|
+
`Show Notes` toggles the **Gradation Notes** group inside that same section, which fails and passes the
|
|
33
|
+
same way — tick `Show Gradation` first so the section is visible, then rename a product. The group has to
|
|
34
|
+
live inside a section that actually re-renders; a group in an untouched section is never regenerated.
|
|
35
|
+
|
|
36
|
+
`Flag the #200 Row` covers the same defect one layer down. `highlighttabularrow` puts a class on a `<tr>`
|
|
37
|
+
that the same render regenerates, so the highlight was dropped too. Every DOM-decorating solver — the
|
|
38
|
+
highlight pair, the tabular row/column colors, and the section/group/input background colors — shares this
|
|
39
|
+
and is restored by the same replay. `MI-BatchSheetCombined` calls `highlighttabularrow(…, "is-hidden")` to
|
|
40
|
+
hide rows inside its CSB tables, so there the symptom is a hidden row coming back.
|
|
41
|
+
|
|
42
|
+
Reported against a Headlight combined form (`MI-BatchSheetCombined`), where picking a Source/Name on
|
|
43
|
+
the Aggregate Products table un-hid every CSB worksheet generated from it.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Regression harness for solver-driven SECTION and GROUP visibility.
|
|
3
|
+
|
|
4
|
+
The hide class that setsectionvisibility / setgroupvisibility applies lives on
|
|
5
|
+
#SECTION-<formID> / #GROUP-<formID>-<hash> -- and BOTH of those elements are emitted by the
|
|
6
|
+
section template. So any render() repaints them carrying only their manifest CSSClass and the
|
|
7
|
+
hide is dropped. Renaming a product below is exactly that: it changes a generated column LABEL,
|
|
8
|
+
which re-renders every table whose DynamicColumns are sourced from the Products table.
|
|
9
|
+
|
|
10
|
+
Repro (see html/index.html for the same steps in the page):
|
|
11
|
+
1. Load. "Average Gradation" is hidden -- Show Gradation is unchecked.
|
|
12
|
+
2. Rename any product in the Products table and tab out.
|
|
13
|
+
3. BEFORE the fix: "Average Gradation" reappears, still unchecked.
|
|
14
|
+
AFTER the fix: it stays hidden, and its column headers still relabel.
|
|
15
|
+
|
|
16
|
+
The "Gradation Notes" group inside that section is the group-level equivalent: tick Show
|
|
17
|
+
Gradation so the section is visible, leave Show Notes unchecked, then rename a product.
|
|
18
|
+
|
|
19
|
+
"Flag the #200 Row" covers the same defect one layer down: highlighttabularrow puts a class on
|
|
20
|
+
a <tr> that the very same render regenerates. MI-BatchSheetCombined uses that solver with
|
|
21
|
+
"is-hidden" to hide rows inside its CSB tables, so there the symptom is a hidden row coming back.
|
|
22
|
+
*/
|
|
23
|
+
const libPictSectionForm = require('../../source/Pict-Section-Form.js');
|
|
24
|
+
|
|
25
|
+
module.exports = libPictSectionForm.PictFormApplication;
|
|
26
|
+
|
|
27
|
+
module.exports.default_configuration = libPictSectionForm.PictFormApplication.default_configuration;
|
|
28
|
+
module.exports.default_configuration.pict_configuration = (
|
|
29
|
+
{
|
|
30
|
+
"Product": "SectionVisibility",
|
|
31
|
+
|
|
32
|
+
"DefaultAppData": require('./ProductData.json'),
|
|
33
|
+
|
|
34
|
+
"DefaultFormManifest":
|
|
35
|
+
{
|
|
36
|
+
"Scope": "SectionVisibilityForm",
|
|
37
|
+
|
|
38
|
+
"Sections":
|
|
39
|
+
[
|
|
40
|
+
{
|
|
41
|
+
"Hash": "Workflow",
|
|
42
|
+
"Name": "Worksheet Selection",
|
|
43
|
+
|
|
44
|
+
"Solvers":
|
|
45
|
+
[
|
|
46
|
+
"SetSectionVisibility(\"Gradation\", IF(ShowGradation, \"==\", 1, 1, 0))",
|
|
47
|
+
"SetGroupVisibility(\"Gradation\", \"GradationNotes\", IF(ShowNotes, \"==\", 1, 1, 0))",
|
|
48
|
+
"highlighttabularrow(\"Gradation\", \"Gradation\", 3, IF(FlagFinesRow, \"==\", 1, 1, 0))"
|
|
49
|
+
],
|
|
50
|
+
|
|
51
|
+
"Groups": [ { "Hash": "Workflow", "Name": "Show / Hide Worksheets" } ]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"Hash": "Products",
|
|
55
|
+
"Name": "Aggregate Products",
|
|
56
|
+
|
|
57
|
+
"Groups":
|
|
58
|
+
[
|
|
59
|
+
{
|
|
60
|
+
"Hash": "Products",
|
|
61
|
+
"Name": "Products",
|
|
62
|
+
|
|
63
|
+
"Layout": "Tabular",
|
|
64
|
+
|
|
65
|
+
"RecordSetAddress": "Products",
|
|
66
|
+
"RecordManifest": "ProductEditor"
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"Hash": "Gradation",
|
|
72
|
+
"Name": "Average Gradation",
|
|
73
|
+
|
|
74
|
+
"Groups":
|
|
75
|
+
[
|
|
76
|
+
{
|
|
77
|
+
"Hash": "Gradation",
|
|
78
|
+
"Name": "Percent Passing",
|
|
79
|
+
|
|
80
|
+
"Layout": "Tabular",
|
|
81
|
+
|
|
82
|
+
"RecordSetAddress": "Gradation",
|
|
83
|
+
"RecordManifest": "GradationRowEditor",
|
|
84
|
+
|
|
85
|
+
// One generated column per Products row, labeled from that row's name.
|
|
86
|
+
// Renaming a product is a label-only change: the column SET is identical,
|
|
87
|
+
// so this takes the Tabular layout's namesChanged render() path.
|
|
88
|
+
"DynamicColumns":
|
|
89
|
+
[
|
|
90
|
+
{
|
|
91
|
+
"SourceAddress": "Products",
|
|
92
|
+
"HashTemplate": "PassingCol_{~D:Record.IDProduct~}",
|
|
93
|
+
"NameTemplate": "{~D:Record.ProductName~}",
|
|
94
|
+
"InformaryDataAddressTemplate": "Passing.{~D:Record.IDProduct~}",
|
|
95
|
+
"DataType": "Number",
|
|
96
|
+
"PictForm": { "InputType": "Number" }
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"Hash": "GradationNotes",
|
|
102
|
+
"Name": "Gradation Notes"
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
],
|
|
107
|
+
|
|
108
|
+
"Descriptors":
|
|
109
|
+
{
|
|
110
|
+
"Workflow.ShowGradation":
|
|
111
|
+
{
|
|
112
|
+
"Name": "Show Gradation",
|
|
113
|
+
"Hash": "ShowGradation",
|
|
114
|
+
"DataType": "Boolean",
|
|
115
|
+
"Default": 0,
|
|
116
|
+
"PictForm": { "InputType": "Boolean", "Section": "Workflow", "Group": "Workflow", "Row": 1 }
|
|
117
|
+
},
|
|
118
|
+
"Workflow.FlagFinesRow":
|
|
119
|
+
{
|
|
120
|
+
"Name": "Flag the #200 Row",
|
|
121
|
+
"Hash": "FlagFinesRow",
|
|
122
|
+
"DataType": "Boolean",
|
|
123
|
+
"Default": 0,
|
|
124
|
+
"PictForm": { "InputType": "Boolean", "Section": "Workflow", "Group": "Workflow", "Row": 2 }
|
|
125
|
+
},
|
|
126
|
+
"Workflow.ShowNotes":
|
|
127
|
+
{
|
|
128
|
+
"Name": "Show Product Notes",
|
|
129
|
+
"Hash": "ShowNotes",
|
|
130
|
+
"DataType": "Boolean",
|
|
131
|
+
"Default": 0,
|
|
132
|
+
"PictForm": { "InputType": "Boolean", "Section": "Workflow", "Group": "Workflow", "Row": 1 }
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
"Products":
|
|
136
|
+
{
|
|
137
|
+
"Name": "Aggregate Products",
|
|
138
|
+
"Hash": "ProductGrid",
|
|
139
|
+
"DataType": "Array",
|
|
140
|
+
"Default": [],
|
|
141
|
+
"PictForm": { "Section": "Products", "Group": "Products" }
|
|
142
|
+
},
|
|
143
|
+
"Gradation":
|
|
144
|
+
{
|
|
145
|
+
"Name": "Average Gradation",
|
|
146
|
+
"Hash": "GradationGrid",
|
|
147
|
+
"DataType": "Array",
|
|
148
|
+
"Default": [],
|
|
149
|
+
"PictForm": { "Section": "Gradation", "Group": "Gradation" }
|
|
150
|
+
},
|
|
151
|
+
"Workflow.GradationNote":
|
|
152
|
+
{
|
|
153
|
+
"Name": "Note",
|
|
154
|
+
"Hash": "GradationNote",
|
|
155
|
+
"DataType": "String",
|
|
156
|
+
"PictForm": { "Section": "Gradation", "Group": "GradationNotes", "Row": 1 }
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
"ReferenceManifests":
|
|
161
|
+
{
|
|
162
|
+
"ProductEditor":
|
|
163
|
+
{
|
|
164
|
+
"Scope": "ProductEditor",
|
|
165
|
+
"Descriptors":
|
|
166
|
+
{
|
|
167
|
+
"IDProduct":
|
|
168
|
+
{
|
|
169
|
+
"Name": "ID",
|
|
170
|
+
"Hash": "IDProduct",
|
|
171
|
+
"DataType": "Number",
|
|
172
|
+
"PictForm": { "Section": "Products", "Group": "Products" }
|
|
173
|
+
},
|
|
174
|
+
"ProductName":
|
|
175
|
+
{
|
|
176
|
+
"Name": "Product Name",
|
|
177
|
+
"Hash": "ProductName",
|
|
178
|
+
"DataType": "String",
|
|
179
|
+
"Default": "(unnamed product)",
|
|
180
|
+
"PictForm": { "Section": "Products", "Group": "Products" }
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
"GradationRowEditor":
|
|
186
|
+
{
|
|
187
|
+
"Scope": "GradationRowEditor",
|
|
188
|
+
"Descriptors":
|
|
189
|
+
{
|
|
190
|
+
"SieveSize":
|
|
191
|
+
{
|
|
192
|
+
"Name": "Sieve",
|
|
193
|
+
"Hash": "SieveSize",
|
|
194
|
+
"DataType": "String",
|
|
195
|
+
"PictForm": { "Section": "Gradation", "Group": "Gradation" }
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Section Visibility - Pict Example</title>
|
|
7
|
+
<!-- PICT Dynamic View CSS Container -->
|
|
8
|
+
<style id="PICT-CSS"></style>
|
|
9
|
+
<style>
|
|
10
|
+
*, *::before, *::after { box-sizing: border-box; }
|
|
11
|
+
body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; background: #FAEDCD; color: #264653; }
|
|
12
|
+
|
|
13
|
+
.pict-example-header { display: flex; align-items: stretch; background: #264653; border-bottom: 3px solid #E76F51; }
|
|
14
|
+
.pict-example-badge { background: #E76F51; color: #fff; padding: 0.6rem 1rem; font-size: 0.7rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; display: flex; align-items: center; gap: 0.5rem; }
|
|
15
|
+
.pict-example-badge svg { width: 14px; height: 14px; fill: #fff; flex-shrink: 0; }
|
|
16
|
+
.pict-example-app-name { padding: 0.6rem 1rem; color: #FAEDCD; font-size: 1.1rem; font-weight: 600; display: flex; align-items: center; }
|
|
17
|
+
.pict-example-module { margin-left: auto; padding: 0.6rem 1rem; color: #D4A373; font-size: 0.75rem; display: flex; align-items: center; letter-spacing: 0.03em; }
|
|
18
|
+
|
|
19
|
+
.pict-example-content { padding: 1.5rem; }
|
|
20
|
+
|
|
21
|
+
.pict-example-steps { background: #fff; border: 1px solid #D4A373; border-left: 4px solid #264653; border-radius: 6px; padding: 1rem 1.25rem; margin-bottom: 1.25rem; font-size: 0.9rem; line-height: 1.5; }
|
|
22
|
+
.pict-example-steps h3 { margin: 0 0 0.5rem; font-size: 0.95rem; }
|
|
23
|
+
.pict-example-steps ol { margin: 0 0 0.75rem; padding-left: 1.25rem; }
|
|
24
|
+
.pict-example-steps code { background: #FFF3E4; padding: 0.1rem 0.3rem; border-radius: 3px; font-size: 0.85em; }
|
|
25
|
+
.pict-example-steps .pict-example-expect { margin: 0; padding-top: 0.6rem; border-top: 1px dashed #E8D9C0; }
|
|
26
|
+
.pict-example-steps .pict-example-bad { color: #B23A24; font-weight: 600; }
|
|
27
|
+
.pict-example-steps .pict-example-good { color: #2A7F5F; font-weight: 600; }
|
|
28
|
+
|
|
29
|
+
#Pict-Form-Container { background: #fff; border: 1px solid #D4A373; border-top: 4px solid #E76F51; border-radius: 6px; padding: 1.25rem; box-shadow: 0 2px 8px rgba(38,70,83,0.08); }
|
|
30
|
+
|
|
31
|
+
#Pict-Form-Container input[type="text"],
|
|
32
|
+
#Pict-Form-Container input[type="number"],
|
|
33
|
+
#Pict-Form-Container select { border: 1px solid #D4C4A8; background: #FFFCF7; padding: 0.45rem 0.6rem; border-radius: 4px; font-size: 0.9rem; color: #264653; width: 100%; }
|
|
34
|
+
#Pict-Form-Container input[type="checkbox"] { width: auto; }
|
|
35
|
+
#Pict-Form-Container input:focus, #Pict-Form-Container select:focus { outline: none; border-color: #E76F51; box-shadow: 0 0 0 2px rgba(231,111,81,0.15); }
|
|
36
|
+
#Pict-Form-Container label { color: #264653; font-weight: 600; font-size: 0.85rem; }
|
|
37
|
+
#Pict-Form-Container h2, #Pict-Form-Container h3 { color: #264653; }
|
|
38
|
+
#Pict-Form-Container table { width: 100%; border-collapse: collapse; }
|
|
39
|
+
#Pict-Form-Container th { background: #264653; color: #FAEDCD; padding: 0.5rem 0.75rem; text-align: left; font-size: 0.8rem; }
|
|
40
|
+
#Pict-Form-Container td { padding: 0.5rem 0.75rem; border-bottom: 1px solid #E8D9C0; font-size: 0.85rem; }
|
|
41
|
+
#Pict-Form-Container tr:nth-child(even) td { background: #FFF9F0; }
|
|
42
|
+
</style>
|
|
43
|
+
<script src="./pict.min.js" type="text/javascript"></script>
|
|
44
|
+
<script type="text/javascript">Pict.safeOnDocumentReady(() => { Pict.safeLoadPictApplication(SectionVisibilityApplication, 3)});</script>
|
|
45
|
+
</head>
|
|
46
|
+
<body>
|
|
47
|
+
<div class="pict-example-header">
|
|
48
|
+
<div class="pict-example-badge">
|
|
49
|
+
<svg viewBox="0 0 16 16"><polygon points="8,1 10,6 16,6 11,9.5 13,15 8,11.5 3,15 5,9.5 0,6 6,6"/></svg>
|
|
50
|
+
Pict Example
|
|
51
|
+
</div>
|
|
52
|
+
<div class="pict-example-app-name">Section Visibility</div>
|
|
53
|
+
<div class="pict-example-module">pict-section-form</div>
|
|
54
|
+
</div>
|
|
55
|
+
<div class="pict-example-content">
|
|
56
|
+
<div class="pict-example-steps">
|
|
57
|
+
<h3>Does solver-driven visibility survive a re-render?</h3>
|
|
58
|
+
<ol>
|
|
59
|
+
<li>On load, <strong>Average Gradation</strong> is hidden — <code>Show Gradation</code> is unchecked and the section solver hid it.</li>
|
|
60
|
+
<li>Rename any product in <strong>Aggregate Products</strong> and tab out. That changes a generated column <em>label</em>, so every section whose columns come from Products re-renders.</li>
|
|
61
|
+
<li>For the <em>group</em> equivalent: tick <code>Show Gradation</code> so the section is visible, leave <code>Show Notes</code> unchecked, and rename a product again — the hidden <strong>Gradation Notes</strong> group inside it behaves the same way.</li>
|
|
62
|
+
<li>For the <em>row</em> equivalent: with Gradation visible, tick <code>Flag the #200 Row</code> to highlight it, then rename a product once more.</li>
|
|
63
|
+
</ol>
|
|
64
|
+
<p class="pict-example-expect">
|
|
65
|
+
<span class="pict-example-bad">Broken:</span> Average Gradation (or the Gradation Notes group) reappears with its box still unchecked, and the row highlight vanishes.<br>
|
|
66
|
+
<span class="pict-example-good">Fixed:</span> everything stays as you left it — hidden stays hidden, the flagged row stays flagged — and the column headers still pick up the new product name.
|
|
67
|
+
</p>
|
|
68
|
+
</div>
|
|
69
|
+
<div id="Pict-Form-Container"></div>
|
|
70
|
+
</div>
|
|
71
|
+
<script src="./section_visibility_application.min.js" type="text/javascript"></script>
|
|
72
|
+
</body>
|
|
73
|
+
</html>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "section_visibility_application",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Section visibility survives a DynamicColumns re-render.",
|
|
5
|
+
"main": "Section-Visibility-Application.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "node Section-Visibility-Application.js",
|
|
8
|
+
"build": "npx quack build && npx quack copy"
|
|
9
|
+
},
|
|
10
|
+
"author": "steven",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"devDependencies": {},
|
|
13
|
+
"copyFilesSettings": {
|
|
14
|
+
"whenFileExists": "overwrite"
|
|
15
|
+
},
|
|
16
|
+
"copyFiles": [
|
|
17
|
+
{
|
|
18
|
+
"from": "./html/*",
|
|
19
|
+
"to": "./dist/"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"from": "../../node_modules/pict/dist/*",
|
|
23
|
+
"to": "./dist/"
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"retold": {
|
|
27
|
+
"ExampleApplication": {
|
|
28
|
+
"Stage": true,
|
|
29
|
+
"Title": "Section Visibility",
|
|
30
|
+
"Summary": "A regression harness for solver-driven section and group visibility surviving a DynamicColumns re-render. Renaming a source row re-renders every dependent table; the hide class lives on an element that render regenerates, so it used to be silently dropped.",
|
|
31
|
+
"Complexity": "Basic"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -42,6 +42,22 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
|
|
|
42
42
|
/** @type {string} */
|
|
43
43
|
this.cssHideSectionClass = 'pict-section-form-hidden-section';
|
|
44
44
|
this.cssHideGroupClass = 'pict-section-form-hidden-group';
|
|
45
|
+
|
|
46
|
+
// #SECTION-<formID> and #GROUP-<formID>-<hash> are both emitted by the section template, so a
|
|
47
|
+
// render() regenerates them without the hide class and the hide silently reverts. Record what
|
|
48
|
+
// was asked for so reapplySectionVisibility can restore it after a render.
|
|
49
|
+
/** @type {Record<string, boolean>} */
|
|
50
|
+
this.sectionVisibilityState = {};
|
|
51
|
+
/** @type {Record<string, boolean>} */
|
|
52
|
+
this.groupVisibilityState = {};
|
|
53
|
+
|
|
54
|
+
// Same story for every solver that decorates the DOM -- highlight classes and inline background
|
|
55
|
+
// colors all land on markup the section template regenerates. Keyed by what the decoration
|
|
56
|
+
// targets so re-applying one overwrites rather than accumulating.
|
|
57
|
+
/** @type {Record<string, {Section: string, Method: string, Arguments: Array<any>}>} */
|
|
58
|
+
this.decorationState = {};
|
|
59
|
+
/** @type {boolean} */
|
|
60
|
+
this.decorationReplayInProgress = false;
|
|
45
61
|
/** @type {string} */
|
|
46
62
|
this.cssTabularRowHighlightClass = 'pict-tabular-row-highlight';
|
|
47
63
|
/** @type {string} */
|
|
@@ -367,6 +383,10 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
|
|
|
367
383
|
return false;
|
|
368
384
|
}
|
|
369
385
|
|
|
386
|
+
// Record BEFORE the DOM guard below: the guard short-circuits when the DOM already matches, and
|
|
387
|
+
// the state map has to stay accurate even then so a later render can restore it.
|
|
388
|
+
this.sectionVisibilityState[pSectionHash] = false;
|
|
389
|
+
|
|
370
390
|
if (this.pict.ContentAssignment.hasClass(this.getSectionSelector(tmpSectionView.formID), this.cssHideSectionClass))
|
|
371
391
|
{
|
|
372
392
|
// Already hidden.
|
|
@@ -386,6 +406,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
|
|
|
386
406
|
return false;
|
|
387
407
|
}
|
|
388
408
|
|
|
409
|
+
this.sectionVisibilityState[pSectionHash] = true;
|
|
410
|
+
|
|
389
411
|
if (!this.pict.ContentAssignment.hasClass(this.getSectionSelector(tmpSectionView.formID), this.cssHideSectionClass))
|
|
390
412
|
{
|
|
391
413
|
// Already visible.
|
|
@@ -422,6 +444,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
|
|
|
422
444
|
return false;
|
|
423
445
|
}
|
|
424
446
|
|
|
447
|
+
this.groupVisibilityState[this.getGroupVisibilityStateKey(pSectionHash, pGroupHash)] = false;
|
|
448
|
+
|
|
425
449
|
if (this.pict.ContentAssignment.hasClass(this.getGroupSelector(tmpGroupView.formID, pGroupHash), this.cssHideGroupClass))
|
|
426
450
|
{
|
|
427
451
|
// Already hidden.
|
|
@@ -441,6 +465,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
|
|
|
441
465
|
return false;
|
|
442
466
|
}
|
|
443
467
|
|
|
468
|
+
this.groupVisibilityState[this.getGroupVisibilityStateKey(pSectionHash, pGroupHash)] = true;
|
|
469
|
+
|
|
444
470
|
if (!this.pict.ContentAssignment.hasClass(this.getGroupSelector(tmpGroupView.formID, pGroupHash), this.cssHideGroupClass))
|
|
445
471
|
{
|
|
446
472
|
// Already visible.
|
|
@@ -451,6 +477,196 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
|
|
|
451
477
|
return true;
|
|
452
478
|
}
|
|
453
479
|
|
|
480
|
+
/**
|
|
481
|
+
* @param {string} pSectionHash
|
|
482
|
+
* @param {string} pGroupHash
|
|
483
|
+
*
|
|
484
|
+
* @return {string} - The groupVisibilityState key for a section/group pair.
|
|
485
|
+
*/
|
|
486
|
+
getGroupVisibilityStateKey(pSectionHash, pGroupHash)
|
|
487
|
+
{
|
|
488
|
+
return `${pSectionHash}::${pGroupHash}`;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Re-apply a section's recorded visibility (and that of its groups) after a render regenerated its DOM.
|
|
493
|
+
*
|
|
494
|
+
* Every render path -- DynamicColumns rebuild, dependent-view rebuild, row add/delete/move, the
|
|
495
|
+
* group-scoped swap in renderGroupInPlace -- repaints those elements with only their manifest
|
|
496
|
+
* CSSClass, and solvers run BEFORE the marshal that triggers them, so nothing else puts the hide
|
|
497
|
+
* back. Called from the view's onAfterRender so one restore covers them all. A section with no
|
|
498
|
+
* recorded state is left as the template rendered it.
|
|
499
|
+
*
|
|
500
|
+
* @param {string} pSectionHash - The section that was just rendered.
|
|
501
|
+
*
|
|
502
|
+
* @return {void}
|
|
503
|
+
*/
|
|
504
|
+
reapplySectionVisibility(pSectionHash)
|
|
505
|
+
{
|
|
506
|
+
if (typeof pSectionHash !== 'string' || pSectionHash.length < 1)
|
|
507
|
+
{
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
if (pSectionHash in this.sectionVisibilityState)
|
|
512
|
+
{
|
|
513
|
+
this.setSectionVisibility(pSectionHash, this.sectionVisibilityState[pSectionHash] ? 1 : 0);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
const tmpGroupKeyPrefix = `${pSectionHash}::`;
|
|
517
|
+
const tmpGroupKeys = Object.keys(this.groupVisibilityState);
|
|
518
|
+
for (let i = 0; i < tmpGroupKeys.length; i++)
|
|
519
|
+
{
|
|
520
|
+
if (tmpGroupKeys[i].indexOf(tmpGroupKeyPrefix) !== 0)
|
|
521
|
+
{
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
const tmpGroupHash = tmpGroupKeys[i].substring(tmpGroupKeyPrefix.length);
|
|
525
|
+
this.setGroupVisibility(pSectionHash, tmpGroupHash, this.groupVisibilityState[tmpGroupKeys[i]] ? 1 : 0);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Remember a DOM decoration a solver just applied so it can be replayed after a render.
|
|
531
|
+
*
|
|
532
|
+
* @param {string} pSectionHash - The section the decoration targets.
|
|
533
|
+
* @param {string} pKey - Stable identity for what is decorated; a repeat overwrites it.
|
|
534
|
+
* @param {string} pMethod - The method on this provider that applies it.
|
|
535
|
+
* @param {Array<any>} pArguments - The arguments to replay it with.
|
|
536
|
+
*
|
|
537
|
+
* @return {void}
|
|
538
|
+
*/
|
|
539
|
+
recordDecoration(pSectionHash, pKey, pMethod, pArguments)
|
|
540
|
+
{
|
|
541
|
+
if (this.decorationReplayInProgress)
|
|
542
|
+
{
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
this.decorationState[`${pSectionHash}::${pKey}`] = { Section: pSectionHash, Method: pMethod, Arguments: pArguments };
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Replay every decoration recorded against a section after a render repainted its markup.
|
|
550
|
+
*
|
|
551
|
+
* Highlight classes and inline colors live on rows, cells and containers that the section
|
|
552
|
+
* template regenerates, exactly like the hide classes. Replay is idempotent: each entry is
|
|
553
|
+
* keyed by its target, and a recorded "remove" simply re-runs a removal against fresh markup.
|
|
554
|
+
*
|
|
555
|
+
* @param {string} pSectionHash - The section that was just rendered.
|
|
556
|
+
*
|
|
557
|
+
* @return {void}
|
|
558
|
+
*/
|
|
559
|
+
reapplySectionDecorations(pSectionHash)
|
|
560
|
+
{
|
|
561
|
+
if (typeof pSectionHash !== 'string' || pSectionHash.length < 1)
|
|
562
|
+
{
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
const tmpKeys = Object.keys(this.decorationState);
|
|
567
|
+
this.decorationReplayInProgress = true;
|
|
568
|
+
try
|
|
569
|
+
{
|
|
570
|
+
for (let i = 0; i < tmpKeys.length; i++)
|
|
571
|
+
{
|
|
572
|
+
const tmpEntry = this.decorationState[tmpKeys[i]];
|
|
573
|
+
if (!tmpEntry || (tmpEntry.Section !== pSectionHash) || (typeof this[tmpEntry.Method] !== 'function'))
|
|
574
|
+
{
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
this[tmpEntry.Method].apply(this, tmpEntry.Arguments);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
finally
|
|
581
|
+
{
|
|
582
|
+
this.decorationReplayInProgress = false;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Restore everything a solver put on this section's DOM that a render just wiped -- visibility
|
|
588
|
+
* first, then decorations. This is what the section view calls from its own onAfterRender.
|
|
589
|
+
*
|
|
590
|
+
* @param {string} pSectionHash - The section that was just rendered.
|
|
591
|
+
*
|
|
592
|
+
* @return {void}
|
|
593
|
+
*/
|
|
594
|
+
reapplySectionDOMState(pSectionHash)
|
|
595
|
+
{
|
|
596
|
+
this.reapplySectionVisibility(pSectionHash);
|
|
597
|
+
this.reapplySectionDecorations(pSectionHash);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Re-render a single group in place, leaving the rest of the section's DOM untouched.
|
|
602
|
+
*
|
|
603
|
+
* The section template is one string (wrap/section prefixes + every group's
|
|
604
|
+
* generateGroupLayoutTemplate + postfixes), so a normal render rebuilds all of it.
|
|
605
|
+
* This regenerates just the requested group's slice and swaps that one element.
|
|
606
|
+
*
|
|
607
|
+
* Init is then run the normal way (the view's own post-render pass) rather than being
|
|
608
|
+
* hand-scoped: input providers guard their own re-initialization (a select2 picker
|
|
609
|
+
* checks for an existing instance before creating one), so untouched groups no-op and
|
|
610
|
+
* only the freshly-rendered group actually initializes.
|
|
611
|
+
*
|
|
612
|
+
* @param {import('../views/Pict-View-DynamicForm.js')} pView - The section view.
|
|
613
|
+
* @param {string} pGroupHash - The group to re-render.
|
|
614
|
+
* @return {boolean} - True if the group was rendered in place; false to fall back to a full render.
|
|
615
|
+
*/
|
|
616
|
+
renderGroupInPlace(pView, pGroupHash)
|
|
617
|
+
{
|
|
618
|
+
try
|
|
619
|
+
{
|
|
620
|
+
if (!pView || !pView.formID || (typeof pView.getGroupIndexFromHash !== 'function'))
|
|
621
|
+
{
|
|
622
|
+
return false;
|
|
623
|
+
}
|
|
624
|
+
const tmpGroupIndex = pView.getGroupIndexFromHash(pGroupHash);
|
|
625
|
+
if (tmpGroupIndex < 0)
|
|
626
|
+
{
|
|
627
|
+
return false;
|
|
628
|
+
}
|
|
629
|
+
const tmpGroup = pView.getGroup(tmpGroupIndex);
|
|
630
|
+
const tmpGenerator = this.pict.providers.MetatemplateGenerator;
|
|
631
|
+
if (!tmpGroup || !tmpGenerator || (typeof tmpGenerator.getGroupLayoutProvider !== 'function'))
|
|
632
|
+
{
|
|
633
|
+
return false;
|
|
634
|
+
}
|
|
635
|
+
const tmpLayout = tmpGenerator.getGroupLayoutProvider(pView, tmpGroup);
|
|
636
|
+
if (!tmpLayout || (typeof tmpLayout.generateGroupLayoutTemplate !== 'function'))
|
|
637
|
+
{
|
|
638
|
+
return false;
|
|
639
|
+
}
|
|
640
|
+
const tmpElements = this.pict.ContentAssignment.getElement(`#GROUP-${pView.formID}-${tmpGroup.Hash}`);
|
|
641
|
+
const tmpElement = (tmpElements && tmpElements.length) ? tmpElements[0] : null;
|
|
642
|
+
if (!tmpElement || (typeof tmpElement.outerHTML !== 'string'))
|
|
643
|
+
{
|
|
644
|
+
return false;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
// Same parse shape the view uses for the whole section: the view is Context[0],
|
|
648
|
+
// which the group templates reference for formID/UUID/Hash.
|
|
649
|
+
const tmpTemplateHash = `Pict-Form-Template-Group-InPlace-${pView.options.Hash}-G${tmpGroup.GroupIndex}`;
|
|
650
|
+
this.pict.TemplateProvider.addTemplate(tmpTemplateHash, tmpLayout.generateGroupLayoutTemplate(pView, tmpGroup));
|
|
651
|
+
const tmpRecordAddress = pView.options.DefaultTemplateRecordAddress;
|
|
652
|
+
const tmpRecord = (typeof tmpRecordAddress === 'string') ? this.pict.DataProvider.getDataByAddress(tmpRecordAddress) : undefined;
|
|
653
|
+
const tmpContent = this.pict.parseTemplateByHash(tmpTemplateHash, tmpRecord, null, [ pView ]);
|
|
654
|
+
if (typeof tmpContent !== 'string' || !tmpContent.length)
|
|
655
|
+
{
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
tmpElement.outerHTML = tmpContent;
|
|
660
|
+
pView.onAfterRender({ RenderableHash: `GroupInPlace-${tmpGroup.Hash}` });
|
|
661
|
+
return true;
|
|
662
|
+
}
|
|
663
|
+
catch (pError)
|
|
664
|
+
{
|
|
665
|
+
this.log.warn(`renderGroupInPlace failed for group [${pGroupHash}]; falling back to a full section render: ${pError.message || pError}`);
|
|
666
|
+
return false;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
454
670
|
/**
|
|
455
671
|
* Causes a tabular section to refresh its display
|
|
456
672
|
*
|
|
@@ -501,7 +717,15 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
|
|
|
501
717
|
// We expect this view to be in the set.
|
|
502
718
|
for (let i = 0; i < tmpViewsToRender.length; i++)
|
|
503
719
|
{
|
|
504
|
-
|
|
720
|
+
// Re-render ONLY the group that actually changed when we can. A full
|
|
721
|
+
// section render replaces every group's DOM, which destroys any widget
|
|
722
|
+
// the user is mid-interaction with (select2 pickers blank for ~700ms) and
|
|
723
|
+
// drops layout state. Falls back to the full render when the group-scoped
|
|
724
|
+
// path is not possible, so behaviour is unchanged for anything it cannot handle.
|
|
725
|
+
if (!this.renderGroupInPlace(tmpViewsToRender[i], pGroupHash))
|
|
726
|
+
{
|
|
727
|
+
tmpViewsToRender[i].render();
|
|
728
|
+
}
|
|
505
729
|
}
|
|
506
730
|
|
|
507
731
|
//NOTE: not running a solve, since this is run from the solver; if you need a solve, call runSolvers()
|
|
@@ -601,6 +825,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
|
|
|
601
825
|
return true;
|
|
602
826
|
}
|
|
603
827
|
|
|
828
|
+
this.recordDecoration(pSectionHash, 'sectionbackground', 'colorSectionBackground', [ pSectionHash, pColor, pApplyChange ]);
|
|
829
|
+
|
|
604
830
|
let tmpSectionView = this.pict.views.PictFormMetacontroller.getSectionViewFromHash(pSectionHash)
|
|
605
831
|
if (!tmpSectionView)
|
|
606
832
|
{
|
|
@@ -630,6 +856,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
|
|
|
630
856
|
return true;
|
|
631
857
|
}
|
|
632
858
|
|
|
859
|
+
this.recordDecoration(pSectionHash, `${pGroupHash}::groupbackground`, 'colorGroupBackground', [ pSectionHash, pGroupHash, pColor, pApplyChange ]);
|
|
860
|
+
|
|
633
861
|
let tmpGroupView = this.pict.views.PictFormMetacontroller.getSectionViewFromHash(pSectionHash)
|
|
634
862
|
if (!tmpGroupView)
|
|
635
863
|
{
|
|
@@ -667,6 +895,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
|
|
|
667
895
|
return true;
|
|
668
896
|
}
|
|
669
897
|
|
|
898
|
+
this.recordDecoration(pSectionHash, `input::${pInputHash}`, 'colorInputBackground', [ pSectionHash, pInputHash, pColor, pApplyChange, pCSSSelector ]);
|
|
899
|
+
|
|
670
900
|
/** @type {import('../views/Pict-View-DynamicForm.js')} */
|
|
671
901
|
let tmpInputView = this.pict.views.PictFormMetacontroller.getSectionViewFromHash(pSectionHash);
|
|
672
902
|
|
|
@@ -719,6 +949,9 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
|
|
|
719
949
|
return true;
|
|
720
950
|
}
|
|
721
951
|
|
|
952
|
+
this.recordDecoration(pSectionHash, `${pGroupHash}::inputcell::${pInputHash}::${pRowIndex}`, 'colorInputBackgroundTabular',
|
|
953
|
+
[ pSectionHash, pGroupHash, pInputHash, pRowIndex, pColor, pApplyChange, pCSSSelector, pElementIDPrefix ]);
|
|
954
|
+
|
|
722
955
|
/** @type {import('../views/Pict-View-DynamicForm.js')} */
|
|
723
956
|
let tmpInputView = this.pict.views.PictFormMetacontroller.getSectionViewFromHash(pSectionHash);
|
|
724
957
|
|
|
@@ -862,6 +1095,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
|
|
|
862
1095
|
return false;
|
|
863
1096
|
}
|
|
864
1097
|
let tmpClass = (typeof pHighlightClass === 'string' && pHighlightClass.length > 0) ? pHighlightClass : this.cssTabularRowHighlightClass;
|
|
1098
|
+
this.recordDecoration(pSectionHash, `${pGroupHash}::row::${pRowIndex}::${tmpClass}`, 'highlightTabularRow',
|
|
1099
|
+
[ pSectionHash, pGroupHash, pRowIndex, pApplyFlag, pHighlightClass ]);
|
|
865
1100
|
let tmpRowSelector = `${tmpGroupSelector} tr[data-tabular-row-index="${pRowIndex}"]`;
|
|
866
1101
|
if (this.isSolverFlagEnabled(pApplyFlag))
|
|
867
1102
|
{
|
|
@@ -894,6 +1129,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
|
|
|
894
1129
|
return false;
|
|
895
1130
|
}
|
|
896
1131
|
let tmpClass = (typeof pHighlightClass === 'string' && pHighlightClass.length > 0) ? pHighlightClass : this.cssTabularColumnHighlightClass;
|
|
1132
|
+
this.recordDecoration(pSectionHash, `${pGroupHash}::column::${pColumnIndex}::${tmpClass}`, 'highlightTabularColumn',
|
|
1133
|
+
[ pSectionHash, pGroupHash, pColumnIndex, pApplyFlag, pHighlightClass ]);
|
|
897
1134
|
let tmpColumnSelector = `${tmpGroupSelector} [data-tabular-column-index="${pColumnIndex}"]`;
|
|
898
1135
|
if (this.isSolverFlagEnabled(pApplyFlag))
|
|
899
1136
|
{
|
|
@@ -928,6 +1165,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
|
|
|
928
1165
|
return false;
|
|
929
1166
|
}
|
|
930
1167
|
let tmpApply = this.isSolverFlagEnabled(pApplyFlag) && (typeof pColor === 'string') && (pColor.length > 0);
|
|
1168
|
+
this.recordDecoration(pSectionHash, `${pGroupHash}::rowcolor::${pRowIndex}`, 'colorTabularRow',
|
|
1169
|
+
[ pSectionHash, pGroupHash, pRowIndex, pColor, pApplyFlag ]);
|
|
931
1170
|
let tmpElementSet = this.pict.ContentAssignment.getElement(`${tmpGroupSelector} tr[data-tabular-row-index="${pRowIndex}"] td`);
|
|
932
1171
|
for (let i = 0; i < tmpElementSet.length; i++)
|
|
933
1172
|
{
|
|
@@ -962,6 +1201,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
|
|
|
962
1201
|
return false;
|
|
963
1202
|
}
|
|
964
1203
|
let tmpApply = this.isSolverFlagEnabled(pApplyFlag) && (typeof pColor === 'string') && (pColor.length > 0);
|
|
1204
|
+
this.recordDecoration(pSectionHash, `${pGroupHash}::columncolor::${pColumnIndex}`, 'colorTabularColumn',
|
|
1205
|
+
[ pSectionHash, pGroupHash, pColumnIndex, pColor, pApplyFlag ]);
|
|
965
1206
|
let tmpElementSet = this.pict.ContentAssignment.getElement(`${tmpGroupSelector} [data-tabular-column-index="${pColumnIndex}"]`);
|
|
966
1207
|
for (let i = 0; i < tmpElementSet.length; i++)
|
|
967
1208
|
{
|
|
@@ -684,6 +684,16 @@ class PictViewDynamicForm extends libPictViewClass
|
|
|
684
684
|
{
|
|
685
685
|
this.finalizeTransaction(tmpTransactionGUID);
|
|
686
686
|
}
|
|
687
|
+
|
|
688
|
+
// The render that just happened repainted this section's markup without anything the solvers put
|
|
689
|
+
// on it -- the setsectionvisibility / setgroupvisibility hide classes, and any highlight class or
|
|
690
|
+
// inline color. Solvers run before the marshal that triggers most renders, so nothing else puts
|
|
691
|
+
// them back: restore them here, once, for every render path.
|
|
692
|
+
if (this.pict.providers.DynamicFormSolverBehaviors && this.sectionDefinition)
|
|
693
|
+
{
|
|
694
|
+
this.pict.providers.DynamicFormSolverBehaviors.reapplySectionDOMState(this.sectionDefinition.Hash);
|
|
695
|
+
}
|
|
696
|
+
|
|
687
697
|
return super.onAfterRender(pRenderable);
|
|
688
698
|
}
|
|
689
699
|
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/*
|
|
2
|
+
`refreshtabularsection` used to re-render the WHOLE section, rebuilding every group's DOM --
|
|
3
|
+
which destroys any widget the user is mid-interaction with. Measured in a Headlight form: a
|
|
4
|
+
select2 picker in a sibling group was torn down and rebuilt on every tabular refresh, blanking
|
|
5
|
+
its tags for ~700ms, and the section's active tab reset with it.
|
|
6
|
+
|
|
7
|
+
renderGroupInPlace re-renders only the group that changed. These tests cover the SAFETY
|
|
8
|
+
contract rather than the happy path: every reason the scoped path cannot run must return false
|
|
9
|
+
-- never throw -- so refreshTabularSection falls back to the original full-section render and
|
|
10
|
+
behaviour is unchanged for anything it cannot handle.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const Chai = require('chai');
|
|
14
|
+
const Expect = Chai.expect;
|
|
15
|
+
|
|
16
|
+
const libDynamicFormSolverBehaviors = require('../source/providers/Pict-Provider-DynamicFormSolverBehaviors.js');
|
|
17
|
+
|
|
18
|
+
// The provider without its constructor -- these tests exercise one pure-ish method and only
|
|
19
|
+
// need the few collaborators it touches.
|
|
20
|
+
function buildProvider(pOverrides)
|
|
21
|
+
{
|
|
22
|
+
const tmpProvider = Object.create(libDynamicFormSolverBehaviors.prototype);
|
|
23
|
+
tmpProvider.warnings = [];
|
|
24
|
+
tmpProvider.log = { warn: (pMessage) => tmpProvider.warnings.push(pMessage), error: () => {} };
|
|
25
|
+
tmpProvider.pict = Object.assign(
|
|
26
|
+
{
|
|
27
|
+
providers: { MetatemplateGenerator: { getGroupLayoutProvider: () => ({ generateGroupLayoutTemplate: () => '<div></div>' }) } },
|
|
28
|
+
ContentAssignment: { getElement: () => [ { outerHTML: '<div></div>' } ] },
|
|
29
|
+
TemplateProvider: { addTemplate: () => {} },
|
|
30
|
+
DataProvider: { getDataByAddress: () => ({}) },
|
|
31
|
+
parseTemplateByHash: () => '<div id="GROUP-F1-Grid"></div>',
|
|
32
|
+
},
|
|
33
|
+
pOverrides || {});
|
|
34
|
+
return tmpProvider;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function buildView(pOverrides)
|
|
38
|
+
{
|
|
39
|
+
return Object.assign(
|
|
40
|
+
{
|
|
41
|
+
formID: 'F1',
|
|
42
|
+
options: { Hash: 'TestSection', DefaultTemplateRecordAddress: 'AppData.Form' },
|
|
43
|
+
getGroupIndexFromHash: () => 0,
|
|
44
|
+
getGroup: () => ({ Hash: 'Grid', GroupIndex: 0 }),
|
|
45
|
+
onAfterRender: () => true,
|
|
46
|
+
},
|
|
47
|
+
pOverrides || {});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
suite('Pict-Section-Form - DynamicFormSolverBehaviors group-scoped render', () =>
|
|
51
|
+
{
|
|
52
|
+
test('renders the group in place when everything resolves', () =>
|
|
53
|
+
{
|
|
54
|
+
let tmpRenderedInPlace = false;
|
|
55
|
+
const tmpProvider = buildProvider();
|
|
56
|
+
const tmpView = buildView({ onAfterRender: () => { tmpRenderedInPlace = true; return true; } });
|
|
57
|
+
Expect(tmpProvider.renderGroupInPlace(tmpView, 'Grid')).to.equal(true);
|
|
58
|
+
Expect(tmpRenderedInPlace).to.equal(true);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('falls back when the view is missing or has no formID', () =>
|
|
62
|
+
{
|
|
63
|
+
const tmpProvider = buildProvider();
|
|
64
|
+
Expect(tmpProvider.renderGroupInPlace(null, 'Grid')).to.equal(false);
|
|
65
|
+
Expect(tmpProvider.renderGroupInPlace(buildView({ formID: undefined }), 'Grid')).to.equal(false);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('falls back when the group hash is not in the section', () =>
|
|
69
|
+
{
|
|
70
|
+
const tmpProvider = buildProvider();
|
|
71
|
+
Expect(tmpProvider.renderGroupInPlace(buildView({ getGroupIndexFromHash: () => -1 }), 'Nope')).to.equal(false);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('falls back when the layout provider cannot generate a template', () =>
|
|
75
|
+
{
|
|
76
|
+
const tmpProvider = buildProvider({ providers: { MetatemplateGenerator: { getGroupLayoutProvider: () => ({}) } } });
|
|
77
|
+
Expect(tmpProvider.renderGroupInPlace(buildView(), 'Grid')).to.equal(false);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('falls back when the group element is not in the DOM', () =>
|
|
81
|
+
{
|
|
82
|
+
const tmpProvider = buildProvider({ ContentAssignment: { getElement: () => [] } });
|
|
83
|
+
Expect(tmpProvider.renderGroupInPlace(buildView(), 'Grid')).to.equal(false);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('falls back when the template parses to nothing', () =>
|
|
87
|
+
{
|
|
88
|
+
const tmpProvider = buildProvider({ parseTemplateByHash: () => '' });
|
|
89
|
+
Expect(tmpProvider.renderGroupInPlace(buildView(), 'Grid')).to.equal(false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('a throwing collaborator is caught, warned, and falls back', () =>
|
|
93
|
+
{
|
|
94
|
+
const tmpProvider = buildProvider({ parseTemplateByHash: () => { throw new Error('boom'); } });
|
|
95
|
+
Expect(tmpProvider.renderGroupInPlace(buildView(), 'Grid')).to.equal(false);
|
|
96
|
+
Expect(tmpProvider.warnings.length).to.equal(1);
|
|
97
|
+
Expect(tmpProvider.warnings[0]).to.contain('falling back');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -696,6 +696,225 @@ suite('PictSectionForm Tabular Features', () =>
|
|
|
696
696
|
}, fDone);
|
|
697
697
|
});
|
|
698
698
|
|
|
699
|
+
/*
|
|
700
|
+
The <section> and <div> that carry a section's and a group's hide class are emitted BY the
|
|
701
|
+
section template, so every render regenerates them without whatever setsectionvisibility /
|
|
702
|
+
setgroupvisibility applied. Solvers run BEFORE the marshal that triggers a DynamicColumns
|
|
703
|
+
re-render, so nothing put it back: a hidden section silently reappeared the moment a source
|
|
704
|
+
row was renamed (reported on MI-BatchSheetCombined -- picking a Source/Name on the Aggregate
|
|
705
|
+
Products table un-hid the CSB worksheets whose columns are generated from it).
|
|
706
|
+
*/
|
|
707
|
+
function makeVisibilityApp()
|
|
708
|
+
{
|
|
709
|
+
return makeApplication({
|
|
710
|
+
Hash: 'Grades',
|
|
711
|
+
Layout: 'Tabular',
|
|
712
|
+
RecordSetAddress: 'Grades',
|
|
713
|
+
RecordManifest: 'GradeRowEditor',
|
|
714
|
+
DynamicColumns:
|
|
715
|
+
[
|
|
716
|
+
{
|
|
717
|
+
SourceAddress: 'Assignments',
|
|
718
|
+
HashTemplate: 'Grade_{~D:Record.IDAssignment~}',
|
|
719
|
+
NameTemplate: '{~D:Record.Title~}',
|
|
720
|
+
InformaryDataAddressTemplate: 'Grades.{~D:Record.IDAssignment~}',
|
|
721
|
+
DataType: 'Number',
|
|
722
|
+
PictForm: { InputType: 'Number' }
|
|
723
|
+
}
|
|
724
|
+
]
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
// Paint the view into a real destination element so #SECTION-<formID> exists to assert on.
|
|
729
|
+
function paintView(pView)
|
|
730
|
+
{
|
|
731
|
+
document.body.innerHTML = `<div id="${String(pView.options.DefaultDestinationAddress).replace(/^#/, '')}"></div>`;
|
|
732
|
+
pView.render();
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
test('A hidden section STAYS hidden across a DynamicColumns re-render', (fDone) =>
|
|
736
|
+
{
|
|
737
|
+
bootstrap(makeVisibilityApp(), (_Pict) =>
|
|
738
|
+
{
|
|
739
|
+
let tmpView = _Pict.views['PictSectionForm-Class'];
|
|
740
|
+
let tmpGroup = tmpView.sectionDefinition.Groups[0];
|
|
741
|
+
let tmpBehaviors = _Pict.providers.DynamicFormSolverBehaviors;
|
|
742
|
+
let fSection = () => document.querySelector(`#SECTION-${tmpView.formID}`);
|
|
743
|
+
|
|
744
|
+
paintView(tmpView);
|
|
745
|
+
Expect(fSection()).to.not.equal(null, 'the section painted');
|
|
746
|
+
|
|
747
|
+
tmpBehaviors.hideSection('Class');
|
|
748
|
+
Expect(fSection().className).to.contain('pict-section-form-hidden-section', 'baseline: section hidden');
|
|
749
|
+
|
|
750
|
+
// Rename a source row: namesChanged, so the Tabular layout re-renders the section mid-marshal.
|
|
751
|
+
_Pict.AppData.Assignments[0].Title = 'Renamed';
|
|
752
|
+
_Pict.providers['Pict-Layout-Tabular'].onDataMarshalToForm(tmpView, tmpGroup);
|
|
753
|
+
|
|
754
|
+
Expect(tmpGroup.supportingManifest.elementDescriptors['Grade_1'].Name).to.equal('Renamed',
|
|
755
|
+
'the re-render did happen (header label re-baked)');
|
|
756
|
+
Expect(fSection()).to.not.equal(null, 'the section re-painted');
|
|
757
|
+
Expect(fSection().className).to.contain('pict-section-form-hidden-section',
|
|
758
|
+
'the hide class survived the DynamicColumns re-render');
|
|
759
|
+
}, fDone);
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
test('A section shown again STAYS visible across a DynamicColumns re-render', (fDone) =>
|
|
763
|
+
{
|
|
764
|
+
bootstrap(makeVisibilityApp(), (_Pict) =>
|
|
765
|
+
{
|
|
766
|
+
let tmpView = _Pict.views['PictSectionForm-Class'];
|
|
767
|
+
let tmpGroup = tmpView.sectionDefinition.Groups[0];
|
|
768
|
+
let tmpBehaviors = _Pict.providers.DynamicFormSolverBehaviors;
|
|
769
|
+
let fSection = () => document.querySelector(`#SECTION-${tmpView.formID}`);
|
|
770
|
+
|
|
771
|
+
paintView(tmpView);
|
|
772
|
+
tmpBehaviors.hideSection('Class');
|
|
773
|
+
tmpBehaviors.showSection('Class');
|
|
774
|
+
|
|
775
|
+
_Pict.AppData.Assignments[0].Title = 'Renamed';
|
|
776
|
+
_Pict.providers['Pict-Layout-Tabular'].onDataMarshalToForm(tmpView, tmpGroup);
|
|
777
|
+
|
|
778
|
+
Expect(fSection().className).to.not.contain('pict-section-form-hidden-section',
|
|
779
|
+
'a re-shown section must not be re-hidden by the restore');
|
|
780
|
+
}, fDone);
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
test('A hidden GROUP stays hidden across renderGroupInPlace', (fDone) =>
|
|
784
|
+
{
|
|
785
|
+
bootstrap(makeVisibilityApp(), (_Pict) =>
|
|
786
|
+
{
|
|
787
|
+
let tmpView = _Pict.views['PictSectionForm-Class'];
|
|
788
|
+
let tmpBehaviors = _Pict.providers.DynamicFormSolverBehaviors;
|
|
789
|
+
let fGroup = () => document.querySelector(`#GROUP-${tmpView.formID}-Grades`);
|
|
790
|
+
|
|
791
|
+
paintView(tmpView);
|
|
792
|
+
Expect(fGroup()).to.not.equal(null, 'the group painted');
|
|
793
|
+
|
|
794
|
+
tmpBehaviors.hideGroup('Class', 'Grades');
|
|
795
|
+
Expect(fGroup().className).to.contain('pict-section-form-hidden-group', 'baseline: group hidden');
|
|
796
|
+
|
|
797
|
+
// renderGroupInPlace swaps the group element's outerHTML for freshly parsed template
|
|
798
|
+
// output, which carries only the manifest CSSClass -- the hide class has to be restored.
|
|
799
|
+
Expect(tmpBehaviors.renderGroupInPlace(tmpView, 'Grades')).to.equal(true, 'scoped render ran');
|
|
800
|
+
|
|
801
|
+
Expect(fGroup()).to.not.equal(null, 'the group re-painted');
|
|
802
|
+
Expect(fGroup().className).to.contain('pict-section-form-hidden-group',
|
|
803
|
+
'the group hide class survived the in-place group render');
|
|
804
|
+
}, fDone);
|
|
805
|
+
});
|
|
806
|
+
|
|
807
|
+
/*
|
|
808
|
+
Highlight classes and inline colors land on rows and cells the section template regenerates,
|
|
809
|
+
so they die on the same renders the hide class did. MI-BatchSheetCombined hides rows inside
|
|
810
|
+
its CSB tables with highlighttabularrow(..., "is-hidden"), which is the same defect one layer
|
|
811
|
+
down: the row would come back visible on a Source/Name change.
|
|
812
|
+
*/
|
|
813
|
+
test('A tabular row highlight survives a DynamicColumns re-render', (fDone) =>
|
|
814
|
+
{
|
|
815
|
+
bootstrap(makeVisibilityApp(), (_Pict) =>
|
|
816
|
+
{
|
|
817
|
+
let tmpView = _Pict.views['PictSectionForm-Class'];
|
|
818
|
+
let tmpGroup = tmpView.sectionDefinition.Groups[0];
|
|
819
|
+
let tmpBehaviors = _Pict.providers.DynamicFormSolverBehaviors;
|
|
820
|
+
let fRow = () => document.querySelector(`#GROUP-${tmpView.formID}-Grades tr[data-tabular-row-index="1"]`);
|
|
821
|
+
|
|
822
|
+
paintView(tmpView);
|
|
823
|
+
Expect(fRow()).to.not.equal(null, 'the row painted');
|
|
824
|
+
|
|
825
|
+
tmpBehaviors.highlightTabularRow('Class', 'Grades', 1, 1, 'is-flagged');
|
|
826
|
+
Expect(fRow().className).to.contain('is-flagged', 'baseline: row highlighted');
|
|
827
|
+
|
|
828
|
+
_Pict.AppData.Assignments[0].Title = 'Renamed';
|
|
829
|
+
_Pict.providers['Pict-Layout-Tabular'].onDataMarshalToForm(tmpView, tmpGroup);
|
|
830
|
+
|
|
831
|
+
Expect(fRow()).to.not.equal(null, 'the row re-painted');
|
|
832
|
+
Expect(fRow().className).to.contain('is-flagged', 'the highlight survived the re-render');
|
|
833
|
+
}, fDone);
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
test('A highlight that was turned back off stays off across a re-render', (fDone) =>
|
|
837
|
+
{
|
|
838
|
+
bootstrap(makeVisibilityApp(), (_Pict) =>
|
|
839
|
+
{
|
|
840
|
+
let tmpView = _Pict.views['PictSectionForm-Class'];
|
|
841
|
+
let tmpGroup = tmpView.sectionDefinition.Groups[0];
|
|
842
|
+
let tmpBehaviors = _Pict.providers.DynamicFormSolverBehaviors;
|
|
843
|
+
let fRow = () => document.querySelector(`#GROUP-${tmpView.formID}-Grades tr[data-tabular-row-index="1"]`);
|
|
844
|
+
|
|
845
|
+
paintView(tmpView);
|
|
846
|
+
tmpBehaviors.highlightTabularRow('Class', 'Grades', 1, 1, 'is-flagged');
|
|
847
|
+
tmpBehaviors.highlightTabularRow('Class', 'Grades', 1, 0, 'is-flagged');
|
|
848
|
+
|
|
849
|
+
_Pict.AppData.Assignments[0].Title = 'Renamed';
|
|
850
|
+
_Pict.providers['Pict-Layout-Tabular'].onDataMarshalToForm(tmpView, tmpGroup);
|
|
851
|
+
|
|
852
|
+
Expect(fRow().className).to.not.contain('is-flagged', 'a cleared highlight must not come back');
|
|
853
|
+
}, fDone);
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
test('Re-highlighting the same row does not accumulate registry entries', (fDone) =>
|
|
857
|
+
{
|
|
858
|
+
bootstrap(makeVisibilityApp(), (_Pict) =>
|
|
859
|
+
{
|
|
860
|
+
let tmpView = _Pict.views['PictSectionForm-Class'];
|
|
861
|
+
let tmpBehaviors = _Pict.providers.DynamicFormSolverBehaviors;
|
|
862
|
+
paintView(tmpView);
|
|
863
|
+
|
|
864
|
+
for (let i = 0; i < 5; i++)
|
|
865
|
+
{
|
|
866
|
+
tmpBehaviors.highlightTabularRow('Class', 'Grades', 1, 1, 'is-flagged');
|
|
867
|
+
}
|
|
868
|
+
let tmpKeys = Object.keys(tmpBehaviors.decorationState).filter((pKey) => pKey.indexOf('Class::Grades::row::1::is-flagged') === 0);
|
|
869
|
+
Expect(tmpKeys.length).to.equal(1, 'keyed by target, so repeats overwrite');
|
|
870
|
+
}, fDone);
|
|
871
|
+
});
|
|
872
|
+
|
|
873
|
+
test('Decorations recorded against another section are not replayed here', (fDone) =>
|
|
874
|
+
{
|
|
875
|
+
bootstrap(makeVisibilityApp(), (_Pict) =>
|
|
876
|
+
{
|
|
877
|
+
let tmpView = _Pict.views['PictSectionForm-Class'];
|
|
878
|
+
let tmpBehaviors = _Pict.providers.DynamicFormSolverBehaviors;
|
|
879
|
+
paintView(tmpView);
|
|
880
|
+
|
|
881
|
+
let tmpCalls = [];
|
|
882
|
+
let tmpOriginal = tmpBehaviors.highlightTabularRow;
|
|
883
|
+
tmpBehaviors.decorationState['SomeOtherSection::Grid::row::0::is-flagged'] =
|
|
884
|
+
{ Section: 'SomeOtherSection', Method: 'highlightTabularRow', Arguments: [ 'SomeOtherSection', 'Grid', 0, 1, 'is-flagged' ] };
|
|
885
|
+
tmpBehaviors.highlightTabularRow = function () { tmpCalls.push(Array.from(arguments)); return true; };
|
|
886
|
+
try
|
|
887
|
+
{
|
|
888
|
+
tmpBehaviors.reapplySectionDecorations('Class');
|
|
889
|
+
}
|
|
890
|
+
finally
|
|
891
|
+
{
|
|
892
|
+
tmpBehaviors.highlightTabularRow = tmpOriginal;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
Expect(tmpCalls.length).to.equal(0, 'replay is scoped to the rendered section');
|
|
896
|
+
}, fDone);
|
|
897
|
+
});
|
|
898
|
+
|
|
899
|
+
test('A section with no recorded visibility is left exactly as the template rendered it', (fDone) =>
|
|
900
|
+
{
|
|
901
|
+
bootstrap(makeVisibilityApp(), (_Pict) =>
|
|
902
|
+
{
|
|
903
|
+
let tmpView = _Pict.views['PictSectionForm-Class'];
|
|
904
|
+
let tmpGroup = tmpView.sectionDefinition.Groups[0];
|
|
905
|
+
let fSection = () => document.querySelector(`#SECTION-${tmpView.formID}`);
|
|
906
|
+
|
|
907
|
+
paintView(tmpView);
|
|
908
|
+
let tmpBaseline = fSection().className;
|
|
909
|
+
|
|
910
|
+
_Pict.AppData.Assignments[0].Title = 'Renamed';
|
|
911
|
+
_Pict.providers['Pict-Layout-Tabular'].onDataMarshalToForm(tmpView, tmpGroup);
|
|
912
|
+
|
|
913
|
+
Expect(fSection().className).to.equal(tmpBaseline,
|
|
914
|
+
'forms that never call the visibility solvers are untouched');
|
|
915
|
+
}, fDone);
|
|
916
|
+
});
|
|
917
|
+
|
|
699
918
|
test('Steady-state re-run reports neither changed nor namesChanged', (fDone) =>
|
|
700
919
|
{
|
|
701
920
|
let App = makeApplication({
|