Skip to content

Commit

Permalink
ui: add new search criteria to SQL Activity page
Browse files Browse the repository at this point in the history
Create new Search Criteria component, and add
to Statements and Transactions page.
This commit also updates the UI, with the new
position of filters and reset sql stats.

Part Of #98891

Release note (ui change): Add Search Criteria to Statements and
Transactions pages, updates UX with improvements.
  • Loading branch information
maryliag authored and xinhaoz committed Mar 20, 2023
1 parent 61d2073 commit ae9c259
Show file tree
Hide file tree
Showing 24 changed files with 519 additions and 322 deletions.
5 changes: 2 additions & 3 deletions pkg/ui/workspaces/cluster-ui/src/api/statementsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export type StatementDetailsResponseWithKey = {
};

export type SqlStatsResponse = cockroach.server.serverpb.StatementsResponse;
export const SqlStatsSortOptions = cockroach.server.serverpb.StatsSortOptions;
export type SqlStatsSortType = cockroach.server.serverpb.StatsSortOptions;

const FetchStatsMode =
cockroach.server.serverpb.CombinedStatementsStatsRequest.StatsType;
Expand All @@ -45,9 +47,6 @@ export type ErrorWithKey = {
key: string;
};

export const SqlStatsSortOptions = cockroach.server.serverpb.StatsSortOptions;
export type SqlStatsSortType = cockroach.server.serverpb.StatsSortOptions;

export const DEFAULT_STATS_REQ_OPTIONS = {
limit: 100,
sort: SqlStatsSortOptions.SERVICE_LAT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}

&__btn {
height: $line-height--large;
height: $line-height--larger;
width: 67px;
font-size: $font-size--small;
}
Expand Down Expand Up @@ -36,9 +36,10 @@
}
}

