-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathsnapshotPage.tsx
99 lines (86 loc) · 2.74 KB
/
snapshotPage.tsx
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
// 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 {
api,
SnapshotPage,
SnapshotPageStateProps,
SortSetting,
} from "@cockroachlabs/cluster-ui";
import { connect } from "react-redux";
import { RouteComponentProps, withRouter } from "react-router-dom";
import { createSelector } from "reselect";
import {
CachedDataReducerState,
refreshSnapshot,
refreshSnapshots,
} from "src/redux/apiReducers";
import { LocalSetting } from "src/redux/localsettings";
import { AdminUIState } from "src/redux/state";
import { getMatchParamByName } from "src/util/query";
import { Pick } from "src/util/pick";
export const sortSetting = new LocalSetting<AdminUIState, SortSetting>(
"sortSetting/spans",
s => s.localSettings,
{ columnTitle: "creationTime", ascending: false },
);
type SnapshotState = Pick<AdminUIState, "cachedData", "snapshots">;
const selectSnapshotsState = (state: SnapshotState) => {
if (!state.cachedData.snapshots) {
return null;
}
return state.cachedData.snapshots;
};
const selectSnapshotState = createSelector(
[
(state: AdminUIState) => state.cachedData.snapshot,
(_state: AdminUIState, props: RouteComponentProps) => props,
],
(
snapshot,
props,
): CachedDataReducerState<api.GetTracingSnapshotResponseMessage> => {
const snapshotID = getMatchParamByName(props.match, "snapshotID");
if (!snapshot) {
return null;
}
return snapshot[snapshotID];
},
);
const mapStateToProps = (
state: AdminUIState,
props: RouteComponentProps,
): SnapshotPageStateProps => {
const sort = sortSetting.selector(state);
const snapshotsState = selectSnapshotsState(state);
const snapshots = snapshotsState ? snapshotsState.data : null;
const snapshotsLoading = snapshotsState ? snapshotsState.inFlight : false;
const snapshotsError = snapshotsState ? snapshotsState.lastError : null;
const snapshotState = selectSnapshotState(state, props);
const snapshot = snapshotState ? snapshotState.data : null;
const snapshotLoading = snapshotState ? snapshotState.inFlight : false;
const snapshotError = snapshotState ? snapshotState.lastError : null;
return {
sort,
snapshots,
snapshotsLoading,
snapshotsError,
snapshot,
snapshotLoading,
snapshotError,
};
};
const mapDispatchToProps = {
setSort: sortSetting.set,
refreshSnapshots,
refreshSnapshot,
};
export default withRouter(
connect(mapStateToProps, mapDispatchToProps)(SnapshotPage),
);