Skip to content

Commit c8914df

Browse files
authored
Support shared entry in collections (#3071)
1 parent 2809f72 commit c8914df

File tree

24 files changed

+395
-173
lines changed

24 files changed

+395
-173
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const CollectionItemEntities = {
2+
COLLECTION: 'collection',
3+
WORKBOOK: 'workbook',
4+
ENTRY: 'entry',
5+
} as const;

src/shared/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './common';
2+
export * from './collections';
23
export * from './connections';
34
export * from './datasets';
45
export * from './dash';

src/shared/constants/qa/collections.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const enum CollectionContentTableQa {
22
Table = 'coll-content-table',
33
CollectionLinkRow = 'coll-content-table-coll-link-row',
44
WorkbookLinkRow = 'coll-content-table-workbook-link-row',
5+
EntryLinkRow = 'coll-content-table-entry-link-row',
56
CollectionTitleCell = 'coll-content-table-coll-title-cell',
67
}
78

src/shared/schema/us/actions/collections.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {getEntryNameByKey} from '../../../modules';
12
import {createAction} from '../../gateway-utils';
23
import type {
34
CreateCollectionArgs,
@@ -82,6 +83,15 @@ export const collectionsActions = {
8283
},
8384
headers,
8485
}),
86+
transformResponseData: (data) => ({
87+
...data,
88+
items: data.items.map((item) => {
89+
if ('displayKey' in item) {
90+
return {...item, title: getEntryNameByKey({key: item.displayKey})};
91+
}
92+
return item;
93+
}),
94+
}),
8595
}),
8696

8797
getCollectionBreadcrumbs: createAction<

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import type {CollectionItemEntities} from '../../../constants';
2+
3+
import type {SharedEntryFieldsWithPermissions} from './fields';
14
import type {GetDatalensOperationResponse} from './operations';
25
import type {OrderBasicField, OrderDirection} from './sort';
3-
import type {Workbook, WorkbookWithPermissions} from './workbooks';
6+
import type {ExtendedWorkbook} from './workbooks';
47

58
export type GetStructureItemsMode = 'all' | 'onlyCollections' | 'onlyWorkbooks';
69

@@ -39,6 +42,10 @@ export type CollectionWithOptionalPermissions = Collection & {
3942
permissions?: CollectionPermissions;
4043
};
4144

