Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster-ui: create node regions selector #131046

Merged
merged 1 commit into from
Sep 22, 2024

Conversation

xinhaoz
Copy link
Member

@xinhaoz xinhaoz commented Sep 19, 2024

Please review only the latest commit in this PR.
Previous: #130958


This commit adds a select component which allows users
to select nodes by region.

Epic: CRDB-37558
Fixes: #131032

Release note: None

@xinhaoz xinhaoz requested review from a team as code owners September 19, 2024 18:57
@xinhaoz xinhaoz requested review from angles-n-daemons and removed request for a team September 19, 2024 18:57
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@xinhaoz xinhaoz removed the request for review from a team September 19, 2024 18:59
@xinhaoz xinhaoz changed the title cluster-ui: create databases v2 api cluster-ui: create node regions selector Sep 19, 2024
@xinhaoz
Copy link
Member Author

xinhaoz commented Sep 19, 2024

TODO: Going to post a loom wtih a demo in a bit.

revalidateOnFocus: false,
});

const nodeIDToRegion = useMemo(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My react is a bit rusty, and I'm not too familiar with SWR, but why do we need to use useMemo here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's so that we only recompute this value when the data changes. This hook will get called on every re-render, but since the data changes less ferquently than that we can useMemo can be used to only recompute items when necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the SWR hook, you mostly just need to know that it caches based on a unique key, which in this case is just the nodes api route path, since we don't provide any params to it (see https://swr.vercel.app/#overview for more if you're curious).
So for now, because we're also not polling this nodes data yet (we can set that in the swr options param), these maps will only be computed once when the data loads, instead of every time the parent component re-renders (which is often).

return result;
}, [data]);

const storeIDToNodeID = useMemo(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need two separate useMemos here? Can the generation of both nodeIdToRegion and storeIdToNodeId be done in a single iteration of data.nodes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do that - I find it's sometimes a little cleaner to separate but we can consolidate here. Done.
Also, I think you meant to leave this comment and the one above on #130958. This PR should only focus on the latest commit.

);
});

it("renders without crashing", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we probably don't need to say "without crashing". Maybe something as simple as it("should render")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@xinhaoz
Copy link
Member Author

xinhaoz commented Sep 20, 2024

@xinhaoz xinhaoz force-pushed the node-regions-comp branch 2 times, most recently from 0227a1a to 7d2aa9a Compare September 20, 2024 20:55
Copy link
Contributor

@kyle-a-wong kyle-a-wong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. Just one minor nit

@@ -41,7 +41,7 @@ export type DatabaseMetadataRequest = {
sortBy?: string;
sortOrder?: string;
pagination: SimplePaginationState;
storeId?: number;
storeId?: number[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit should this be storeIds?

@xinhaoz xinhaoz force-pushed the node-regions-comp branch 2 times, most recently from 9b79952 to 3382ee8 Compare September 20, 2024 22:00
@bitomukesh
Copy link

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
New Feature - Node Regions Selector Component

nodeRegionsSelector.tsx - Created new NodeRegionsSelector component

nodeRegionsSelector.spec.tsx - Added unit tests for NodeRegionsSelector component

index.tsx - Integrated NodeRegionsSelector into DatabasesPageV2

selectTypes.ts - Added GroupedReactSelectOption type for grouped select options

Feature Improvement - Enhanced Database Metadata API

getDatabaseMetadataApi.ts - Updated API to support multiple store IDs

This commit adds a select component which allows users
to select nodes by region.

Epic: CRDB-37558
Fixes: cockroachdb#131032

Release note: None
@xinhaoz
Copy link
Member Author

xinhaoz commented Sep 22, 2024

bors r+

@craig craig bot merged commit 663af90 into cockroachdb:master Sep 22, 2024
23 checks passed
craig bot pushed a commit that referenced this pull request Sep 23, 2024
131123: cluster-ui: add getTableMetadataApi and connect tables page  r=xinhaoz a=xinhaoz

Only the latest commit should be reviewed in this PR.
Previous: #131046

----------------------

This commit connects the v2 db details - tables page to the
new `api/v2/table_metadata` api route.

The following components are now connected to the api:
- listing tables for a db
- sorting by column
- searching by table name
- filtering by node id

Epic: [CRDB-37558](https://cockroachlabs.atlassian.net/browse/CRDB-37558)
Fixes: #131122

Release note: None

Co-authored-by: Xin Hao Zhang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cluster-ui: create node/regions selector
4 participants