Skip to content

Commit

Permalink
ui: remove option 10/30 min from SQL Activity page
Browse files Browse the repository at this point in the history
Previously we had the options for 10 and 30min on
SQL Activity pages, which created some confusion, since
we would always show the last 1h info.
This commit remove those 2 options.
If the user select any of those options on the Metrics
page, it will get updated to 1h on the SQL Activity
pages.

Fixes cockroachdb#82914

Release note (ui change): Removal of the 10 and 30min options
on the SQL Activity page.
  • Loading branch information
maryliag committed Jun 22, 2022
1 parent 80a728b commit 5fb02f5
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ import { UIConfigState } from "../store";
import moment from "moment";
import { StatementDetailsRequest } from "src/api/statementsApi";
import {
getValidOption,
TimeScale,
timeScale1hMinOptions,
TimeScaleDropdown,
toRoundedDateRange,
} from "../timeScaleDropdown";
Expand Down Expand Up @@ -320,6 +322,14 @@ export class StatementDetails extends React.Component<
currentTab: searchParams.get("tab") || "overview",
};
this.activateDiagnosticsRef = React.createRef();

// In case the user selected a option not available on this page,
// force a selection of a valid option. This is necessary for the case
// where the value 10/30 min is selected on the Metrics page.
const ts = getValidOption(this.props.timeScale, timeScale1hMinOptions);
if (ts !== this.props.timeScale) {
this.props.onTimeScaleChange(ts);
}
}

static defaultProps: Partial<StatementDetailsProps> = {
Expand Down Expand Up @@ -542,6 +552,7 @@ export class StatementDetails extends React.Component<
<PageConfig>
<PageConfigItem>
<TimeScaleDropdown
options={timeScale1hMinOptions}
currentScale={this.props.timeScale}
setTimeScale={this.props.onTimeScaleChange}
/>
Expand Down Expand Up @@ -667,6 +678,7 @@ export class StatementDetails extends React.Component<
<PageConfig>
<PageConfigItem>
<TimeScaleDropdown
options={timeScale1hMinOptions}
currentScale={this.props.timeScale}
setTimeScale={this.props.onTimeScaleChange}
/>
Expand Down Expand Up @@ -805,6 +817,7 @@ export class StatementDetails extends React.Component<
<PageConfig>
<PageConfigItem>
<TimeScaleDropdown
options={timeScale1hMinOptions}
currentScale={this.props.timeScale}
setTimeScale={this.props.onTimeScaleChange}
/>
Expand Down
11 changes: 11 additions & 0 deletions pkg/ui/workspaces/cluster-ui/src/statementsPage/statementsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ import {
TimeScaleDropdown,
TimeScale,
toDateRange,
timeScale1hMinOptions,
getValidOption,
} from "../timeScaleDropdown";

import { commonStyles } from "../common";
Expand Down Expand Up @@ -192,6 +194,14 @@ export class StatementsPage extends React.Component<
const stateFromHistory = this.getStateFromHistory();
this.state = merge(defaultState, stateFromHistory);
this.activateDiagnosticsRef = React.createRef();

// In case the user selected a option not available on this page,
// force a selection of a valid option. This is necessary for the case
// where the value 10/30 min is selected on the Metrics page.
const ts = getValidOption(this.props.timeScale, timeScale1hMinOptions);
if (ts !== this.props.timeScale) {
this.changeTimeScale(ts);
}
}

