Skip to content

Commit

Permalink
feat(Navigation/MapNode): add UIFactory.getMapNodeExtraCreateActions(…
Browse files Browse the repository at this point in the history
…...) method
  • Loading branch information
Flunt1k committed Jul 2, 2024
1 parent 28a47ec commit ae6ae51
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 31 deletions.
13 changes: 13 additions & 0 deletions packages/ui/src/ui/UIFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {PreparedRole} from './utils/acl';
import {UISettingsMonitoring} from '../shared/ui-settings';
import {DefaultSubjectCard, type SubjectCardProps} from './components/SubjectLink/SubjectLink';
import type {QueryItem} from './pages/query-tracker/module/api';
import type {DropdownMenuItem} from '@gravity-ui/uikit';

type HeaderItemOrPage =
| {
Expand Down Expand Up @@ -404,6 +405,11 @@ export interface UIFactory {
onChytAliasSqlClick(params: {alias: string; cluster: string}): void;

getNavigationExtraTabs(): Array<ExtraTab>;

getMapNodeExtraCreateActions(baseActions: Array<DropdownMenuItem>): {
menuItems: Array<DropdownMenuItem>;
renderModals: () => React.ReactNode;
};
}

const experimentalPages: string[] = [];
Expand Down Expand Up @@ -681,6 +687,13 @@ const uiFactory: UIFactory = {
getNavigationExtraTabs() {
return [];
},

getMapNodeExtraCreateActions(baseActions) {
return {
menuItems: baseActions,
renderModals: () => undefined,
};
},
};

function configureUIFactoryItem<K extends keyof UIFactory>(k: K, redefinition: UIFactory[K]) {
Expand Down
66 changes: 35 additions & 31 deletions packages/ui/src/ui/pages/navigation/content/MapNode/MapNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {NoWrap} from '../../../../components/Text/Text';
import {showLinkToModal} from '../../../../store/actions/navigation/modals/link-to-modal';
import {openCreateACOModal} from '../../../../store/actions/navigation/modals/create-aco';
import NavigationExtraActions from '../../../../containers/NavigationExtraActions/NavigationExtraActions';
import UIFactory from '../../../../UIFactory';

import './MapNode.scss';

Expand Down Expand Up @@ -238,6 +239,38 @@ class MapNodeToolbar extends React.PureComponent {
showACOCreateButton,
} = this.props;

const {menuItems, renderModals} = UIFactory.getMapNodeExtraCreateActions([
{
action: this.createTableButtonClick,
text: <NoWrap>Table</NoWrap>,
icon: <Icon awesome={'table'} face={'solid'} />,
},
{
action: this.createDirectoryButtonClick,
text: <NoWrap>Directory</NoWrap>,
icon: <Icon awesome={'folder'} face={'solid'} />,
},
...(!getConfigUploadTable().uploadTableExcelBaseUrl
? []
: [
{
action: this.uploadTableButtonClick,
text: <NoWrap>Upload xlsx</NoWrap>,
icon: <Icon awesome={'upload'} />,
},
]),
{
action: this.createLinkButtonClick,
text: <NoWrap>Link</NoWrap>,
icon: <Icon awesome={'link'} />,
},
showACOCreateButton && {
action: this.createACOButtonClick,
text: <NoWrap>ACO</NoWrap>,
icon: <Icon awesome={'acl-object'} />,
},
]);

return (
<React.Fragment>
<div className={tbBlock('container')}>
Expand Down Expand Up @@ -295,37 +328,7 @@ class MapNodeToolbar extends React.PureComponent {
<DropdownMenu
menuSize={'n'}
popupClass={block('create-popup')}
items={[
{
action: this.createTableButtonClick,
text: <NoWrap>Table</NoWrap>,
icon: <Icon awesome={'table'} face={'solid'} />,
},
{
action: this.createDirectoryButtonClick,
text: <NoWrap>Directory</NoWrap>,
icon: <Icon awesome={'folder'} face={'solid'} />,
},
...(!getConfigUploadTable().uploadTableExcelBaseUrl
? []
: [
{
action: this.uploadTableButtonClick,
text: <NoWrap>Upload xlsx</NoWrap>,
icon: <Icon awesome={'upload'} />,
},
]),
{
action: this.createLinkButtonClick,
text: <NoWrap>Link</NoWrap>,
icon: <Icon awesome={'link'} />,
},
showACOCreateButton && {
action: this.createACOButtonClick,
text: <NoWrap>ACO</NoWrap>,
icon: <Icon awesome={'acl-object'} />,
},
]}
items={menuItems}
switcher={
<Button size="m" title="Create object">
Create object
Expand All @@ -338,6 +341,7 @@ class MapNodeToolbar extends React.PureComponent {
<NodesTypes />
</div>
<UploadManagerCreate ref={this.uploadXlsRef} />
{renderModals()}
</React.Fragment>
);
}
Expand Down

0 comments on commit ae6ae51

Please sign in to comment.