Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
98189: ui: add check for adminUI r=maryliag a=maryliag

If is the first time the user opens the console,
the `adminUI` might not yet be created, so we need to add a check to all its usages so the page doesn't crash.

Epic: None

Release note: None

Co-authored-by: maryliag <[email protected]>
  • Loading branch information
craig[bot] and maryliag committed Mar 8, 2023
2 parents 0b02d6f + bb340bc commit 1b162d1
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const selectIndexDetails = createSelector(
getMatchParamByName(props.match, tableNameAttr),
(_state: AppState, props: RouteComponentProps): string =>
getMatchParamByName(props.match, indexNameAttr),
(state: AppState) => state.adminUI.indexStats.cachedData,
(state: AppState) => state.adminUI?.indexStats.cachedData,
(state: AppState) => selectIsTenant(state),
(state: AppState) => selectHasViewActivityRedactedRole(state),
(state: AppState) => nodeRegionsByIDSelector(state),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ const statementMapStateToProps = (
state: AppState,
_props: RouteComponentProps,
): StatementInsightsViewStateProps => ({
isDataValid: state.adminUI.stmtInsights?.valid,
lastUpdated: state.adminUI.stmtInsights.lastUpdated,
isDataValid: state.adminUI?.stmtInsights?.valid,
lastUpdated: state.adminUI?.stmtInsights.lastUpdated,
statements: selectStmtInsights(state),
statementsError: selectStmtInsightsError(state),
insightTypes: selectInsightTypes(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import {
// pages that are specific to cluster-ui.
// They should NOT be exported with the cluster-ui package.

const selectSessions = (state: AppState) => state.adminUI.sessions?.data;
const selectSessions = (state: AppState) => state.adminUI?.sessions?.data;

const selectClusterLocks = (state: AppState) =>
state.adminUI.clusterLocks?.data?.results;
state.adminUI?.clusterLocks?.data?.results;

export const selectClusterLocksMaxApiSizeReached = (state: AppState) =>
!!state.adminUI.clusterLocks?.data?.maxSizeReached;
!!state.adminUI?.clusterLocks?.data?.maxSizeReached;

export const selectRecentExecutions = createSelector(
selectSessions,
Expand Down Expand Up @@ -94,7 +94,7 @@ export const selectContentionDetailsForStatement = createSelector(
);

export const selectAppName = createSelector(
(state: AppState) => state.adminUI.sessions,
(state: AppState) => state.adminUI?.sessions,
response => {
if (!response.data) return null;
return response.data.internal_app_name_prefix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const SessionDetailsPageConnected = withRouter(
? {}
: nodeDisplayNameByIDSelector(state),
session: selectSession(state, props),
sessionError: state.adminUI.sessions.lastError,
sessionError: state.adminUI?.sessions.lastError,
uiConfig: selectSessionDetailsUiConfig(state),
isTenant: selectIsTenant(state),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const selectSessionsData = createSelector(
);

export const selectSessions = createSelector(
(state: AppState) => state.adminUI.sessions,
(state: AppState) => state.adminUI?.sessions,
(state: SessionsState) => {
if (!state.data) {
return null;
Expand All @@ -46,7 +46,7 @@ export const selectSessions = createSelector(
);

export const selectAppName = createSelector(
(state: AppState) => state.adminUI.sessions,
(state: AppState) => state.adminUI?.sessions,
(state: SessionsState) => {
if (!state.data) {
return null;
Expand All @@ -56,7 +56,7 @@ export const selectAppName = createSelector(
);

export const selectSortSetting = createSelector(
(state: AppState) => state.adminUI.localStorage,
(state: AppState) => state.adminUI?.localStorage,
localStorage => localStorage["sortSetting/SessionsPage"],
);

Expand All @@ -78,7 +78,7 @@ export const SessionsPageConnected = withRouter(
(state: AppState, props: RouteComponentProps) => ({
sessions: selectSessions(state),
internalAppNamePrefix: selectAppName(state),
sessionsError: state.adminUI.sessions.lastError,
sessionsError: state.adminUI?.sessions.lastError,
sortSetting: selectSortSetting(state),
columns: selectColumns(state),
filters: selectFilters(state),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const selectStatementDetails = createSelector(
(_state: AppState, props: RouteComponentProps): string =>
queryByName(props.location, appNamesAttr),
(state: AppState): TimeScale => selectTimeScale(state),
(state: AppState) => state.adminUI.sqlDetailsStats.cachedData,
(state: AppState) => state.adminUI?.sqlDetailsStats.cachedData,
(
fingerprintID,
appNames,
Expand Down Expand Up @@ -75,6 +75,6 @@ export const selectStatementDetails = createSelector(
);

export const selectStatementDetailsUiConfig = createSelector(
(state: AppState) => state.adminUI.uiConfig.pages.statementDetails,
(state: AppState) => state.adminUI?.uiConfig.pages.statementDetails,
statementDetailsUiConfig => statementDetailsUiConfig,
);
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const mapStateToRecentStatementsPageProps = (
state: AppState,
): RecentStatementsViewStateProps => ({
statements: selectRecentStatements(state),
sessionsError: state.adminUI.sessions.lastError,
sessionsError: state.adminUI?.sessions.lastError,
selectedColumns: selectColumns(state),
sortSetting: selectSortSetting(state),
filters: selectFilters(state),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { TxnInsightEvent } from "src/insights";
import { selectStmtInsights } from "src/store/insights/statementInsights";

const selectTxnContentionInsightsDetails = createSelector(
(state: AppState) => state.adminUI.txnInsightDetails.cachedData,
(state: AppState) => state.adminUI?.txnInsightDetails.cachedData,
selectID,
(cachedTxnInsightDetails, execId) => {
return cachedTxnInsightDetails[execId];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import { selectStatementFingerprintID, selectID } from "src/selectors/common";
import { InsightEnumToLabel, StmtInsightEvent } from "src/insights";

export const selectStmtInsights = (state: AppState): StmtInsightEvent[] =>
state.adminUI.stmtInsights?.data?.results;
state.adminUI?.stmtInsights?.data?.results;

export const selectStmtInsightsError = (state: AppState): Error | null =>
state.adminUI.stmtInsights?.lastError;
state.adminUI?.stmtInsights?.lastError;

export const selectStmtInsightsMaxApiReached = (state: AppState): boolean =>
!!state.adminUI.stmtInsights?.data?.maxSizeReached;
!!state.adminUI?.stmtInsights?.data?.maxSizeReached;

export const selectStmtInsightDetails = createSelector(
selectStmtInsights,
Expand All @@ -53,8 +53,8 @@ export const selectColumns = createSelector(
// Show the data as 'Loading' when the request is in flight AND the
// data is invalid or null.
export const selectStmtInsightsLoading = (state: AppState): boolean =>
state.adminUI.stmtInsights?.inFlight &&
(!state.adminUI.stmtInsights?.valid || !state.adminUI.stmtInsights?.data);
state.adminUI?.stmtInsights?.inFlight &&
(!state.adminUI?.stmtInsights?.valid || !state.adminUI?.stmtInsights?.data);

export const selectInsightsByFingerprint = createSelector(
selectStmtInsights,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { createSelector } from "@reduxjs/toolkit";
import { AppState } from "../reducers";

const livenessesSelector = (state: AppState) => state.adminUI.liveness.data;
const livenessesSelector = (state: AppState) => state.adminUI?.liveness.data;

export const livenessStatusByNodeIDSelector = createSelector(
livenessesSelector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { cockroach } from "@cockroachlabs/crdb-protobuf-client";
type ILocality = cockroach.roachpb.ILocality;

export const nodeStatusesSelector = (state: AppState) =>
state.adminUI.nodes.data || [];
state.adminUI?.nodes.data || [];

export const nodesSelector = createSelector(
nodeStatusesSelector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { getMatchParamByName } from "src/util/query";
import { byteArrayToUuid } from "src/sessions/sessionsTable";

export const selectSession = createSelector(
(state: AppState) => state.adminUI.sessions,
(state: AppState) => state.adminUI?.sessions,
(_state: AppState, props: RouteComponentProps) => props,
(state: SessionsState, props: RouteComponentProps<any>) => {
if (!state.data) {
Expand All @@ -33,6 +33,6 @@ export const selectSession = createSelector(
);

export const selectSessionDetailsUiConfig = createSelector(
(state: AppState) => state.adminUI.uiConfig.pages.sessionDetails,
(state: AppState) => state.adminUI?.uiConfig.pages.sessionDetails,
statementDetailsUiConfig => statementDetailsUiConfig,
);
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createSelector } from "reselect";
import { AppState } from "../reducers";

export const selectUIConfig = createSelector(
(state: AppState) => state.adminUI.uiConfig,
(state: AppState) => state.adminUI?.uiConfig,
uiConfig => uiConfig,
);

Expand Down
2 changes: 1 addition & 1 deletion pkg/ui/workspaces/cluster-ui/src/store/utils/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const adminUISelector = createSelector(

export const localStorageSelector = createSelector(
adminUISelector,
adminUiState => adminUiState.localStorage,
adminUiState => adminUiState?.localStorage,
);

export const selectTimeScale = createSelector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const mapStateToRecentTransactionsPageProps = (
state: AppState,
): RecentTransactionsViewStateProps => ({
transactions: selectRecentTransactions(state),
sessionsError: state.adminUI.sessions.lastError,
sessionsError: state.adminUI?.sessions.lastError,
selectedColumns: selectColumns(state),
sortSetting: selectSortSetting(state),
filters: selectFilters(state),
Expand Down

0 comments on commit 1b162d1

Please sign in to comment.