@saltcorn/builder 0.9.1-beta.10 → 0.9.1-beta.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/builder",
3
- "version": "0.9.1-beta.10",
3
+ "version": "0.9.1-beta.12",
4
4
  "description": "Drag and drop view builder for Saltcorn, open-source no-code platform",
5
5
  "main": "index.js",
6
6
  "homepage": "https://saltcorn.com",
@@ -18,7 +18,9 @@ import {
18
18
  DynamicFontAwesomeIcon,
19
19
  setAPropGen,
20
20
  buildOptions,
21
+ ConfigField,
21
22
  } from "./utils";
23
+ import { ntimes } from "./Columns";
22
24
 
23
25
  export /**
24
26
  *
@@ -104,6 +106,10 @@ const ActionSettings = () => {
104
106
  action_bgcol: node.data.props.action_bgcol,
105
107
  action_bordercol: node.data.props.action_bordercol,
106
108
  action_textcol: node.data.props.action_textcol,
109
+ nsteps: node.data.props.nsteps,
110
+ step_only_ifs: node.data.props.step_only_ifs,
111
+ step_action_names: node.data.props.step_action_names,
112
+ setting_action_n: node.data.props.setting_action_n,
107
113
  }));
108
114
  const {
109
115
  actions: { setProp },
@@ -117,11 +123,22 @@ const ActionSettings = () => {
117
123
  configuration,
118
124
  action_label,
119
125
  action_style,
126
+ nsteps,
127
+ setting_action_n,
128
+ step_only_ifs,
129
+ step_action_names,
120
130
  } = node;
121
131
  const options = useContext(optionsCtx);
122
132
  const getCfgFields = (fv) => (options.actionConfigForms || {})[fv];
123
133
  const cfgFields = getCfgFields(name);
124
134
  const setAProp = setAPropGen(setProp);
135
+ const use_setting_action_n =
136
+ setting_action_n || setting_action_n === 0 ? setting_action_n : 0;
137
+ const stepCfgFields =
138
+ name === "Multi-step action"
139
+ ? getCfgFields(step_action_names?.[use_setting_action_n])
140
+ : null;
141
+
125
142
  return (
126
143
  <div>
127
144
  <table className="w-100">
@@ -154,6 +171,12 @@ const ActionSettings = () => {
154
171
  prop.action_row_variable = "state";
155
172
  }
156
173
  }
174
+ if (value === "Multi-step action" && !nsteps)
175
+ prop.nsteps = 1;
176
+ if (value === "Multi-step action" && !setting_action_n)
177
+ prop.setting_action_n = 0;
178
+ if (value === "Multi-step action" && !configuration.steps)
179
+ prop.configuration = { steps: [] };
157
180
  });
158
181
  setInitialConfig(setProp, value, getCfgFields(value));
159
182
  }}
@@ -163,6 +186,9 @@ const ActionSettings = () => {
163
186
  {f}
164
187
  </option>
165
188
  ))}
189
+ {options.allowMultiStepAction ? (
190
+ <option value={"Multi-step action"}>Multi-step action</option>
191
+ ) : null}
166
192
  </select>
167
193
  </td>
168
194
  </tr>
@@ -255,7 +281,92 @@ const ActionSettings = () => {
255
281
  {action_style !== "on_page_load" ? (
256
282
  <BlockSetting block={block} setProp={setProp} />
257
283
  ) : null}
258
- {cfgFields ? (
284
+ {name === "Multi-step action" ? (
285
+ <Fragment>
286
+ <label>#Steps</label>{" "}
287
+ <input
288
+ type="number"
289
+ value={nsteps}
290
+ className="form-control w-50 d-inline"
291
+ step="1"
292
+ min="1"
293
+ onChange={(e) => {
294
+ if (!e.target) return;
295
+ const value = e.target.value;
296
+ setProp((prop) => {
297
+ prop.nsteps = value;
298
+ });
299
+ }}
300
+ />
301
+ <ConfigField
302
+ field={{
303
+ name: "setting_action_n",
304
+ label: "Column number",
305
+ type: "btn_select",
306
+ options: ntimes(nsteps, (i) => ({
307
+ value: i,
308
+ title: `${i + 1}`,
309
+ label: `${i + 1}`,
310
+ })),
311
+ }}
312
+ node={node}
313
+ setProp={setProp}
314
+ props={node}
315
+ ></ConfigField>
316
+ <label>Action</label>
317
+ <select
318
+ value={step_action_names?.[use_setting_action_n] || ""}
319
+ className="form-control form-select"
320
+ onChange={(e) => {
321
+ if (!e.target) return;
322
+ const value = e.target.value;
323
+ setProp((prop) => {
324
+ if (!prop.step_action_names) prop.step_action_names = [];
325
+ prop.step_action_names[use_setting_action_n] = value;
326
+ });
327
+ }}
328
+ >
329
+ {options.actions.map((f, ix) => (
330
+ <option key={ix} value={f}>
331
+ {f}
332
+ </option>
333
+ ))}
334
+ </select>
335
+ <label>Only if... (formula)</label>
336
+ <input
337
+ type="text"
338
+ className="form-control text-to-display"
339
+ value={step_only_ifs?.[use_setting_action_n] || ""}
340
+ onChange={(e) => {
341
+ if (!e.target) return;
342
+ const value = e.target.value;
343
+ setProp((prop) => {
344
+ if (!prop.step_only_ifs) prop.step_only_ifs = [];
345
+ prop.step_only_ifs[use_setting_action_n] = value;
346
+ });
347
+ }}
348
+ />
349
+ {stepCfgFields ? (
350
+ <Fragment>
351
+ Step configuration:
352
+ <ConfigForm
353
+ fields={stepCfgFields}
354
+ configuration={
355
+ configuration?.steps?.[use_setting_action_n] || {}
356
+ }
357
+ setProp={setProp}
358
+ setter={(prop, fldname, v) => {
359
+ if (!prop.configuration.steps) prop.configuration.steps = [];
360
+ if (!prop.configuration.steps[use_setting_action_n])
361
+ prop.configuration.steps[use_setting_action_n] = {};
362
+ prop.configuration.steps[use_setting_action_n][fldname] = v;
363
+ }}
364
+ node={node}
365
+ />
366
+ </Fragment>
367
+ ) : null}
368
+ </Fragment>
369
+ ) : cfgFields ? (
259
370
  <ConfigForm
260
371
  fields={cfgFields}
261
372
  configuration={configuration}
@@ -272,6 +383,7 @@ const ActionSettings = () => {
272
383
  */
