Skip to content

Commit 7117b96

Browse files
feat(Tenant): transform general tabs into left navigation items (#431)
1 parent 8a6c9ff commit 7117b96

File tree

22 files changed

+168
-216
lines changed

22 files changed

+168
-216
lines changed

src/containers/AsideNavigation/AsideNavigation.tsx

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import cn from 'bem-cn-lite';
77
import {Icon, Button} from '@gravity-ui/uikit';
88
import {AsideHeader, MenuItem as AsideHeaderMenuItem, FooterItem} from '@gravity-ui/navigation';
99

10+
import squareChartBarIcon from '@gravity-ui/icons/svgs/square-chart-bar.svg';
11+
import pulseIcon from '@gravity-ui/icons/svgs/pulse.svg';
12+
1013
import signOutIcon from '../../assets/icons/signOut.svg';
1114
import signInIcon from '../../assets/icons/signIn.svg';
1215
import ydbLogoIcon from '../../assets/icons/ydb.svg';
@@ -15,18 +18,20 @@ import userChecked from '../../assets/icons/user-check.svg';
1518
import settingsIcon from '../../assets/icons/settings.svg';
1619
import supportIcon from '../../assets/icons/support.svg';
1720

18-
import {UserSettings} from '../UserSettings/UserSettings';
19-
20-
import routes, {createHref} from '../../routes';
21-
2221
import {logout} from '../../store/reducers/authentication';
2322
import {getParsedSettingValue, setSettingValue} from '../../store/reducers/settings/settings';
23+
import {TENANT_PAGE, TENANT_PAGES_IDS} from '../../store/reducers/tenant/constants';
24+
import routes, {TENANT, createHref, parseQuery} from '../../routes';
25+
import {useSetting, useTypedSelector} from '../../utils/hooks';
26+
import {ASIDE_HEADER_COMPACT_KEY, TENANT_INITIAL_PAGE_KEY} from '../../utils/constants';
2427

25-
import {ASIDE_HEADER_COMPACT_KEY} from '../../utils/constants';
28+
import {getTenantPath} from '../Tenant/TenantPages';
29+
import {UserSettings} from '../UserSettings/UserSettings';
2630

2731
import './AsideNavigation.scss';
2832

2933
const b = cn('kv-navigation');
34+
3035
interface MenuItem {
3136
id: string;
3237
title: string;
@@ -111,9 +116,6 @@ interface AsideNavigationProps {
111116
setSettingValue: (name: string, value: string) => void;
112117
}
113118

114-
// FIXME: add items or delete
115-
const items: MenuItem[] = [];
116-
117119
enum Panel {
118120
UserSettings = 'UserSettings',
119121
}
@@ -124,32 +126,62 @@ function AsideNavigation(props: AsideNavigationProps) {
124126

125127
const [visiblePanel, setVisiblePanel] = useState<Panel>();
126128

129+
const [initialTenantPage, setInitialTenantPage] = useSetting<string>(TENANT_INITIAL_PAGE_KEY);
130+
const {tenantPage = initialTenantPage} = useTypedSelector((state) => state.tenant);
131+
127132
const setIsCompact = (compact: boolean) => {
128133
props.setSettingValue(ASIDE_HEADER_COMPACT_KEY, JSON.stringify(compact));
129134
};
130135

136+
const {pathname} = location;
137+
const queryParams = parseQuery(location);
138+
139+
const isTenantPage = pathname === `/${TENANT}`;
140+
131141
const menuItems: AsideHeaderMenuItem[] = React.useMemo(() => {
132-
const {pathname} = location;
133-
const menuItems: AsideHeaderMenuItem[] = items.map((item) => {
134-
const locationKeysCoincidence = item.locationKeys?.filter((key) =>
135-
pathname.startsWith(key),
136-
);
137-
const current =
138-
(locationKeysCoincidence && locationKeysCoincidence.length > 0) ||
139-
item.location.startsWith(pathname);
142+
if (!isTenantPage) {
143+
return [];
144+
}
145+
146+
const items: MenuItem[] = [
147+
{
148+
id: TENANT_PAGES_IDS.diagnostics,
149+
title: 'Diagnostics',
150+
icon: squareChartBarIcon,
151+
iconSize: 20,
152+
location: getTenantPath({
153+
...queryParams,
154+
[TENANT_PAGE]: TENANT_PAGES_IDS.diagnostics,
155+
}),
156+
},
157+
{
158+
id: TENANT_PAGES_IDS.query,
159+
title: 'Query',
160+
icon: pulseIcon,
161+
iconSize: 20,
162+
location: getTenantPath({
163+
...queryParams,
164+
[TENANT_PAGE]: TENANT_PAGES_IDS.query,
165+
}),
166+
},
167+
];
168+
169+
return items.map((item) => {
170+
const current = item.id === tenantPage;
171+
140172
return {
141173
id: item.id,
142174
title: item.title,
143175
icon: item.icon,
144176
iconSize: item.iconSize,
145177
current,
146178
onItemClick: () => {
179+
setInitialTenantPage(item.id);
147180
history.push(item.location);
148181
},
149182
};
150183
});
151-
return menuItems;
152-
}, [location, history]);
184+
}, [tenantPage, isTenantPage, setInitialTenantPage, history, queryParams]);
153185

154186
return (
155187
<React.Fragment>

src/containers/Tenant/Diagnostics/Diagnostics.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import type {EPathType} from '../../../types/api/schema';
1111

1212
import {useTypedSelector} from '../../../utils/hooks';
1313
import routes, {createHref} from '../../../routes';
14-
import type {TenantDiagnosticsTab, TenantGeneralTab} from '../../../store/reducers/tenant/types';
14+
import type {TenantDiagnosticsTab} from '../../../store/reducers/tenant/types';
1515
import {enableAutorefresh, disableAutorefresh} from '../../../store/reducers/schema/schema';
16-
import {setTopLevelTab, setDiagnosticsTab} from '../../../store/reducers/tenant/tenant';
16+
import { setDiagnosticsTab} from '../../../store/reducers/tenant/tenant';
1717
import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../store/reducers/tenant/constants';
1818

1919
import {Loader} from '../../../components/Loader';
@@ -96,10 +96,6 @@ function Diagnostics(props: DiagnosticsProps) {
9696
}
9797
};
9898

99-
const forwardToGeneralTab = (tab: TenantGeneralTab) => {
100-
dispatch(setTopLevelTab(tab));
101-
};
102-
10399
const renderTabContent = () => {
104100
const {type} = props;
105101

@@ -116,13 +112,7 @@ function Diagnostics(props: DiagnosticsProps) {
116112
);
117113
}
118114
case TENANT_DIAGNOSTICS_TABS_IDS.topQueries: {
119-
return (
120-
<TopQueries
121-
path={tenantNameString}
122-
changeSchemaTab={forwardToGeneralTab}
123-
type={type}
124-
/>
125-
);
115+
return <TopQueries path={tenantNameString} type={type} />;
126116
}
127117
case TENANT_DIAGNOSTICS_TABS_IDS.topShards: {
128118
return <TopShards tenantPath={tenantNameString} type={type} />;

src/containers/Tenant/Diagnostics/TopQueries/TopQueries.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ import type {KeyValueRow} from '../../../../types/api/query';
2222
import type {EPathType} from '../../../../types/api/schema';
2323
import type {ITopQueriesFilters} from '../../../../types/store/executeTopQueries';
2424
import type {IQueryResult} from '../../../../types/store/query';
25-
import type {TenantGeneralTab} from '../../../../store/reducers/tenant/types';
2625

27-
import {
28-
TENANT_GENERAL_TABS_IDS,
29-
TENANT_QUERY_TABS_ID,
30-
} from '../../../../store/reducers/tenant/constants';
26+
import {TENANT_PAGE, TENANT_PAGES_IDS, TENANT_QUERY_TABS_ID} from '../../../../store/reducers/tenant/constants';
3127
import {formatDateTime, formatNumber} from '../../../../utils';
3228
import {HOUR_IN_SECONDS} from '../../../../utils/constants';
3329
import {useAutofetcher, useTypedSelector} from '../../../../utils/hooks';
@@ -85,7 +81,6 @@ const COLUMNS: Column<KeyValueRow>[] = [
8581

8682
interface TopQueriesProps {
8783
path: string;
88-
changeSchemaTab: (tab: TenantGeneralTab) => void;
8984
type?: EPathType;
9085
}
9186

@@ -177,7 +172,7 @@ export const TopQueries = ({path, type}: TopQueriesProps) => {
177172

178173
const queryPath = getTenantPath({
179174
...queryParams,
180-
[TenantTabsGroups.general]: TENANT_GENERAL_TABS_IDS.query,
175+
[TENANT_PAGE]: TENANT_PAGES_IDS.query,
181176
[TenantTabsGroups.queryTab]: TENANT_QUERY_TABS_ID.newQuery,
182177
});
183178

src/containers/Tenant/ObjectGeneral/ObjectGeneral.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import qs from 'qs';
21
import {useLocation} from 'react-router';
32
import cn from 'bem-cn-lite';
43

54
import {useThemeValue} from '@gravity-ui/uikit';
65

76
import type {EPathType} from '../../../types/api/schema';
8-
import {TENANT_GENERAL_TABS_IDS} from '../../../store/reducers/tenant/constants';
7+
import {TENANT_PAGES_IDS} from '../../../store/reducers/tenant/constants';
8+
import {useSetting} from '../../../utils/hooks';
9+
import {TENANT_INITIAL_PAGE_KEY} from '../../../utils/constants';
10+
import {parseQuery} from '../../../routes';
911

1012
import {Query} from '../Query/Query';
1113
import Diagnostics from '../Diagnostics/Diagnostics';
@@ -22,19 +24,17 @@ interface ObjectGeneralProps {
2224

2325
function ObjectGeneral(props: ObjectGeneralProps) {
2426
const location = useLocation();
25-
2627
const theme = useThemeValue();
2728

28-
const queryParams = qs.parse(location.search, {
29-
ignoreQueryPrefix: true,
30-
});
29+
const [initialPage] = useSetting<string>(TENANT_INITIAL_PAGE_KEY);
3130

32-
const {name: tenantName, general: generalTab} = queryParams;
31+
const queryParams = parseQuery(location);
32+
const {name: tenantName, tenantPage = initialPage} = queryParams;
3333

3434
const renderTabContent = () => {
3535
const {type, additionalTenantInfo, additionalNodesInfo} = props;
36-
switch (generalTab) {
37-
case TENANT_GENERAL_TABS_IDS.query: {
36+
switch (tenantPage) {
37+
case TENANT_PAGES_IDS.query: {
3838
return <Query path={tenantName as string} theme={theme} type={type} />;
3939
}
4040
default: {

src/containers/Tenant/ObjectGeneralTabs/ObjectGeneralTabs.scss

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/containers/Tenant/ObjectGeneralTabs/ObjectGeneralTabs.tsx

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/containers/Tenant/ObjectSummary/ObjectSummary.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ import {
4747
PaneVisibilityToggleButtons,
4848
} from '../utils/paneVisibilityToggleHelpers';
4949
import {setShowPreview} from '../../../store/reducers/schema/schema';
50-
import {setQueryTab, setTopLevelTab} from '../../../store/reducers/tenant/tenant';
50+
import {setQueryTab, setTenantPage} from '../../../store/reducers/tenant/tenant';
5151
import {
52-
TENANT_GENERAL_TABS_IDS,
52+
TENANT_PAGES_IDS,
5353
TENANT_QUERY_TABS_ID,
5454
} from '../../../store/reducers/tenant/constants';
5555

@@ -278,7 +278,7 @@ function ObjectSummary(props: ObjectSummaryProps) {
278278

279279
const onOpenPreview = () => {
280280
dispatch(setShowPreview(true));
281-
dispatch(setTopLevelTab(TENANT_GENERAL_TABS_IDS.query));
281+
dispatch(setTenantPage(TENANT_PAGES_IDS.query));
282282
dispatch(setQueryTab(TENANT_QUERY_TABS_ID.newQuery));
283283
};
284284

src/containers/Tenant/Query/QueryEditor/QueryEditor.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
goToNextQuery,
1616
MONACO_HOT_KEY_ACTIONS,
1717
setMonacoHotKey,
18+
setTenantPath,
1819
} from '../../../../store/reducers/executeQuery';
1920
import {getExplainQuery, getExplainQueryAst} from '../../../../store/reducers/explainQuery';
2021
import {getParsedSettingValue, setSettingValue} from '../../../../store/reducers/settings/settings';
@@ -75,6 +76,7 @@ const propTypes = {
7576
theme: PropTypes.string,
7677
type: PropTypes.string,
7778
initialQueryMode: PropTypes.string,
79+
setTenantPath: PropTypes.func,
7880
};
7981

8082
const initialTenantCommonInfoState = {
@@ -83,6 +85,9 @@ const initialTenantCommonInfoState = {
8385
collapsed: true,
8486
};
8587
function QueryEditor(props) {
88+
const {path, executeQuery, theme, setTenantPath, changeUserInput} = props;
89+
const {tenantPath: savedPath} = executeQuery;
90+
8691
const [resultType, setResultType] = useState(RESULT_TYPES.EXECUTE);
8792

8893
const [isResultLoaded, setIsResultLoaded] = useState(false);
@@ -96,6 +101,13 @@ function QueryEditor(props) {
96101
}
97102
}, [enableAdditionalQueryModes, queryMode, setQueryMode]);
98103

104+
useEffect(() => {
105+
if (savedPath !== path) {
106+
setTenantPath(path);
107+
changeUserInput({input: ''});
108+
}
109+
}, [changeUserInput, setTenantPath, path, savedPath]);
110+
99111
const [resultVisibilityState, dispatchResultVisibilityState] = useReducer(
100112
paneVisibilityToggleReducerCreator(DEFAULT_IS_QUERY_RESULT_COLLAPSED),
101113
initialTenantCommonInfoState,
@@ -507,7 +519,6 @@ function QueryEditor(props) {
507519
);
508520
};
509521

510-
const {executeQuery, theme} = props;
511522
const result = renderResult();
512523

513524
return (
@@ -569,6 +580,7 @@ const mapDispatchToProps = {
569580
setSettingValue,
570581
setShowPreview,
571582
setMonacoHotKey,
583+
setTenantPath,
572584
};
573585

574586
QueryEditor.propTypes = propTypes;

src/containers/Tenant/Tenant.scss

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,4 @@
66
font-size: var(--yc-text-body-2-font-size);
77
line-height: var(--yc-text-body-2-line-height);
88
@include flex-container();
9-
10-
.yc-tabs {
11-
overflow: initial;
12-
}
13-
14-
&__tab-content {
15-
height: calc(100% - 56px); // general tabs height
16-
}
179
}

0 commit comments

Comments
 (0)