Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
81006: ui: Fix the custom time picker reverting to the previously selected time r=jocrl a=jocrl

This commit fixes a bug introduced by
cockroachdb#80660; where if a user selects a
different time in the custom time selection, the component may revert to the
currently select time.

Before:

https://user-images.githubusercontent.com/91907326/166824410-5ab5e6f1-51ed-44a2-afe4-fffdfc8f955a.mov

After:

https://user-images.githubusercontent.com/91907326/166831351-ae0deee5-a116-4ed1-b2ca-c85160339bd3.mov


Release note: None

Release justification: Category 2, UI bug fix

81055: *: remove unused proto imports r=nicktrav,knz,rail a=rickystewart

Release note: None

Co-authored-by: Josephine Lee <[email protected]>
Co-authored-by: Ricky Stewart <[email protected]>
  • Loading branch information
3 people committed May 5, 2022
3 parents 2b8443d + a23777f + d1879eb commit 51c7020
Show file tree
Hide file tree
Showing 28 changed files with 38 additions and 57 deletions.
2 changes: 0 additions & 2 deletions pkg/blobs/blobspb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ proto_library(
srcs = ["blobs.proto"],
strip_import_prefix = "/pkg",
visibility = ["//visibility:public"],
deps = ["@com_github_gogo_protobuf//gogoproto:gogo_proto"],
)