273
384
  Action.craft = {
274
385
  displayName: "Action",
386
+ defaultProps: { setting_action_n: 0, nsteps: 1 },
275
387
  related: {
276
388
  settings: ActionSettings,
277
389
  },
@@ -260,24 +260,6 @@ const TabsSettings = () => {
260
260
  </select>
261
261
  </td>
262
262
  </tr>
263
- {options.mode === "edit" && !serverRendered ? (
264
- <tr>
265
- <td colSpan="2">
266
- <div className="form-check">
267
- <input
268
- className="form-check-input"
269
- name="block"
270
- type="checkbox"
271
- checked={disable_inactive}
272
- onChange={setAProp("disable_inactive", { checked: true })}
273
- />
274
- <label className="form-check-label">
275
- Disable inactive inputs
276
- </label>
277
- </div>
278
- </td>
279
- </tr>
280
- ) : null}
281
263
  </Fragment>
282
264
  ) : (
283
265
  <Fragment>
@@ -652,6 +652,7 @@ const ConfigForm = ({
652
652
  fields,
653
653
  configuration,
654
654
  setProp,
655
+ setter,
655
656
  node,
656
657
  onChange,
657
658
  tableName,
@@ -663,7 +664,7 @@ const ConfigForm = ({
663
664
  let noshow = false;
664
665
  Object.entries(f.showIf).forEach(([nm, value]) => {
665
666
  if (Array.isArray(value))
666
- noshow = noshow || value.includes(configuration[nm]);
667
+ noshow = noshow || !value.includes(configuration[nm]);
667
668
  else noshow = noshow || value !== configuration[nm];
668
669
  });
669
670
  if (noshow) return null;
@@ -684,6 +685,7 @@ const ConfigForm = ({
684
685
  ) : null}
685
686
  <ConfigField
686
687
  field={f}
688
+ setter={setter}
687
689
  configuration={configuration}
688
690
  setProp={setProp}
689
691
  onChange={onChange}
@@ -734,6 +736,7 @@ const ConfigField = ({
734
736
  setProp,
735
737
  onChange,
736
738
  props,
739
+ setter,
737
740
  isStyle,
738
741
  }) => {
739
742
  /**
@@ -744,7 +747,8 @@ const ConfigField = ({
744
747
 
745
748
  const myOnChange = (v) => {
746
749
  setProp((prop) => {
747
- if (configuration) {
750
+ if (setter) setter(prop, field.name, v);
751
+ else if (configuration) {
748
752
  if (!prop.configuration) prop.configuration = {};
749
753
  prop.configuration[field.name] = v;
750
754
  } else if (isStyle) {
@@ -1004,7 +1008,7 @@ const SettingsFromFields =
1004
1008
  let noshow = false;
1005
1009
  Object.entries(f.showIf).forEach(([nm, value]) => {
1006
1010
  if (Array.isArray(value))
1007
- noshow = noshow || value.includes(node[nm]);
1011
+ noshow = noshow || !value.includes(node[nm]);
1008
1012
  else noshow = noshow || value !== node[nm];
1009
1013
  });
1010
1014
  if (noshow) return null;
@@ -167,6 +167,9 @@ const layoutToNodes = (layout, query, actions, parent = "ROOT") => {
167
167
  action_bgcol={segment.action_bgcol || ""}
168
168
  action_bordercol={segment.action_bordercol || ""}
169
169
  action_textcol={segment.action_textcol || ""}
170
+ nsteps={segment.nsteps || ""}
171
+ step_only_ifs={segment.step_only_ifs || ""}
172
+ step_action_names={segment.step_action_names || ""}
170
173
  confirm={segment.confirm}
171
174
  configuration={segment.configuration || {}}
172
175
  block={segment.block || false}
@@ -555,6 +558,9 @@ const craftToSaltcorn = (nodes, startFrom = "ROOT") => {
555
558
  action_textcol: node.props.action_textcol,
556
559
  minRole: node.props.minRole,
557
560
  confirm: node.props.confirm,
561
+ nsteps: node.props.nsteps,
562
+ step_only_ifs: node.props.step_only_ifs,
563
+ step_action_names: node.props.step_action_names,
558
564
  configuration: node.props.configuration,
559
565
  isFormula: node.props.isFormula,
560
566
  rndid: node.props.rndid === "not_assigned" ? newid : node.props.rndid,
@@ -578,6 +584,9 @@ const craftToSaltcorn = (nodes, startFrom = "ROOT") => {
578
584
  action_bgcol: node.props.action_bgcol,
579
585
  action_bordercol: node.props.action_bordercol,
580
586
  action_textcol: node.props.action_textcol,
587
+ nsteps: node.props.nsteps,
588
+ step_only_ifs: node.props.step_only_ifs,
589
+ step_action_names: node.props.step_action_names,
581
590
  minRole: node.props.minRole,
582
591
  isFormula: node.props.isFormula,
583
592
  rndid: node.props.rndid === "not_assigned" ? newid : node.props.rndid,