@origen-ui/admin-cli 1.0.3 → 1.1.0
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 +3 -3
- package/templates/current/clean/CHANGELOG.md +34 -0
- package/templates/current/clean/component-catalog.json +9 -9
- package/templates/current/clean/package.json +41 -41
- package/templates/current/clean/scaffold.lock.json +2 -2
- package/templates/current/clean/scripts/vite-build-policy.spec.ts +71 -0
- package/templates/current/clean/src/App.vue +10 -3
- package/templates/current/clean/src/api/client.ts +90 -10
- package/templates/current/clean/src/api/generated/data-contracts.ts +3 -3
- package/templates/current/clean/src/api/generated/http-client.ts +1 -1
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +1 -1
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +1 -1
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +1 -1
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +2 -3
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +3 -5
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +2 -3
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +2 -3
- package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +1 -1
- package/templates/current/clean/src/app/adminLocale.ts +90 -0
- package/templates/current/clean/src/app/createAdminUi.spec.ts +65 -9
- package/templates/current/clean/src/app/createAdminUi.ts +14 -29
- package/templates/current/clean/src/app/embedded-token.spec.ts +40 -0
- package/templates/current/clean/src/app/embedded.spec.ts +135 -0
- package/templates/current/clean/src/app/embedded.ts +255 -0
- package/templates/current/clean/src/app/localeFormat.ts +52 -0
- package/templates/current/clean/src/app/menu.spec.ts +26 -0
- package/templates/current/clean/src/app/menu.ts +4 -0
- package/templates/current/clean/src/app/menuTypes.ts +1 -0
- package/templates/current/clean/src/app/origenUiLocale.spec.ts +6 -5
- package/templates/current/clean/src/app/origenUiLocale.ts +3 -58
- package/templates/current/clean/src/app/permission.spec.ts +26 -0
- package/templates/current/clean/src/app/runtimeConfig.ts +8 -7
- package/templates/current/clean/src/env.d.ts +18 -0
- package/templates/current/clean/src/features/appearance/components/ThemePanel.vue +21 -17
- package/templates/current/clean/src/features/appearance/store/theme.ts +2 -1
- package/templates/current/clean/src/features/auth/pages/Login.vue +15 -11
- package/templates/current/clean/src/features/auth/store/auth.ts +13 -3
- package/templates/current/clean/src/features/security/components/DevtoolsProtectionOverlay.vue +5 -2
- package/templates/current/clean/src/features/security/devtoolsProtection.spec.ts +7 -10
- package/templates/current/clean/src/features/security/devtoolsProtection.ts +2 -1
- package/templates/current/clean/src/features/system/access/api/admin-repository.spec.ts +14 -0
- package/templates/current/clean/src/features/system/access/api/admin-repository.ts +38 -15
- package/templates/current/clean/src/features/system/access/api/rbac.ts +37 -27
- package/templates/current/clean/src/features/workspace/pages/Empty.vue +4 -1
- package/templates/current/clean/src/features/workspace/pages/Profile.vue +13 -11
- package/templates/current/clean/src/layouts/AdminLayout.vue +3 -1
- package/templates/current/clean/src/layouts/TopBar.vue +26 -8
- package/templates/current/clean/src/locales/en-US.json +490 -0
- package/templates/current/clean/src/locales/en-US.runtime.ts +20 -0
- package/templates/current/clean/src/locales/index.ts +129 -45
- package/templates/current/clean/src/locales/messages-types.ts +62 -0
- package/templates/current/clean/src/locales/messages.spec.ts +113 -6
- package/templates/current/clean/src/locales/vue-i18n.d.ts +5 -0
- package/templates/current/clean/src/locales/zh-CN.json +490 -0
- package/templates/current/clean/src/locales/zh-CN.runtime.ts +20 -0
- package/templates/current/clean/src/locales/zh-TW.json +490 -0
- package/templates/current/clean/src/locales/zh-TW.runtime.ts +20 -0
- package/templates/current/clean/src/router/bootstrap.ts +22 -7
- package/templates/current/clean/src/router/dynamicRoutes.ts +5 -1
- package/templates/current/clean/src/router/queryEncryption.spec.ts +30 -4
- package/templates/current/clean/src/router/queryEncryption.ts +48 -44
- package/templates/current/clean/src/router/useRouteQueryDefaults.spec.ts +2 -1
- package/templates/current/clean/src/router/useRouteQueryDefaults.types.ts +2 -1
- package/templates/current/clean/src/templates/og-table.ts +81 -37
- package/templates/current/clean/src/templates/templates.spec.ts +19 -0
- package/templates/current/clean/vite.build-policy.ts +114 -289
- package/templates/current/clean/vite.config.ts +4 -5
- package/templates/current/examples/CHANGELOG.md +34 -0
- package/templates/current/examples/component-catalog.json +9 -9
- package/templates/current/examples/package.json +41 -41
- package/templates/current/examples/scaffold.lock.json +2 -2
- package/templates/current/examples/scripts/vite-build-policy.spec.ts +71 -0
- package/templates/current/examples/src/App.vue +10 -3
- package/templates/current/examples/src/api/client.ts +90 -10
- package/templates/current/examples/src/api/generated/data-contracts.ts +3 -3
- package/templates/current/examples/src/api/generated/http-client.ts +1 -1
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +1 -1
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +1 -1
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +1 -1
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +2 -3
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +3 -5
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +2 -3
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +2 -3
- package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +1 -1
- package/templates/current/examples/src/app/adminLocale.ts +90 -0
- package/templates/current/examples/src/app/createAdminUi.spec.ts +65 -9
- package/templates/current/examples/src/app/createAdminUi.ts +14 -29
- package/templates/current/examples/src/app/embedded-token.spec.ts +40 -0
- package/templates/current/examples/src/app/embedded.spec.ts +135 -0
- package/templates/current/examples/src/app/embedded.ts +255 -0
- package/templates/current/examples/src/app/localeFormat.ts +52 -0
- package/templates/current/examples/src/app/menu.spec.ts +26 -0
- package/templates/current/examples/src/app/menu.ts +4 -0
- package/templates/current/examples/src/app/menuTypes.ts +1 -0
- package/templates/current/examples/src/app/origenUiLocale.spec.ts +6 -5
- package/templates/current/examples/src/app/origenUiLocale.ts +3 -58
- package/templates/current/examples/src/app/permission.spec.ts +26 -0
- package/templates/current/examples/src/app/runtimeConfig.ts +8 -7
- package/templates/current/examples/src/env.d.ts +18 -0
- package/templates/current/examples/src/features/appearance/components/ThemePanel.vue +21 -17
- package/templates/current/examples/src/features/appearance/store/theme.ts +2 -1
- package/templates/current/examples/src/features/auth/pages/Login.vue +15 -11
- package/templates/current/examples/src/features/auth/store/auth.ts +13 -3
- package/templates/current/examples/src/features/errors/pages/Forbidden.vue +6 -2
- package/templates/current/examples/src/features/errors/pages/NotFound.vue +6 -2
- package/templates/current/examples/src/features/errors/pages/ServerError.vue +6 -2
- package/templates/current/examples/src/features/errors/pages/error-pages.spec.ts +9 -1
- package/templates/current/examples/src/features/feature-composables.spec.ts +36 -9
- package/templates/current/examples/src/features/security/components/DevtoolsProtectionOverlay.vue +5 -2
- package/templates/current/examples/src/features/security/devtoolsProtection.spec.ts +7 -10
- package/templates/current/examples/src/features/security/devtoolsProtection.ts +2 -1
- package/templates/current/examples/src/features/system/access/api/admin-repository.spec.ts +14 -0
- package/templates/current/examples/src/features/system/access/api/admin-repository.ts +38 -15
- package/templates/current/examples/src/features/system/access/api/rbac.ts +37 -27
- package/templates/current/examples/src/features/system/audit/composables/useAuditManagement.ts +43 -38
- package/templates/current/examples/src/features/system/menus/components/MenuEditorForm.vue +33 -30
- package/templates/current/examples/src/features/system/menus/composables/useMenuManagement.ts +81 -69
- package/templates/current/examples/src/features/system/menus/pages/MenuList.vue +3 -1
- package/templates/current/examples/src/features/system/roles/components/RoleEditorForm.vue +18 -15
- package/templates/current/examples/src/features/system/roles/composables/useRoleManagement.ts +49 -53
- package/templates/current/examples/src/features/system/roles/pages/RoleList.vue +3 -1
- package/templates/current/examples/src/features/system/users/components/UserEditorForm.vue +22 -19
- package/templates/current/examples/src/features/system/users/composables/useUserManagement.ts +59 -64
- package/templates/current/examples/src/features/system/users/pages/UserList.vue +3 -1
- package/templates/current/examples/src/features/workspace/pages/Dashboard.spec.ts +9 -0
- package/templates/current/examples/src/features/workspace/pages/Dashboard.vue +54 -26
- package/templates/current/examples/src/features/workspace/pages/Empty.vue +4 -1
- package/templates/current/examples/src/features/workspace/pages/Profile.vue +13 -11
- package/templates/current/examples/src/layouts/AdminLayout.vue +3 -1
- package/templates/current/examples/src/layouts/TopBar.vue +26 -8
- package/templates/current/examples/src/locales/en-US.json +490 -0
- package/templates/current/examples/src/locales/en-US.runtime.ts +20 -0
- package/templates/current/examples/src/locales/index.ts +129 -45
- package/templates/current/examples/src/locales/messages-types.ts +62 -0
- package/templates/current/examples/src/locales/messages.spec.ts +113 -6
- package/templates/current/examples/src/locales/vue-i18n.d.ts +5 -0
- package/templates/current/examples/src/locales/zh-CN.json +490 -0
- package/templates/current/examples/src/locales/zh-CN.runtime.ts +20 -0
- package/templates/current/examples/src/locales/zh-TW.json +490 -0
- package/templates/current/examples/src/locales/zh-TW.runtime.ts +20 -0
- package/templates/current/examples/src/main.ts +31 -5
- package/templates/current/examples/src/router/bootstrap.ts +22 -7
- package/templates/current/examples/src/router/dynamicRoutes.spec.ts +17 -0
- package/templates/current/examples/src/router/dynamicRoutes.ts +5 -1
- package/templates/current/examples/src/router/queryEncryption.spec.ts +30 -4
- package/templates/current/examples/src/router/queryEncryption.ts +48 -44
- package/templates/current/examples/src/router/staticRoutes.ts +1 -1
- package/templates/current/examples/src/router/useRouteQueryDefaults.spec.ts +2 -1
- package/templates/current/examples/src/router/useRouteQueryDefaults.types.ts +2 -1
- package/templates/current/examples/src/templates/og-table.ts +81 -37
- package/templates/current/examples/src/templates/templates.spec.ts +19 -0
- package/templates/current/examples/vite.build-policy.ts +114 -289
- package/templates/current/examples/vite.config.ts +4 -5
- package/templates/current/clean/scripts/check-admin-bundle.mjs +0 -214
- package/templates/current/clean/scripts/performance/baselines/bundle-gzip-v2-pre-entry-unification.json +0 -38
- package/templates/current/clean/src/locales/en-US.ts +0 -55
- package/templates/current/clean/src/locales/zh-CN.ts +0 -55
- package/templates/current/clean/src/locales/zh-TW.ts +0 -44
- package/templates/current/examples/scripts/check-admin-bundle.mjs +0 -214
- package/templates/current/examples/scripts/performance/baselines/bundle-gzip-v2-pre-entry-unification.json +0 -38
- package/templates/current/examples/src/locales/en-US.ts +0 -55
- package/templates/current/examples/src/locales/zh-CN.ts +0 -55
- package/templates/current/examples/src/locales/zh-TW.ts +0 -44
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { LocationQuery, LocationQueryRaw } from 'vue-router'
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import Base64 from 'crypto-js/enc-base64'
|
|
5
|
-
import HmacSHA256 from 'crypto-js/hmac-sha256'
|
|
2
|
+
import { gcm } from '@noble/ciphers/aes.js'
|
|
3
|
+
import { randomBytes } from '@noble/ciphers/utils.js'
|
|
6
4
|
|
|
7
5
|
const QUERY_PARAMETER = '_q'
|
|
8
|
-
const VERSION = '
|
|
6
|
+
const VERSION = 'v2'
|
|
9
7
|
const HEX_KEY = /^[\dA-F]{64}$/i
|
|
10
8
|
const URL_SAFE_BASE64 = /^[\w-]+$/
|
|
9
|
+
const NONCE_LENGTH = 12
|
|
10
|
+
const TAG_LENGTH = 16
|
|
11
|
+
const encoder = new TextEncoder()
|
|
12
|
+
const decoder = new TextDecoder('utf-8', { fatal: true })
|
|
11
13
|
|
|
12
14
|
type QueryValue = string | null | string[] | (string | null)[]
|
|
13
15
|
type EncodedQuery = Record<string, QueryValue>
|
|
@@ -22,22 +24,24 @@ export interface RouteQueryEncryption {
|
|
|
22
24
|
stringifyQuery: (query: LocationQueryRaw | undefined) => string
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
function toUrlSafeBase64(value:
|
|
26
|
-
|
|
27
|
+
function toUrlSafeBase64(value: Uint8Array): string {
|
|
28
|
+
let binary = ''
|
|
29
|
+
for (const byte of value) binary += String.fromCharCode(byte)
|
|
30
|
+
return btoa(binary).replaceAll('+', '-').replaceAll('/', '_').replace(/=+$/u, '')
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
function fromUrlSafeBase64(value: string):
|
|
30
|
-
if (!URL_SAFE_BASE64.test(value)) return undefined
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
function fromUrlSafeBase64(value: string): Uint8Array | undefined {
|
|
34
|
+
if (!URL_SAFE_BASE64.test(value) || value.length % 4 === 1) return undefined
|
|
35
|
+
try {
|
|
36
|
+
const padded = `${value.replaceAll('-', '+').replaceAll('_', '/')}${'='.repeat(
|
|
37
|
+
(4 - (value.length % 4)) % 4,
|
|
38
|
+
)}`
|
|
39
|
+
const binary = atob(padded)
|
|
40
|
+
const bytes = Uint8Array.from(binary, (character) => character.charCodeAt(0))
|
|
41
|
+
return toUrlSafeBase64(bytes) === value ? bytes : undefined
|
|
42
|
+
} catch {
|
|
43
|
+
return undefined
|
|
44
|
+
}
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
function normalizeQuery(query: LocationQueryRaw | undefined): EncodedQuery {
|
|
@@ -72,6 +76,10 @@ function readCiphertext(search: string): string | undefined {
|
|
|
72
76
|
return values.length === 1 ? values[0] : undefined
|
|
73
77
|
}
|
|
74
78
|
|
|
79
|
+
function keyFromHex(value: string): Uint8Array {
|
|
80
|
+
return Uint8Array.from(value.match(/../gu)!.map((pair) => Number.parseInt(pair, 16)))
|
|
81
|
+
}
|
|
82
|
+
|
|
75
83
|
export function createRouteQueryEncryption(
|
|
76
84
|
options: RouteQueryEncryptionOptions = {},
|
|
77
85
|
): RouteQueryEncryption | undefined {
|
|
@@ -82,47 +90,43 @@ export function createRouteQueryEncryption(
|
|
|
82
90
|
)
|
|
83
91
|
}
|
|
84
92
|
|
|
85
|
-
const encryptionKey =
|
|
86
|
-
const authenticationKey = HmacSHA256('route-query-authentication', encryptionKey)
|
|
87
|
-
|
|
88
|
-
function mac(value: string): string {
|
|
89
|
-
return HmacSHA256(value, authenticationKey).toString(CryptoJS.enc.Hex)
|
|
90
|
-
}
|
|
93
|
+
const encryptionKey = keyFromHex(options.key)
|
|
91
94
|
|
|
92
95
|
return {
|
|
93
96
|
stringifyQuery(query) {
|
|
94
97
|
const normalized = normalizeQuery(query)
|
|
95
98
|
if (Object.keys(normalized).length === 0) return ''
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
const nonce = randomBytes(NONCE_LENGTH)
|
|
100
|
+
const ciphertextAndTag = gcm(encryptionKey, nonce).encrypt(
|
|
101
|
+
encoder.encode(JSON.stringify(normalized)),
|
|
102
|
+
)
|
|
103
|
+
const payload = `${VERSION}.${toUrlSafeBase64(nonce)}.${toUrlSafeBase64(ciphertextAndTag)}`
|
|
104
|
+
return `${QUERY_PARAMETER}=${encodeURIComponent(payload)}`
|
|
100
105
|
},
|
|
101
106
|
parseQuery(search) {
|
|
102
107
|
const value = readCiphertext(search)
|
|
103
108
|
if (!value) return {}
|
|
104
109
|
try {
|
|
105
|
-
const [version,
|
|
110
|
+
const [version, nonceValue, ciphertextValue, ...extra] = value.split('.')
|
|
106
111
|
if (
|
|
107
112
|
version !== VERSION ||
|
|
108
|
-
!
|
|
113
|
+
!nonceValue ||
|
|
109
114
|
!ciphertextValue ||
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
115
|
+
extra.length > 0
|
|
116
|
+
) {
|
|
117
|
+
return {}
|
|
118
|
+
}
|
|
119
|
+
const nonce = fromUrlSafeBase64(nonceValue)
|
|
120
|
+
const ciphertextAndTag = fromUrlSafeBase64(ciphertextValue)
|
|
121
|
+
if (
|
|
122
|
+
!nonce ||
|
|
123
|
+
nonce.length !== NONCE_LENGTH ||
|
|
124
|
+
!ciphertextAndTag ||
|
|
125
|
+
ciphertextAndTag.length <= TAG_LENGTH
|
|
113
126
|
) {
|
|
114
127
|
return {}
|
|
115
128
|
}
|
|
116
|
-
const
|
|
117
|
-
if (!equalsMac(suppliedMac, mac(payload))) return {}
|
|
118
|
-
const iv = fromUrlSafeBase64(ivValue)
|
|
119
|
-
const ciphertext = fromUrlSafeBase64(ciphertextValue)
|
|
120
|
-
if (!iv || !ciphertext) return {}
|
|
121
|
-
const plaintext = AES.decrypt(
|
|
122
|
-
CryptoJS.lib.CipherParams.create({ ciphertext }),
|
|
123
|
-
encryptionKey,
|
|
124
|
-
{ iv },
|
|
125
|
-
).toString(CryptoJS.enc.Utf8)
|
|
129
|
+
const plaintext = decoder.decode(gcm(encryptionKey, nonce).decrypt(ciphertextAndTag))
|
|
126
130
|
const query: unknown = JSON.parse(plaintext)
|
|
127
131
|
return isEncodedQuery(query) ? (query as LocationQuery) : {}
|
|
128
132
|
} catch {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { VNode } from 'vue'
|
|
1
2
|
import { mount } from '@vue/test-utils'
|
|
2
3
|
import { describe, expect, it } from 'vitest'
|
|
3
|
-
import { defineComponent, h, KeepAlive, nextTick
|
|
4
|
+
import { defineComponent, h, KeepAlive, nextTick } from 'vue'
|
|
4
5
|
import { createMemoryHistory, createRouter, RouterView } from 'vue-router'
|
|
5
6
|
import { routeStatus } from './routeQuery'
|
|
6
7
|
import { useRouteQueryDefaults } from './useRouteQueryDefaults'
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { RouteQueryParsers } from './useRouteQueryDefaults'
|
|
1
2
|
import { routeStatus } from './routeQuery'
|
|
2
|
-
import {
|
|
3
|
+
import { useRouteQueryDefaults } from './useRouteQueryDefaults'
|
|
3
4
|
|
|
4
5
|
interface Query {
|
|
5
6
|
status?: 'active' | 'suspended'
|
|
@@ -8,6 +8,24 @@ import type {
|
|
|
8
8
|
TableColumn,
|
|
9
9
|
TableRowKey,
|
|
10
10
|
} from '@origen-ui/table'
|
|
11
|
+
import type { AdminMessageKey } from '../locales'
|
|
12
|
+
import { getAdminI18n } from '../locales'
|
|
13
|
+
|
|
14
|
+
function tableText(key: AdminMessageKey): string {
|
|
15
|
+
const global = getAdminI18n()?.global as unknown as
|
|
16
|
+
{ t: (key: AdminMessageKey) => string } | undefined
|
|
17
|
+
return global ? global.t(key) : key
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function withLocalizedLabel<T extends object>(
|
|
21
|
+
value: T,
|
|
22
|
+
key: AdminMessageKey,
|
|
23
|
+
): T & { label: string } {
|
|
24
|
+
return Object.defineProperty(value, 'label', {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: () => tableText(key),
|
|
27
|
+
}) as T & { label: string }
|
|
28
|
+
}
|
|
11
29
|
|
|
12
30
|
export interface OgTableTemplateOptions<TRow extends OgTableRow, TQuery extends object> {
|
|
13
31
|
tableId: string
|
|
@@ -65,7 +83,12 @@ function actionColumn<TRow extends OgTableRow>(
|
|
|
65
83
|
actions: OgTableAction<TRow>[],
|
|
66
84
|
): TableColumn<TRow>[] {
|
|
67
85
|
return actions.length
|
|
68
|
-
? [
|
|
86
|
+
? [
|
|
87
|
+
withLocalizedLabel(
|
|
88
|
+
{ type: 'action', key: 'actions', fixed: 'right', actions },
|
|
89
|
+
'common.actions.operations',
|
|
90
|
+
),
|
|
91
|
+
]
|
|
69
92
|
: []
|
|
70
93
|
}
|
|
71
94
|
|
|
@@ -89,20 +112,30 @@ export function createPermissionCrudTableTemplate<TRow extends OgTableRow, TQuer
|
|
|
89
112
|
const permissions = adapter.permissions ?? {}
|
|
90
113
|
const actions: OgTableAction<TRow>[] = []
|
|
91
114
|
if (adapter.edit) {
|
|
92
|
-
actions.push(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
115
|
+
actions.push(
|
|
116
|
+
withLocalizedLabel(
|
|
117
|
+
{
|
|
118
|
+
key: 'edit',
|
|
119
|
+
label: '',
|
|
120
|
+
permission: permissions.edit,
|
|
121
|
+
onClick: adapter.edit,
|
|
122
|
+
},
|
|
123
|
+
'common.actions.edit',
|
|
124
|
+
),
|
|
125
|
+
)
|
|
98
126
|
}
|
|
99
127
|
if (adapter.remove) {
|
|
100
|
-
actions.push(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
128
|
+
actions.push(
|
|
129
|
+
withLocalizedLabel(
|
|
130
|
+
{
|
|
131
|
+
key: 'remove',
|
|
132
|
+
label: '',
|
|
133
|
+
permission: permissions.remove,
|
|
134
|
+
onClick: (row) => adapter.remove!([row]),
|
|
135
|
+
},
|
|
136
|
+
'common.actions.delete',
|
|
137
|
+
),
|
|
138
|
+
)
|
|
106
139
|
}
|
|
107
140
|
return baseTemplate(
|
|
108
141
|
options,
|
|
@@ -112,12 +145,15 @@ export function createPermissionCrudTableTemplate<TRow extends OgTableRow, TQuer
|
|
|
112
145
|
actions: {
|
|
113
146
|
batch: adapter.remove
|
|
114
147
|
? [
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
148
|
+
withLocalizedLabel(
|
|
149
|
+
{
|
|
150
|
+
key: 'remove',
|
|
151
|
+
label: '',
|
|
152
|
+
permission: permissions.remove,
|
|
153
|
+
onClick: (rows) => adapter.remove!([...rows]),
|
|
154
|
+
},
|
|
155
|
+
'common.actions.batchRemove',
|
|
156
|
+
),
|
|
121
157
|
]
|
|
122
158
|
: undefined,
|
|
123
159
|
},
|
|
@@ -128,12 +164,15 @@ export function createPermissionCrudTableTemplate<TRow extends OgTableRow, TQuer
|
|
|
128
164
|
reset: true,
|
|
129
165
|
actions: adapter.create
|
|
130
166
|
? [
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
167
|
+
withLocalizedLabel(
|
|
168
|
+
{
|
|
169
|
+
key: 'create',
|
|
170
|
+
label: '',
|
|
171
|
+
permission: permissions.create,
|
|
172
|
+
onClick: () => adapter.create!(),
|
|
173
|
+
},
|
|
174
|
+
'common.actions.create',
|
|
175
|
+
),
|
|
137
176
|
]
|
|
138
177
|
: undefined,
|
|
139
178
|
},
|
|
@@ -143,10 +182,7 @@ export function createPermissionCrudTableTemplate<TRow extends OgTableRow, TQuer
|
|
|
143
182
|
}
|
|
144
183
|
|
|
145
184
|
/** Row editing with an explicit optimistic commit permission and optional approval adapter. */
|
|
146
|
-
export function createEditableApprovalTableTemplate<
|
|
147
|
-
TRow extends OgTableRow,
|
|
148
|
-
TQuery extends object,
|
|
149
|
-
>(
|
|
185
|
+
export function createEditableApprovalTableTemplate<TRow extends OgTableRow, TQuery extends object>(
|
|
150
186
|
options: OgTableTemplateOptions<TRow, TQuery> & {
|
|
151
187
|
adapter?: Pick<OgTableBusinessAdapter<TRow, TQuery>, 'approve' | 'permissions'>
|
|
152
188
|
},
|
|
@@ -154,7 +190,12 @@ export function createEditableApprovalTableTemplate<
|
|
|
154
190
|
const approval = options.adapter?.approve
|
|
155
191
|
const permission = options.adapter?.permissions?.approve
|
|
156
192
|
const actions: OgTableAction<TRow>[] = approval
|
|
157
|
-
? [
|
|
193
|
+
? [
|
|
194
|
+
withLocalizedLabel(
|
|
195
|
+
{ key: 'approve', label: '', permission, onClick: (row) => approval([row]) },
|
|
196
|
+
'common.actions.approve',
|
|
197
|
+
),
|
|
198
|
+
]
|
|
158
199
|
: []
|
|
159
200
|
return baseTemplate(
|
|
160
201
|
options,
|
|
@@ -197,13 +238,16 @@ export function createQueryScopeBatchTableTemplate<TRow extends OgTableRow, TQue
|
|
|
197
238
|
actions: {
|
|
198
239
|
batch: options.adapter.permissions?.batch
|
|
199
240
|
? [
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
241
|
+
withLocalizedLabel(
|
|
242
|
+
{
|
|
243
|
+
key: 'query-batch',
|
|
244
|
+
label: '',
|
|
245
|
+
permission: options.adapter.permissions.batch,
|
|
246
|
+
queryScope: { enabled: true },
|
|
247
|
+
onClick: () => undefined,
|
|
248
|
+
},
|
|
249
|
+
'common.actions.batchProcess',
|
|
250
|
+
),
|
|
207
251
|
]
|
|
208
252
|
: undefined,
|
|
209
253
|
},
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { OgTableDataSource } from '@origen-ui/table'
|
|
2
2
|
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
+
import { createI18n } from 'vue-i18n'
|
|
4
|
+
import { createAdminI18n } from '../locales'
|
|
3
5
|
import { createOgFormTemplate } from './og-form'
|
|
4
6
|
import {
|
|
5
7
|
createEditableApprovalTableTemplate,
|
|
@@ -50,6 +52,23 @@ describe('admin local templates', () => {
|
|
|
50
52
|
).toBe(true)
|
|
51
53
|
})
|
|
52
54
|
|
|
55
|
+
it('keeps generated table action labels reactive to the active locale', async () => {
|
|
56
|
+
const i18n = createI18n({ legacy: false, locale: 'zh-CN' })
|
|
57
|
+
const { language } = createAdminI18n(i18n)
|
|
58
|
+
await language.ready
|
|
59
|
+
const template = createPermissionCrudTableTemplate({
|
|
60
|
+
...base,
|
|
61
|
+
adapter: { create: vi.fn(), edit: vi.fn(), remove: vi.fn() },
|
|
62
|
+
})
|
|
63
|
+
const actionColumn = template.columns.at(-1)
|
|
64
|
+
|
|
65
|
+
expect(actionColumn?.label).toBe('操作')
|
|
66
|
+
await language.setLocale('en-US')
|
|
67
|
+
i18n.global.locale.value = 'en-US'
|
|
68
|
+
expect(actionColumn?.label).toBe('Actions')
|
|
69
|
+
expect(template.config.toolbar?.actions?.[0]?.label).toBe('Create')
|
|
70
|
+
})
|
|
71
|
+
|
|
53
72
|
it('keeps OgForm transformation and validation in the caller adapter', async () => {
|
|
54
73
|
const template = createOgFormTemplate({
|
|
55
74
|
schema: {
|