go_proto_library(
Expand All @@ -16,7 +15,6 @@ go_proto_library(
importpath = "github.com/cockroachdb/cockroach/pkg/blobs/blobspb",
proto = ":blobspb_proto",
visibility = ["//visibility:public"],
deps = ["@com_github_gogo_protobuf//gogoproto"],
)

go_library(
Expand Down
2 changes: 0 additions & 2 deletions pkg/blobs/blobspb/blobs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ syntax = "proto3";
package cockroach.blobs;
option go_package = "blobspb";

import "gogoproto/gogo.proto";

// GetRequest is used to read a file from a remote node.
// It's path is specified by `filename`, which can either
// be a relative path from the base of external IO dir, or
Expand Down
2 changes: 0 additions & 2 deletions pkg/ccl/baseccl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ proto_library(
srcs = ["encryption_options.proto"],
strip_import_prefix = "/pkg",
visibility = ["//visibility:public"],
deps = ["@com_github_gogo_protobuf//gogoproto:gogo_proto"],
)

go_proto_library(
Expand All @@ -39,5 +38,4 @@ go_proto_library(
importpath = "github.com/cockroachdb/cockroach/pkg/ccl/baseccl",
proto = ":baseccl_proto",
visibility = ["//visibility:public"],
deps = ["@com_github_gogo_protobuf//gogoproto"],
)
2 changes: 0 additions & 2 deletions pkg/ccl/baseccl/encryption_options.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ syntax = "proto3";
package cockroach.ccl.baseccl;
option go_package = "baseccl";

import "gogoproto/gogo.proto";

enum EncryptionKeySource {
// Plain key files.
KeyFiles = 0;
Expand Down
2 changes: 0 additions & 2 deletions pkg/ccl/storageccl/engineccl/enginepbccl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ proto_library(
],
strip_import_prefix = "/pkg",
visibility = ["//visibility:public"],
deps = ["@com_github_gogo_protobuf//gogoproto:gogo_proto"],
)

go_proto_library(
Expand All @@ -19,7 +18,6 @@ go_proto_library(
importpath = "github.com/cockroachdb/cockroach/pkg/ccl/storageccl/engineccl/enginepbccl",
proto = ":enginepbccl_proto",
visibility = ["//visibility:public"],
deps = ["@com_github_gogo_protobuf//gogoproto"],
)

go_library(
Expand Down
2 changes: 0 additions & 2 deletions pkg/ccl/storageccl/engineccl/enginepbccl/key_registry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ syntax = "proto3";
package cockroach.ccl.storageccl.engineccl.enginepbccl;
option go_package = "enginepbccl";

import "gogoproto/gogo.proto";

enum EncryptionType {
// No encryption.
Plaintext = 0;
Expand Down
1 change: 0 additions & 1 deletion pkg/ccl/storageccl/engineccl/enginepbccl/stats.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ syntax = "proto3";
package cockroach.ccl.storageccl.engineccl.enginepbccl;
option go_package = "enginepbccl";

import "gogoproto/gogo.proto";
import "ccl/storageccl/engineccl/enginepbccl/key_registry.proto";

// EncryptionStatus contains encryption-related information.
Expand Down
1 change: 0 additions & 1 deletion pkg/jobs/jobspb/schedule.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ syntax = "proto3";
package cockroach.jobs.jobspb;
option go_package = "jobspb";

import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";

// ScheduleDetails describes how to schedule and execute the job.
Expand Down
2 changes: 0 additions & 2 deletions pkg/kv/kvserver/closedts/ctpb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ proto_library(
"//pkg/roachpb:roachpb_proto",
"//pkg/util/hlc:hlc_proto",
"@com_github_gogo_protobuf//gogoproto:gogo_proto",
"@go_googleapis//google/api:annotations_proto",
],
)

Expand All @@ -37,6 +36,5 @@ go_proto_library(
"//pkg/roachpb",
"//pkg/util/hlc",
"@com_github_gogo_protobuf//gogoproto",
"@org_golang_google_genproto//googleapis/api/annotations:go_default_library",
],
)
1 change: 0 additions & 1 deletion pkg/kv/kvserver/closedts/ctpb/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import "roachpb/data.proto";
import "util/hlc/timestamp.proto";

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";

// Update contains information about (the advancement of) closed timestamps for
// ranges with leases on the sender node. Updates are of two types: snapshots
Expand Down
2 changes: 0 additions & 2 deletions pkg/kv/kvserver/concurrency/poison/policy.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ syntax = "proto3";
package cockroach.kv.kvserver.concurrency.poison;
option go_package = "poison";

import "gogoproto/gogo.proto";

// Policy determines how a request will react to encountering a poisoned
// latch. A poisoned latch is a latch for which the holder is unable to make
// progress. That is, waiters of this latch should not expect to be able to
Expand Down
2 changes: 0 additions & 2 deletions pkg/kv/kvserver/protectedts/ptpb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ proto_library(
"//pkg/roachpb:roachpb_proto",
"//pkg/util/hlc:hlc_proto",
"@com_github_gogo_protobuf//gogoproto:gogo_proto",
"@go_googleapis//google/api:annotations_proto",
],
)

Expand All @@ -27,7 +26,6 @@ go_proto_library(
"//pkg/util/hlc",
"//pkg/util/uuid", # keep
"@com_github_gogo_protobuf//gogoproto",
"@org_golang_google_genproto//googleapis/api/annotations:go_default_library",
],
)

Expand Down
1 change: 0 additions & 1 deletion pkg/kv/kvserver/protectedts/ptpb/protectedts.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ package cockroach.protectedts;
option go_package = "ptpb";

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "roachpb/data.proto";
import "util/hlc/timestamp.proto";

Expand Down
2 changes: 0 additions & 2 deletions pkg/kv/kvserver/protectedts/ptstorage/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ proto_library(
deps = [
"//pkg/roachpb:roachpb_proto",
"@com_github_gogo_protobuf//gogoproto:gogo_proto",
"@go_googleapis//google/api:annotations_proto",
],
)

Expand All @@ -101,6 +100,5 @@ go_proto_library(
deps = [
"//pkg/roachpb",
"@com_github_gogo_protobuf//gogoproto",
"@org_golang_google_genproto//googleapis/api/annotations:go_default_library",
],
)
1 change: 0 additions & 1 deletion pkg/kv/kvserver/protectedts/ptstorage/storage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ package cockroach.protectedts;
option go_package = "ptstorage";

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "roachpb/data.proto";

// Spans is the format of the message encoded in the spans column of a the
Expand Down
1 change: 0 additions & 1 deletion pkg/kv/kvserver/storage_services.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ option go_package = "kvserver";

import "kv/kvserver/kvserverpb/raft.proto";
import "kv/kvserver/api.proto";
import "gogoproto/gogo.proto";

service MultiRaft {
rpc RaftMessageBatch (stream cockroach.kv.kvserver.kvserverpb.RaftMessageRequestBatch) returns (stream cockroach.kv.kvserver.kvserverpb.RaftMessageResponse) {}
Expand Down
5 changes: 1 addition & 4 deletions pkg/server/serverpb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ proto_library(
"//pkg/server/diagnostics/diagnosticspb:diagnosticspb_proto",
"//pkg/server/status/statuspb:statuspb_proto",
"//pkg/sql/contentionpb:contentionpb_proto",
"//pkg/sql/execinfrapb:execinfrapb_proto",
"//pkg/storage/enginepb:enginepb_proto",
"//pkg/ts/catalog:catalog_proto",
"//pkg/util:util_proto",
"//pkg/util/hlc:hlc_proto",
"//pkg/util/log/logpb:logpb_proto",
"//pkg/util/metric:metric_proto",
"//pkg/util/tracing/tracingpb:tracingpb_proto",
Expand Down Expand Up @@ -67,12 +65,11 @@ go_proto_library(
"//pkg/server/status/statuspb",
"//pkg/sql/catalog/descpb", # keep
"//pkg/sql/contentionpb",
"//pkg/sql/execinfrapb",
"//pkg/sql/execinfrapb", # keep
"//pkg/sql/pgwire/pgwirecancel", # keep
"//pkg/storage/enginepb",
"//pkg/ts/catalog",
"//pkg/util",
"//pkg/util/hlc",
"//pkg/util/log/logpb",
"//pkg/util/metric",
"//pkg/util/tracing/tracingpb",
Expand Down
3 changes: 0 additions & 3 deletions pkg/server/serverpb/status.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import "server/diagnostics/diagnosticspb/diagnostics.proto";
import "server/serverpb/index_recommendations.proto";
import "server/status/statuspb/status.proto";
import "sql/contentionpb/contention.proto";
import "sql/execinfrapb/api.proto";
import "storage/enginepb/engine.proto";
import "storage/enginepb/mvcc.proto";
import "storage/enginepb/rocksdb.proto";
Expand All @@ -32,8 +31,6 @@ import "kv/kvserver/kvserverpb/state.proto";
import "kv/kvserver/liveness/livenesspb/liveness.proto";
import "util/log/logpb/log.proto";
import "util/unresolved_addr.proto";
import "util/hlc/timestamp.proto";
import "util/tracing/tracingpb/recorded_span.proto";
import "util/tracing/tracingpb/tracing.proto";

import "etcd/raft/v3/raftpb/raft.proto";
Expand Down
2 changes: 0 additions & 2 deletions pkg/sql/catalog/descpb/encoded_datum.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ syntax = "proto2";
package cockroach.sql.sqlbase;
option go_package = "descpb";

import "gogoproto/gogo.proto";

// DatumEncoding identifies the encoding used for an EncDatum.
enum DatumEncoding {
// Indicates that the datum is encoded using the order-preserving encoding
Expand Down
5 changes: 1 addition & 4 deletions pkg/sql/execinfrapb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ proto_library(
deps = [
"//pkg/jobs/jobspb:jobspb_proto",
"//pkg/roachpb:roachpb_proto",
"//pkg/sql/catalog/catpb:catpb_proto",
"//pkg/sql/catalog/descpb:descpb_proto",
"//pkg/sql/inverted:inverted_proto",
"//pkg/sql/pgwire/pgerror:pgerror_proto",
"//pkg/sql/sessiondatapb:sessiondatapb_proto",
"//pkg/sql/types:types_proto",
"//pkg/util/hlc:hlc_proto",
Expand All @@ -133,10 +131,9 @@ go_proto_library(
deps = [
"//pkg/jobs/jobspb",
"//pkg/roachpb",
"//pkg/sql/catalog/catpb",
"//pkg/sql/catalog/catpb", # keep
"//pkg/sql/catalog/descpb",
"//pkg/sql/inverted",
"//pkg/sql/pgwire/pgerror",
"//pkg/sql/sessiondatapb",
"//pkg/sql/types",
"//pkg/util/hlc",
Expand Down
5 changes: 0 additions & 5 deletions pkg/sql/execinfrapb/data.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,15 @@ syntax = "proto2";
package cockroach.sql.distsqlrun;
option go_package = "execinfrapb";

import "jobs/jobspb/jobs.proto";
import "roachpb/api.proto";
import "roachpb/data.proto";
import "roachpb/errors.proto";
import "errorspb/errors.proto";
import "sql/pgwire/pgerror/errors.proto";
import "sql/catalog/descpb/structured.proto";
import "sql/catalog/descpb/encoded_datum.proto";
import "sql/types/types.proto";
import "util/tracing/tracingpb/recorded_span.proto";
import "gogoproto/gogo.proto";
import "util/hlc/timestamp.proto";
import "google/protobuf/any.proto";
import "google/protobuf/timestamp.proto";

// Error is a generic representation including a string message.
message Error {
Expand Down
2 changes: 0 additions & 2 deletions pkg/sql/execinfrapb/processors_bulk_io.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ option go_package = "execinfrapb";

import "jobs/jobspb/jobs.proto";
import "roachpb/io-formats.proto";
import "sql/catalog/catpb/catalog.proto";
import "sql/catalog/descpb/structured.proto";
import "sql/execinfrapb/processors_base.proto";
import "util/hlc/timestamp.proto";
import "gogoproto/gogo.proto";
import "roachpb/data.proto";
Expand Down
2 changes: 0 additions & 2 deletions pkg/sql/rowenc/rowencpb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ proto_library(
srcs = ["index_encoding.proto"],
strip_import_prefix = "/pkg",
visibility = ["//visibility:public"],
deps = ["@com_github_gogo_protobuf//gogoproto:gogo_proto"],
)

go_proto_library(
Expand All @@ -16,7 +15,6 @@ go_proto_library(
importpath = "github.com/cockroachdb/cockroach/pkg/sql/rowenc/rowencpb",
proto = ":rowencpb_proto",
visibility = ["//visibility:public"],
deps = ["@com_github_gogo_protobuf//gogoproto"],
)

go_library(
Expand Down
2 changes: 0 additions & 2 deletions pkg/sql/rowenc/rowencpb/index_encoding.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ syntax = "proto3";
package cockroach.rowenc;
option go_package = "rowencpb";

import "gogoproto/gogo.proto";

// Wrapper for the bytes of the value of an index that also contains bit for
// whether or not the value was deleted. A wrapper of arbitrary index values
// with the additional delete bit was chosen over a separate index encoding type
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/sessiondatapb/session_revival_token.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ syntax = "proto3";
package cockroach.sql.sessiondatapb;
option go_package = "sessiondatapb";

import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";

// SessionRevivalToken is an opaque piece of data that can be used to
Expand Down
2 changes: 0 additions & 2 deletions pkg/storage/enginepb/file_registry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ syntax = "proto3";
package cockroach.storage.enginepb;
option go_package = "enginepb";

import "gogoproto/gogo.proto";

// RegistryVersion defines the version of a registry. Newly added versions
// should be larger than all currently and previously existing versions.
enum RegistryVersion {
Expand Down
21 changes: 17 additions & 4 deletions pkg/ui/workspaces/cluster-ui/src/dateRange/dateRange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Button } from "src/button";
import { Text, TextTypes } from "src/text";

import styles from "./dateRange.module.scss";
import { usePrevious } from "../util/hooks";

const cx = classNames.bind(styles);

Expand Down Expand Up @@ -51,14 +52,26 @@ export function DateRangeMenu({
startInit || moment.utc(),
);
const [endMoment, setEndMoment] = useState<Moment>(endInit || moment.utc());
const prevStartInit = usePrevious(startInit);
const prevEndInit = usePrevious(endInit);

useEffect(() => {
setStartMoment(startInit);
}, [startInit]);
// .unix() is needed compare the actual time value instead of referential equality of the Moment object.
// Otherwise, triggering `setStartMoment` unnecessarily can cause a bug where the selection jumps back to the
// currently selected time while the user is in the middle of making a different selection.
if (startInit?.unix() != prevStartInit?.unix()) {
setStartMoment(startInit);
}
}, [startInit, prevStartInit]);

useEffect(() => {
setEndMoment(endInit);
}, [endInit]);
// .unix() is needed compare the actual time value instead of referential equality of the Moment object.
// Otherwise, triggering `setEndMoment` unnecessarily can cause a bug where the selection jumps back to the
// currently selected time while the user is in the middle of making a different selection.
if (endInit?.unix() != prevEndInit?.unix()) {
setEndMoment(endInit);
}
}, [endInit, prevEndInit]);

const onChangeStart = (m?: Moment) => {
m && setStartMoment(m);
Expand Down
19 changes: 19 additions & 0 deletions pkg/ui/workspaces/cluster-ui/src/util/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 { useEffect, useRef } from "react";

export const usePrevious = <T>(value: T): T | undefined => {
const ref = useRef<T>();
useEffect(() => {
ref.current = value;
});
return ref.current;
};

0 comments on commit 51c7020

Please sign in to comment.