Merge branch '16041-valid-name' refs #16041
[arvados.git] / src / store / sharing-dialog / sharing-dialog-types.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { PermissionLevel } from '~/models/permission';
6 import { getFormValues, isDirty } from 'redux-form';
7 import { RootState } from '~/store/store';
8
9 export const SHARING_DIALOG_NAME = 'SHARING_DIALOG_NAME';
10 export const SHARING_PUBLIC_ACCESS_FORM_NAME = 'SHARING_PUBLIC_ACCESS_FORM_NAME';
11 export const SHARING_MANAGEMENT_FORM_NAME = 'SHARING_MANAGEMENT_FORM_NAME';
12 export const SHARING_INVITATION_FORM_NAME = 'SHARING_INVITATION_FORM_NAME';
13
14 export enum VisibilityLevel {
15     PRIVATE = 'Private',
16     SHARED = 'Shared',
17     PUBLIC = 'Public',
18 }
19
20 export interface SharingPublicAccessFormData {
21     visibility: VisibilityLevel;
22     permissionUuid: string;
23 }
24
25 export interface SharingManagementFormData {
26     permissions: SharingManagementFormDataRow[];
27     initialPermissions: SharingManagementFormDataRow[];
28 }
29
30 export interface SharingManagementFormDataRow {
31     email: string;
32     permissions: PermissionLevel;
33     permissionUuid: string;
34 }
35
36 export interface SharingInvitationFormData {
37     permissions: PermissionLevel;
38     invitedPeople: SharingInvitationFormPersonData[];
39 }
40
41 export interface SharingInvitationFormPersonData {
42     email: string;
43     name: string;
44     uuid: string;
45 }
46
47 export const getSharingMangementFormData = (state: any) =>
48     getFormValues(SHARING_MANAGEMENT_FORM_NAME)(state) as SharingManagementFormData;
49
50 export const getSharingPublicAccessFormData = (state: any) =>
51     getFormValues(SHARING_PUBLIC_ACCESS_FORM_NAME)(state) as SharingPublicAccessFormData;
52
53 export const hasChanges = (state: RootState) =>
54     isDirty(SHARING_PUBLIC_ACCESS_FORM_NAME)(state) ||
55     isDirty(SHARING_MANAGEMENT_FORM_NAME)(state) ||
56     isDirty(SHARING_INVITATION_FORM_NAME)(state);