@raketa-cloud/admin 0.0.98 → 0.0.99

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.98",
3
+ "version": "0.0.99",
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
@@ -10,6 +10,7 @@ import form_for from "./helpers/form_for";
10
10
  import history from "./helpers/historyUtils";
11
11
  import pagination from "./helpers/pagination_helper";
12
12
  import sort_button from "./helpers/sort_button";
13
+ import utils from "./helpers/utils";
13
14
 
14
15
  function escapeHtml(string) {
15
16
  var matchHtmlRegExp = /["'&<>]/;
@@ -172,6 +173,7 @@ export default class Adapter {
172
173
  f,
173
174
  form_for: form_for(viewHelpersConfig),
174
175
  history,
176
+ utils,
175
177
  sort_button,
176
178
  pagination,
177
179
  Inflector,
@@ -0,0 +1,21 @@
1
+ function includedInCollection(value, collection) {
2
+ if (!collection) {
3
+ return false;
4
+ }
5
+
6
+ if (typeof collection === "string") {
7
+ return value === collection;
8
+ }
9
+
10
+ if (Array.isArray(collection)) {
11
+ return collection.includes(value);
12
+ }
13
+
14
+ throw new Error(
15
+ "Invalid input for collection. Expected a string or an array."
16
+ );
17
+ }
18
+
19
+ export default {
20
+ includedInCollection,
21
+ };
@@ -0,0 +1,27 @@
1
+ import utils from "../../helpers/utils";
2
+
3
+ describe("includedInCollection", () => {
4
+ it("returns true when the given collection is a string equal to the given value", () => {
5
+ expect(utils.includedInCollection("key", "key")).toEqual(true);
6
+ });
7
+
8
+ it("returns false when the given collection is a string not equal to the given value", () => {
9
+ expect(utils.includedInCollection("key", "key-2")).toEqual(false);
10
+ });
11
+
12
+ it("returns true when the given collection is an array including the given value", () => {
13
+ expect(utils.includedInCollection("key", ["key"])).toEqual(true);
14
+ });
15
+
16
+ it("returns false when the given collection is an array not including the given value", () => {
17
+ expect(utils.includedInCollection("key", ["key-2"])).toEqual(false);
18
+ });
19
+
20
+ it("returns false when the given collection null", () => {
21
+ expect(utils.includedInCollection("key", null)).toEqual(false);
22
+ });
23
+
24
+ it("returns false when the given collection undefined", () => {
25
+ expect(utils.includedInCollection("key", undefined)).toEqual(false);
26
+ });
27
+ });
@@ -58,7 +58,7 @@
58
58
  <div class="checkbox-group mb-4">
59
59
  <% Object.entries(history.changeTypes(_context.resourceConfig.articleType)).forEach(([key, {label}])=> { %>
60
60
  <div class="flex items-center gap-1">
61
- <% if (Array.from(_context.query["f:change_type"] || []).includes(key)) { %>
61
+ <% if (utils.includedInCollection(key, _context.query["f:change_type"])) { %>
62
62
  <input type="checkbox" name="f:change_type" id='change-<%= key %>' checked value="<%= key %>" class="hover:cursor-pointer">
63
63
  <% } else { %>
64
64
  <input type="checkbox" name="f:change_type" id='change-<%= key %>' value="<%= key %>" class="hover:cursor-pointer">
@@ -144,7 +144,7 @@
144
144
  <div class="checkbox-group mb-4">
145
145
  <% tags.forEach((item,idx)=> { %>
146
146
  <div class="flex items-center gap-1">
147
- <% if (Array.from(_context.query["f:tags"] || []).includes(item.id)) { %>
147
+ <% if (utils.includedInCollection(item.id, _context.query["f:tags"])) { %>
148
148
  <input type="checkbox" name="f:tags" id='tag-<%= item.id %>' checked value="<%= item.id %>" class="hover:cursor-pointer">
149
149
  <% } else { %>
150
150
  <input type="checkbox" name="f:tags" id='tag-<%= item.id %>' value="<%= item.id %>" class="hover:cursor-pointer">
@@ -58,7 +58,7 @@
58
58
  <div class="checkbox-group mb-4">
59
59
  <% Object.entries(history.changeTypes(_context.resourceConfig.eventType)).forEach(([key, {label}])=> { %>
60
60
  <div class="flex items-center gap-1">
61
- <% if (Array.from(_context.query["f:change_type"] || []).includes(key)) { %>
61
+ <% if (utils.includedInCollection(key, _context.query["f:change_type"])) { %>
62
62
  <input type="checkbox" name="f:change_type" id='change-<%= key %>' checked value="<%= key %>" class="hover:cursor-pointer">
63
63
  <% } else { %>
64
64
  <input type="checkbox" name="f:change_type" id='change-<%= key %>' value="<%= key %>" class="hover:cursor-pointer">
@@ -144,7 +144,7 @@
144
144
  <div class="checkbox-group mb-4">
145
145
  <% tags.forEach((item,idx)=> { %>
146
146
  <div class="flex items-center gap-1">
147
- <% if (Array.from(_context.query["f:tags"] || []).includes(item.id)) { %>
147
+ <% if (utils.includedInCollection(item.id, _context.query["f:tags"])) { %>
148
148
  <input type="checkbox" name="f:tags" id='tag-<%= item.id %>' checked value="<%= item.id %>" class="hover:cursor-pointer">
149
149
  <% } else { %>
150
150
  <input type="checkbox" name="f:tags" id='tag-<%= item.id %>' value="<%= item.id %>" class="hover:cursor-pointer">
@@ -58,7 +58,7 @@
58
58
  <div class="checkbox-group mb-4">
59
59
  <% Object.entries(history.changeTypes(_context.resourceConfig.pageType)).forEach(([key, {label}])=> { %>
60
60
  <div class="flex items-center gap-1">
61
- <% if (Array.from(_context.query["f:change_type"] || []).includes(key)) { %>
61
+ <% if (utils.includedInCollection(key, _context.query["f:change_type"])) { %>
62
62
  <input type="checkbox" name="f:change_type" id='change-<%= key %>' checked value="<%= key %>" class="hover:cursor-pointer">
63
63
  <% } else { %>
64
64
  <input type="checkbox" name="f:change_type" id='change-<%= key %>' value="<%= key %>" class="hover:cursor-pointer">
@@ -139,7 +139,7 @@
139
139
  <div class="checkbox-group mb-4">
140
140
  <% tags.forEach((item,idx)=> { %>
141
141
  <div class="flex items-center gap-1">
142
- <% if (Array.from(_context.query["f:tags"] || []).includes(item.id)) { %>
142
+ <% if (utils.includedInCollection(item.id, _context.query["f:tags"])) { %>
143
143
  <input type="checkbox" name="f:tags" id='tag-<%= item.id %>' checked value="<%= item.id %>" class="hover:cursor-pointer">
144
144
  <% } else { %>
145
145
  <input type="checkbox" name="f:tags" id='tag-<%= item.id %>' value="<%= item.id %>" class="hover:cursor-pointer">