@saltcorn/builder 0.7.4 → 0.8.0-beta.1

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.
@@ -29,46 +29,45 @@ export /**
29
29
  * @subcategory components
30
30
  * @namespace
31
31
  */
32
- const View = ({ name, view, configuration, state }) => {
33
- const {
34
- selected,
35
- node_id,
36
- connectors: { connect, drag },
37
- } = useNode((node) => ({ selected: node.events.selected, node_id: node.id }));
38
- const options = useContext(optionsCtx);
39
-
40
- const views = options.views;
41
- const theview = views.find((v) => v.name === view);
42
- const label = theview ? theview.label : view;
43
- const { previews, setPreviews } = useContext(previewCtx);
44
- const myPreview = previews[node_id];
45
- useEffect(() => {
46
- fetchViewPreview({
47
- options,
48
- view,
49
- setPreviews,
50
- configuration,
32
+ const View = ({ name, view, configuration, state }) => {
33
+ const {
34
+ selected,
51
35
  node_id,
52
- })();
53
- }, [view, configuration, state]);
54
- return (
55
- <div
56
- ref={(dom) => connect(drag(dom))}
57
- className={`${myPreview ? "" : "builder-embed-view"} text-center ${
58
- selected ? "selected-node" : ""
59
- }`}
60
- >
61
- {myPreview ? (
62
- <div
63
- className="d-inline"
64
- dangerouslySetInnerHTML={{ __html: myPreview }}
65
- ></div>
66
- ) : (
67
- `View: ${label}`
68
- )}
69
- </div>
70
- );
71
- };
36
+ connectors: { connect, drag },
37
+ } = useNode((node) => ({ selected: node.events.selected, node_id: node.id }));
38
+ const options = useContext(optionsCtx);
39
+
40
+ const views = options.views;
41
+ const theview = views.find((v) => v.name === view);
42
+ const label = theview ? theview.label : view;
43
+ const { previews, setPreviews } = useContext(previewCtx);
44
+ const myPreview = previews[node_id];
45
+ useEffect(() => {
46
+ fetchViewPreview({
47
+ options,
48
+ view,
49
+ setPreviews,
50
+ configuration,
51
+ node_id,
52
+ })();
53
+ }, [view, configuration, state]);
54
+ return (
55
+ <div
56
+ ref={(dom) => connect(drag(dom))}
57
+ className={`${myPreview ? "" : "builder-embed-view"} ${selected ? "selected-node" : ""
58
+ }`}
59
+ >
60
+ {myPreview ? (
61
+ <div
62
+ className="d-inline"
63
+ dangerouslySetInnerHTML={{ __html: myPreview }}
64
+ ></div>
65
+ ) : (
66
+ `View: ${label}`
67
+ )}
68
+ </div>
69
+ );
70
+ };
72
71
 
73
72
  export /**
74
73
  * @returns {div}
@@ -76,115 +75,161 @@ export /**
76
75
  * @subcategory components
77
76
  * @namespace
78
77
  */
