From 4a31c95b6b8432519ac3d5fa6dbe2d4fc308de0c Mon Sep 17 00:00:00 2001 From: Icemap Date: Mon, 30 Oct 2023 14:23:19 +0800 Subject: [PATCH 1/8] feat: version-compare-component --- locale/en/translation.json | 17 ++ locale/ja/translation.json | 17 ++ locale/zh/translation.json | 17 ++ src/components/MDXComponents/VersionVars.tsx | 60 ++++ .../MDXComponents/VersionVarsFilter.tsx | 274 ++++++++++++++++++ src/components/MDXComponents/index.tsx | 3 + 6 files changed, 388 insertions(+) create mode 100644 src/components/MDXComponents/VersionVars.tsx create mode 100644 src/components/MDXComponents/VersionVarsFilter.tsx diff --git a/locale/en/translation.json b/locale/en/translation.json index 552b0594e..a3b900014 100644 --- a/locale/en/translation.json +++ b/locale/en/translation.json @@ -117,5 +117,22 @@ "fab": { "scrollToTop": "Scroll to top", "goToFeedback": "Was this page helpful?" + }, + "versionFilter": { + "yes": "Yes", + "no": "No", + "filterModeVersion": "Version", + "filterModeDiff": "Diff", + "diffModeOlderVersion": "Older Version", + "diffModeNewerVersion": "Newer Version", + "involvedInitVersion": "From the beginning", + "involvedVersion": "New in {{version}}", + "type": "Type: ", + "persists": "Persists to cluster: ", + "hintSetVar": "Applies to hint SET_VAR: ", + "default": "Default value: ", + "range": "Range: ", + "possibleValues": "Possible values: ", + "unit": "Unit: " } } diff --git a/locale/ja/translation.json b/locale/ja/translation.json index 850bc9ec6..068864973 100644 --- a/locale/ja/translation.json +++ b/locale/ja/translation.json @@ -117,5 +117,22 @@ "fab": { "scrollToTop": "トップへ戻る", "goToFeedback": "このページは役に立ちましたか?" + }, + "versionFilter": { + "yes": "はい", + "no": "いいえ", + "filterModeVersion": "バージョン", + "filterModeDiff": "差異", + "diffModeOlderVersion": "古いバージョン", + "diffModeNewerVersion": "新しいバージョン", + "involvedInitVersion": "最初から", + "involvedVersion": "{{version}} から新しい", + "type": "タイプ:", + "persists": "クラスターに保持:", + "hintSetVar": "ヒント SET_VAR に適用:", + "default": "デフォルト値:", + "range": "範囲:", + "possibleValues": "可能な値:", + "unit": "単位:" } } diff --git a/locale/zh/translation.json b/locale/zh/translation.json index a3e849298..a80ffc60f 100644 --- a/locale/zh/translation.json +++ b/locale/zh/translation.json @@ -114,5 +114,22 @@ "fab": { "scrollToTop": "回到顶部", "goToFeedback": "文档内容是否有帮助?" + }, + "versionFilter": { + "yes": "是", + "no": "否", + "filterModeVersion": "版本号", + "filterModeDiff": "差异比较", + "diffModeOlderVersion": "较旧版本", + "diffModeNewerVersion": "较新版本", + "involvedInitVersion": "初始版本引入", + "involvedVersion": "从 {{version}} 版本开始引入", + "type": "类型:", + "persists": "是否持久化到集群:", + "hintSetVar": "是否受 Hint SET_VAR 控制:", + "default": "默认值:", + "range": "范围:", + "possibleValues": "可选值:", + "unit": "单位:" } } diff --git a/src/components/MDXComponents/VersionVars.tsx b/src/components/MDXComponents/VersionVars.tsx new file mode 100644 index 000000000..74b37a76d --- /dev/null +++ b/src/components/MDXComponents/VersionVars.tsx @@ -0,0 +1,60 @@ +import * as React from "react"; +import Stack from "@mui/material/Stack"; +import Typography from "@mui/material/Typography"; +import { Card, CardContent, Chip } from '@mui/material'; + +type ScopeType = "SESSION" | "GLOBAL" | "BOTH"; + +export function VersionVars(props: { + name: string; + scope: ScopeType; + type: string; + applyHint: boolean; + defaultValue: string; + involveVersion?: string; + possibleValues?: string; + range?: string; + unit?: string; + children?: any; + }) { + + const INIT_VERSION = "v0.0.1" + const { + name = "", + involveVersion = INIT_VERSION, + scope = "GLOBAL", + type = "", + applyHint = false, + defaultValue = "", + children = [], + possibleValues = "", + range = "", + unit = "", + } = props; + + return ( + + + {name} + + { involveVersion === INIT_VERSION ? "From the beginning" : "New in " + involveVersion } + + + {scope === "SESSION" || scope === "BOTH" ? : null} + {scope === "GLOBAL" || scope === "BOTH" ? : null} + + + Type: {type} + Applies to hint SET_VAR: {applyHint ? "Yes" : "No"} + Default value: {defaultValue} + {range === "" ? "" : Range: {range} } + {possibleValues === "" ? "" : Possible values: {possibleValues} } + {unit === "" ? "" : Unit: {unit} } + + + {...children} + + + + ); +} \ No newline at end of file diff --git a/src/components/MDXComponents/VersionVarsFilter.tsx b/src/components/MDXComponents/VersionVarsFilter.tsx new file mode 100644 index 000000000..6d911a94d --- /dev/null +++ b/src/components/MDXComponents/VersionVarsFilter.tsx @@ -0,0 +1,274 @@ +import * as React from "react"; +import Stack from "@mui/material/Stack"; +import Typography from "@mui/material/Typography"; +import { Link, Trans, useI18next } from "gatsby-plugin-react-i18next"; +import { Container, Autocomplete, TextField, ToggleButtonGroup, ToggleButton, Card, CardContent, Chip, Accordion, AccordionDetails, AccordionSummary } from '@mui/material'; + +type FilterType = "version" | "diff"; +type ScopeType = "SESSION" | "GLOBAL" | "BOTH"; + +export function VersionVarsFilter(props: { + versions: string; + children?: React.FC[]; + }) { + + const [filterType, setFilterType] = React.useState("version"); + const [version, setVersion] = React.useState(""); + const [startVersion, setStartVersion] = React.useState(""); + const [endVersion, setEndVersion] = React.useState(""); + + const { + versions = "", + children = [], + } = props; + + const versionArray = versions.split(","); + + const compareVersions = (ver1: string, ver2: string) => { + if (ver1.startsWith("v")) { + ver1 = ver1.substring(1); + } + + if (ver2.startsWith("v")) { + ver2 = ver2.substring(1); + } + + const ver1Array = ver1.split("."); + const ver2Array = ver2.split("."); + + if (ver1Array.length !== 3 || ver2Array.length !== 3) { + console.log(ver1, ver2); + throw new Error("Version format is incorrect"); + } + + for (let i = 0; i < ver1Array.length; i++) { + if (parseInt(ver1Array[i]) > parseInt(ver2Array[i])) { + return 1; + } else if (parseInt(ver1Array[i]) < parseInt(ver2Array[i])) { + return -1; + } + } + return 0; + } + + versionArray.sort((a, b) => -compareVersions(a, b)); + + const MIN_VERSION = "v0.0.0"; + const MAX_VERSION = "v999.999.999"; + const filterVersion = (versions: string[], includeEqual: boolean, left?: string|null, right?: string|null) => { + return versions.filter((version) => { + if (left === undefined || left === null || left === "") { + left = MIN_VERSION; + } + + if (right === undefined || right === null || right === "") { + right = MAX_VERSION; + } + + let leftCompare = compareVersions(version, left); + let rightCompare = compareVersions(right, version); + let standard = includeEqual ? 0 : 1; + + return leftCompare >= standard && rightCompare >= standard; + }); + } + + const filterVersionVars = (children: any[]) => { + if (!Array.isArray(children)) { + children = [children]; + } + + return children.map((child) => { + if (child.props?.mdxType !== VersionVars.name) { + // It's not of the filter scope, skip it. + return child; + } + + if (filterType === "version" && version === "") { + // No version is selected, skip it. + return ; + } + + if (filterType === "diff" && (startVersion === "" || endVersion === "")) { + // No version is selected, skip it. + return ; + } + + let involveVersion = child.props.involveVersion; + if (!involveVersion) { + involveVersion = "v0.0.1"; + } + + if (filterType === "version" && compareVersions(version!, involveVersion) >= 0) { + return ( + + ) + } + + if (filterType === "diff" && + compareVersions(startVersion!, involveVersion) <= 0 && + compareVersions(involveVersion, endVersion!) <= 0) { + return ( + + ) + } + + return ""; + }); + } + + const { language } = useI18next(); + + return ( +
+ + { + setFilterType(newMode); + }} + aria-label="filter type" + > + + + + + + + + + {filterType === "version" && ( + {setVersion(newVersion == null ? "" : newVersion)}} + sx={{ width: 200, margin: 1 }} + renderInput={(params) => } />} + /> + )} + + {filterType === "diff" && ( + + { + setStartVersion(newVersion ? newVersion : "") + }} + renderInput={(params) => } />} + /> + + {setEndVersion(newVersion ? newVersion : "")}} + renderInput={(params) => } />} + /> + + )} + + + + {filterVersionVars(children)} + +
+ ); +} + + +export function VersionVars(props: { + name: string; + scope: ScopeType; + type?: string; + applyHint: string; + defaultValue: string; + persists?: string; + involveVersion?: string; + possibleValues?: string; + range?: string; + unit?: string; + children?: any; + }) { + + const INIT_VERSION = "v0.0.1" + const { + name = "", + involveVersion = INIT_VERSION, + scope = "GLOBAL", + type = "", + applyHint = "false", + defaultValue = "", + children = [], + possibleValues = "", + range = "", + unit = "", + } = props; + + const yesOrNoI18n = (value: string) => { + return value === "true" ? : ; + } + + return ( + + + + {name} + + {scope === "SESSION" || scope === "BOTH" ? : null} + {scope === "GLOBAL" || scope === "BOTH" ? : null} + + + + { involveVersion === INIT_VERSION ? + : + } + + {type === "" ? "" : {type} } + {props.persists === undefined ? "" : {yesOrNoI18n(props.persists)}} + {yesOrNoI18n(applyHint)} + {defaultValue} + {range === "" ? "" : {range} } + {possibleValues === "" ? "" : {possibleValues} } + {unit === "" ? "" : {unit} } + + + {children} + + ); +} \ No newline at end of file diff --git a/src/components/MDXComponents/index.tsx b/src/components/MDXComponents/index.tsx index df02beaea..f04898cd7 100644 --- a/src/components/MDXComponents/index.tsx +++ b/src/components/MDXComponents/index.tsx @@ -25,3 +25,6 @@ export { DocHomeCard, } from "components/MDXComponents/DocHome"; export { MDSvgIcon } from "components/MDXComponents/MDSvgIcon"; +export { + VersionVarsFilter, +} from "components/MDXComponents/VersionVarsFilter"; From b6b5ab9a21235d0e94d2d66dc85171bb250c336c Mon Sep 17 00:00:00 2001 From: czhen <56986964+shczhen@users.noreply.github.com> Date: Mon, 30 Oct 2023 14:44:38 +0800 Subject: [PATCH 2/8] feat: mdx components support context --- src/components/Layout/MDXContent.tsx | 21 ++++++++++++------- .../MDXComponents/VersionVarsFilter.tsx | 5 +++++ src/context/MdxContext.tsx | 8 +++++++ 3 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 src/context/MdxContext.tsx diff --git a/src/components/Layout/MDXContent.tsx b/src/components/Layout/MDXContent.tsx index 692ce12c6..28c55f73b 100644 --- a/src/components/Layout/MDXContent.tsx +++ b/src/components/Layout/MDXContent.tsx @@ -17,6 +17,7 @@ import { Locale, PathConfig, FrontMatter, BuildType } from "static/Type"; import { useTotalContributors } from "components/Avatar/Contributors"; import replaceInternalHref from "utils/anchor"; import { Pre } from "components/MDXComponents/Pre"; +import { MdxContext } from "context/MdxContext"; export default function MDXContent(props: { data: any; @@ -74,15 +75,19 @@ export default function MDXContent(props: { availIn={availIn} /> )} - - {data} - + + {data} + + ); diff --git a/src/components/MDXComponents/VersionVarsFilter.tsx b/src/components/MDXComponents/VersionVarsFilter.tsx index 6d911a94d..04612c0f8 100644 --- a/src/components/MDXComponents/VersionVarsFilter.tsx +++ b/src/components/MDXComponents/VersionVarsFilter.tsx @@ -4,6 +4,8 @@ import Typography from "@mui/material/Typography"; import { Link, Trans, useI18next } from "gatsby-plugin-react-i18next"; import { Container, Autocomplete, TextField, ToggleButtonGroup, ToggleButton, Card, CardContent, Chip, Accordion, AccordionDetails, AccordionSummary } from '@mui/material'; +import { MdxContext } from "context/MdxContext"; + type FilterType = "version" | "diff"; type ScopeType = "SESSION" | "GLOBAL" | "BOTH"; @@ -17,6 +19,9 @@ export function VersionVarsFilter(props: { const [startVersion, setStartVersion] = React.useState(""); const [endVersion, setEndVersion] = React.useState(""); + const mdxContextData = React.useContext(MdxContext); + const { version: ctxVersion, language: ctxLang } = mdxContextData; + const { versions = "", children = [], diff --git a/src/context/MdxContext.tsx b/src/context/MdxContext.tsx new file mode 100644 index 000000000..207be048e --- /dev/null +++ b/src/context/MdxContext.tsx @@ -0,0 +1,8 @@ +import * as React from "react"; + +export const DefalutMdxContext = { + version: "", + language: "", +}; + +export const MdxContext = React.createContext(DefalutMdxContext); From 2863a10794aa8b4eb4abe1b55f862331c8763498 Mon Sep 17 00:00:00 2001 From: Icemap Date: Mon, 30 Oct 2023 15:52:15 +0800 Subject: [PATCH 3/8] feat: i18n and markdown link component --- locale/en/translation.json | 2 +- locale/ja/translation.json | 2 +- locale/zh/translation.json | 2 +- src/components/MDXComponents/MDLink.tsx | 21 +++++++++++++++++++ .../MDXComponents/VersionVarsFilter.tsx | 7 ++----- src/context/MdxContext.tsx | 15 ++++++++++--- src/templates/DocTemplate.tsx | 2 +- 7 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 src/components/MDXComponents/MDLink.tsx diff --git a/locale/en/translation.json b/locale/en/translation.json index a3b900014..3300de21d 100644 --- a/locale/en/translation.json +++ b/locale/en/translation.json @@ -129,7 +129,7 @@ "involvedVersion": "New in {{version}}", "type": "Type: ", "persists": "Persists to cluster: ", - "hintSetVar": "Applies to hint SET_VAR: ", + "hintSetVar": "Applies to hint <0>SET_VAR: ", "default": "Default value: ", "range": "Range: ", "possibleValues": "Possible values: ", diff --git a/locale/ja/translation.json b/locale/ja/translation.json index 068864973..21b788883 100644 --- a/locale/ja/translation.json +++ b/locale/ja/translation.json @@ -129,7 +129,7 @@ "involvedVersion": "{{version}} から新しい", "type": "タイプ:", "persists": "クラスターに保持:", - "hintSetVar": "ヒント SET_VAR に適用:", + "hintSetVar": "ヒント <0>SET_VAR に適用:", "default": "デフォルト値:", "range": "範囲:", "possibleValues": "可能な値:", diff --git a/locale/zh/translation.json b/locale/zh/translation.json index a80ffc60f..afd2182c1 100644 --- a/locale/zh/translation.json +++ b/locale/zh/translation.json @@ -126,7 +126,7 @@ "involvedVersion": "从 {{version}} 版本开始引入", "type": "类型:", "persists": "是否持久化到集群:", - "hintSetVar": "是否受 Hint SET_VAR 控制:", + "hintSetVar": "是否受 Hint <0>SET_VAR 控制:", "default": "默认值:", "range": "范围:", "possibleValues": "可选值:", diff --git a/src/components/MDXComponents/MDLink.tsx b/src/components/MDXComponents/MDLink.tsx new file mode 100644 index 000000000..a1ff7f1b8 --- /dev/null +++ b/src/components/MDXComponents/MDLink.tsx @@ -0,0 +1,21 @@ +import * as React from "react"; + +import { MdxContext } from "context/MdxContext"; +import { Link } from "gatsby-plugin-react-i18next"; +import { Locale } from "static/Type"; + +export function MDLink(props: { + url: string; + children?: any; + }) { + const mdxContextData = React.useContext(MdxContext); + const { pathConfig } = mdxContextData; + const {url} = props; + const localeURL = pathConfig.locale === Locale.en ? "" : "/" + pathConfig.locale; + const relativeURL = url.startsWith("/") ? url : "/" + url; + const realURL = localeURL + "/" + pathConfig.repo + "/" + pathConfig.version + relativeURL; + + return ( + {props.children} + ) +} \ No newline at end of file diff --git a/src/components/MDXComponents/VersionVarsFilter.tsx b/src/components/MDXComponents/VersionVarsFilter.tsx index 04612c0f8..f3c7abdd9 100644 --- a/src/components/MDXComponents/VersionVarsFilter.tsx +++ b/src/components/MDXComponents/VersionVarsFilter.tsx @@ -3,8 +3,8 @@ import Stack from "@mui/material/Stack"; import Typography from "@mui/material/Typography"; import { Link, Trans, useI18next } from "gatsby-plugin-react-i18next"; import { Container, Autocomplete, TextField, ToggleButtonGroup, ToggleButton, Card, CardContent, Chip, Accordion, AccordionDetails, AccordionSummary } from '@mui/material'; +import { MDLink } from "./MDLink"; -import { MdxContext } from "context/MdxContext"; type FilterType = "version" | "diff"; type ScopeType = "SESSION" | "GLOBAL" | "BOTH"; @@ -19,9 +19,6 @@ export function VersionVarsFilter(props: { const [startVersion, setStartVersion] = React.useState(""); const [endVersion, setEndVersion] = React.useState(""); - const mdxContextData = React.useContext(MdxContext); - const { version: ctxVersion, language: ctxLang } = mdxContextData; - const { versions = "", children = [], @@ -266,7 +263,7 @@ export function VersionVars(props: { {type === "" ? "" : {type} } {props.persists === undefined ? "" : {yesOrNoI18n(props.persists)}} - {yesOrNoI18n(applyHint)} + ]}/> {yesOrNoI18n(applyHint)} {defaultValue} {range === "" ? "" : {range} } {possibleValues === "" ? "" : {possibleValues} } diff --git a/src/context/MdxContext.tsx b/src/context/MdxContext.tsx index 207be048e..fcfe8f0c0 100644 --- a/src/context/MdxContext.tsx +++ b/src/context/MdxContext.tsx @@ -1,8 +1,17 @@ import * as React from "react"; +import { Locale, PathConfig, Repo } from "static/Type"; -export const DefalutMdxContext = { - version: "", - language: "", +interface IDefalutMdxContext { + pathConfig: PathConfig; +} + +export const DefalutMdxContext: IDefalutMdxContext = { + pathConfig: { + repo: Repo.tidb, + locale: Locale.en, + branch: "dev", + version: null + } }; export const MdxContext = React.createContext(DefalutMdxContext); diff --git a/src/templates/DocTemplate.tsx b/src/templates/DocTemplate.tsx index 439be158a..108b4f964 100644 --- a/src/templates/DocTemplate.tsx +++ b/src/templates/DocTemplate.tsx @@ -67,7 +67,7 @@ export default function DocTemplate({ const stableBranch = getStable(pathConfig.repo); const { language } = useI18next(); - + console.log(pathConfig); return ( <> Date: Mon, 30 Oct 2023 15:52:52 +0800 Subject: [PATCH 4/8] feat: i18n and markdown link component --- src/components/Layout/MDXContent.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Layout/MDXContent.tsx b/src/components/Layout/MDXContent.tsx index 28c55f73b..1346b4537 100644 --- a/src/components/Layout/MDXContent.tsx +++ b/src/components/Layout/MDXContent.tsx @@ -76,7 +76,7 @@ export default function MDXContent(props: { /> )} Date: Tue, 31 Oct 2023 10:20:13 +0800 Subject: [PATCH 5/8] remove: useless output log --- src/templates/DocTemplate.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/templates/DocTemplate.tsx b/src/templates/DocTemplate.tsx index 108b4f964..b8166d0a0 100644 --- a/src/templates/DocTemplate.tsx +++ b/src/templates/DocTemplate.tsx @@ -65,9 +65,8 @@ export default function DocTemplate({ }, [tableOfContents.items]); const stableBranch = getStable(pathConfig.repo); - const { language } = useI18next(); - console.log(pathConfig); + return ( <> Date: Tue, 31 Oct 2023 11:54:16 +0800 Subject: [PATCH 6/8] feat: wording and remove version type --- locale/en/translation.json | 5 +- locale/ja/translation.json | 5 +- locale/zh/translation.json | 5 +- .../MDXComponents/VersionVarsFilter.tsx | 115 ++++++------------ 4 files changed, 40 insertions(+), 90 deletions(-) diff --git a/locale/en/translation.json b/locale/en/translation.json index 3300de21d..5beccce1e 100644 --- a/locale/en/translation.json +++ b/locale/en/translation.json @@ -121,12 +121,11 @@ "versionFilter": { "yes": "Yes", "no": "No", - "filterModeVersion": "Version", "filterModeDiff": "Diff", "diffModeOlderVersion": "Older Version", "diffModeNewerVersion": "Newer Version", - "involvedInitVersion": "From the beginning", - "involvedVersion": "New in {{version}}", + "introducedInitVersion": "From the beginning", + "introducedVersion": "New in {{version}}", "type": "Type: ", "persists": "Persists to cluster: ", "hintSetVar": "Applies to hint <0>SET_VAR: ", diff --git a/locale/ja/translation.json b/locale/ja/translation.json index 21b788883..0e54fab11 100644 --- a/locale/ja/translation.json +++ b/locale/ja/translation.json @@ -121,12 +121,11 @@ "versionFilter": { "yes": "はい", "no": "いいえ", - "filterModeVersion": "バージョン", "filterModeDiff": "差異", "diffModeOlderVersion": "古いバージョン", "diffModeNewerVersion": "新しいバージョン", - "involvedInitVersion": "最初から", - "involvedVersion": "{{version}} から新しい", + "introducedInitVersion": "最初から", + "introducedVersion": "{{version}} から新しい", "type": "タイプ:", "persists": "クラスターに保持:", "hintSetVar": "ヒント <0>SET_VAR に適用:", diff --git a/locale/zh/translation.json b/locale/zh/translation.json index afd2182c1..6835e6f3f 100644 --- a/locale/zh/translation.json +++ b/locale/zh/translation.json @@ -118,12 +118,11 @@ "versionFilter": { "yes": "是", "no": "否", - "filterModeVersion": "版本号", "filterModeDiff": "差异比较", "diffModeOlderVersion": "较旧版本", "diffModeNewerVersion": "较新版本", - "involvedInitVersion": "初始版本引入", - "involvedVersion": "从 {{version}} 版本开始引入", + "introducedInitVersion": "初始版本引入", + "introducedVersion": "从 {{version}} 版本开始引入", "type": "类型:", "persists": "是否持久化到集群:", "hintSetVar": "是否受 Hint <0>SET_VAR 控制:", diff --git a/src/components/MDXComponents/VersionVarsFilter.tsx b/src/components/MDXComponents/VersionVarsFilter.tsx index f3c7abdd9..3adc5a774 100644 --- a/src/components/MDXComponents/VersionVarsFilter.tsx +++ b/src/components/MDXComponents/VersionVarsFilter.tsx @@ -5,8 +5,6 @@ import { Link, Trans, useI18next } from "gatsby-plugin-react-i18next"; import { Container, Autocomplete, TextField, ToggleButtonGroup, ToggleButton, Card, CardContent, Chip, Accordion, AccordionDetails, AccordionSummary } from '@mui/material'; import { MDLink } from "./MDLink"; - -type FilterType = "version" | "diff"; type ScopeType = "SESSION" | "GLOBAL" | "BOTH"; export function VersionVarsFilter(props: { @@ -14,8 +12,6 @@ export function VersionVarsFilter(props: { children?: React.FC[]; }) { - const [filterType, setFilterType] = React.useState("version"); - const [version, setVersion] = React.useState(""); const [startVersion, setStartVersion] = React.useState(""); const [endVersion, setEndVersion] = React.useState(""); @@ -86,30 +82,18 @@ export function VersionVarsFilter(props: { return child; } - if (filterType === "version" && version === "") { - // No version is selected, skip it. - return ; - } - - if (filterType === "diff" && (startVersion === "" || endVersion === "")) { + if (startVersion === "" || endVersion === "") { // No version is selected, skip it. return ; } - let involveVersion = child.props.involveVersion; - if (!involveVersion) { - involveVersion = "v0.0.1"; - } - - if (filterType === "version" && compareVersions(version!, involveVersion) >= 0) { - return ( - - ) + let introducedVersion = child.props.introducedVersion; + if (!introducedVersion) { + introducedVersion = "v0.0.1"; } - if (filterType === "diff" && - compareVersions(startVersion!, involveVersion) <= 0 && - compareVersions(involveVersion, endVersion!) <= 0) { + if (compareVersions(startVersion!, introducedVersion) <= 0 && + compareVersions(introducedVersion, endVersion!) <= 0) { return ( ) @@ -119,13 +103,12 @@ export function VersionVarsFilter(props: { }); } - const { language } = useI18next(); - return (
- { - setFilterType(newMode); - }} - aria-label="filter type" + - - - - - - - - - {filterType === "version" && ( +
Diff filter:
{setVersion(newVersion == null ? "" : newVersion)}} + id="start-version" + value={startVersion} + options={filterVersion(versionArray, false, MIN_VERSION, endVersion)} sx={{ width: 200, margin: 1 }} - renderInput={(params) => } />} + onChange={(_, newVersion) => { + setStartVersion(newVersion ? newVersion : "") + }} + renderInput={(params) => } />} /> - )} - - {filterType === "diff" && ( - - { - setStartVersion(newVersion ? newVersion : "") - }} - renderInput={(params) => } />} - /> - {setEndVersion(newVersion ? newVersion : "")}} - renderInput={(params) => } />} - /> - - )} + {setEndVersion(newVersion ? newVersion : "")}} + renderInput={(params) => } />} + /> +
- { involveVersion === INIT_VERSION ? - : - } + { introducedVersion === INIT_VERSION ? + : + } {type === "" ? "" : {type} } {props.persists === undefined ? "" : {yesOrNoI18n(props.persists)}} From 3626eefde811c456df1e6b8102bd2b9a98274b85 Mon Sep 17 00:00:00 2001 From: Icemap Date: Tue, 31 Oct 2023 11:57:20 +0800 Subject: [PATCH 7/8] feat: new tag i18n --- locale/en/translation.json | 2 +- locale/ja/translation.json | 2 +- locale/zh/translation.json | 2 +- src/components/MDXComponents/VersionVarsFilter.tsx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/locale/en/translation.json b/locale/en/translation.json index 5beccce1e..8976a33ba 100644 --- a/locale/en/translation.json +++ b/locale/en/translation.json @@ -121,7 +121,7 @@ "versionFilter": { "yes": "Yes", "no": "No", - "filterModeDiff": "Diff", + "diffLabel": "Diff filter:", "diffModeOlderVersion": "Older Version", "diffModeNewerVersion": "Newer Version", "introducedInitVersion": "From the beginning", diff --git a/locale/ja/translation.json b/locale/ja/translation.json index 0e54fab11..8308dd879 100644 --- a/locale/ja/translation.json +++ b/locale/ja/translation.json @@ -121,7 +121,7 @@ "versionFilter": { "yes": "はい", "no": "いいえ", - "filterModeDiff": "差異", + "diffLabel": "差分フィルタ:", "diffModeOlderVersion": "古いバージョン", "diffModeNewerVersion": "新しいバージョン", "introducedInitVersion": "最初から", diff --git a/locale/zh/translation.json b/locale/zh/translation.json index 6835e6f3f..3237322a4 100644 --- a/locale/zh/translation.json +++ b/locale/zh/translation.json @@ -118,7 +118,7 @@ "versionFilter": { "yes": "是", "no": "否", - "filterModeDiff": "差异比较", + "diffLabel": "差异过滤:", "diffModeOlderVersion": "较旧版本", "diffModeNewerVersion": "较新版本", "introducedInitVersion": "初始版本引入", diff --git a/src/components/MDXComponents/VersionVarsFilter.tsx b/src/components/MDXComponents/VersionVarsFilter.tsx index 3adc5a774..5a6879193 100644 --- a/src/components/MDXComponents/VersionVarsFilter.tsx +++ b/src/components/MDXComponents/VersionVarsFilter.tsx @@ -123,7 +123,7 @@ export function VersionVarsFilter(props: { direction="row" alignItems="center" > -
Diff filter:
+
Date: Tue, 31 Oct 2023 13:44:32 +0800 Subject: [PATCH 8/8] Delete src/components/MDXComponents/VersionVars.tsx Delete useless `VersionVars` --- src/components/MDXComponents/VersionVars.tsx | 60 -------------------- 1 file changed, 60 deletions(-) delete mode 100644 src/components/MDXComponents/VersionVars.tsx diff --git a/src/components/MDXComponents/VersionVars.tsx b/src/components/MDXComponents/VersionVars.tsx deleted file mode 100644 index 74b37a76d..000000000 --- a/src/components/MDXComponents/VersionVars.tsx +++ /dev/null @@ -1,60 +0,0 @@ -import * as React from "react"; -import Stack from "@mui/material/Stack"; -import Typography from "@mui/material/Typography"; -import { Card, CardContent, Chip } from '@mui/material'; - -type ScopeType = "SESSION" | "GLOBAL" | "BOTH"; - -export function VersionVars(props: { - name: string; - scope: ScopeType; - type: string; - applyHint: boolean; - defaultValue: string; - involveVersion?: string; - possibleValues?: string; - range?: string; - unit?: string; - children?: any; - }) { - - const INIT_VERSION = "v0.0.1" - const { - name = "", - involveVersion = INIT_VERSION, - scope = "GLOBAL", - type = "", - applyHint = false, - defaultValue = "", - children = [], - possibleValues = "", - range = "", - unit = "", - } = props; - - return ( - - - {name} - - { involveVersion === INIT_VERSION ? "From the beginning" : "New in " + involveVersion } - - - {scope === "SESSION" || scope === "BOTH" ? : null} - {scope === "GLOBAL" || scope === "BOTH" ? : null} - - - Type: {type} - Applies to hint SET_VAR: {applyHint ? "Yes" : "No"} - Default value: {defaultValue} - {range === "" ? "" : Range: {range} } - {possibleValues === "" ? "" : Possible values: {possibleValues} } - {unit === "" ? "" : Unit: {unit} } - - - {...children} - - - - ); -} \ No newline at end of file