-
Notifications
You must be signed in to change notification settings - Fork 33
feat(nav): render Preview badges consistently #721
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
Open
qiancai
wants to merge
6
commits into
pingcap:master
Choose a base branch
from
qiancai:show-preview-in-toc-entries
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bff93eb
Update LeftNavTree.tsx
qiancai 1f64a6c
fix issues
qiancai 11aabfd
fix(toc): guard missing image tag alt text
qiancai cb5a142
fix(header-nav): mark TiDB for AI as preview
qiancai 73b15be
fix(nav): unify Preview badge styles
qiancai 7642320
fix(nav): preserve Preview badge layout
qiancai 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { mdxAstToToc } from "../toc"; | ||
|
|
||
| describe("mdxAstToToc tag query parsing", () => { | ||
| it("does not emit a bogus ?undefined query when the image URL has no query string", () => { | ||
| const toc = mdxAstToToc( | ||
| [ | ||
| { | ||
| type: "list", | ||
| children: [ | ||
| { | ||
| type: "listItem", | ||
| children: [ | ||
| { | ||
| type: "paragraph", | ||
| children: [ | ||
| { type: "text", value: "Data Service" }, | ||
| { | ||
| type: "image", | ||
| alt: "PREVIEW", | ||
| url: "/media/tidb-cloud/blank_transparent_placeholder.png", | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| ] as any, | ||
| "en/tidbcloud/master/TOC" | ||
| ); | ||
|
|
||
| expect(toc[0].tag).toEqual({ | ||
| value: "PREVIEW", | ||
| query: undefined, | ||
| }); | ||
| }); | ||
|
|
||
| it("does not create a tag when the TOC image has no alt text", () => { | ||
| const toc = mdxAstToToc( | ||
| [ | ||
| { | ||
| type: "list", | ||
| children: [ | ||
| { | ||
| type: "listItem", | ||
| children: [ | ||
| { | ||
| type: "paragraph", | ||
| children: [ | ||
| { type: "text", value: "Data Service" }, | ||
| { | ||
| type: "image", | ||
| alt: null, | ||
| url: "/media/tidb-cloud/blank_transparent_placeholder.png", | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| ] as any, | ||
| "en/tidbcloud/master/TOC" | ||
| ); | ||
|
|
||
| expect(toc[0].tag).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("keeps tag query params when the image URL includes them", () => { | ||
| const toc = mdxAstToToc( | ||
| [ | ||
| { | ||
| type: "list", | ||
| children: [ | ||
| { | ||
| type: "listItem", | ||
| children: [ | ||
| { | ||
| type: "paragraph", | ||
| children: [ | ||
| { type: "text", value: "Beta Feature" }, | ||
| { | ||
| type: "image", | ||
| alt: "BETA", | ||
| url: "/media/tidb-cloud/blank_transparent_placeholder.png?color=%232d9cd2", | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| ] as any, | ||
| "en/tidbcloud/master/TOC" | ||
| ); | ||
|
|
||
| expect(toc[0].tag).toEqual({ | ||
| value: "BETA", | ||
| query: "?color=%232d9cd2", | ||
| }); | ||
| }); | ||
| }); |
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
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,29 @@ | ||
| import Chip from "@mui/material/Chip"; | ||
| import { useTheme } from "@mui/material/styles"; | ||
|
|
||
| const PreviewBadge = (props: { label: string }) => { | ||
| const theme = useTheme(); | ||
|
|
||
| return ( | ||
| <Chip | ||
| label={props.label} | ||
| size="small" | ||
| variant="outlined" | ||
| sx={{ | ||
| height: "20px", | ||
| fontSize: "12px", | ||
| fontWeight: 400, | ||
| borderRadius: "10px", | ||
| pointerEvents: "none", | ||
| "& .MuiChip-label": { | ||
| paddingLeft: "8px", | ||
| paddingRight: "8px", | ||
| lineHeight: "20px", | ||
| color: theme.palette.carbon[700], | ||
| }, | ||
| }} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default PreviewBadge; |
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
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.
Uh oh!
There was an error while loading. Please reload this page.