@7365admin1/layer-common 4.4.2-staging.291 → 4.4.2-staging.292

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.
@@ -112,7 +112,7 @@
112
112
  <v-list-item-title
113
113
  class="text-capitalize role-create__row-title"
114
114
  >
115
- {{ String(actionKey).replace(/-/g, " ") }}
115
+ {{ formatActionLabel(String(actionKey)) }}
116
116
  </v-list-item-title>
117
117
  <v-list-item-subtitle class="role-create__row-sub">
118
118
  {{ action.description }}
@@ -143,6 +143,11 @@
143
143
  </template>
144
144
 
145
145
  <script setup lang="ts">
146
+ // Relative import: this layer's `utils/` is not auto-imported into consumers.
147
+ import {
148
+ formatActionLabel,
149
+ formatResourceLabel,
150
+ } from "../utils/permission-labels";
146
151
  import useRole from "../composables/useRole";
147
152
  import useUtils from "../composables/useUtils";
148
153
  import useSite from "../composables/useSite";
@@ -191,13 +196,7 @@ const permState = shallowRef({
191
196
  enabled: [] as string[],
192
197
  });
193
198
 
194
- const resourceLabels: Record<string, string> = {
195
- "access-card-mgmt": "Access Mgmt",
196
- };
197
199
 
198
- function formatResourceLabel(key: string): string {
199
- return resourceLabels[key] ?? key.replace(/-/g, " ");
200
- }
201
200
 
202
201
  function isCategoryEnabled(resource: string) {
203
202
  return permState.value.enabled.includes(resource);
@@ -75,7 +75,7 @@
75
75
  />
76
76
  </template>
77
77
  <v-list-item-title class="text-capitalize role-perm__row-title">
78
- {{ String(actionKey).replace(/-/g, " ") }}
78
+ {{ formatActionLabel(String(actionKey)) }}
79
79
  </v-list-item-title>
80
80
  <v-list-item-subtitle class="role-perm__row-sub">
81
81
  {{ action.description }}
@@ -119,6 +119,11 @@
119
119
  </template>
120
120
 
121
121
  <script setup lang="ts">
122
+ // Relative import: this layer's `utils/` is not auto-imported into consumers.
123
+ import {
124
+ formatActionLabel,
125
+ formatResourceLabel,
126
+ } from "../utils/permission-labels";
122
127
  import useRole from "../composables/useRole";
123
128
  import useUtils from "../composables/useUtils";
124
129
  import {
@@ -163,13 +168,7 @@ const message = ref("");
163
168
  const disable = ref(false);
164
169
  const expandedResources = ref<string[]>([]);
165
170
 
166
- const resourceLabels: Record<string, string> = {
167
- "access-card-mgmt": "Access Mgmt",
168
- };
169
171
 
170
- function formatResourceLabel(key: string) {
171
- return resourceLabels[key] ?? key.replace(/-/g, " ");
172
- }
173
172
 
174
173
  /**
175
174
  * Is this box ticked?
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "4.4.2-staging.291",
5
+ "version": "4.4.2-staging.292",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
@@ -0,0 +1,98 @@
1
+ /**
2
+ * READABLE NAMES FOR THE ROLE EDITOR.
3
+ *
4
+ * Owner requirement R5, 2026-09-10: the whole thing must be user-friendly,
5
+ * straightforward, and not hard to understand, use or assign.
6
+ *
7
+ * The role editor showed the raw catalogue keys — `work_orders`, `SOA-mgmt`,
8
+ * `buildingUnitManagement`, `toilet_locations`, `bulletin-videos-mgmt` — and
9
+ * asked a client to build a role out of them. Production has 238 distinct role
10
+ * names across 390 roles, all hand-built from that list.
11
+ *
12
+ * ## Derived, not hand-listed
13
+ *
14
+ * A hand-written map of 47 names stops covering the catalogue the day a module
15
+ * is added to it, silently and invisibly. The rule handles forty of them;
16
+ * `RESOURCE_LABELS` exists only for the names the rule still gets wrong, and a
17
+ * test fails if it grows into a catalogue of its own.
18
+ *
19
+ * ## The key is never touched
20
+ *
21
+ * These functions are display only. Every stored value, every request body and
22
+ * every `resource:action` string is unchanged — a label that drifts can confuse
23
+ * somebody, but it cannot grant or revoke anything.
24
+ *
25
+ * Lives in `utils/` because BOTH role dialogs render the same tree and each had
26
+ * its own private copy of a weaker version. Two copies of a display rule is how
27
+ * the create dialog and the edit dialog start naming the same module
28
+ * differently.
29
+ */
30
+
31
+ /** Words that are acronyms, not words. `SOA-mgmt` must not read as "Soa". */
32
+ const ACRONYMS: Record<string, string> = {
33
+ soa: "SOA",
34
+ nfc: "NFC",
35
+ cctv: "CCTV",
36
+ anpr: "ANPR",
37
+ qr: "QR",
38
+ hid: "HID",
39
+ id: "ID",
40
+ };
41
+
42
+ /** Only where the rule below still reads wrong. Keep it short. */
43
+ export const RESOURCE_LABELS: Record<string, string> = {
44
+ "SOA-mgmt": "Statements of account",
45
+ buildingUnitManagement: "Building units",
46
+ "daily-occurrence-books": "Daily occurrence book",
47
+ "daily-occurrence-entries": "Daily occurrence entries",
48
+ "my-attendance": "My attendance",
49
+ "online-form-configuration": "Online forms",
50
+ "bulletin-videos-mgmt": "Bulletin videos",
51
+ "access-card-mgmt": "Access cards",
52
+ feedbacks: "Feedback",
53
+ roles: "Roles and permissions",
54
+ };
55
+
56
+ /**
57
+ * `work_orders` -> `Work orders`.
58
+ *
59
+ * Sentence case, not Title Case: a list of 47 Title Cased phrases is harder to
60
+ * scan, not easier.
61
+ */
62
+ export function formatResourceLabel(key: string): string {
63
+ if (!key) return "";
64
+ if (RESOURCE_LABELS[key]) return RESOURCE_LABELS[key];
65
+
66
+ const words = key
67
+ // `buildingUnitManagement` -> `building Unit Management`
68
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
69
+ .split(/[-_\s]+/)
70
+ .filter(Boolean)
71
+ .map((word) => (word.toLowerCase() === "mgmt" ? "management" : word));
72
+
73
+ return words
74
+ .map((word, index) => {
75
+ const acronym = ACRONYMS[word.toLowerCase()];
76
+ if (acronym) return acronym;
77
+ const lower = word.toLowerCase();
78
+ return index === 0 ? lower.charAt(0).toUpperCase() + lower.slice(1) : lower;
79
+ })
80
+ .join(" ");
81
+ }
82
+
83
+ /**
84
+ * `see-all-work-orders` -> `see all work orders`.
85
+ *
86
+ * Left lower case: it sits under a resource heading and reads as a phrase
87
+ * completing it, not as a title of its own. Both dialogs did
88
+ * `.replace(/-/g, " ")` inline; this keeps them from drifting apart, and keeps
89
+ * an acronym from being lower-cased into nonsense.
90
+ */
91
+ export function formatActionLabel(action: string): string {
92
+ if (!action) return "";
93
+ return action
94
+ .split(/[-_\s]+/)
95
+ .filter(Boolean)
96
+ .map((word) => ACRONYMS[word.toLowerCase()] ?? word.toLowerCase())
97
+ .join(" ");
98
+ }