1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { PermissionLevel } from 'models/permission';
6 import { getFormValues, isDirty } from 'redux-form';
7 import { RootState } from 'store/store';
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';
14 export enum VisibilityLevel {
17 ALL_USERS = 'All users',
21 export interface SharingPublicAccessFormData {
22 visibility: VisibilityLevel;
23 initialVisibility: VisibilityLevel;
24 permissionUuid: string;
27 export interface SharingManagementFormData {
28 permissions: SharingManagementFormDataRow[];
29 initialPermissions: SharingManagementFormDataRow[];
32 export interface SharingManagementFormDataRow {
34 permissions: PermissionLevel;
35 permissionUuid: string;
38 export interface SharingInvitationFormData {
39 permissions: PermissionLevel;
40 invitedPeople: SharingInvitationFormPersonData[];
43 export interface SharingInvitationFormPersonData {
49 export const getSharingMangementFormData = (state: any) =>
50 getFormValues(SHARING_MANAGEMENT_FORM_NAME)(state) as SharingManagementFormData;
52 export const getSharingPublicAccessFormData = (state: any) =>
53 getFormValues(SHARING_PUBLIC_ACCESS_FORM_NAME)(state) as SharingPublicAccessFormData;
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);