Skip to content

Commit 4e42f43

Browse files
authored
Support shared dataset page (#3209)
1 parent 8724b8c commit 4e42f43

File tree

22 files changed

+253
-62
lines changed

22 files changed

+253
-62
lines changed

src/shared/schema/us/types/fields.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export interface EntryMetaFields {
4444
publishedId: EntryFieldPublishedId;
4545
tenantId: string;
4646
workbookId: WorkbookId;
47+
collectionId: CollectionId;
4748
accessDescription?: string;
4849
supportDescription?: string;
4950
}

src/shared/types/dataset.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export interface Dataset {
131131
description?: string;
132132
};
133133
workbook_id?: string;
134+
collection_id?: string;
134135
permissions?: Permissions;
135136

136137
// This part of the fields moved to the dataset field. right here saved for backward compatibility

src/ui/components/ActionPanel/components/EntryPanel/EntryPanel.tsx

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ import type {FilterEntryContextMenuItems} from 'ui/components/EntryContextMenu';
1616
import {CounterName, GoalId, reachMetricaGoal} from 'ui/libs/metrica';
1717
import {registry} from 'ui/registry';
1818
import type {BreadcrumbsItem} from 'ui/registry/units/common/types/components/EntryBreadcrumbs';
19-
import {getCollectionBreadcrumbs} from 'ui/store/actions/collectionsStructure';
20-
import {selectGetCollectionBreadcrumbs} from 'ui/store/selectors/collectionsStructure';
21-
import {addWorkbookInfo, resetWorkbookPermissions} from 'units/workbooks/store/actions';
22-
import {selectWorkbookBreadcrumbs, selectWorkbookName} from 'units/workbooks/store/selectors';
19+
import {
20+
addCollectionBreadcrumbs,
21+
addWorkbookInfo,
22+
resetWorkbookPermissions,
23+
} from 'units/workbooks/store/actions';
24+
import {selectEntityBreadcrumbs, selectWorkbookName} from 'units/workbooks/store/selectors';
2325

2426
import type {GetEntryResponse} from '../../../../../shared/schema';
2527
import {DL} from '../../../../constants/common';
@@ -109,9 +111,8 @@ class EntryPanel extends React.Component<Props, State> {
109111

110112
if (workbookId) {
111113
this.props.actions.addWorkbookInfo(workbookId, true);
112-
}
113-
if (collectionId) {
114-
this.props.actions.getCollectionBreadcrumbs({collectionId});
114+
} else if (collectionId) {
115+
this.props.actions.addCollectionBreadcrumbs({collectionId});
115116
}
116117
}
117118

@@ -123,19 +124,17 @@ class EntryPanel extends React.Component<Props, State> {
123124

124125
if (prevWorkbookId !== workbookId && workbookId) {
125126
this.props.actions.addWorkbookInfo(workbookId, true);
127+
} else if (prevCollectionId !== collectionId && collectionId) {
128+
this.props.actions.addCollectionBreadcrumbs({collectionId});
126129
}
127130

128131
if (prevWorkbookId && !workbookId) {
129132
this.props.actions.resetWorkbookPermissions();
130133
}
131-
132-
if (prevCollectionId !== collectionId && collectionId) {
133-
this.props.actions.getCollectionBreadcrumbs({collectionId});
134-
}
135134
}
136135

137136
render() {
138-
const {children, workbookName, workbookBreadcrumbs, collectionBreadcrumbs} = this.props;
137+
const {children, workbookName, entityBreadcrumbs} = this.props;
139138
const {EntryBreadcrumbs} = registry.common.components.getAll();
140139

141140
return (
@@ -145,7 +144,7 @@ class EntryPanel extends React.Component<Props, State> {
145144
renderRootContent={this.renderRootContent}
146145
entry={this.state.entry}
147146
workbookName={workbookName}
148-
entityBreadcrumbs={workbookBreadcrumbs ?? collectionBreadcrumbs.data}
147+
entityBreadcrumbs={entityBreadcrumbs}
149148
endContent={
150149
<React.Fragment>
151150
{this.renderControls()}
@@ -342,16 +341,15 @@ const mapStateToProps = (state: DatalensGlobalState, ownProps: OwnProps) => {
342341

343342
return {
344343
workbookName: selectWorkbookName(state, workbookId),
345-
workbookBreadcrumbs: selectWorkbookBreadcrumbs(state),
346-
collectionBreadcrumbs: selectGetCollectionBreadcrumbs(state),
344+
entityBreadcrumbs: selectEntityBreadcrumbs(state),
347345
};
348346
};
349347

350348
const mapDispatchToProps = (dispatch: Dispatch) => {
351349
return {
352350
actions: bindActionCreators(
353351
{
354-
getCollectionBreadcrumbs,
352+
addCollectionBreadcrumbs,
355353
addWorkbookInfo,
356354
resetWorkbookPermissions,
357355
},

src/ui/components/DialogSharedEntryBindings/components/DirectionControl.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ export const DirectionControl = ({currentDirection, onUpdate}: DirectionControlP
2323
width="auto"
2424
>
2525
<RadioButton.Option value={Attachment.SOURCE}>
26-
{getSharedEntryMockText('label-attachment-source')}
26+
{getSharedEntryMockText('label-attachment-target')}
2727
</RadioButton.Option>
2828
<RadioButton.Option value={Attachment.TARGET}>
29-
{getSharedEntryMockText('label-attachment-target')}
29+
{getSharedEntryMockText('label-attachment-source')}
3030
</RadioButton.Option>
3131
</RadioButton>
3232
);

src/ui/components/DialogSharedEntryBindings/components/Relations.tsx

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,35 @@ export const Relations = ({
6565

6666
const getListItemActions = React.useCallback(
6767
(item: SharedEntryBindingsItem) => {
68+
const isRelationUnbind = getIsRelationUnbind(currentDirection, item);
69+
const relation = isRelationUnbind ? undefined : item;
70+
const parentEntry = isRelationUnbind ? item : entry;
71+
const sourceId = isRelationUnbind ? item.entryId : entry.entryId;
72+
const target = isRelationUnbind ? entry : item;
73+
74+
let targetId = '';
75+
76+
if ('entity' in target && target.entity === CollectionItemEntities.WORKBOOK) {
77+
targetId = target.workbookId!;
78+
} else if ('entryId' in target) {
79+
targetId = target.entryId;
80+
}
81+
6882
return [
6983
{
7084
text: getSharedEntryMockText('shared-bindings-list-action-unbind'),
71-
action: () =>
85+
action: () => {
7286
dispatch(
7387
openDialog({
7488
id: DIALOG_SHARED_ENTRY_UNBIND,
7589
props: {
76-
entry: getIsRelationUnbind(currentDirection, item)
77-
? item
78-
: entry,
90+
entry: parentEntry,
7991
onClose: () => dispatch(closeDialog()),
8092
onApply: async () => {
8193
try {
8294
await getSdk().sdk.us.deleteSharedEntryBinding({
83-
sourceId: entry.entryId,
84-
targetId:
85-
item.entity === CollectionItemEntities.WORKBOOK
86-
? item.workbookId!
87-
: item.entryId,
95+
sourceId,
96+
targetId,
8897
});
8998
dispatch(closeDialog());
9099
fetchEntityBindings(isDeleteDialog ? '' : searchValue);
@@ -93,12 +102,11 @@ export const Relations = ({
93102
}
94103
},
95104
open: true,
96-
relation: getIsRelationUnbind(currentDirection, item)
97-
? undefined
98-
: item,
105+
relation,
99106
},
100107
}),
101-
),
108+
);
109+
},
102110
},
103111
{
104112
text: getSharedEntryMockText('shared-bindings-list-action-change-permissions'),
@@ -107,16 +115,13 @@ export const Relations = ({
107115
openDialog({
108116
id: DIALOG_SHARED_ENTRY_PERMISSIONS,
109117
props: {
110-
entry,
118+
entry: parentEntry,
111119
onClose: () => dispatch(closeDialog()),
112120
onApply: async (delegate) => {
113121
try {
114122
await getSdk().sdk.us.updateSharedEntryBinding({
115-
sourceId: entry.entryId,
116-
targetId:
117-
item.entity === CollectionItemEntities.WORKBOOK
118-
? item.workbookId!
119-
: item.entryId,
123+
sourceId,
124+
targetId,
120125
delegation: delegate,
121126
});
122127
dispatch(closeDialog());
@@ -127,7 +132,7 @@ export const Relations = ({
127132
},
128133
open: true,
129134
delegation: item.isDelegated,
130-
relation: item,
135+
relation,
131136
},
132137
}),
133138
),

src/ui/components/DialogSharedEntryBindings/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export const Attachment = {
88
export type AttachmentValue = (typeof Attachment)[keyof typeof Attachment];
99

1010
export const ObjectsListTitles: Record<AttachmentValue, keyof typeof mockSharedEntriesTexts> = {
11-
target: 'entries-list-title-workbook',
12-
source: 'entries-list-title-connection',
11+
source: 'entries-list-title-workbook',
12+
target: 'entries-list-title-connection',
1313
};
1414

1515
export const SEARCH_DELAY = 1000;

src/ui/components/DialogSharedEntryPermissions/DialogSharedEntryPermissions.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import './DialogSharedEntryPermissions.scss';
1717

1818
type DialogSharedEntryPermissionsProps = {
1919
open: boolean;
20-
onClose: () => void;
20+
onClose: (delegate: boolean) => void;
2121
entry: SharedEntry;
2222
relation?: SharedEntryBindingsItem;
2323
onApply: (delegate: boolean) => Promise<void> | void;
@@ -50,8 +50,12 @@ export const DialogSharedEntryPermissions: React.FC<DialogSharedEntryPermissions
5050
setIsLoading(false);
5151
};
5252

53+
const onCloseHandler = () => {
54+
onClose(delegate);
55+
};
56+
5357
return (
54-
<Dialog size="m" open={open} onClose={onClose} className={b()}>
58+
<Dialog size="m" open={open} onClose={onCloseHandler} className={b()}>
5559
<Dialog.Header caption={getSharedEntryMockText('title-permissions-dialog')} />
5660
<Dialog.Body className={b('body')}>
5761
<div className={b('objects-wrapper')}>
@@ -110,7 +114,7 @@ export const DialogSharedEntryPermissions: React.FC<DialogSharedEntryPermissions
110114
loading={isLoading}
111115
textButtonCancel={getSharedEntryMockText('cancel-unbind-dialog')}
112116
onClickButtonApply={onSubmit}
113-
onClickButtonCancel={onClose}
117+
onClickButtonCancel={onCloseHandler}
114118
/>
115119
</Dialog>
116120
);

src/ui/units/datasets/constants/datasets.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {ENTRY_CONTEXT_MENU_ACTION} from 'ui/components/EntryContextMenu';
2+
13
import {DL} from '../../../constants';
24

35
const preprodEnv = DL.IS_DEVELOPMENT || DL.IS_PREPROD;
@@ -32,3 +34,12 @@ export const MANAGED_BY = {
3234

3335
export const MIN_AVAILABLE_DATASET_REV_DATE = '2024-12-01T00:00:00.000Z';
3436
export const DATASET_DATE_AVAILABLE_FORMAT = 'DD.MM.YYYY';
37+
38+
export const SharedDatasetHiddenContextMenuItems = new Set<string>([
39+
ENTRY_CONTEXT_MENU_ACTION.SHOW_RELATED_ENTITIES,
40+
ENTRY_CONTEXT_MENU_ACTION.DELETE,
41+
ENTRY_CONTEXT_MENU_ACTION.ACCESS,
42+
ENTRY_CONTEXT_MENU_ACTION.MOVE,
43+
ENTRY_CONTEXT_MENU_ACTION.COPY,
44+
ENTRY_CONTEXT_MENU_ACTION.MIGRATE_TO_WORKBOOK,
45+
]);

src/ui/units/datasets/constants/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {i18n} from 'i18n';
2-
import type {EntryScope, WorkbookId} from 'shared';
2+
import type {CollectionId, EntryScope, WorkbookId} from 'shared';
33
import {DL} from 'ui';
44

55
import {getFakeEntry as genericGetFakeEntry} from '../../../components/ActionPanel';
@@ -51,7 +51,7 @@ export const getAppMetricGroupNameI18n = (key: string) => _getSelectItemTitle()[
5151
export const getFakeEntry = (
5252
scope: EntryScope.Connection | EntryScope.Dataset,
5353
workbookId?: WorkbookId,
54-
collectionId?: string,
54+
collectionId?: CollectionId,
5555
searchCurrentPath?: string,
5656
) => {
5757
let path = searchCurrentPath || DL.USER_FOLDER;

src/ui/units/datasets/containers/Dataset/ActionPanelRightItems.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,16 @@ type Props = {
4949
isCreationProcess?: boolean;
5050
onClickCreateWidgetButton: () => void;
5151
onClickSaveDatasetButton: () => void;
52+
canCreateWidget: boolean;
5253
};
5354

5455
export function ActionPanelRightItems(props: Props) {
55-
const {isCreationProcess, onClickCreateWidgetButton, onClickSaveDatasetButton} = props;
56+
const {
57+
isCreationProcess,
58+
onClickCreateWidgetButton,
59+
onClickSaveDatasetButton,
60+
canCreateWidget,
61+
} = props;
5662
const dispatch = useDispatch();
5763
const isDatasetRevisionMismatch = useSelector(isDatasetRevisionMismatchSelector);
5864
const isLoadPreviewByDefault = useSelector(isLoadPreviewByDefaultSelector);
@@ -197,7 +203,7 @@ export function ActionPanelRightItems(props: Props) {
197203
<Button
198204
view="normal"
199205
size="m"
200-
disabled={isCreationProcess}
206+
disabled={isCreationProcess || !canCreateWidget}
201207
onClick={onClickCreateWidgetButton}
202208
>
203209
{i18n('button_create-widget')}

0 commit comments

Comments
 (0)