79
- const ViewSettings = () => {
80
- const node = useNode((node) => ({
81
- name: node.data.props.name,
82
- view: node.data.props.view,
83
- state: node.data.props.state,
84
- extra_state_fml: node.data.props.extra_state_fml,
85
- configuration: node.data.props.configuration, // fixed states
86
- node_id: node.id,
87
- }));
78
+ const ViewSettings = () => {
79
+ const node = useNode((node) => ({
80
+ view_name: node.data.props.view_name,
81
+ name: node.data.props.name,
82
+ view: node.data.props.view,
83
+ state: node.data.props.state,
84
+ extra_state_fml: node.data.props.extra_state_fml,
85
+ configuration: node.data.props.configuration, // fixed states
86
+ node_id: node.id,
87
+ }));
88
88
 
89
- const {
90
- actions: { setProp },
91
- name,
92
- view,
93
- state,
94
- node_id,
95
- configuration,
96
- extra_state_fml,
97
- } = node;
98
- const options = useContext(optionsCtx);
99
- const views = options.views;
100
- const fixed_state_fields =
101
- options.fixed_state_fields && options.fixed_state_fields[view];
102
- const { setPreviews } = useContext(previewCtx);
89
+ const {
90
+ actions: { setProp },
91
+ name,
92
+ view,
93
+ state,
94
+ node_id,
95
+ configuration,
96
+ extra_state_fml,
97
+ view_name,
98
+ } = node;
99
+ const options = useContext(optionsCtx);
100
+ const views = options.views;
101
+ const fixed_state_fields =
102
+ options.fixed_state_fields && options.fixed_state_fields[view];
103
+ const { setPreviews } = useContext(previewCtx);
103
104
 
104
- const setAProp = setAPropGen(setProp);
105
- let errorString = false;
106
- try {
107
- Function("return " + extra_state_fml);
108
- } catch (error) {
109
- errorString = error.message;
110
- }
111
- let viewname = view;
112
- if (viewname && viewname.includes(":")) viewname = viewname.split(":")[1];
113
- if (viewname && viewname.includes(".")) viewname = viewname.split(".")[0];
105
+ const setAProp = setAPropGen(setProp);
106
+ let errorString = false;
107
+ try {
108
+ Function("return " + extra_state_fml);
109
+ } catch (error) {
110
+ errorString = error.message;
111
+ }
112
+ let viewname = view_name || view;
113
+ if (viewname && viewname.includes(":")) viewname = viewname.split(":")[1];
114
+ if (viewname && viewname.includes(".")) viewname = viewname.split(".")[0];
115
+ const set_view_name = (e) => {
116
+ if (e.target) {
117
+ const target_value = e.target.value;
118
+ setProp((prop) => (prop.view_name = target_value));
119
+ if (target_value !== viewname) {
120
+ setProp((prop) => (prop.view = options.view_relation_opts[target_value][0].value));
114
121
 
115
- return (
116
- <div>
122
+ }
123
+ }
124
+ };
125
+ return (
117
126
  <div>
118
- <label>View to {options.mode === "show" ? "embed" : "show"}</label>
119
- <select
120
- value={view}
121
- className="form-control form-select"
122
- onChange={setAProp("view")}
123
- >
124
- {views.map((f, ix) => (
125
- <option key={ix} value={f.name}>
126
- {f.label || f.name}
127
- </option>
128
- ))}
129
- </select>
130
- </div>
131
- {options.mode === "page" && (
132
- <Fragment>
133
- <div>
134
- <label>State</label>
127
+ {options.view_name_opts
128
+ ? <Fragment>
129
+ <div>
130
+ <label>View to {options.mode === "show" ? "embed" : "show"}</label>
131
+ <select
132
+ value={viewname}
133
+ className="form-control form-select"
134
+ onChange={set_view_name}
135
+ onBlur={set_view_name}
136
+ >
137
+ {options.view_name_opts.map((f, ix) => (
138
+ <option key={ix} value={f.name}>
139
+ {f.label}
140
+ </option>
141
+ ))}
142
+ </select>
143
+ </div>
144
+ <div>
145
+ <label>Relation</label>
146
+ <select
147
+ value={view}
148
+ className="form-control form-select"
149
+ onChange={setAProp("view")}
150
+ onBlur={setAProp("view")}
151
+ >
152
+ {(options.view_relation_opts[viewname] || []).map((f, ix) => (
153
+ <option key={ix} value={f.value}>
154
+ {f.label}
155
+ </option>
156
+ ))}
157
+ </select>
158
+ </div>
159
+ </Fragment>
160
+ : <div>
161
+ <label>View to {options.mode === "show" ? "embed" : "show"}</label>
135
162
  <select
136
- value={state}
163
+ value={view}
137
164
  className="form-control form-select"
138
- onChange={setAProp("state")}
165
+ onChange={setAProp("view")}
166
+ onBlur={setAProp("view")}
139
167
  >
140
- <option value="shared">Shared</option>
141
- <option value="fixed">Fixed</option>
168
+ {views.map((f, ix) => (
169
+ <option key={ix} value={f.name}>
170
+ {f.label || f.name}
171
+ </option>
172
+ ))}
142
173
  </select>
143
- </div>
144
- {state === "fixed" &&
145
- fixed_state_fields &&
146
- fixed_state_fields.length > 0 && (
147
- <Fragment>
148
- <h6>View state fields</h6>
149
- <ConfigForm
150
- fields={fixed_state_fields}
151
- configuration={configuration || {}}
152
- setProp={setProp}
153
- node={node}
154
- />
155
- </Fragment>
156
- )}
157
- </Fragment>
158
- )}
159
- {(state === "shared" || options.mode === "page") && (
160
- <Fragment>
161
- {" "}
162
- <label>Extra state Formula <FormulaTooltip /></label>
163
- <input
164
- type="text"
165
- className="viewlink-label form-control"
166
- value={extra_state_fml}
167
- onChange={setAProp("extra_state_fml")}
168
- />
169
- {errorString ? (
170
- <small className="text-danger font-monospace d-block">
171
- {errorString}
172
- </small>
173
- ) : null}
174
- </Fragment>
175
- )}
176
- {view ? (
177
- <a
178
- className="d-block mt-2"
179
- target="_blank"
180
- href={`/viewedit/config/${viewname}`}
181
- >
182
- Configure this view
183
- </a>
184
- ) : null}
185
- </div>
186
- );
187
- };
174
+ </div>}
175
+ {options.mode === "page" && (
176
+ <Fragment>
177
+ <div>
178
+ <label>State</label>
179
+ <select
180
+ value={state}
181
+ className="form-control form-select"
182
+ onChange={setAProp("state")}
183
+ onBlur={setAProp("state")}
184
+ >
185
+ <option value="shared">Shared</option>
186
+ <option value="fixed">Fixed</option>
187
+ </select>
188
+ </div>
189
+ {state === "fixed" &&
190
+ fixed_state_fields &&
191
+ fixed_state_fields.length > 0 && (
192
+ <Fragment>
193
+ <h6>View state fields</h6>
194
+ <ConfigForm
195
+ fields={fixed_state_fields}
196
+ configuration={configuration || {}}
197
+ setProp={setProp}
198
+ node={node}
199
+ />
200
+ </Fragment>
201
+ )}
202
+ </Fragment>
203
+ )}
204
+ {(state === "shared" || options.mode === "page") && (
205
+ <Fragment>
206
+ {" "}
207
+ <label>Extra state Formula <FormulaTooltip /></label>
208
+ <input
209
+ type="text"
210
+ className="viewlink-label form-control"
211
+ value={extra_state_fml}
212
+ onChange={setAProp("extra_state_fml")}
213
+ />
214
+ {errorString ? (
215
+ <small className="text-danger font-monospace d-block">
216
+ {errorString}
217
+ </small>
218
+ ) : null}
219
+ </Fragment>
220
+ )}
221
+ {view ? (
222
+ <a
223
+ className="d-block mt-2"
224
+ target="_blank"
225
+ href={`/viewedit/config/${viewname}`}
226
+ >
227
+ Configure this view
228
+ </a>
229
+ ) : null}
230
+ </div>
231
+ );
232
+ };
188
233
 
189
234
  /**
190
235
  * @type {object}