-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Fran McDade <[email protected]>
- Loading branch information
Showing
14 changed files
with
274 additions
and
2 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
...components/Footer/components/VersionInfo/components/Tooltip/components/Title/constants.ts
This file contains 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,5 @@ | ||
import { LinkOwnProps } from "@mui/material"; | ||
|
||
export const LINK_PROPS: Partial<LinkOwnProps> = { | ||
color: "inherit", | ||
}; |
53 changes: 53 additions & 0 deletions
53
...ut/components/Footer/components/VersionInfo/components/Tooltip/components/Title/title.tsx
This file contains 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,53 @@ | ||
import { Typography } from "@mui/material"; | ||
import React from "react"; | ||
import { useConfig } from "../../../../../../../../../../hooks/useConfig"; | ||
import { TEXT_BODY_SMALL_400_2_LINES } from "../../../../../../../../../../theme/common/typography"; | ||
import { Link } from "../../../../../../../../../Links/components/Link/link"; | ||
import { VersionInfoProps } from "../../../../types"; | ||
import { getGitHash, getVersion } from "../../../../utils"; | ||
import { LINK_PROPS } from "./constants"; | ||
import { getCommitUrl, getReleaseUrl } from "./utils"; | ||
|
||
export const Title = ({ | ||
versionInfo, | ||
}: Pick<VersionInfoProps, "versionInfo">): JSX.Element | null => { | ||
const { | ||
config: { gitHubUrl }, | ||
} = useConfig(); | ||
if (!versionInfo) return null; | ||
const { buildDate, catalog, gitHash, version } = versionInfo; | ||
return ( | ||
<Typography component="div" variant={TEXT_BODY_SMALL_400_2_LINES}> | ||
{buildDate && ( | ||
<div> | ||
<span>Build Date: </span> | ||
<span>{buildDate}</span> | ||
</div> | ||
)} | ||
<div> | ||
<span>Version: </span> | ||
<Link | ||
{...LINK_PROPS} | ||
label={getVersion(version)} | ||
url={getReleaseUrl(gitHubUrl, versionInfo)} | ||
/> | ||
</div> | ||
{gitHash && ( | ||
<div> | ||
<span>Git Commit: </span> | ||
<Link | ||
{...LINK_PROPS} | ||
label={getGitHash(gitHash)} | ||
url={getCommitUrl(gitHubUrl, versionInfo)} | ||
/> | ||
</div> | ||
)} | ||
{catalog && ( | ||
<div> | ||
<span>Catalog: </span> | ||
<span>{catalog}</span> | ||
</div> | ||
)} | ||
</Typography> | ||
); | ||
}; |
31 changes: 31 additions & 0 deletions
31
...out/components/Footer/components/VersionInfo/components/Tooltip/components/Title/utils.ts
This file contains 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,31 @@ | ||
import { VersionInfo } from "../../../../types"; | ||
|
||
/** | ||
* Returns GitHub commit URL for the given git hash. | ||
* @param gitHubRepoUrl - GitHub repository URL. | ||
* @param versionInfo - Version info. | ||
* @returns GitHub commit URL. | ||
*/ | ||
export function getCommitUrl( | ||
gitHubRepoUrl?: string, | ||
versionInfo?: VersionInfo | ||
): string { | ||
if (!gitHubRepoUrl || !versionInfo) return ""; | ||
if (!versionInfo.gitHash) return ""; | ||
return `${gitHubRepoUrl}/commit/${versionInfo.gitHash}`; | ||
} | ||
|
||
/** | ||
* Returns GitHub release URL for the given release version. | ||
* @param gitHubRepoUrl - GitHub repository URL. | ||
* @param versionInfo - Version info. | ||
* @returns GitHub release URL. | ||
*/ | ||
export function getReleaseUrl( | ||
gitHubRepoUrl?: string, | ||
versionInfo?: VersionInfo | ||
): string { | ||
if (!gitHubRepoUrl || !versionInfo) return ""; | ||
if (!versionInfo.version) return ""; | ||
return `${gitHubRepoUrl}/releases/tag/${versionInfo.version}`; | ||
} |
30 changes: 30 additions & 0 deletions
30
src/components/Layout/components/Footer/components/VersionInfo/constants.ts
This file contains 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,30 @@ | ||
import { ChipProps, TooltipProps } from "@mui/material"; | ||
import { CHIP_PROPS as MUI_CHIP_PROPS } from "../../../../../../styles/common/mui/chip"; | ||
|
||
export const CHIP_PROPS: Partial<ChipProps> = { | ||
color: MUI_CHIP_PROPS.COLOR.DEFAULT, | ||
size: MUI_CHIP_PROPS.SIZE.SMALL, | ||
}; | ||
|
||
export const TOOLTIP_PROPS: Partial<TooltipProps> = { | ||
arrow: true, | ||
slotProps: { | ||
popper: { | ||
modifiers: [ | ||
{ | ||
name: "offset", | ||
options: { | ||
offset: [0, -4], | ||
}, | ||
}, | ||
{ | ||
name: "preventOverflow", | ||
options: { padding: 8 }, | ||
}, | ||
], | ||
}, | ||
tooltip: { | ||
sx: { maxWidth: "none" }, | ||
}, | ||
}, | ||
}; |
14 changes: 14 additions & 0 deletions
14
src/components/Layout/components/Footer/components/VersionInfo/types.ts
This file contains 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,14 @@ | ||
import { ChipProps, TooltipProps } from "@mui/material"; | ||
|
||
export interface VersionInfo { | ||
buildDate?: string; | ||
catalog?: string; | ||
gitHash?: string; | ||
version?: string; | ||
} | ||
|
||
export interface VersionInfoProps { | ||
chipProps?: Partial<ChipProps>; | ||
tooltipProps?: Partial<TooltipProps>; | ||
versionInfo?: VersionInfo; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/components/Layout/components/Footer/components/VersionInfo/utils.ts
This file contains 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,32 @@ | ||
import { VersionInfo } from "./types"; | ||
|
||
/** | ||
* Returns displayable shortened version of Git hash. | ||
* @param gitHash - Git hash. | ||
* @returns displayable shortened version of Git hash. | ||
*/ | ||
export function getGitHash(gitHash?: string): string | undefined { | ||
return gitHash?.substring(0, 7); | ||
} | ||
|
||
/** | ||
* Returns Chip label based on version info. | ||
* @param versionInfo - Version info. | ||
* @returns Chip label. | ||
*/ | ||
export function getLabel(versionInfo?: VersionInfo): string | undefined { | ||
if (!versionInfo) return; | ||
const { catalog, gitHash, version } = versionInfo; | ||
return [getVersion(version), getGitHash(gitHash), catalog] | ||
.filter(Boolean) | ||
.join("-"); | ||
} | ||
|
||
/** | ||
* Returns displayable version, or "Unversioned" if version is not provided. | ||
* @param version - Version info. | ||
* @returns Version. | ||
*/ | ||
export function getVersion(version?: string): string { | ||
return version || "Unversioned"; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/components/Layout/components/Footer/components/VersionInfo/versionInfo.styles.ts
This file contains 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,10 @@ | ||
import styled from "@emotion/styled"; | ||
import { Chip } from "@mui/material"; | ||
import { inkLight } from "../../../../../../styles/common/mixins/colors"; | ||
|
||
export const StyledChip = styled(Chip)` | ||
border-radius: 4px; | ||
.MuiChip-label { | ||
color: ${inkLight}; | ||
} | ||
`; |
31 changes: 31 additions & 0 deletions
31
src/components/Layout/components/Footer/components/VersionInfo/versionInfo.tsx
This file contains 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,31 @@ | ||
import { Tooltip } from "@mui/material"; | ||
import React from "react"; | ||
import { BaseComponentProps } from "../../../../../types"; | ||
import { Title } from "./components/Tooltip/components/Title/title"; | ||
import { CHIP_PROPS, TOOLTIP_PROPS } from "./constants"; | ||
import { VersionInfoProps } from "./types"; | ||
|
||
import { getLabel } from "./utils"; | ||
import { StyledChip } from "./versionInfo.styles"; | ||
|
||
export const VersionInfo = ({ | ||
chipProps, | ||
className, | ||
tooltipProps, | ||
versionInfo, | ||
}: BaseComponentProps & VersionInfoProps): JSX.Element | null => { | ||
return ( | ||
<Tooltip | ||
{...TOOLTIP_PROPS} | ||
title={<Title versionInfo={versionInfo} />} | ||
{...tooltipProps} | ||
> | ||
<StyledChip | ||
{...CHIP_PROPS} | ||
className={className} | ||
label={getLabel(versionInfo)} | ||
{...chipProps} | ||
/> | ||
</Tooltip> | ||
); | ||
}; |
This file contains 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 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 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 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 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,36 @@ | ||
import { ChipProps } from "@mui/material"; | ||
|
||
type ChipPropsOptions = { | ||
COLOR: typeof COLOR; | ||
SIZE: typeof SIZE; | ||
VARIANT: typeof VARIANT; | ||
}; | ||
|
||
const COLOR: Record<string, ChipProps["color"]> = { | ||
DEFAULT: "default", | ||
ERROR: "error", | ||
INFO: "info", | ||
PRIMARY: "primary", | ||
SECONDARY: "secondary", | ||
SUCCESS: "success", | ||
WARNING: "warning", | ||
}; | ||
|
||
const SIZE: Record<string, ChipProps["size"]> = { | ||
MEDIUM: "medium", | ||
SMALL: "small", | ||
}; | ||
|
||
const VARIANT: Record<string, ChipProps["variant"]> = { | ||
FILLED: "filled", | ||
FILTER_TAG: "filterTag", | ||
N_TAG: "ntag", | ||
OUTLINED: "outlined", | ||
STATUS: "status", | ||
}; | ||
|
||
export const CHIP_PROPS: ChipPropsOptions = { | ||
COLOR, | ||
SIZE, | ||
VARIANT, | ||
}; |
This file contains 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