-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[vtadmin-web] Add simple /schema view with table definition #7615
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
Merged
rohit-nayak-ps
merged 5 commits into
vitessio:master
from
tinyspeck:sarabee-vtadmin-web-schema
Mar 9, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5aeb9ac
Add /schema view with table definition
doeg ea0c13e
Update 'schema not found' placeholder text
doeg 3aec202
Add commentary for HTTP errors
doeg 80f6d29
Only link to schemas if all link components are defined
doeg 40d2b36
Fix overflow on long table definitions
doeg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /** | ||
| * Copyright 2021 The Vitess Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| .table { | ||
| margin: 8px 0; | ||
| } | ||
|
|
||
| .table tr { | ||
| border: none; | ||
| } | ||
|
|
||
| .table td { | ||
| border: none; | ||
| line-height: 1.6; | ||
| margin: 0; | ||
| } | ||
|
|
||
| .lineNumber { | ||
| box-sizing: border-box; | ||
| color: var(--textColorSecondary); | ||
| font-family: var(--fontFamilyMonospace); | ||
| font-size: var(--fontSizeDefault); | ||
| line-height: 2.4rem; | ||
| min-width: 5rem; | ||
| padding: 0 1.2rem; | ||
| text-align: right; | ||
| user-select: none; | ||
| vertical-align: top; | ||
| white-space: nowrap; | ||
| width: 1%; | ||
| } | ||
|
|
||
| .lineNumber::before { | ||
| content: attr(data-line-number); | ||
| } | ||
|
|
||
| .code { | ||
| font-family: var(--fontFamilyMonospace); | ||
| font-size: var(--fontSizeDefault); | ||
| line-height: 2.4rem; | ||
| padding: 0 1.2rem; | ||
| tab-size: 8; | ||
| white-space: pre; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /** | ||
| * Copyright 2021 The Vitess Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| import * as React from 'react'; | ||
|
|
||
| import style from './Code.module.scss'; | ||
|
|
||
| interface Props { | ||
| code?: string | null | undefined; | ||
| } | ||
|
|
||
| export const Code = ({ code }: Props) => { | ||
| if (typeof code !== 'string') return null; | ||
|
|
||
| const codeLines = code.split('\n'); | ||
| return ( | ||
| <table className={style.table}> | ||
| <tbody> | ||
| {codeLines.map((line, idx) => { | ||
| return ( | ||
| <tr key={idx}> | ||
| <td id={`L${idx}`} className={style.lineNumber} data-line-number={idx} /> | ||
| <td className={style.code}> | ||
| <code>{line}</code> | ||
| </td> | ||
| </tr> | ||
| ); | ||
| })} | ||
| </tbody> | ||
| </table> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /** | ||
| * Copyright 2021 The Vitess Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| .header { | ||
| margin: 4.8rem 0; | ||
| } | ||
|
|
||
| .header h1 { | ||
| margin: 2.4rem 0 0 0; | ||
| padding: 0; | ||
| } | ||
|
|
||
| .headingMeta { | ||
| display: flex; | ||
| } | ||
|
|
||
| .headingMeta span { | ||
| display: inline-block; | ||
| font-size: var(--fontSizeLarge); | ||
| line-height: 2; | ||
|
|
||
| &::after { | ||
| color: var(--colorScaffoldingHighlight); | ||
| content: '/'; | ||
| display: inline-block; | ||
| margin: 0 1.2rem; | ||
| } | ||
|
|
||
| &:last-child::after { | ||
| content: none; | ||
| } | ||
| } | ||
|
|
||
| .panel { | ||
| border: solid 1px var(--colorScaffoldingHighlight); | ||
| border-radius: 6px; | ||
| padding: 0 2.4rem 2.4rem 2.4rem; | ||
| max-width: 960px; | ||
| overflow: auto; | ||
| } | ||
|
|
||
| .errorPlaceholder { | ||
| align-items: center; | ||
| display: flex; | ||
| flex-direction: column; | ||
| font-size: var(--fontSizeLarge); | ||
| justify-content: center; | ||
| margin: 25vh auto; | ||
| max-width: 720px; | ||
| text-align: center; | ||
|
|
||
| h1 { | ||
| margin: 1.6rem 0; | ||
| } | ||
| } | ||
|
|
||
| .errorEmoji { | ||
| display: block; | ||
| font-size: 5.6rem; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /** | ||
| * Copyright 2021 The Vitess Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| import * as React from 'react'; | ||
| import { Link, useParams } from 'react-router-dom'; | ||
|
|
||
| import style from './Schema.module.scss'; | ||
| import { useSchema } from '../../hooks/api'; | ||
| import { Code } from '../Code'; | ||
| import { useDocumentTitle } from '../../hooks/useDocumentTitle'; | ||
|
|
||
| interface RouteParams { | ||
| clusterID: string; | ||
| keyspace: string; | ||
| table: string; | ||
| } | ||
|
|
||
| export const Schema = () => { | ||
| const { clusterID, keyspace, table } = useParams<RouteParams>(); | ||
| const { data, error, isError, isLoading, isSuccess } = useSchema({ clusterID, keyspace, table }); | ||
|
|
||
| useDocumentTitle(`${table} (${keyspace})`); | ||
|
|
||
| const tableDefinition = React.useMemo( | ||
| () => | ||
| data && Array.isArray(data.table_definitions) | ||
| ? data?.table_definitions.find((t) => t.name === table) | ||
| : null, | ||
| [data, table] | ||
| ); | ||
|
|
||
| const is404 = isSuccess && !tableDefinition; | ||
|
|
||
| return ( | ||
| <div> | ||
| {!is404 && !isError && ( | ||
| <header className={style.header}> | ||
| <p> | ||
| <Link to="/schemas">← All schemas</Link> | ||
| </p> | ||
| <code> | ||
| <h1>{table}</h1> | ||
| </code> | ||
| <div className={style.headingMeta}> | ||
| <span> | ||
| Cluster: <code>{clusterID}</code> | ||
| </span> | ||
| <span> | ||
| Keyspace: <code>{keyspace}</code> | ||
| </span> | ||
| </div> | ||
| </header> | ||
| )} | ||
|
|
||
| {/* TODO: skeleton placeholder */} | ||
| {isLoading && <div className={style.loadingPlaceholder}>Loading...</div>} | ||
|
|
||
| {isError && ( | ||
| <div className={style.errorPlaceholder}> | ||
| <span className={style.errorEmoji}>😰</span> | ||
| <h1>An error occurred</h1> | ||
| <code>{(error as any).response?.error?.message || error?.message}</code> | ||
| <p> | ||
| <Link to="/schemas">← All schemas</Link> | ||
| </p> | ||
| </div> | ||
| )} | ||
|
|
||
| {is404 && ( | ||
| <div className={style.errorPlaceholder}> | ||
| <span className={style.errorEmoji}>😖</span> | ||
| <h1>Schema not found</h1> | ||
| <p> | ||
| No schema found with table <code>{table}</code> in keyspace <code>{keyspace}</code> (cluster{' '} | ||
| <code>{clusterID}</code>). | ||
| </p> | ||
| <p> | ||
| <Link to="/schemas">← All schemas</Link> | ||
| </p> | ||
| </div> | ||
| )} | ||
|
|
||
| {!is404 && !isError && tableDefinition && ( | ||
| <div className={style.container}> | ||
| <section className={style.panel}> | ||
| <h3>Table Definition</h3> | ||
| <Code code={tableDefinition.schema} /> | ||
| </section> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"NotOkError" seems redundant to me, how about either
throw HttpResponseNotOkorthrow HttpResponseError? (also if this is "just a react/ts convention" please let me know!)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(also i know this is a type from previous PRs ....... which i probably approved without comment so .........)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it's redundant but I do find it descriptive. This error is specifically when
response.ok(in the JSON response envelope) is false.There are other kinds of "HTTP response errors", like
MalformedHttpResponseErrorwhich occurs when the response envelope is an unexpected shape. (In all cases, theErrorsuffix is there since it extends the baseErrorclass.)I added a commit with bit of commentary on the above. If you still feel like
HttpResponseNotOkErroris redundant, I can change it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, this makes sense to me!