Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No create permissions dialog #1934

Merged
merged 16 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
bb3b211
Bump version to 0.2398.0 [release]
Dec 3, 2024
72c9acf
CHARTS-9786: show no create permissions dialog
sjorobekov Dec 12, 2024
d2b2e3f
CHARTS-9786: show no create permissions dialog
sjorobekov Dec 12, 2024
8497486
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
sjorobekov Dec 13, 2024
83701e0
no create collection permissions dialog
sjorobekov Dec 13, 2024
78b31b3
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
sjorobekov Dec 16, 2024
437189a
make CollectionNoCreatePermissionDialog customizable
sjorobekov Dec 17, 2024
df7b822
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
sjorobekov Dec 17, 2024
2ee6471
unwrap CollectionNoCreatePermissionDialog from React.memo
sjorobekov Dec 18, 2024
b934ecb
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
sjorobekov Dec 18, 2024
7cffb42
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
sjorobekov Dec 19, 2024
4308048
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
sjorobekov Dec 19, 2024
218ab11
Translations update from Weblate Gravity for PR #1934 (#1960)
datalens-weblate-robot Dec 19, 2024
f43618c
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
sjorobekov Dec 20, 2024
28a7aac
Merge branch 'main' into CHARTS-9786_no_create_permissions_dialog_2
sjorobekov Dec 20, 2024
4c03d8d
Merge branch 'main' into CHARTS-9786_no_create_permissions_dialog_2
sjorobekov Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"button_ok": "Ok",
"label_title": "Not enough 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": "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');
sjorobekov marked this conversation as resolved.
Show resolved Hide resolved

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 = React.memo<Props>(({visible, onClose}) => {
sjorobekov marked this conversation as resolved.
Show resolved Hide resolved
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;
sjorobekov marked this conversation as resolved.
Show resolved Hide resolved

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
Loading