Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions src/shared/constants/collections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const CollectionItemEntities = {
COLLECTION: 'collection',
WORKBOOK: 'workbook',
ENTRY: 'entry',
} as const;
1 change: 1 addition & 0 deletions src/shared/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './common';
export * from './collections';
export * from './connections';
export * from './datasets';
export * from './dash';
Expand Down
1 change: 1 addition & 0 deletions src/shared/constants/qa/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const enum CollectionContentTableQa {
Table = 'coll-content-table',
CollectionLinkRow = 'coll-content-table-coll-link-row',
WorkbookLinkRow = 'coll-content-table-workbook-link-row',
EntryLinkRow = 'coll-content-table-entry-link-row',
CollectionTitleCell = 'coll-content-table-coll-title-cell',
}

Expand Down
10 changes: 10 additions & 0 deletions src/shared/schema/us/actions/collections.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {getEntryNameByKey} from '../../../modules';
import {createAction} from '../../gateway-utils';
import type {
CreateCollectionArgs,
Expand Down Expand Up @@ -82,6 +83,15 @@ export const collectionsActions = {
},
headers,
}),
transformResponseData: (data) => ({
...data,
items: data.items.map((item) => {
if ('displayKey' in item) {
return {...item, title: getEntryNameByKey({key: item.displayKey})};
}
return item;
}),
}),
}),

getCollectionBreadcrumbs: createAction<
Expand Down
16 changes: 14 additions & 2 deletions src/shared/schema/us/types/collections.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type {CollectionItemEntities} from '../../../constants';

import type {SharedEntryFieldsWithPermissions} from './fields';
import type {GetDatalensOperationResponse} from './operations';
import type {OrderBasicField, OrderDirection} from './sort';
import type {Workbook, WorkbookWithPermissions} from './workbooks';
import type {ExtendedWorkbook} from './workbooks';

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

Expand Down Expand Up @@ -39,6 +42,10 @@ export type CollectionWithOptionalPermissions = Collection & {
permissions?: CollectionPermissions;
};

export type ExtendedCollection = CollectionWithPermissions & {
entity?: typeof CollectionItemEntities.COLLECTION;
};

