-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathtransactionDetails.tsx
109 lines (105 loc) · 3.54 KB
/
transactionDetails.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
100
101
102
103
104
105
106
107
108
109
// Copyright 2021 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 { connect } from "react-redux";
import { createSelector } from "reselect";
import { RouteComponentProps, withRouter } from "react-router-dom";
import {
refreshNodes,
refreshTxns,
refreshTxnInsights,
refreshUserSQLRoles,
} from "src/redux/apiReducers";
import { AdminUIState } from "src/redux/state";
import { txnFingerprintIdAttr } from "src/util/constants";
import { getMatchParamByName } from "src/util/query";
import { nodeRegionsByIDSelector } from "src/redux/nodes";
import {
reqSortSetting,
selectData,
selectLastError,
} from "src/views/transactions/transactionsPage";
import {
TransactionDetailsStateProps,
TransactionDetailsDispatchProps,
TransactionDetailsProps,
TransactionDetails,
} from "@cockroachlabs/cluster-ui";
import { setGlobalTimeScaleAction } from "src/redux/statements";
import { selectTimeScale } from "src/redux/timeScale";
import { selectTxnInsightsByFingerprint } from "src/views/insights/insightsSelectors";
import { selectHasAdminRole } from "src/redux/user";
import { limitSetting } from "./transactionsPage";
export const selectTransaction = createSelector(
(state: AdminUIState) => state.cachedData.transactions,
(_state: AdminUIState, props: RouteComponentProps) => props,
(transactionState, props) => {
const transactions = transactionState.data?.transactions;
if (!transactions) {
return {
isLoading: transactionState.inFlight,
transaction: null,
lastUpdated: null,
isValid: transactionState.valid,
};
}
const txnFingerprintId = getMatchParamByName(
props.match,
txnFingerprintIdAttr,
);
const transaction = transactions.filter(
txn =>
txn.stats_data.transaction_fingerprint_id.toString() ==
txnFingerprintId,
)[0];
return {
isLoading: transactionState.inFlight,
transaction: transaction,
lastUpdated: transactionState?.setAt?.utc(),
isValid: transactionState.valid,
};
},
);
export default withRouter(
connect<TransactionDetailsStateProps, TransactionDetailsDispatchProps>(
(
state: AdminUIState,
props: TransactionDetailsProps,
): TransactionDetailsStateProps => {
const { isLoading, transaction, lastUpdated, isValid } =
selectTransaction(state, props);
return {
timeScale: selectTimeScale(state),
error: selectLastError(state),
isTenant: false,
nodeRegions: nodeRegionsByIDSelector(state),
statements: selectData(state)?.statements,
transaction: transaction,
transactionFingerprintId: getMatchParamByName(
props.match,
txnFingerprintIdAttr,
),
isLoading: isLoading,
lastUpdated: lastUpdated,
transactionInsights: selectTxnInsightsByFingerprint(state, props),
hasAdminRole: selectHasAdminRole(state),
isDataValid: isValid,
limit: limitSetting.selector(state),
reqSortSetting: reqSortSetting.selector(state),
};
},
{
refreshData: refreshTxns,
refreshNodes,
refreshUserSQLRoles,
onTimeScaleChange: setGlobalTimeScaleAction,
refreshTransactionInsights: refreshTxnInsights,
},
)(TransactionDetails),
);