@raketa-cloud/admin 0.0.72 → 0.0.73

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": "@raketa-cloud/admin",
3
- "version": "0.0.72",
3
+ "version": "0.0.73",
4
4
  "main": "src/index.js",
5
5
  "scripts": {
6
6
  "dev": "npx tailwindcss -i ./src/styles/application.css -o ../../apps/admin/static/application.css --watch",
package/src/Adapter.js CHANGED
@@ -68,13 +68,25 @@ const renderError = (message, stack) => {
68
68
  return `<style>${errorCSS}</style><div class="fail-squid">🦑</div><h1>${message}</h1><pre>${escapeHtml(stack)}</pre>`;
69
69
  };
70
70
 
71
+ function toArray(value) {
72
+ if (Array.isArray(value)) {
73
+ return value;
74
+ }
75
+
76
+ return [value].filter(Boolean);
77
+ }
78
+
71
79
  function putIn(result, key, value) {
72
80
  const segments = key.split(/[\[\]]+/).filter(Boolean);
73
81
  let current = result;
74
82
 
75
83
  segments.forEach((segment, idx) => {
76
84
  if (idx === segments.length - 1) {
77
- current[segment] = value;
85
+ if (key.endsWith("[]") || Array.isArray(value)) {
86
+ current[segment] = toArray(value);
87
+ } else {
88
+ current[segment] = value;
89
+ }
78
90
  } else {
79
91
  if (!current[segment]) {
80
92
  current[segment] = {};
@@ -1,4 +1,4 @@
1
- import { toDateTimeInput, checkboxesToArray } from "../../utils";
1
+ import { toDateTimeInput } from "../../utils";
2
2
 
3
3
  const edit_form = async (ctx) => {
4
4
  const { parent_id } = ctx.params;
@@ -41,7 +41,6 @@ const update = async (ctx) => {
41
41
  }
42
42
 
43
43
  const params = ctx.resourceParams.resource ? ctx.resourceParams.resource : {};
44
- params.tags = checkboxesToArray(params.tags);
45
44
 
46
45
  const resource = ctx.client.articleRevisions.deepMerge(
47
46
  revision,
@@ -1,4 +1,4 @@
1
- import { toDateTimeInput, checkboxesToArray } from "../../utils";
1
+ import { toDateTimeInput } from "../../utils";
2
2
 
3
3
  const edit_form = async (ctx) => {
4
4
  const { parent_id } = ctx.params;
@@ -37,8 +37,6 @@ const update = async (ctx) => {
37
37
  }
38
38
 
39
39
  const params = ctx.resourceParams.resource ? ctx.resourceParams.resource : {};
40
- params.tags = checkboxesToArray(params.tags);
41
-
42
40
  const resource = ctx.client.eventRevisions.deepMerge(
43
41
  revision,
44
42
  ctx.client.eventRevisions.formatDates(params)
@@ -1,5 +1,3 @@
1
- import { checkboxesToArray } from "../../utils";
2
-
3
1
  const fetchDefaultLocaleTags = async (ctx, resource) => {
4
2
  if (ctx.locale === ctx.defaultLocale) {
5
3
  return { defaultLocaleName: "", defaultLocaleTags: [] };
@@ -68,10 +66,10 @@ const update = async (ctx) => {
68
66
  }
69
67
 
70
68
  const params = ctx.resourceParams.resource ? ctx.resourceParams.resource : {};
71
- params.tags = checkboxesToArray(params.tags);
72
-
73
69
  const resource = ctx.client.pageRevisions.deepMerge(revision, params);
74
70
 
71
+ console.log({ params });
72
+
75
73
  const { errors } = await ctx.client.pageRevisions.update(
76
74
  revision.id,
77
75
  ctx.locale,
@@ -207,7 +207,7 @@ export default class FormBuilder extends HTMLBuilder {
207
207
  }
208
208
 
209
209
  checkbox_group(name, opts = {}) {
210
- const { value, options = [], hint = "", ...rest } = opts;
210
+ const { value, options = [], hint = "", name: optsName, ...rest } = opts;
211
211
  const selected = value || this.__getValue(name);
212
212
 
213
213
  const renderedOpts = [];
@@ -219,7 +219,7 @@ export default class FormBuilder extends HTMLBuilder {
219
219
 
220
220
  const checkbox = this.tag("input", null, {
221
221
  type: "checkbox",
222
- name: `${opts.name}[]`,
222
+ name: `${optsName}[]`,
223
223
  value: o[0],
224
224
  ...additionalOpts,
225
225
  });
@@ -227,6 +227,16 @@ export default class FormBuilder extends HTMLBuilder {
227
227
  renderedOpts.push(this.tag("label", `${checkbox} ${o[1]}`));
228
228
  }
229
229
 
230
+ if (renderedOpts.length) {
231
+ renderedOpts.push(
232
+ this.tag("input", null, {
233
+ type: "hidden",
234
+ name: `${optsName}[]`,
235
+ value: "",
236
+ })
237
+ );
238
+ }
239
+
230
240
  return this.withHint(
231
241
  this.tag(
232
242
  "div",
@@ -234,8 +244,8 @@ export default class FormBuilder extends HTMLBuilder {
234
244
  renderedOpts.length
235
245
  ? renderedOpts.join("")
236
246
  : this.tag("div", "No items available.", {
237
- class: "italic opacity-50",
238
- }),
247
+ class: "italic opacity-50",
248
+ }),
239
249
 
240
250
  {
241
251
  ...rest,
package/src/utils.js CHANGED
@@ -28,15 +28,3 @@ export function toDateTimeInput(initialDate = null) {
28
28
  now.getMinutes().toString().padStart(2, "0"),
29
29
  ].join("");
30
30
  }
31
-
32
- export function checkboxesToArray(value) {
33
- if (Array.isArray(value)) {
34
- return value;
35
- }
36
-
37
- if (!value) {
38
- return [];
39
- }
40
-
41
- return [value];
42
- }