21128: fixed unwanted rowselects on other operational clicks Arvados-DCO-1.1-Signed...
[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     ALL_USERS = 'All users',
18     PUBLIC = 'Public',
19 }
20
21 export interface SharingPublicAccessFormData {
22     visibility: VisibilityLevel;
23     initialVisibility: VisibilityLevel;
24     permissionUuid: string;
25 }
26
27 export interface SharingManagementFormData {
28     permissions: SharingManagementFormDataRow[];
29     initialPermissions: SharingManagementFormDataRow[];
30 }
31
32 export interface SharingManagementFormDataRow {
33     email: string;
34     permissions: PermissionLevel;
35     permissionUuid: string;
36 }
37
38 export interface SharingInvitationFormData {
39     permissions: PermissionLevel;
40     invitedPeople: SharingInvitationFormPersonData[];
41 }
42
43 export interface SharingInvitationFormPersonData {
44     email: string;
45     name: string;
46     uuid: string;
47 }
48
49 export const getSharingMangementFormData = (state: any) =>
50     getFormValues(SHARING_MANAGEMENT_FORM_NAME)(state) as SharingManagementFormData;
51
52 export const getSharingPublicAccessFormData = (state: any) =>
53     getFormValues(SHARING_PUBLIC_ACCESS_FORM_NAME)(state) as SharingPublicAccessFormData;
54
55 export const hasChanges = (state: RootState) =>
56     isDirty(SHARING_PUBLIC_ACCESS_FORM_NAME)(state) ||
57     isDirty(SHARING_MANAGEMENT_FORM_NAME)(state) ||
58     (isDirty(SHARING_INVITATION_FORM_NAME)(state) && !!state.form[SHARING_INVITATION_FORM_NAME].values?.invitedPeople.length);