Skip to content

Commit 57031ab

Browse files
authored
fix(QueriesHistory): should save history to local storage (#8)
1 parent c329db2 commit 57031ab

File tree

7 files changed

+44
-13
lines changed

7 files changed

+44
-13
lines changed

src/containers/Tenant/Acl/Acl.scss

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
@import '../../../styles/mixins.scss';
22

33
.kv-acl {
4+
display: flex;
5+
overflow: auto;
6+
flex-grow: 1;
7+
48
padding: 0 12px 16px;
59
@include query-data-table;
610
&__message-container {
@@ -38,8 +42,4 @@
3842
color: var(--yc-color-text-danger);
3943
}
4044
}
41-
42-
&__result {
43-
overflow: auto;
44-
}
4545
}

src/containers/Tenant/ObjectSummary/ObjectSummary.scss

+10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
max-height: 100%;
1414

1515
&__overview-wrapper {
16+
display: flex;
1617
overflow: auto;
18+
flex-grow: 1;
1719

1820
padding: 0 12px 16px;
1921
}
@@ -91,7 +93,15 @@
9193
}
9294

9395
&__info {
96+
display: flex;
9497
overflow: hidden;
98+
flex-direction: column;
99+
}
100+
101+
&__schema {
102+
display: flex;
103+
overflow: auto;
104+
flex-grow: 1;
95105
}
96106

97107
&__info-controls {

src/containers/Tenant/ObjectSummary/ObjectSummary.tsx

+12-4
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ interface ObjectSummaryProps {
7878
onCollapseSummary: VoidFunction;
7979
onExpandSummary: VoidFunction;
8080
isCollapsed: boolean;
81-
additionalTenantInfo?: any
81+
additionalTenantInfo?: any;
8282
}
8383

8484
function ObjectSummary(props: ObjectSummaryProps) {
@@ -168,10 +168,16 @@ function ObjectSummary(props: ObjectSummaryProps) {
168168
const renderTabContent = () => {
169169
switch (infoTab) {
170170
case TenantInfoTabsIds.acl: {
171-
return <Acl additionalTenantInfo={props.additionalTenantInfo}/>;
171+
return <Acl additionalTenantInfo={props.additionalTenantInfo} />;
172172
}
173173
case TenantInfoTabsIds.schema: {
174-
return loadingSchema ? renderLoader() : <SchemaViewer data={schema} />;
174+
return loadingSchema ? (
175+
renderLoader()
176+
) : (
177+
<div className={b('schema')}>
178+
<SchemaViewer data={schema} />
179+
</div>
180+
);
175181
}
176182
default: {
177183
return renderObjectOverview();
@@ -194,7 +200,9 @@ function ObjectSummary(props: ObjectSummaryProps) {
194200
<div className={b('tree-title')}>Navigation</div>
195201
</div>
196202
<div className={b('tree')}>
197-
{tenantData && <SchemaNode fullPath={tenantName as string} data={tenantData} isRoot />}
203+
{tenantData && (
204+
<SchemaNode fullPath={tenantName as string} data={tenantData} isRoot />
205+
)}
198206
</div>
199207
</div>
200208
);

src/containers/Tenant/QueryEditor/QueriesHistory/QueriesHistory.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function QueriesHistory(props: QueriesHistoryProps) {
3838
};
3939

4040
const renderSavedQueries = () => {
41+
const reversedHistory = ([] as string[]).concat(history).reverse();
4142
return (
4243
<Popup
4344
className={b('popup-wrapper')}
@@ -47,7 +48,7 @@ function QueriesHistory(props: QueriesHistoryProps) {
4748
onClose={onCloseHistory}
4849
>
4950
<div className={b()}>
50-
{history.length === 0 ? (
51+
{reversedHistory.length === 0 ? (
5152
<div className={b('empty')}>History is empty</div>
5253
) : (
5354
<React.Fragment>
@@ -57,7 +58,7 @@ function QueriesHistory(props: QueriesHistoryProps) {
5758
</div>
5859
</div>
5960
<div>
60-
{history?.reverse().map((query, index) => {
61+
{reversedHistory.map((query, index) => {
6162
return (
6263
<div
6364
className={b('saved-queries-row')}

src/containers/Tenant/Schema/SchemaViewer/SchemaViewer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class SchemaViewer extends React.Component {
6767
theme="yandex-cloud"
6868
data={tableData}
6969
columns={columns}
70-
settings={{...DEFAULT_TABLE_SETTINGS, stickyTop: 107}}
70+
settings={DEFAULT_TABLE_SETTINGS}
7171
dynamicRender={true}
7272
initialSortOrder={{columnId: SchemaViewerColumns.key, order: DataTable.DESCENDING}}
7373
/>

src/store/reducers/executeQuery.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import {createRequestActionTypes, createApiRequest} from '../utils';
22
import '../../services/api';
3+
import {getValueFromLS, parseJson} from '../../utils/utils';
4+
import {QUERIES_HISTORY_KEY} from '../../utils/constants';
5+
6+
const MAXIMUM_QUERIES_IN_HISTORY = 20;
37

48
const SEND_QUERY = createRequestActionTypes('query', 'SEND_QUERY');
59
const CHANGE_USER_INPUT = 'query/CHANGE_USER_INPUT';
@@ -9,6 +13,10 @@ const GO_TO_NEXT_QUERY = 'query/GO_TO_NEXT_QUERY';
913
const SELECT_RUN_ACTION = 'query/SELECT_RUN_ACTION';
1014
const MONACO_HOT_KEY = 'query/MONACO_HOT_KEY';
1115

16+
const queriesHistoryInitial = parseJson(getValueFromLS(QUERIES_HISTORY_KEY, []));
17+
18+
const sliceLimit = queriesHistoryInitial.length - MAXIMUM_QUERIES_IN_HISTORY;
19+
1220
export const RUN_ACTIONS_VALUES = {
1321
script: 'execute-script',
1422
scan: 'execute-scan',
@@ -25,7 +33,7 @@ const initialState = {
2533
loading: false,
2634
input: '',
2735
history: {
28-
queries: [],
36+
queries: queriesHistoryInitial.slice(sliceLimit < 0 ? 0 : sliceLimit),
2937
currentIndex: -1,
3038
},
3139
runAction: RUN_ACTIONS_VALUES.script,
@@ -76,7 +84,10 @@ const executeQuery = (state = initialState, action) => {
7684

7785
case SAVE_QUERY_TO_HISTORY: {
7886
const query = action.data;
79-
const newQueries = [...state.history.queries, query];
87+
const newQueries = [...state.history.queries, query].slice(
88+
state.history.queries.length >= MAXIMUM_QUERIES_IN_HISTORY ? 1 : 0,
89+
);
90+
window.localStorage.setItem(QUERIES_HISTORY_KEY, JSON.stringify(newQueries));
8091
const currentIndex = newQueries.length - 1;
8192

8293
return {

src/utils/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export const PROBLEMS = 'With problems';
120120

121121
export const THEME_KEY = 'theme';
122122
export const SAVED_QUERIES_KEY = 'saved_queries';
123+
export const QUERIES_HISTORY_KEY = 'queries_history';
123124
export const DATA_QA_TUNE_COLUMNS_POPUP = 'tune-columns-popup';
124125

125126
export const defaultUserSettings = {

0 commit comments

Comments
 (0)