@isoftdata/svelte-user-configuration 2.2.1 → 2.3.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.
@@ -37,6 +37,7 @@
37
37
  interface Props extends HTMLDivAttributes {
38
38
  permissions: Array<Permission>
39
39
  siteLabel?: SiteLabel
40
+ enableSiteScope?: boolean
40
41
  permissionValueChange?:
41
42
  | ((change: { value: PermissionValue; permissionIds: Array<number> }) => void | Promise<void>)
42
43
  | undefined
@@ -50,6 +51,7 @@
50
51
  let {
51
52
  permissions,
52
53
  siteLabel = 'Site',
54
+ enableSiteScope = true,
53
55
  permissionValueChange = undefined,
54
56
  icon = 'user-lock',
55
57
  cardHeaderTitle = translate('common:permissions', 'Permissions'),
@@ -63,16 +65,6 @@
63
65
  let selectedPermissionValue: string | null = $state(null)
64
66
 
65
67
  const permissionColumns: ComputedPermissionColumns = getColumns(groupPermissionValueMap)
66
- const permissionValueList: Record<Scope, { label: string; value: Scope; color: ButtonColors }> = {
67
- NONE: { label: translate('common:permissionLevel.none', 'None'), value: 'NONE', color: 'danger' },
68
- SITE: {
69
- label: translate(`common:permissionLevel.${siteLabel.toLowerCase()}`, siteLabel),
70
- value: 'SITE',
71
- color: 'primary',
72
- },
73
- GLOBAL: { label: translate('common:permissionLevel.global', 'Global'), value: 'GLOBAL', color: 'success' },
74
- }
75
- const permissionValues = Object.values(permissionValueList)
76
68
 
77
69
  function getColumns(groupPermissionValueMap: PermissionValueMap | undefined): ComputedPermissionColumns {
78
70
  let columns: ComputedPermissionColumns = [
@@ -157,9 +149,37 @@
157
149
  })
158
150
  }
159
151
 
160
- let computedPermissions = $derived(getComputedPermissions(permissions, permissionValueMap, groupPermissionValueMap))
161
-
162
- $inspect(computedPermissions)
152
+ const permissionValueList: Record<Scope, { label: string; value: Scope; color: ButtonColors }> = $derived({
153
+ NONE: {
154
+ label: enableSiteScope ? translate('common:permissionLevel.none', 'None') : translate('common:off', 'Off'),
155
+ value: 'NONE',
156
+ color: 'danger',
157
+ },
158
+ SITE: {
159
+ label: translate(`common:permissionLevel.${siteLabel.toLowerCase()}`, siteLabel),
160
+ value: 'SITE',
161
+ color: 'primary',
162
+ },
163
+ GLOBAL: {
164
+ label: enableSiteScope ? translate('common:permissionLevel.global', 'Global') : translate('common:on', 'On'),
165
+ value: 'GLOBAL',
166
+ color: 'success',
167
+ },
168
+ })
169
+ const permissionValues = $derived(
170
+ Object.values(permissionValueList).filter(permissionValue => enableSiteScope || permissionValue.value !== 'SITE'),
171
+ )
172
+ const computedPermissions = $derived(getComputedPermissions(permissions, permissionValueMap, groupPermissionValueMap))
173
+ $effect(() => {
174
+ if (
175
+ !enableSiteScope &&
176
+ computedPermissions.some(permission => [permission.value, permission.groupValue].includes('SITE'))
177
+ ) {
178
+ console.warn(
179
+ 'PermissionList: Permissions with site scope are not supported when `enableSiteScope` is false. Please ensure you want to disable site scope, or update/remove these permissions.',
180
+ )
181
+ }
182
+ })
163
183
  </script>
164
184
 
165
185
  <div
@@ -254,7 +274,9 @@
254
274
  }}
255
275
  >
