@isoftdata/svelte-user-configuration 1.0.10 → 1.0.12

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.
@@ -133,14 +133,14 @@ $: computedPermissions = getComputedPermissions(permissions, permissionValueMap,
133
133
  {/each}
134
134
  </div>
135
135
  </Td>
136
- {#if permission.groupValue && permission.computedValue}
136
+ {#if groupPermissionValueMap}
137
137
  <Td
138
138
  property="groupValue"
139
139
  class="px-4"
140
140
  >
141
141
  <span
142
142
  style="width: 5em;"
143
- class="badge badge-pill badge-{permissionValueList[permission.groupValue].color}">{permissionValueList[permission.groupValue].label}</span
143
+ class="badge badge-pill badge-{permissionValueList[permission.groupValue ?? 'NONE'].color}">{permissionValueList[permission.groupValue ?? 'NONE'].label}</span
144
144
  >
145
145
  </Td>
146
146
  <Td
@@ -149,7 +149,7 @@ $: computedPermissions = getComputedPermissions(permissions, permissionValueMap,
149
149
  >
150
150
  <span
151
151
  style="width: 5em;"
152
- class="badge badge-pill badge-{permissionValueList[permission.computedValue].color}">{permissionValueList[permission.computedValue].label}</span
152
+ class="badge badge-pill badge-{permissionValueList[permission.computedValue ?? 'NONE'].color}">{permissionValueList[permission.computedValue ?? 'NONE'].label}</span
153
153
  >
154
154
  </Td>
155
155
  {/if}
package/dist/util.d.ts CHANGED
@@ -26,6 +26,8 @@ export interface UserAccount {
26
26
  export type { IconName } from '@fortawesome/fontawesome-common-types';
27
27
  export type HTMLDivAttributes = HTMLAttributes<HTMLDivElement>;
28
28
  export type SiteLabel = string;
29
+ export type PermissionValue = 'NONE' | 'SITE' | 'GLOBAL';
30
+ export declare const valueRank: Record<PermissionValue, number>;
29
31
  export type GenerateNewActivationPINFn = ComponentProps<UserAccountInfo>['generateNewActivationPIN'];
30
32
  export type SuccessFn = ComponentProps<UserAccountInfo>['success'];
31
33
  export type ErrorFn = ComponentProps<UserAccountInfo>['error'];
@@ -48,3 +50,11 @@ export type PermissionValueMap = ComponentProps<PermissionList>['permissionValue
48
50
  export type GroupPermissionValueMap = ComponentProps<PermissionList>['groupPermissionValueMap'];
49
51
  export type PermissionValueChangeFn = ComponentProps<PermissionList>['permissionValueChange'];
50
52
  export type PermissionListCardHeaderTitle = ComponentProps<PermissionList>['cardHeaderTitle'];
53
+ /** Returns a Map where the key is the `permissioniId` and the value is the highest permission level for the given group membership
54
+ *
55
+ * You'll probably want to call this in your code when the group membership changes, and pass the result to the `groupPermissionValueMap` prop of the `PermissionList` component.
56
+ */
57
+ export declare function getGroupHighestPermissionValueMap(groupMembershipSet: Set<number>, groupPermissionMap: Map<number, {
58
+ permissionId: number;
59
+ value: PermissionValue;
60
+ }[]>): Map<number, PermissionValue>;
package/dist/util.js CHANGED
@@ -3,3 +3,27 @@ import PasswordSetModal from './PasswordSetModal.svelte';
3
3
  import UserAccountInfo from './UserAccountInfo.svelte';
4
4
  import UserSiteAccess from './UserSiteAccess.svelte';
5
5
  import UserGroupMembership from './UserGroupMembership.svelte';
6
+ export const valueRank = {
7
+ NONE: 0,
8
+ SITE: 1,
9
+ GLOBAL: 2,
10
+ };
11
+ /** Returns a Map where the key is the `permissioniId` and the value is the highest permission level for the given group membership
12
+ *
13
+ * You'll probably want to call this in your code when the group membership changes, and pass the result to the `groupPermissionValueMap` prop of the `PermissionList` component.
14
+ */
15
+ export function getGroupHighestPermissionValueMap(groupMembershipSet, groupPermissionMap) {
16
+ const valueMap = new Map();
17
+ for (const groupId of groupMembershipSet) {
18
+ const groupPermissions = groupPermissionMap.get(groupId);
19
+ if (groupPermissions) {
20
+ for (const { permissionId, value } of groupPermissions) {
21
+ const currentValue = valueMap.get(permissionId);
22
+ if (!currentValue || valueRank[value] > valueRank[currentValue]) {
23
+ valueMap.set(permissionId, value);
24
+ }
25
+ }
26
+ }
27
+ }
28
+ return valueMap;
29
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isoftdata/svelte-user-configuration",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",