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
4 changes: 0 additions & 4 deletions src/containers/AsideNavigation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {UserSettings} from '../UserSettings/UserSettings';
import type {YDBEmbeddedUISettings} from '../UserSettings/settings';

import {YdbInternalUser} from './YdbInternalUser/YdbInternalUser';
import {useNavigationMenuItems} from './useNavigationMenuItems';

interface NavigationProps {
userSettings?: YDBEmbeddedUISettings;
Expand All @@ -12,12 +11,9 @@ interface NavigationProps {
export function Navigation({children, userSettings}: NavigationProps) {
const AsideNavigation = useComponent('AsideNavigation');

const menuItems = useNavigationMenuItems();

return (
<AsideNavigation
settings={<UserSettings settings={userSettings} />}
menuItems={menuItems}
ydbInternalUser={<YdbInternalUser />}
content={children}
/>
Expand Down
3 changes: 0 additions & 3 deletions src/containers/AsideNavigation/i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"pages.query": "Query",
"pages.diagnostics": "Diagnostics",

"navigation-item.documentation": "Documentation",
"navigation-item.settings": "Settings",
"navigation-item.account": "Account",
Expand Down
3 changes: 1 addition & 2 deletions src/containers/AsideNavigation/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {registerKeysets} from '../../../utils/i18n';

import en from './en.json';
import ru from './ru.json';

const COMPONENT = 'ydb-aside-navigation';

export default registerKeysets(COMPONENT, {ru, en});
export default registerKeysets(COMPONENT, {en});
13 changes: 0 additions & 13 deletions src/containers/AsideNavigation/i18n/ru.json

This file was deleted.

83 changes: 0 additions & 83 deletions src/containers/AsideNavigation/useNavigationMenuItems.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/containers/Tenant/Diagnostics/Diagnostics.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
height: 100%;

&__header-wrapper {
padding: 13px 20px 16px;
padding: 0 20px 16px;

background-color: var(--g-color-base-background);
}
Expand Down
10 changes: 8 additions & 2 deletions src/containers/Tenant/ObjectGeneral/ObjectGeneral.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {cn} from '../../../utils/cn';
import {useTypedSelector} from '../../../utils/hooks';
import Diagnostics from '../Diagnostics/Diagnostics';
import {Query} from '../Query/Query';
import {TenantNavigation} from '../TenantNavigation/TenantNavigation';

import './ObjectGeneral.scss';

Expand All @@ -24,7 +25,7 @@ function ObjectGeneral(props: ObjectGeneralProps) {

const {tenantPage} = useTypedSelector((state) => state.tenant);

const renderTabContent = () => {
const renderPageContent = () => {
const {type, additionalTenantProps, additionalNodesProps, tenantName} = props;
switch (tenantPage) {
case TENANT_PAGES_IDS.query: {
Expand All @@ -47,7 +48,12 @@ function ObjectGeneral(props: ObjectGeneralProps) {
if (!tenantName) {
return null;
}
return <div className={b()}>{renderTabContent()}</div>;
return (
<div className={b()}>
<TenantNavigation />
{renderPageContent()}
</div>
);
};

return renderContent();
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Tenant/Query/Query.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@include flex-container();

&__tabs {
padding: 13px 20px 16px;
padding: 0 20px 16px;
}

&__content {
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Tenant/Query/i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"controls.query-mode-selector_type": "Query type:",

"tabs.newQuery": "Query",
"tabs.newQuery": "Editor",
"tabs.history": "History",
"tabs.saved": "Saved",

Expand Down
18 changes: 18 additions & 0 deletions src/containers/Tenant/TenantNavigation/TenantNavigation.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.ydb-tenant-navigation {
padding: 12px 16px 8px;

&__item {
display: flex;
align-items: center;
gap: 5px;
}

&__icon {
flex-shrink: 0;
}
&__text {
overflow: hidden;

text-overflow: ellipsis;
}
}
48 changes: 48 additions & 0 deletions src/containers/Tenant/TenantNavigation/TenantNavigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type {RadioButtonOption} from '@gravity-ui/uikit';
import {Icon, RadioButton} from '@gravity-ui/uikit';

import {cn} from '../../../utils/cn';

import {useTenantNavigation} from './useTenantNavigation';

import './TenantNavigation.scss';

const b = cn('ydb-tenant-navigation');

type MenuItem = ReturnType<typeof useTenantNavigation>[0];

const transformItemToOption = ({id, title, icon}: MenuItem): RadioButtonOption => {
const content = (
<span className={b('item')}>
<Icon data={icon} size={16} className={b('icon')} />
<span className={b('text')}>{title}</span>
</span>
);

return {value: id, content};
};

export const TenantNavigation = () => {
const navigationItems = useTenantNavigation();

const handleUpdate = (value: string) => {
const nextItem = navigationItems.find((item) => item.id === value);

nextItem?.onForward();
};

const getCurrentItem = () => navigationItems.find((item) => item.current) || navigationItems[0];

return (
<div className={b()}>
<RadioButton
width="auto"
onUpdate={handleUpdate}
size="l"
className={b('body')}
defaultValue={getCurrentItem().id}
options={navigationItems.map(transformItemToOption)}
/>
</div>
);
};
59 changes: 59 additions & 0 deletions src/containers/Tenant/TenantNavigation/useTenantNavigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';

import {Pulse, Terminal} from '@gravity-ui/icons';
import {useHistory, useLocation} from 'react-router';

import routes, {parseQuery} from '../../../routes';
import {TENANT_PAGE, TENANT_PAGES_IDS} from '../../../store/reducers/tenant/constants';
import {TENANT_INITIAL_PAGE_KEY} from '../../../utils/constants';
import {useSetting, useTypedSelector} from '../../../utils/hooks';
import {getTenantPath} from '../TenantPages';
import i18n from '../i18n';

type TenantPages = keyof typeof TENANT_PAGES_IDS;

const pagesList: Array<TenantPages> = ['query', 'diagnostics'];

const mapPageToIcon = {
query: Terminal,
diagnostics: Pulse,
};

export function useTenantNavigation() {
const history = useHistory();

const location = useLocation();
const queryParams = parseQuery(location);

const [, setInitialTenantPage] = useSetting<string>(TENANT_INITIAL_PAGE_KEY);
const {tenantPage} = useTypedSelector((state) => state.tenant);

const menuItems = React.useMemo(() => {
if (location.pathname !== routes.tenant) {
return [];
}

const items = pagesList.map((key) => {
const pageId = TENANT_PAGES_IDS[key];
const pagePath = getTenantPath({...queryParams, [TENANT_PAGE]: pageId});

const nextItem = {
id: pageId,
title: i18n(`pages.${key}`),
icon: mapPageToIcon[key],
path: pagePath,
current: tenantPage === pageId,
onForward: () => {
setInitialTenantPage(pageId);
history.push(pagePath);
},
};

return nextItem;
});

return items;
}, [tenantPage, setInitialTenantPage, location.pathname, history, queryParams]);

return menuItems;
}
3 changes: 3 additions & 0 deletions src/containers/Tenant/i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"page.title": "Database",

"pages.query": "Query",
"pages.diagnostics": "Diagnostics",

"acl.owner": "Owner",
"acl.empty": "No Acl data",

Expand Down