static defaultProps: Partial<StatementsPageProps> = {
Expand Down Expand Up @@ -658,6 +668,7 @@ export class StatementsPage extends React.Component<
</PageConfigItem>
<PageConfigItem className={commonStyles("separator")}>
<TimeScaleDropdown
options={timeScale1hMinOptions}
currentScale={this.props.timeScale}
setTimeScale={this.changeTimeScale}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import React, { useMemo } from "react";
import moment from "moment";
import classNames from "classnames/bind";
import {
TimeScale,
TimeWindow,
ArrowDirection,
TimeScale,
TimeScaleOptions,
TimeWindow,
} from "./timeScaleTypes";
import TimeFrameControls from "./timeFrameControls";
import RangeSelect, {
Expand Down Expand Up @@ -263,3 +263,20 @@ export const TimeScaleDropdown: React.FC<TimeScaleDropdownProps> = ({
</div>
);
};

// getValidOption check if the option selected is valid. If is valid returns
// the selected option, otherwise returns the first valid option.
export const getValidOption = (
currentScale: TimeScale,
options: TimeScaleOptions,
): TimeScale => {
if (!(currentScale.key in options)) {
const firstValidKey = Object.keys(options)[0];
return {
...options[firstValidKey],
key: firstValidKey,
fixedWindowEnd: false,
};
}
return currentScale;
};
32 changes: 20 additions & 12 deletions pkg/ui/workspaces/cluster-ui/src/timeScaleDropdown/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,10 @@ import moment from "moment";
import { TimeScale, TimeScaleOption, TimeScaleOptions } from "./timeScaleTypes";

/**
* defaultTimeScaleOptions is a preconfigured set of time scales that can be
* timeScale1hMinOptions is a preconfigured set of time scales with 1h minimum that can be
* selected by the user.
*/
export const defaultTimeScaleOptions: TimeScaleOptions = {
"Past 10 Minutes": {
windowSize: moment.duration(10, "minutes"),
windowValid: moment.duration(10, "seconds"),
sampleSize: moment.duration(10, "seconds"),
},
"Past 30 Minutes": {
windowSize: moment.duration(30, "minutes"),
windowValid: moment.duration(30, "seconds"),
sampleSize: moment.duration(30, "seconds"),
},
export const timeScale1hMinOptions: TimeScaleOptions = {
"Past 1 Hour": {
windowSize: moment.duration(1, "hour"),
windowValid: moment.duration(1, "minute"),
Expand Down Expand Up @@ -73,6 +63,24 @@ export const defaultTimeScaleOptions: TimeScaleOptions = {
},
};

/**
* defaultTimeScaleOptions is a preconfigured set of time scales that can be
* selected by the user.
*/
export const defaultTimeScaleOptions: TimeScaleOptions = {
"Past 10 Minutes": {
windowSize: moment.duration(10, "minutes"),
windowValid: moment.duration(10, "seconds"),
sampleSize: moment.duration(10, "seconds"),
},
"Past 30 Minutes": {
windowSize: moment.duration(30, "minutes"),
windowValid: moment.duration(30, "seconds"),
sampleSize: moment.duration(30, "seconds"),
},
...timeScale1hMinOptions,
};

export const defaultTimeScaleSelected: TimeScale = {
...defaultTimeScaleOptions["Past 1 Hour"],
key: "Past 1 Hour",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ import { Transaction } from "src/transactionsTable";
import Long from "long";
import { StatementsRequest } from "../api";
import {
getValidOption,
TimeScale,
timeScale1hMinOptions,
TimeScaleDropdown,
toDateRange,
} from "../timeScaleDropdown";
Expand Down Expand Up @@ -129,6 +131,14 @@ export class TransactionDetails extends React.Component<
},
latestTransactionText: "",
};

// In case the user selected a option not available on this page,
// force a selection of a valid option. This is necessary for the case
// where the value 10/30 min is selected on the Metrics page.
const ts = getValidOption(this.props.timeScale, timeScale1hMinOptions);
if (ts !== this.props.timeScale) {
this.props.onTimeScaleChange(ts);
}
}

static defaultProps: Partial<TransactionDetailsProps> = {
Expand Down Expand Up @@ -237,6 +247,7 @@ export class TransactionDetails extends React.Component<
<PageConfig>
<PageConfigItem>
<TimeScaleDropdown
options={timeScale1hMinOptions}
currentScale={this.props.timeScale}
setTimeScale={this.props.onTimeScaleChange}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ import {
TimeScaleDropdown,
TimeScale,
toDateRange,
timeScale1hMinOptions,
getValidOption,
} from "../timeScaleDropdown";
import { InlineAlert } from "@cockroachlabs/ui-components";
import { TransactionViewType } from "./transactionsPageTypes";
Expand Down Expand Up @@ -134,6 +136,14 @@ export class TransactionsPage extends React.Component<
};
const stateFromHistory = this.getStateFromHistory();
this.state = merge(this.state, stateFromHistory);

// In case the user selected a option not available on this page,
// force a selection of a valid option. This is necessary for the case
// where the value 10/30 min is selected on the Metrics page.
const ts = getValidOption(this.props.timeScale, timeScale1hMinOptions);
if (ts !== this.props.timeScale) {
this.changeTimeScale(ts);
}
}

getStateFromHistory = (): Partial<TState> => {
Expand Down Expand Up @@ -408,6 +418,7 @@ export class TransactionsPage extends React.Component<
</PageConfigItem>
<PageConfigItem className={commonStyles("separator")}>
<TimeScaleDropdown
options={timeScale1hMinOptions}
currentScale={this.props.timeScale}
setTimeScale={this.changeTimeScale}
/>
Expand Down

0 comments on commit 5fb02f5

Please sign in to comment.