256
276
  {#each Object.values(permissionValueList) as permission}
257
- <option value={permission.value}>{permission.label}</option>
277
+ {#if enableSiteScope || permission.value !== 'SITE'}
278
+ <option value={permission.value}>{permission.label}</option>
279
+ {/if}
258
280
  {/each}
259
281
  </Select>
260
282
  <Button
@@ -8,6 +8,7 @@ declare const PermissionList: import("svelte").Component<HTMLDivAttributes & {
8
8
  codeName: string;
9
9
  }>;
10
10
  siteLabel?: SiteLabel;
11
+ enableSiteScope?: boolean;
11
12
  permissionValueChange?: ((change: {
12
13
  value: "NONE" | "SITE" | "GLOBAL";
13
14
  permissionIds: Array<number>;
@@ -261,6 +261,7 @@
261
261
  bind:input={usernameInput}
262
262
  readonly={myAccountMode || undefined}
263
263
  tabindex={myAccountMode ? -1 : undefined}
264
+ onchange={() => accountInfoChanged?.(userAccount)}
264
265
  />
265
266
  </div>
266
267
  <div class="col-12 col-lg-6"></div>
@@ -269,6 +270,7 @@
269
270
  label={translate('configuration.user.accountInfo.firstName', 'First Name')}
270
271
  bind:value={userAccount.firstName}
271
272
  maxlength={100}
273
+ onchange={() => accountInfoChanged?.(userAccount)}
272
274
  />
273
275
  </div>
274
276
  <div class="col-12 col-md-6">
@@ -276,6 +278,7 @@
276
278
  label={translate('configuration.user.accountInfo.lastName', 'Last Name')}
277
279
  bind:value={userAccount.lastName}
278
280
  maxlength={100}
281
+ onchange={() => accountInfoChanged?.(userAccount)}
279
282
  />
280
283
  </div>
281
284
  <div class="col-12 col-lg-6">
@@ -284,6 +287,7 @@
284
287
  bind:value={userAccount.workEmail}
285
288
  onchange={() => {
286
289
  workEmailIsValid = !myAccountMode && userAccount.workEmail ? emailIsValid(userAccount.workEmail) : true
290
+ accountInfoChanged?.(userAccount)
287
291
  }}
288
292
  autocomplete="email"
289
293
  type="email"
@@ -314,6 +318,7 @@
314
318
  onchange={() => {
315
319
  recoveryEmailIsValid =
316
320
  myAccountMode && userAccount.recoveryEmail ? emailIsValid(userAccount.recoveryEmail) : true
321
+ accountInfoChanged?.(userAccount)
317
322
  }}
318
323
  autocomplete="email"
319
324
  type="email"
@@ -327,11 +332,12 @@
327
332
  {#if !isCreatingNewUser && !myAccountMode}
328
333
  <div class="col-12">
329
334
  <TextArea
335
+ readonly
330
336
  label={translate('configuration.user.accountInfo.lockNote', 'Lock Note')}
331
337
  labelClass="py-0 mb-2"
332
338
  style="min-height:83px;"
333
339
  bind:value={userAccount.lockNotes}
334
- readonly
340
+ onchange={() => accountInfoChanged?.(userAccount)}
335
341
  />
336
342
  </div>
337
343
  {/if}
@@ -178,6 +178,7 @@
178
178
  <PermissionList
179
179
  {siteLabel}
180
180
  {permissions}
181
+ enableSiteScope={showSiteAccess}
181
182
  {permissionValueMap}
182
183
  {groupPermissionValueMap}
183
184
  icon={permissionListIcon}
package/package.json CHANGED
@@ -1,17 +1,6 @@
1
1
  {
2
2
  "name": "@isoftdata/svelte-user-configuration",
3
- "version": "2.2.1",
4
- "scripts": {
5
- "dev": "vite dev",
6
- "build": "vite build && npm run package",
7
- "preview": "vite preview",
8
- "package": "svelte-kit sync && svelte-package && publint",
9
- "prepublishOnly": "npm run package",
10
- "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
11
- "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
12
- "lint": "prettier --check . && eslint .",
13
- "format": "prettier --write ."
14
- },
3
+ "version": "2.3.0",
15
4
  "exports": {
16
5
  ".": {
17
6
  "types": "./dist/index.d.ts",
@@ -77,5 +66,15 @@
77
66
  },
78
67
  "engines": {
79
68
  "pnpm": "10.x"
69
+ },
70
+ "scripts": {
71
+ "dev": "vite dev",
72
+ "build": "vite build && npm run package",
73
+ "preview": "vite preview",
74
+ "package": "svelte-kit sync && svelte-package && publint",
75
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
76
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
77
+ "lint": "prettier --check . && eslint .",
78
+ "format": "prettier --write ."
80
79
  }
81
- }
80
+ }