-
-
Notifications
You must be signed in to change notification settings - Fork 119
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
* Fix Versions page closes #410, credits to EliasVal <3 Original author: https://github.com/EliasVal See #412 * Replace icons with text for better dark and light theme * Remove extra lines and comments * Update completed emoji for better dark and light theme * Update fontSize for arrow icon in versions list
- Loading branch information
Showing
14 changed files
with
514 additions
and
82 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
src/components/docs/versions/builds/build-failure-details.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,93 @@ | ||
import React, { useReducer } from 'react'; | ||
import CodeBlock from '@theme/CodeBlock'; | ||
|
||
interface Props { | ||
ciJob; | ||
ciBuild; | ||
repoVersionInfo; | ||
editorVersionInfo; | ||
style; | ||
} | ||
|
||
const BuildFailureDetails = ({ | ||
ciJob, | ||
repoVersionInfo, | ||
editorVersionInfo, | ||
ciBuild, | ||
...rest | ||
}: Props) => { | ||
const { editorVersion, baseOs, targetPlatform } = ciBuild.buildInfo; | ||
const { major, minor, patch } = repoVersionInfo; | ||
|
||
const reducer = (state, action) => { | ||
const { tag, value } = action; | ||
return { ...state, [tag]: value }; | ||
}; | ||
|
||
const [tags /* , dispatch */] = useReducer(reducer, { | ||
[`${baseOs}-${editorVersion}-${targetPlatform}-${major}`]: '❓', | ||
[`${baseOs}-${editorVersion}-${targetPlatform}-${major}.${minor}`]: '❓', | ||
[`${baseOs}-${editorVersion}-${targetPlatform}-${major}.${minor}.${patch}`]: '❓', | ||
[`${editorVersion}-${targetPlatform}-${major}`]: '❓', | ||
[`${editorVersion}-${targetPlatform}-${major}.${minor}`]: '❓', | ||
[`${editorVersion}-${targetPlatform}-${major}.${minor}.${patch}`]: '❓', | ||
}); | ||
|
||
// Todo - fetch docker info from dockerhub for all tags, or do it on the server | ||
// useEffect(() => { | ||
// (async () => { | ||
// const repo = 'unityci/editor'; | ||
// for (const tag of Object.keys(tags)) { | ||
// const requestUrl = `https://index.docker.io/v1/repositories/${repo}/tags/${tag}`; | ||
// try { | ||
// const response = await fetch(requestUrl); | ||
// dispatch({ tag, value: response.status === 0 }); | ||
// } catch (error) { | ||
// dispatch({ tag, value: false }); | ||
// } | ||
// } | ||
// })(); | ||
// }, []); | ||
|
||
const { changeSet } = editorVersionInfo; | ||
const buildCommand = `#!/usr/bin/env bash | ||
git clone git@github.com:game-ci/docker.git | ||
cd docker | ||
editor_version=${editorVersion} | ||
change_set=${changeSet} | ||
base_os=${baseOs} | ||
target_platform=${targetPlatform} | ||
image_name=unityci-editor:$editor_version-$target_platform | ||
docker build . \\ | ||
--file ./images/$base_os/editor/Dockerfile \\ | ||
-t $image_name \\ | ||
--build-arg=version=$editor_version \\ | ||
--build-arg=changeSet=$change_set \\ | ||
--build-arg=module=$target_platform | ||
`; | ||
|
||
const pullCommand = `docker pull unityci/editor:${baseOs}-${editorVersion}-${targetPlatform}-${major}.${minor}.${patch}`; | ||
|
||
return ( | ||
<div {...rest}> | ||
<h4>CI Job identification</h4> | ||
<CodeBlock language="json">{JSON.stringify(ciJob, null, 2)}</CodeBlock> | ||
<br /> | ||
<h4>Commands</h4> | ||
<p>Build the docker image locally for debugging:</p> | ||
<CodeBlock language="bash">{buildCommand}</CodeBlock> | ||
<p>Pull this docker image:</p> | ||
<CodeBlock language="bash">{pullCommand}</CodeBlock> | ||
<br /> | ||
<h4>Associated tags on docker hub</h4> | ||
<CodeBlock language="json">{JSON.stringify(tags, null, 2)}</CodeBlock> | ||
<br /> | ||
<h4>CI Build details</h4> | ||
<CodeBlock language="json">{JSON.stringify(ciBuild, null, 2)}</CodeBlock> | ||
</div> | ||
); | ||
}; | ||
|
||
export default BuildFailureDetails; |
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,83 @@ | ||
import React, { useState } from 'react'; | ||
import DockerImageLinkOrRetryButton, { | ||
type Record, | ||
} from '@site/src/components/docs/versions/docker-image-link-or-retry-button'; | ||
import Spinner from '@site/src/components/molecules/spinner'; | ||
import Tooltip from '@site/src/components/molecules/tooltip/tooltip'; | ||
import styles from './builds.module.scss'; | ||
|
||
const mapBuildStatusToIcon = { | ||
started: <Spinner type="slow" />, | ||
failed: '⚠', | ||
published: '✅', | ||
}; | ||
|
||
type Props = { | ||
children: React.JSX.Element | React.JSX.Element[]; | ||
build: Record; | ||
}; | ||
|
||
const CopyToClipboard = (copyString: string) => { | ||
navigator.clipboard.writeText(copyString); | ||
}; | ||
|
||
export default function BuildRow({ children, build }: Props) { | ||
const [expanded, setExpanded] = useState(false); | ||
const [toolbarContent, setToolbarContent] = useState('Click to copy'); | ||
|
||
const MapBuildStatusToElement = (status: string) => { | ||
const icon = mapBuildStatusToIcon[status]; | ||
|
||
switch (status) { | ||
case 'started': | ||
return <Spinner type="slow" />; | ||
case 'failed': | ||
return <Tooltip content={build.failure?.reason}>{icon}</Tooltip>; | ||
case 'published': | ||
return icon; | ||
default: | ||
return status; | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<tr className={styles.tableRow}> | ||
<td | ||
onClick={() => setExpanded(!expanded)} | ||
className="text-center select-none cursor-pointer text-2xl" | ||
> | ||
{expanded ? '-' : '+'} | ||
</td> | ||
<td className="text-center">{MapBuildStatusToElement(build.status)}</td> | ||
<td> | ||
<span> | ||
<Tooltip content={toolbarContent}> | ||
<button | ||
onClick={() => { | ||
CopyToClipboard(build.buildId); | ||
setToolbarContent('Copied to clipboard!'); | ||
}} | ||
onMouseLeave={() => { | ||
setToolbarContent('Click to copy'); | ||
}} | ||
type="button" | ||
> | ||
{build.buildId} | ||
</button> | ||
</Tooltip> | ||
<DockerImageLinkOrRetryButton record={build} /> | ||
</span> | ||
</td> | ||
<td>{build.imageType}</td> | ||
<td>{build.buildInfo.baseOs}</td> | ||
<td>{build.buildInfo.targetPlatform}</td> | ||
</tr> | ||
{expanded && ( | ||
<tr className={styles.expandedContentRow}> | ||
<td colSpan={6}>{children}</td> | ||
</tr> | ||
)} | ||
</> | ||
); | ||
} |
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,22 @@ | ||
.stickyRow:global(.ant-table-row.ant-table-row-level-0) > :global(td) { | ||
position: sticky; | ||
top: 99px; /* height of the collapse-item-header + the parent tr > td sticky */ | ||
background-color: rgb(255, 255, 255); | ||
z-index: 2; | ||
box-shadow: 0 0 25px rgba(255,255,255,1), 0 0 15px rgba(255,255,255,1), 0 0 20px rgba(255,255,255,1); | ||
clip-path: inset(-25px 0 0 0); | ||
} | ||
|
||
.stickyRow:global(.ant-table-row.ant-table-row-level-0) > :global(td:not(:last-child)) { | ||
clip-path: inset(-25px -1px 0 0); /* fix for space from responsive vs fixed width on cells */ | ||
} | ||
|
||
.expandedContentRow { | ||
height: 0; | ||
overflow: hidden; | ||
} | ||
|
||
|
||
.tableRow { | ||
width: 100%; | ||
} |
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,62 @@ | ||
import React from 'react'; | ||
import { useFirestore, useFirestoreCollectionData } from 'reactfire'; | ||
import BuildFailureDetails from '@site/src/components/docs/versions/builds/build-failure-details'; | ||
import styles from './builds.module.scss'; | ||
import BuildRow from './build-row'; | ||
import { Record } from '../docker-image-link-or-retry-button'; | ||
|
||
interface RepoVersionInfo { | ||
version: string; | ||
major: number; | ||
minor: number; | ||
patch: number; | ||
} | ||
|
||
interface Props { | ||
ciJobId: string; | ||
repoVersionInfo: RepoVersionInfo; | ||
editorVersionInfo; | ||
} | ||
|
||
const Builds = ({ ciJobId, repoVersionInfo, editorVersionInfo }: Props) => { | ||
const loading = <p>Fetching builds...</p>; | ||
|
||
const ciBuilds = useFirestore().collection('ciBuilds').where('relatedJobId', '==', ciJobId); | ||
|
||
const { status, data } = useFirestoreCollectionData<{ [key: string]: any }>(ciBuilds); | ||
const isLoading = status === 'loading'; | ||
|
||
if (isLoading) { | ||
return loading; | ||
} | ||
|
||
const expandable = { | ||
expandedRowRender: (record) => ( | ||
<BuildFailureDetails | ||
style={{ margin: 0 }} | ||
ciJob={ciJobId} | ||
editorVersionInfo={editorVersionInfo} | ||
repoVersionInfo={repoVersionInfo} | ||
ciBuild={record} | ||
/> | ||
), | ||
}; | ||
|
||
return ( | ||
<table className="w-full max-w-screen-lg block border-collapse"> | ||
<tr className={styles.tableRow}> | ||
<th> </th> | ||
<th className="text-center">Status</th> | ||
<th>Build ID</th> | ||
<th>Image type</th> | ||
<th>OS</th> | ||
<th>Target Platform</th> | ||
</tr> | ||
{data.map((build: Record) => ( | ||
<BuildRow build={build}>{expandable.expandedRowRender(build)}</BuildRow> | ||
))} | ||
</table> | ||
); | ||
}; | ||
|
||
export default Builds; |
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
Oops, something went wrong.