Skip to content

Commit

Permalink
No create permissions dialog (#1934)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Release <>
Co-authored-by: datalens-weblate-robot <[email protected]>
Co-authored-by: Weblate <[email protected]>
Co-authored-by: Darya Tikhonova <[email protected]>
Co-authored-by: Matthew Casserly <[email protected]>
  • Loading branch information
5 people authored Dec 20, 2024
1 parent 351a407 commit c482663
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"button_ok": "Ok",
"label_title": "Insufficient permissions",
"section_message": "To create collections and workbooks, you need the <code>datalens.editor</code> role. Please contact your administrator."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"button_ok": "Понятно",
"label_title": "Недостаточно прав",
"section_message": "Для создания коллекций и воркбуков необходима роль <code>datalens.editor</code>, обратитесь к администратору."
}
5 changes: 5 additions & 0 deletions src/shared/constants/qa/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ export enum DialogConfirmQA {
CancelButton = 'dialog-confirm-cancel-button',
}

export enum DialogInfoQA {
Dialog = 'dialog-info',
CloseButton = 'dialog-close-button',
}

export enum DialogWarningQA {
Dialog = 'dialog-warning',
ApplyButton = 'dialog-warning-apply-button',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from 'react';

import {I18n} from 'i18n';
import DialogWarning from 'ui/components/DialogWarning/DialogWarning';

import {registry} from '../../../registry';
import DialogManager from '../../DialogManager/DialogManager';
import {YfmWrapperContent as YfmWrapper} from '../../YfmWrapper/YfmWrapperContent';

const i18n = I18n.keyset('component.dialog-collection-no-create-permission.view');

export const DIALOG_NO_CREATE_COLLECTION_PERMISSION = Symbol(
'DIALOG_NO_CREATE_COLLECTION_PERMISSION',
);

export type Props = {
visible: boolean;
onClose: () => void;
};

export type OpenDialogCollectionNoCreatePermissionArgs = {
id: typeof DIALOG_NO_CREATE_COLLECTION_PERMISSION;
props: Props;
};

export const CollectionNoCreatePermissionDialog = ({visible, onClose}: Props) => {
const {customizeNoCreatePermissionDialog} = registry.collections.functions.getAll();

const {message} = customizeNoCreatePermissionDialog({
message: <YfmWrapper content={i18n('section_message')} setByInnerHtml={true} />,
});

return (
<DialogWarning
visible={visible}
onApply={onClose}
showIcon={false}
closeOnEnterPress={true}
headerText={i18n('label_title')}
buttonText={i18n('button_ok')}
message={message}
/>
);
};

CollectionNoCreatePermissionDialog.displayName = 'CollectionNoCreatePermissionDialog';

DialogManager.registerDialog(
DIALOG_NO_CREATE_COLLECTION_PERMISSION,
CollectionNoCreatePermissionDialog,
);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './CollectionNoCreatePermissionDialog';
4 changes: 4 additions & 0 deletions src/ui/components/CollectionsStructure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export {
MigrateEntryToWorkbookDialog,
DIALOG_MIGRATE_ENTRY_TO_WORKBOOK,
} from './MigrateEntryToWorkbookDialog';
export {
CollectionNoCreatePermissionDialog,
DIALOG_NO_CREATE_COLLECTION_PERMISSION,
} from './CollectionNoCreatePermissionDialog';
export {CopyEntriesDialog, DIALOG_COPY_ENTRIES} from './CopyEntriesDialog';
export {DeleteCollectionDialog, DIALOG_DELETE_COLLECTION} from './DeleteCollectionDialog';
export {DeleteWorkbookDialog, DIALOG_DELETE_WORKBOOK} from './DeleteWorkbookDialog';
Expand Down
3 changes: 2 additions & 1 deletion src/ui/registry/units/collections/functionts-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {DropdownMenuItem} from '@gravity-ui/uikit';
import type {CollectionWithPermissions, WorkbookWithPermissions} from 'shared/schema';
import {makeFunctionTemplate} from 'shared/utils/makeFunctionTemplate';

import type {CustomizeEmptyPlaceholder} from './types';
import type {CustomizeEmptyPlaceholder, CustomizeNoCreatePermissionDialog} from './types';

export const collectionsFunctionsMap = {
customizeCollectionsActions:
Expand All @@ -20,4 +20,5 @@ export const collectionsFunctionsMap = {
) => (DropdownMenuItem[] | DropdownMenuItem)[]
>(),
customizeEmptyPlaceholder: makeFunctionTemplate<CustomizeEmptyPlaceholder>(),
customizeNoCreatePermissionDialog: makeFunctionTemplate<CustomizeNoCreatePermissionDialog>(),
} as const;
2 changes: 2 additions & 0 deletions src/ui/registry/units/collections/register.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
customizeCollectionsActions,
customizeEmptyPlaceholder,
customizeNoCreatePermissionDialog,
customizeWorkbooksActions,
} from '../../../units/collections/components/CollectionContent/utils';
import {registry} from '../../index';
Expand All @@ -10,5 +11,6 @@ export const registerCollectionsPlugins = () => {
customizeWorkbooksActions,
customizeCollectionsActions,
customizeEmptyPlaceholder,
customizeNoCreatePermissionDialog,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type CustomizeEmptyPlaceholder = (args: {
dispatch: AppDispatch;
history: History;
canCreateWorkbook: boolean;
showCreateWorkbookButton: boolean;
curCollectionId: string | null;
title: string;
description?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type React from 'react';

export type CustomizeNoCreatePermissionDialog = (args: {message?: React.ReactNode}) => {
message?: React.ReactNode;
};
1 change: 1 addition & 0 deletions src/ui/registry/units/collections/types/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './customizeEmptyPlaceholder';
export * from './customizeNoCreatePermissionDialog';
4 changes: 3 additions & 1 deletion src/ui/store/actions/openDialogTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import type {OpenDialogCreateEntryInWorkbookArgs} from '../../components/Collect
import type {OpenDialogIamAccessArgs} from '../../components/IamAccessDialog';
import type {OpenDialogTooltipSettingsArgs} from '../../units/wizard/components/Dialogs/DialogTooltipSettings/DialogTooltipSettings';
import type {OpenDialogChangeDatasetFieldsArgs} from '../../units/datasets/components/DatasetTable/components/BatchActionPanel/components/DialogChangeDatasetFields/DialogChangeDatasetFields';
import type {OpenDialogCollectionNoCreatePermissionArgs} from 'ui/components/CollectionsStructure/CollectionNoCreatePermissionDialog';

export type OpenDialogArgs<T = unknown> =
| OpenDialogMetricSettingsArgs
Expand Down Expand Up @@ -109,4 +110,5 @@ export type OpenDialogArgs<T = unknown> =
| OpenDialogIamAccessArgs
| OpenDialogCreateEntryInWorkbookArgs
| OpenDialogTooltipSettingsArgs
| OpenDialogChangeDatasetFieldsArgs;
| OpenDialogChangeDatasetFieldsArgs
| OpenDialogCollectionNoCreatePermissionArgs;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {Feature} from '../../../../../shared';
import {DL} from '../../../../constants';
import {registry} from '../../../../registry';
import Utils from '../../../../utils';
import {selectCollection, selectRootCollectionPermissions} from '../../store/selectors';
import {selectCollection} from '../../store/selectors';

import collectionIcon from '../../../../assets/icons/collections/collection.svg';
import workbookDemoIcon from '../../../../assets/icons/collections/workbook-demo.svg';
Expand Down Expand Up @@ -49,17 +49,12 @@ export const CollectionActions = React.memo<Props>(
onDeleteClick,
}) => {
const collection = useSelector(selectCollection);
const rootCollectionPermissions = useSelector(selectRootCollectionPermissions);

const {CustomActionPanelCollectionActions} = registry.collections.components.getAll();

const showCreateCollection = collection
? collection.permissions?.createCollection
: rootCollectionPermissions?.createCollectionInRoot;
const showCreateCollection = collection ? collection.permissions?.createCollection : true;

const showCreateWorkbook = collection
? collection.permissions?.createWorkbook
: rootCollectionPermissions?.createWorkbookInRoot;
const showCreateWorkbook = collection ? collection.permissions?.createWorkbook : true;

const showAddDemoWorkbook = showCreateWorkbook && DL.TEMPLATE_WORKBOOK_ID;
const showAddLearningMaterialsWorkbook =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface Props {
itemsAvailableForSelection: (CollectionWithPermissions | WorkbookWithPermissions)[];
isOpenSelectionMode: boolean;
canCreateWorkbook: boolean;
showCreateWorkbookButton: boolean;
isEmptyItems: boolean;
getStructureItemsRecursively: (
args: GetStructureItemsArgs,
Expand All @@ -76,6 +77,7 @@ export const CollectionContent: React.FC<Props> = ({
selectedMapWithDeletePermission,
itemsAvailableForSelection,
isOpenSelectionMode,
showCreateWorkbookButton,
canCreateWorkbook,
isEmptyItems,
getStructureItemsRecursively,
Expand Down Expand Up @@ -162,7 +164,7 @@ export const CollectionContent: React.FC<Props> = ({
if (isDefaultFilters || DL.IS_MOBILE) {
const actions: EmptyPlaceholderAction[] = [];

if (canCreateWorkbook) {
if (showCreateWorkbookButton) {
actions.push({
id: EmptyPlaceholderActionId.ConnectYourData,
title: i18n('action_connect-your-data'),
Expand All @@ -181,6 +183,7 @@ export const CollectionContent: React.FC<Props> = ({
dispatch,
history,
curCollectionId,
showCreateWorkbookButton,
canCreateWorkbook,
title: i18n('label_empty-list'),
description: canCreateWorkbook ? i18n('section_create-first') : undefined,
Expand Down
11 changes: 10 additions & 1 deletion src/ui/units/collections/components/CollectionContent/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import type {DropdownMenuItem} from '@gravity-ui/uikit';
import type {CollectionWithPermissions} from 'shared/schema/us/types/collections';
import type {WorkbookWithPermissions} from 'shared/schema/us/types/workbooks';

import type {CustomizeEmptyPlaceholder} from '../../../../registry/units/collections/types';
import type {
CustomizeEmptyPlaceholder,
CustomizeNoCreatePermissionDialog,
} from '../../../../registry/units/collections/types';

export const customizeCollectionsActions = (
_item: CollectionWithPermissions,
Expand All @@ -21,3 +24,9 @@ export const customizeEmptyPlaceholder: CustomizeEmptyPlaceholder = ({
}) => {
return {title, description, actions};
};

export const customizeNoCreatePermissionDialog: CustomizeNoCreatePermissionDialog = ({message}) => {
return {
message,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
DIALOG_CREATE_WORKBOOK,
DIALOG_DELETE_COLLECTIONS_WORKBOOKS,
DIALOG_MOVE_COLLECTIONS_WORKBOOKS,
DIALOG_NO_CREATE_COLLECTION_PERMISSION,
} from '../../../../components/CollectionsStructure';
import {ViewError} from '../../../../components/ViewError/ViewError';
import type {AppDispatch} from '../../../../store';
Expand Down Expand Up @@ -110,6 +111,20 @@ export const CollectionPage = () => {
);
}, [curCollectionId, dispatch, history]);

const handleShowNoPermissionsDialog = React.useCallback(() => {
dispatch(
openDialog({
id: DIALOG_NO_CREATE_COLLECTION_PERMISSION,
props: {
visible: true,
onClose: () => {
dispatch(closeDialog());
},
},
}),
);
}, [dispatch]);

const handleCreateWorkbookWithConnection = React.useCallback(() => {
dispatch(
openDialog({
Expand Down Expand Up @@ -218,6 +233,19 @@ export const CollectionPage = () => {
fetchStructureItems,
]);

const isRootCollection = curCollectionId === null;

const hasPermissionToCreate =
curCollectionId && collection
? Boolean(collection.permissions?.createWorkbook)
: Boolean(rootCollectionPermissions?.createWorkbookInRoot);

const showCreateWorkbookButton = DL.IS_MOBILE
? false
: hasPermissionToCreate || isRootCollection;

const isFiltersHidden = DL.IS_MOBILE && Utils.isEnabledFeature(Feature.HideMultitenant);

useLayout({
curCollectionId,
filters,
Expand All @@ -230,7 +258,9 @@ export const CollectionPage = () => {
resetSelected,
fetchCollectionInfo,
fetchStructureItems,
handleCreateWorkbook,
handleCreateWorkbook: hasPermissionToCreate
? handleCreateWorkbook
: handleShowNoPermissionsDialog,
handeCloseMoveDialog,
updateAllCheckboxes,
});
Expand All @@ -255,15 +285,6 @@ export const CollectionPage = () => {
);
}

const hasPermissionToCreate =
curCollectionId && collection
? Boolean(collection.permissions?.createWorkbook)
: Boolean(rootCollectionPermissions?.createWorkbookInRoot);

const canCreateWorkbook = DL.IS_MOBILE ? false : hasPermissionToCreate;

const isFiltersHidden = DL.IS_MOBILE && Utils.isEnabledFeature(Feature.HideMultitenant);

return (
<div className={b({mobile: DL.IS_MOBILE})}>
<div className={b('filters', {hidden: isFiltersHidden})}>
Expand All @@ -286,11 +307,16 @@ export const CollectionPage = () => {
selectedMapWithDeletePermission={selectedMapWithDeletePermission}
itemsAvailableForSelection={itemsAvailableForSelection}
isOpenSelectionMode={isOpenSelectionMode}
canCreateWorkbook={canCreateWorkbook}
canCreateWorkbook={hasPermissionToCreate}
showCreateWorkbookButton={showCreateWorkbookButton}
getStructureItemsRecursively={getStructureItemsRecursively}
fetchStructureItems={fetchStructureItems}
onCloseMoveDialog={handeCloseMoveDialog}
onCreateWorkbookWithConnectionClick={handleCreateWorkbookWithConnection}
onCreateWorkbookWithConnectionClick={
hasPermissionToCreate
? handleCreateWorkbookWithConnection
: handleShowNoPermissionsDialog
}
onClearFiltersClick={() => {
updateFilters({
...DEFAULT_FILTERS,
Expand Down
Loading

0 comments on commit c482663

Please sign in to comment.