Skip to content

Commit 7195d0f

Browse files
committed
feat(Tenant): save initial tab preference
1 parent a329018 commit 7195d0f

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

src/containers/Tenant/ObjectGeneral/ObjectGeneral.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {connect} from 'react-redux';
12
import {Link} from 'react-router-dom';
23
import cn from 'bem-cn-lite';
34
import {useLocation} from 'react-router';
@@ -11,16 +12,18 @@ import Diagnostics from '../Diagnostics/Diagnostics';
1112

1213
import {TenantGeneralTabsIds, TenantTabsGroups, TENANT_GENERAL_TABS} from '../TenantPages';
1314
import routes, {createHref} from '../../../routes';
15+
import {setSettingValue} from '../../../store/reducers/settings';
16+
import {TENANT_INITIAL_TAB_KEY} from '../../../utils/constants';
1417

1518
import './ObjectGeneral.scss';
1619

1720
const b = cn('object-general');
1821

19-
interface ObjectGeneralProps {
22+
type ObjectGeneralProps = {
2023
type: string;
2124
additionalTenantInfo?: any;
2225
additionalNodesInfo?: any;
23-
}
26+
} & typeof mapDispatchToProps;
2427

2528
function ObjectGeneral(props: ObjectGeneralProps) {
2629
const location = useLocation();
@@ -63,6 +66,7 @@ function ObjectGeneral(props: ObjectGeneralProps) {
6366
);
6467
}}
6568
allowNotSelected
69+
onSelectTab={(id) => props.setSettingValue(TENANT_INITIAL_TAB_KEY, id)}
6670
/>
6771
</div>
6872
);
@@ -101,4 +105,8 @@ function ObjectGeneral(props: ObjectGeneralProps) {
101105
return renderContent();
102106
}
103107

104-
export default ObjectGeneral;
108+
const mapDispatchToProps = {
109+
setSettingValue,
110+
};
111+
112+
export default connect(null, mapDispatchToProps)(ObjectGeneral);

src/containers/Tenants/Tenants.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import routes, {CLUSTER_PAGES, createHref} from '../../routes';
1717
import {formatCPU, formatBytesToGigabyte} from '../../utils';
1818
import {hideTooltip, showTooltip} from '../../store/reducers/tooltip';
1919
import {withSearch} from '../../HOCS';
20-
import {ALL, DEFAULT_TABLE_SETTINGS} from '../../utils/constants';
20+
import {ALL, DEFAULT_TABLE_SETTINGS, TENANT_INITIAL_TAB_KEY} from '../../utils/constants';
2121
import {getTenantsInfo} from '../../store/reducers/tenants';
22-
import {changeFilter} from '../../store/reducers/settings';
22+
import {changeFilter, getSettingValue} from '../../store/reducers/settings';
2323
import {setHeader} from '../../store/reducers/header';
2424

2525
import {clusterName} from '../../store';
@@ -119,6 +119,7 @@ class Tenants extends React.Component {
119119
filter,
120120
handleSearchQuery,
121121
additionalTenantsInfo = {},
122+
savedTenantInitialTab,
122123
} = this.props;
123124

124125
const filteredTenantsBySearch = tenants.filter(
@@ -129,6 +130,9 @@ class Tenants extends React.Component {
129130
);
130131
const filteredTenants = Tenants.filterTenants(filteredTenantsBySearch, filter);
131132

133+
const initialTenantGeneralTab = savedTenantInitialTab || TENANT_GENERAL_TABS[0].id;
134+
const initialTenantInfoTab = TENANT_INFO_TABS[0].id;
135+
132136
const columns = [
133137
{
134138
name: 'Name',
@@ -150,8 +154,8 @@ class Tenants extends React.Component {
150154
path={createHref(routes.tenant, undefined, {
151155
name: value,
152156
backend: tenantBackend,
153-
[TenantTabsGroups.info]: TENANT_INFO_TABS[0].id,
154-
[TenantTabsGroups.general]: TENANT_GENERAL_TABS[0].id,
157+
[TenantTabsGroups.info]: initialTenantInfoTab,
158+
[TenantTabsGroups.general]: initialTenantGeneralTab,
155159
})}
156160
/>
157161
{additionalTenantsInfo.name && additionalTenantsInfo.name(value, row)}
@@ -347,6 +351,7 @@ const mapStateToProps = (state) => {
347351
loading,
348352
error,
349353
filter: state.settings.problemFilter,
354+
savedTenantInitialTab: getSettingValue(state, TENANT_INITIAL_TAB_KEY),
350355
};
351356
};
352357

src/store/reducers/settings.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ALL, defaultUserSettings, SAVED_QUERIES_KEY, THEME_KEY} from '../../utils/constants';
1+
import {ALL, defaultUserSettings, SAVED_QUERIES_KEY, THEME_KEY, TENANT_INITIAL_TAB_KEY} from '../../utils/constants';
22
import '../../services/api';
33
import {getValueFromLS} from '../../utils/utils';
44

@@ -13,6 +13,9 @@ const theme = window.web_version
1313
const savedQueries = window.web_version
1414
? userSettings[SAVED_QUERIES_KEY]
1515
: getValueFromLS(SAVED_QUERIES_KEY, '[]');
16+
const savedTenantGeneralTab = window.web_version
17+
? userSettings[TENANT_INITIAL_TAB_KEY]
18+
: getValueFromLS(TENANT_INITIAL_TAB_KEY);
1619

1720
export const initialState = {
1821
problemFilter: ALL,
@@ -21,6 +24,7 @@ export const initialState = {
2124
...userSettings,
2225
theme,
2326
[SAVED_QUERIES_KEY]: savedQueries,
27+
[TENANT_INITIAL_TAB_KEY]: savedTenantGeneralTab,
2428
},
2529
systemSettings,
2630
};

src/utils/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,5 @@ export const DEFAULT_TABLE_SETTINGS = {
137137
dynamicRender: true,
138138
highlightRows: true,
139139
};
140+
141+
export const TENANT_INITIAL_TAB_KEY = 'saved_tenant_initial_tab';

0 commit comments

Comments
 (0)