.float {
.btn-area {
float: left;
margin-right: 7px;
font-size: $font-size--medium;
}

.label {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface ColumnsSelectorProps {
// options provides the list of available columns and their initial selection state
options: SelectOption[];
onSubmitColumns: (selectedColumns: string[]) => void;
size?: "default" | "small";
}

export interface ColumnsSelectorState {
Expand Down Expand Up @@ -222,6 +223,7 @@ export default class ColumnsSelector extends React.Component<

render(): React.ReactElement {
const { hide } = this.state;
const { size = "default" } = this.props;
const dropdownArea = hide ? hidden : dropdown;
const options = this.getOptions();
const columnsSelected = options.filter(o => o.isSelected);
Expand All @@ -230,9 +232,9 @@ export default class ColumnsSelector extends React.Component<
<div
onClick={this.insideClick}
ref={this.dropdownRef}
className={cx("float")}
className={cx("btn-area")}
>
<Button type="secondary" size="small" onClick={this.toggleOpen}>
<Button type="secondary" size={size} onClick={this.toggleOpen}>
<Gear className={cx("icon")} />
Columns
</Button>
Expand Down
28 changes: 28 additions & 0 deletions pkg/ui/workspaces/cluster-ui/src/common/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,31 @@ import classNames from "classnames/bind";
import styles from "./styles.module.scss";

export const commonStyles = classNames.bind(styles);

export const selectCustomStyles = {
container: (provided: any) => ({
...provided,
border: "none",
}),
option: (provided: any, state: any) => ({
...provided,
backgroundColor: state.isSelected ? "#DEEBFF" : provided.backgroundColor,
color: "#394455",
}),
control: (provided: any) => ({
...provided,
width: "100%",
borderColor: "#C0C6D9",
}),
dropdownIndicator: (provided: any) => ({
...provided,
color: "#C0C6D9",
}),
singleValue: (provided: any) => ({
...provided,
color: "#475872",
}),
indicatorSeparator: (provided: any) => ({
...provided,
}),
};
11 changes: 10 additions & 1 deletion pkg/ui/workspaces/cluster-ui/src/common/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ h3.base-heading {
font-family: $font-family--semi-bold;
font-style: normal;
font-stretch: normal;
font-size: 20px;
font-size: $font-size--large;
padding-bottom: 12px;
}

h5.base-heading {
color: $colors--neutral-7;
font-family: $font-family--semi-bold;
font-style: normal;
font-stretch: normal;
font-size: $font-size--tall;
padding-bottom: 12px;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ export const StatementInsightsView: React.FC<StatementInsightsViewProps> = ({
<ColumnsSelector
options={tableColumns}
onSubmitColumns={onColumnsChange}
size={"small"}
/>
<TableStatistics
pagination={pagination}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ export class JobsPage extends React.Component<JobsPageProps, PageState> {
<ColumnsSelector
options={tableColumns}
onSubmitColumns={onColumnsChange}
size={"small"}
/>
<div className={cx("jobs-table-summary")}>
<h4 className={cx("cl-count-title")}>
Expand Down
5 changes: 3 additions & 2 deletions pkg/ui/workspaces/cluster-ui/src/pageConfig/pageConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface PageConfigProps {
layout?: "list" | "spread";
children?: React.ReactNode;
whiteBkg?: boolean;
className?: string;
}

const cx = classnames.bind(styles);
Expand All @@ -31,9 +32,9 @@ export function PageConfig(props: PageConfigProps): React.ReactElement {

return (
<div
className={cx("page-config", {
className={`${cx("page-config", {
"page-config__white-background": whiteBkg,
})}
})} ${props.className}`}
>
<ul className={classes}>{props.children}</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ $dropdown-hover-color: darken($colors--background, 2.5%);
font-family: $font-family--semi-bold;
padding: 8px 0 8px 17px;
vertical-align: middle;
border: 1px solid $colors--neutral-5;
border: 1px solid $colors--neutral-4;
border-radius: 3px;
white-space: nowrap;
color: $colors--neutral-7;
cursor: pointer;
position: relative;
background: $colors--neutral-1;
background: white;
display: flex;
align-items: center;
height: 40px;
Expand Down
29 changes: 2 additions & 27 deletions pkg/ui/workspaces/cluster-ui/src/queryFilter/filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from "./filterClasses";
import { MultiSelectCheckbox } from "../multiSelectCheckbox/multiSelectCheckbox";
import { syncHistory } from "../util";
import { selectCustomStyles } from "../common";

interface QueryFilter {
onSubmitFilters: (filters: Filters) => void;
Expand Down Expand Up @@ -417,33 +418,7 @@ export class Filter extends React.Component<QueryFilter, FilterState> {
showWorkloadInsightTypes,
} = this.props;
const dropdownArea = hide ? hidden : dropdown;
const customStyles = {
container: (provided: any) => ({
...provided,
border: "none",
}),
option: (provided: any, state: any) => ({
...provided,
backgroundColor: state.isSelected
? "#DEEBFF"
: provided.backgroundColor,
color: "#394455",
}),
control: (provided: any) => ({
...provided,
width: "100%",
borderColor: "#C0C6D9",
}),
dropdownIndicator: (provided: any) => ({
...provided,
color: "#C0C6D9",
}),
singleValue: (provided: any) => ({
...provided,
color: "#475872",
}),
};
const customStylesSmall = { ...customStyles };
const customStylesSmall = { ...selectCustomStyles };
customStylesSmall.container = (provided: any) => ({
...provided,
width: "141px",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const RecentStatementsSection: React.FC<
<ColumnsSelector
options={tableColumns}
onSubmitColumns={onColumnsSelect}
size={"small"}
/>
<TableStatistics
pagination={pagination}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const RecentTransactionsSection: React.FC<
<ColumnsSelector
options={tableColumns}
onSubmitColumns={onColumnsSelect}
size={"small"}
/>
<TableStatistics
pagination={pagination}
Expand Down
11 changes: 11 additions & 0 deletions pkg/ui/workspaces/cluster-ui/src/searchCriteria/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2023 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.

export * from "./searchCriteria";
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@import "../core/index.module";

.search-area {
border: 1px solid $colors--neutral-3;
border-radius: 3px;
margin-bottom: 10px;
margin-right: 10px;
padding: 20px;
background-color: white;
}

.top-area {
z-index: 5;
background-color: white;
}

.timescale-small {
width: 455px;
}

.label {
color: $colors--neutral-6;
font-family: $font-family--semi-bold;
font-size: $font-size--medium;
}

.margin-top-btn {
margin-top: 22px;
}
126 changes: 126 additions & 0 deletions pkg/ui/workspaces/cluster-ui/src/searchCriteria/searchCriteria.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Copyright 2023 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 React from "react";
import classNames from "classnames/bind";
import styles from "./searchCriteria.module.scss";
import {
Button,
commonStyles,
PageConfig,
PageConfigItem,
selectCustomStyles,
TimeScale,
timeScale1hMinOptions,
TimeScaleDropdown,
} from "src";
import { applyBtn } from "../queryFilter/filterClasses";
import Select from "react-select";
import { limitOptions } from "../util/sqlActivityConstants";
import { SqlStatsSortType } from "src/api/statementsApi";
const cx = classNames.bind(styles);

type SortOption = {
label: string;
value: SqlStatsSortType;
};
export interface SearchCriteriaProps {
sortOptions: SortOption[];
currentScale: TimeScale;
topValue: number;
byValue: SqlStatsSortType;
onChangeTimeScale: (ts: TimeScale) => void;
onChangeTop: (top: number) => void;
onChangeBy: (by: SqlStatsSortType) => void;
onApply: () => void;
}

export function SearchCriteria(props: SearchCriteriaProps): React.ReactElement {
const {
topValue,
byValue,
currentScale,
onChangeTop,
onChangeBy,
onChangeTimeScale,
sortOptions,
} = props;
const customStyles = { ...selectCustomStyles };
customStyles.indicatorSeparator = (provided: any) => ({
...provided,
display: "none",
});

const customStylesTop = { ...customStyles };
customStylesTop.container = (provided: any) => ({
...provided,
width: "80px",
border: "none",
});

const customStylesBy = { ...customStyles };
customStylesBy.container = (provided: any) => ({
...provided,
width: "170px",
border: "none",
});

return (
<div className={cx("search-area")}>
<h5 className={commonStyles("base-heading")}>Search Criteria</h5>
<PageConfig className={cx("top-area")}>
<PageConfigItem>
<label>
<span className={cx("label")}>Top</span>
<Select
options={limitOptions}
value={limitOptions.filter(top => top.value === topValue)}
onChange={event => onChangeTop(event.value)}
styles={customStylesTop}
/>
</label>
</PageConfigItem>
<PageConfigItem>
<label>
<span className={cx("label")}>By</span>
<Select
options={sortOptions}
value={sortOptions.filter(
(top: SortOption) => top.value === byValue,
)}
onChange={event => onChangeBy(event.value as SqlStatsSortType)}
styles={customStylesBy}
/>
</label>
</PageConfigItem>
<PageConfigItem>
<label>
<span className={cx("label")}>Time Range</span>
<TimeScaleDropdown
options={timeScale1hMinOptions}
currentScale={currentScale}
setTimeScale={onChangeTimeScale}
className={cx("timescale-small")}
/>
</label>
</PageConfigItem>
<PageConfigItem>
<Button
className={`${applyBtn.btn} ${cx("margin-top-btn")}`}
textAlign="center"
onClick={props.onApply}
>
Apply
</Button>
</PageConfigItem>
</PageConfig>
</div>
);
}
Loading

0 comments on commit ae9c259

Please sign in to comment.