-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
activeStatementsPage.selectors.ts
112 lines (103 loc) · 3.42 KB
/
activeStatementsPage.selectors.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2022 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
import { Dispatch } from "redux";
import { createSelector } from "reselect";
import {
ActiveStatementFilters,
ActiveStatementsViewDispatchProps,
ActiveStatementsViewStateProps,
AppState,
SortSetting,
} from "src";
import {
selectActiveStatements,
selectAppName,
selectExecutionStatus,
selectClusterLocksMaxApiSizeReached,
} from "src/selectors/activeExecutions.selectors";
import { actions as localStorageActions } from "src/store/localStorage";
import { actions as sessionsActions } from "src/store/sessions";
import { selectIsTenant } from "src/store/uiConfig";
import { localStorageSelector } from "../store/utils/selectors";
export const selectSortSetting = (state: AppState): SortSetting =>
localStorageSelector(state)["sortSetting/ActiveStatementsPage"];
export const selectFilters = (state: AppState): ActiveStatementFilters =>
localStorageSelector(state)["filters/ActiveStatementsPage"];
export const selectIsAutoRefreshEnabled = (state: AppState): boolean => {
return localStorageSelector(state)["isAutoRefreshEnabled/ActiveExecutions"];
};
const selectLocalStorageColumns = (state: AppState) => {
const localStorage = localStorageSelector(state);
return localStorage["showColumns/ActiveStatementsPage"];
};
export const selectColumns = createSelector(
selectLocalStorageColumns,
value => {
if (value == null) return null;
return value.split(",").map(col => col.trim());
},
);
export const mapStateToActiveStatementsPageProps = (
state: AppState,
): ActiveStatementsViewStateProps => ({
statements: selectActiveStatements(state),
sessionsError: state.adminUI?.sessions.lastError,
selectedColumns: selectColumns(state),
sortSetting: selectSortSetting(state),
filters: selectFilters(state),
executionStatus: selectExecutionStatus(),
internalAppNamePrefix: selectAppName(state),
isTenant: selectIsTenant(state),
maxSizeApiReached: selectClusterLocksMaxApiSizeReached(state),
isAutoRefreshEnabled: selectIsAutoRefreshEnabled(state),
});
export const mapDispatchToActiveStatementsPageProps = (
dispatch: Dispatch,
): ActiveStatementsViewDispatchProps => ({
refreshLiveWorkload: () => dispatch(sessionsActions.refresh()),
onColumnsSelect: columns => {
dispatch(
localStorageActions.update({
key: "showColumns/ActiveStatementsPage",
value: columns.join(","),
}),
);
},
onFiltersChange: (filters: ActiveStatementFilters) =>
dispatch(
localStorageActions.update({
key: "filters/ActiveStatementsPage",
value: filters,
}),
),
onSortChange: (ss: SortSetting) =>
dispatch(
localStorageActions.update({
key: "sortSetting/ActiveStatementsPage",
value: ss,
}),
),
onAutoRefreshToggle: (isEnabled: boolean) => {
dispatch(
localStorageActions.update({
key: "isAutoRefreshEnabled/ActiveExecutions",
value: isEnabled,
}),
);
},
onTimestampChange(ts: string) {
dispatch(
localStorageActions.update({
key: "lastTimestampRefresh/ActiveExecutions",
value: ts,
}),
);
},
});