@isoftdata/svelte-user-configuration 1.0.11 → 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.
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.11",
3
+ "version": "1.0.12",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",