45+
export type ExtendedCollection = CollectionWithPermissions & {
46+
entity?: typeof CollectionItemEntities.COLLECTION;
47+
};
48+
4249
export type GetRootCollectionPermissionsResponse = {
4350
createCollectionInRoot: boolean;
4451
createWorkbookInRoot: boolean;
@@ -71,8 +78,13 @@ export type GetStructureItemsArgs = {
7178
includePermissionsInfo?: boolean;
7279
};
7380

81+
export type StructureItem =
82+
| ExtendedCollection
83+
| ExtendedWorkbook
84+
| SharedEntryFieldsWithPermissions;
85+
7486
export type GetStructureItemsResponse = {
75-
items: (Collection | CollectionWithPermissions | Workbook | WorkbookWithPermissions)[];
87+
items: StructureItem[];
7688
nextPageToken?: string | null;
7789
};
7890

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type {CollectionItemEntities} from '../../../constants';
12
import type {EntryAnnotation, WorkbookId} from '../../../types';
23

34
export type EntryFieldData<T = Record<string, unknown>> = null | T;
@@ -65,6 +66,29 @@ export interface EntryNavigationFields {
6566
workbookTitle?: string | null;
6667
}
6768

69+
export interface SharedEntryPermissions {
70+
delete: true;
71+
move: true;
72+
update: true;
73+
}
74+
75+
export interface SharedEntryFields {
76+
collectionId: string;
77+
updatedAt: string;
78+
workbookId: string;
79+
scope: string;
80+
type: string;
81+
key: string;
82+
entryId: string;
83+
entity: typeof CollectionItemEntities.ENTRY;
84+
displayKey: string;
85+
title: string;
86+
}
87+
88+
export interface SharedEntryFieldsWithPermissions extends SharedEntryFields {
89+
permissions: SharedEntryPermissions;
90+
}
91+
6892
// corresponds to RETURN_FAVORITES_COLUMNS from US
6993
export interface EntryFavoriteFields {
7094
entryId: string;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type {CollectionItemEntities} from '../../../constants';
12
import type {WorkbookStatus} from '../../../constants/workbooks';
23

34
import type {GetEntryResponse} from './entries';
@@ -36,6 +37,10 @@ export type WorkbookWithPermissions = Workbook & {
3637
permissions: WorkbookPermission;
3738
};
3839

40+
export type ExtendedWorkbook = WorkbookWithPermissions & {
41+
entity?: typeof CollectionItemEntities.WORKBOOK;
42+
};
43+
3944
export type CreateWorkbookArgs = {
4045
collectionId?: string | null;
4146
title: string;

src/ui/components/EntityIcon/EntityIcon.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ export type EntityIconType = keyof typeof typeIcons;
3737

3838
export type EntityIconSize = 's' | 'm' | 'l' | 'xl';
3939

40-
type EntityIconProps = {
40+
export type EntityIconProps = {
4141
type?: string;
4242
iconData?: IconData;
4343
size?: EntityIconSize;
4444
iconSize?: number;
4545
view?: 'round';
46-
classMixin?: string;
46+
className?: string;
47+
classNameColorBox?: string;
48+
classNameIcon?: string;
4749
};
4850

4951
export const defaultIconSize = {
@@ -58,7 +60,9 @@ export const EntityIcon = ({
5860
type,
5961
iconData,
6062
iconSize = defaultIconSize[size],
61-
classMixin,
63+
className,
64+
classNameIcon,
65+
classNameColorBox,
6266
view,
6367
}: EntityIconProps) => {
6468
let targetIconData;
@@ -69,9 +73,9 @@ export const EntityIcon = ({
6973
}
7074

7175
return (
72-
<div className={b('container', {size, view}, classMixin)}>
73-
<div className={b('color-box', {type})}>
74-
<Icon data={targetIconData} size={iconSize} />
76+
<div className={b('container', {size, view}, className)}>
77+
<div className={b('color-box', {type}, classNameColorBox)}>
78+
<Icon data={targetIconData} size={iconSize} className={classNameIcon} />
7579
</div>
7680
</div>
7781
);

src/ui/components/EntryIcon/EntryIcon.tsx

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {getConnectorIconData} from 'ui/utils';
88
import {registry} from '../../registry';
99
import type {ConnectorIconViewProps} from '../ConnectorIcon/ConnectorIcon';
1010
import {ConnectorIcon} from '../ConnectorIcon/ConnectorIcon';
11-
import type {EntityIconSize, EntityIconType} from '../EntityIcon/EntityIcon';
1211
import {EntityIcon, defaultIconSize} from '../EntityIcon/EntityIcon';
12+
import type {EntityIconProps, EntityIconSize, EntityIconType} from '../EntityIcon/EntityIcon';
1313

1414
import iconFilesBroken from '../../assets/icons/broken.svg';
1515

@@ -53,12 +53,21 @@ export const getEntryIconData = ({type}: EntryData) => {
5353
return iconData;
5454
};
5555

56-
const getEntityIconType = (
57-
{scope, type}: EntryData,
58-
className?: string,
59-
entityIconSize?: EntityIconSize,
60-
overrideIconType?: EntityIconType,
61-
) => {
56+
type EntityIconTypeProps = {
57+
entryData: EntryData;
58+
className?: string;
59+
entityIconSize?: EntityIconSize;
60+
overrideIconType?: EntityIconType;
61+
entityIconProps?: Partial<EntityIconProps>;
62+
};
63+
64+
const getEntityIconType = ({
65+
entryData: {scope, type},
66+
className,
67+
entityIconSize,
68+
overrideIconType,
69+
entityIconProps = {},
70+
}: EntityIconTypeProps) => {
6271
let iconType;
6372

6473
if (type) {
@@ -78,7 +87,8 @@ const getEntityIconType = (
7887
type={entityIconType as EntityIconType}
7988
iconSize={iconSize}
8089
size={entityIconSize}
81-
classMixin={className}
90+
className={className}
91+
{...entityIconProps}
8292
/>
8393
);
8494
}
@@ -90,10 +100,19 @@ interface EntryIconProps extends Partial<ConnectorIconViewProps> {
90100
entityIconSize?: EntityIconSize;
91101
// can be used to use connection icon without type of connection
92102
overrideIconType?: EntityIconType;
103+
entityIconProps?: Partial<EntityIconProps>;
93104
}
94105

95106
export const EntryIcon = (props: EntryIconProps) => {
96-
const {entry, className, entityIconSize, overrideIconType, size, ...restProps} = props;
107+
const {
108+
entry,
109+
className,
110+
entityIconSize,
111+
overrideIconType,
112+
size,
113+
entityIconProps,
114+
...restProps
115+
} = props;
97116
const iconData = getEntryIconData(entry);
98117
const iconSize = size ?? defaultIconSize[entityIconSize || 's'];
99118
if (iconData) {
@@ -108,8 +127,12 @@ export const EntryIcon = (props: EntryIconProps) => {
108127
);
109128
}
110129
return (
111-
getEntityIconType(entry, className, entityIconSize, overrideIconType) || (
112-
<Icon data={iconFilesBroken} className={className} size={iconSize} {...restProps} />
113-
)
130+
getEntityIconType({
131+
entryData: entry,
132+
className,
133+
entityIconSize,
134+
overrideIconType,
135+
entityIconProps,
136+
}) || <Icon data={iconFilesBroken} className={className} size={iconSize} {...restProps} />
114137
);
115138
};

src/ui/components/PathSelect/PathSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class PathSelect extends React.PureComponent<PathSelectProps> {
7373
type="folder"
7474
size="l"
7575
iconSize={22}
76-
classMixin={b('icon-folder')}
76+
className={b('icon-folder')}
7777
/>
7878
<span className={b('path-text')}>{this.text}</span>
7979
{this.props.withInput && (

0 commit comments

Comments
 (0)