export type GetRootCollectionPermissionsResponse = {
createCollectionInRoot: boolean;
createWorkbookInRoot: boolean;
Expand Down Expand Up @@ -71,8 +78,13 @@ export type GetStructureItemsArgs = {
includePermissionsInfo?: boolean;
};

export type StructureItem =
| ExtendedCollection
| ExtendedWorkbook
| SharedEntryFieldsWithPermissions;

export type GetStructureItemsResponse = {
items: (Collection | CollectionWithPermissions | Workbook | WorkbookWithPermissions)[];
items: StructureItem[];
nextPageToken?: string | null;
};

Expand Down
24 changes: 24 additions & 0 deletions src/shared/schema/us/types/fields.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {CollectionItemEntities} from '../../../constants';
import type {EntryAnnotation, WorkbookId} from '../../../types';

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

export interface SharedEntryPermissions {
delete: true;
move: true;
update: true;
}

export interface SharedEntryFields {
collectionId: string;
updatedAt: string;
workbookId: string;
scope: string;
type: string;
key: string;
entryId: string;
entity: typeof CollectionItemEntities.ENTRY;
displayKey: string;
title: string;
}

export interface SharedEntryFieldsWithPermissions extends SharedEntryFields {
permissions: SharedEntryPermissions;
}

// corresponds to RETURN_FAVORITES_COLUMNS from US
export interface EntryFavoriteFields {
entryId: string;
Expand Down
5 changes: 5 additions & 0 deletions src/shared/schema/us/types/workbooks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {CollectionItemEntities} from '../../../constants';
import type {WorkbookStatus} from '../../../constants/workbooks';

import type {GetEntryResponse} from './entries';
Expand Down Expand Up @@ -36,6 +37,10 @@ export type WorkbookWithPermissions = Workbook & {
permissions: WorkbookPermission;
};

export type ExtendedWorkbook = WorkbookWithPermissions & {
entity?: typeof CollectionItemEntities.WORKBOOK;
};

export type CreateWorkbookArgs = {
collectionId?: string | null;
title: string;
Expand Down
16 changes: 10 additions & 6 deletions src/ui/components/EntityIcon/EntityIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ export type EntityIconType = keyof typeof typeIcons;

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

type EntityIconProps = {
export type EntityIconProps = {
type?: string;
iconData?: IconData;
size?: EntityIconSize;
iconSize?: number;
view?: 'round';
classMixin?: string;
className?: string;
classNameColorBox?: string;
classNameIcon?: string;
};

export const defaultIconSize = {
Expand All @@ -58,7 +60,9 @@ export const EntityIcon = ({
type,
iconData,
iconSize = defaultIconSize[size],
classMixin,
className,
classNameIcon,
classNameColorBox,
view,
}: EntityIconProps) => {
let targetIconData;
Expand All @@ -69,9 +73,9 @@ export const EntityIcon = ({
}

return (
<div className={b('container', {size, view}, classMixin)}>
<div className={b('color-box', {type})}>
<Icon data={targetIconData} size={iconSize} />
<div className={b('container', {size, view}, className)}>
<div className={b('color-box', {type}, classNameColorBox)}>
<Icon data={targetIconData} size={iconSize} className={classNameIcon} />
</div>
</div>
);
Expand Down
47 changes: 35 additions & 12 deletions src/ui/components/EntryIcon/EntryIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {getConnectorIconData} from 'ui/utils';
import {registry} from '../../registry';
import type {ConnectorIconViewProps} from '../ConnectorIcon/ConnectorIcon';
import {ConnectorIcon} from '../ConnectorIcon/ConnectorIcon';
import type {EntityIconSize, EntityIconType} from '../EntityIcon/EntityIcon';
import {EntityIcon, defaultIconSize} from '../EntityIcon/EntityIcon';
import type {EntityIconProps, EntityIconSize, EntityIconType} from '../EntityIcon/EntityIcon';

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

Expand Down Expand Up @@ -53,12 +53,21 @@ export const getEntryIconData = ({type}: EntryData) => {
return iconData;
};

const getEntityIconType = (
{scope, type}: EntryData,
className?: string,
entityIconSize?: EntityIconSize,
overrideIconType?: EntityIconType,
) => {
type EntityIconTypeProps = {
entryData: EntryData;
className?: string;
entityIconSize?: EntityIconSize;
overrideIconType?: EntityIconType;
entityIconProps?: Partial<EntityIconProps>;
};

const getEntityIconType = ({
entryData: {scope, type},
className,
entityIconSize,
overrideIconType,
entityIconProps = {},
}: EntityIconTypeProps) => {
let iconType;

if (type) {
Expand All @@ -78,7 +87,8 @@ const getEntityIconType = (
type={entityIconType as EntityIconType}
iconSize={iconSize}
size={entityIconSize}
classMixin={className}
className={className}
{...entityIconProps}
/>
);
}
Expand All @@ -90,10 +100,19 @@ interface EntryIconProps extends Partial<ConnectorIconViewProps> {
entityIconSize?: EntityIconSize;
// can be used to use connection icon without type of connection
overrideIconType?: EntityIconType;
entityIconProps?: Partial<EntityIconProps>;
}

export const EntryIcon = (props: EntryIconProps) => {
const {entry, className, entityIconSize, overrideIconType, size, ...restProps} = props;
const {
entry,
className,
entityIconSize,
overrideIconType,
size,
entityIconProps,
...restProps
} = props;
const iconData = getEntryIconData(entry);
const iconSize = size ?? defaultIconSize[entityIconSize || 's'];
if (iconData) {
Expand All @@ -108,8 +127,12 @@ export const EntryIcon = (props: EntryIconProps) => {
);
}
return (
getEntityIconType(entry, className, entityIconSize, overrideIconType) || (
<Icon data={iconFilesBroken} className={className} size={iconSize} {...restProps} />
)
getEntityIconType({
entryData: entry,
className,
entityIconSize,
overrideIconType,
entityIconProps,
}) || <Icon data={iconFilesBroken} className={className} size={iconSize} {...restProps} />
);
};
2 changes: 1 addition & 1 deletion src/ui/components/PathSelect/PathSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class PathSelect extends React.PureComponent<PathSelectProps> {
type="folder"
size="l"
iconSize={22}
classMixin={b('icon-folder')}
className={b('icon-folder')}
/>
<span className={b('path-text')}>{this.text}</span>
{this.props.withInput && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import {Waypoint} from 'react-waypoint';
import {DL} from 'ui/constants/common';

import type {
CollectionWithPermissions,
GetStructureItemsArgs,
GetStructureItemsResponse,
WorkbookWithPermissions,
StructureItem,
} from '../../../../../shared/schema';
import {AnimateBlock} from '../../../../components/AnimateBlock';
import type {StructureItemsFilters} from '../../../../components/CollectionFilters';
Expand Down Expand Up @@ -49,7 +48,7 @@ interface Props {
selectedMap: SelectedMap;
selectedMapWithMovePermission: SelectedMap;
selectedMapWithDeletePermission: SelectedMap;
itemsAvailableForSelection: (CollectionWithPermissions | WorkbookWithPermissions)[];
itemsAvailableForSelection: StructureItem[];
isOpenSelectionMode: boolean;
canCreateWorkbook: boolean;
showCreateWorkbookButton: boolean;
Expand Down Expand Up @@ -153,7 +152,7 @@ export const CollectionContent: React.FC<Props> = ({
nextPageToken,
]);

const {getCollectionActions, getWorkbookActions} = useActions({
const getItemActions = useActions({
fetchStructureItems,
onCloseMoveDialog,
});
Expand Down Expand Up @@ -255,16 +254,14 @@ export const CollectionContent: React.FC<Props> = ({
<CollectionContentGrid
selectedMap={selectedMap}
isOpenSelectionMode={isOpenSelectionMode}
getWorkbookActions={getWorkbookActions}
getCollectionActions={getCollectionActions}
getItemActions={getItemActions}
onUpdateCheckboxClick={onUpdateCheckboxClick}
/>
) : (
<CollectionContentTable
selectedMap={selectedMap}
itemsAvailableForSelectionCount={itemsAvailableForSelection.length}
getWorkbookActions={getWorkbookActions}
getCollectionActions={getCollectionActions}
getItemActions={getItemActions}
refreshPage={refreshPage}
onUpdateCheckboxClick={onUpdateCheckboxClick}
onUpdateAllCheckboxesClick={onUpdateAllCheckboxesClick}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import {WORKBOOK_STATUS} from 'shared/constants/workbooks';
import {DIALOG_EXPORT_WORKBOOK} from 'ui/components/CollectionsStructure/ExportWorkbookDialog/ExportWorkbookDialog';
import {isEnabledFeature} from 'ui/utils/isEnabledFeature';

import {Feature} from '../../../../../../shared';
import {CollectionItemEntities, Feature} from '../../../../../../shared';
import type {
CollectionWithPermissions,
SharedEntryFieldsWithPermissions,
StructureItem,
UpdateCollectionResponse,
UpdateWorkbookResponse,
WorkbookWithPermissions,
Expand All @@ -33,6 +35,7 @@ import type {AppDispatch} from '../../../../../store';
import {closeDialog, openDialog} from '../../../../../store/actions/dialog';
import {WORKBOOKS_PATH} from '../../../../collections-navigation/constants';
import {deleteCollectionInItems, deleteWorkbookInItems} from '../../../store/actions';
import {getIsWorkbookItem} from '../../helpers';

const i18n = I18n.keyset('collections');

Expand Down Expand Up @@ -356,8 +359,53 @@ export const useActions = ({fetchStructureItems, onCloseMoveDialog}: UseActionsA
],
);

return {
getCollectionActions,
getWorkbookActions,
};
const getEntryActions = React.useCallback(
(item: SharedEntryFieldsWithPermissions): (DropdownMenuItem[] | DropdownMenuItem)[] => {
const actions: (DropdownMenuItem[] | DropdownMenuItem)[] = [];

if (item.permissions.update) {
actions.push({
text: <DropdownAction icon={PencilToLine} text={i18n('action_edit')} />,
action: () => {},
});
}

const otherActions: DropdownMenuItem[] = [];

if (item.permissions.delete) {
otherActions.push({
text: <DropdownAction icon={TrashBin} text={i18n('action_delete')} />,
action: () => {},
theme: 'danger',
});
}

if (otherActions.length > 0) {
actions.push([...otherActions]);
}

return actions;
},
[],
);

const getItemActions = React.useCallback(
(item: StructureItem) => {
switch (item.entity) {
case CollectionItemEntities.COLLECTION:
return getCollectionActions(item);
case CollectionItemEntities.WORKBOOK:
return getWorkbookActions(item);
case CollectionItemEntities.ENTRY:
return getEntryActions(item);
default:
return getIsWorkbookItem(item)
? getWorkbookActions(item)
: getCollectionActions(item);
}
},
[getCollectionActions, getEntryActions, getWorkbookActions],
);

return getItemActions;
};
Loading
Loading