-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add view mode (stacked / code)
- Loading branch information
Showing
33 changed files
with
574 additions
and
44 deletions.
There are no files selected for viewing
Binary file not shown.
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
30 changes: 30 additions & 0 deletions
30
webui/src/Containers/Project/MainContent/Composer/CodePreview/CodePreview.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,30 @@ | ||
import { FC, useEffect } from "react"; | ||
import Prism from "prismjs"; | ||
import "prismjs/components/prism-yaml"; | ||
import "prismjs/themes/prism-funky.css"; | ||
import PlateformSelect from "./PlateformSelect"; | ||
import Menu from "./Menu"; | ||
|
||
export type CodePreviewProps = { | ||
code: string; | ||
}; | ||
|
||
const CodePreview: FC<CodePreviewProps> = ({ code }) => { | ||
useEffect(() => { | ||
Prism.highlightAll(); | ||
}, [code]); | ||
|
||
return ( | ||
<> | ||
<PlateformSelect /> | ||
<div className="Code" style={{ marginTop: 50 }}> | ||
<pre style={{ position: "relative" }}> | ||
<Menu /> | ||
<code className="language-yaml">{code}</code> | ||
</pre> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default CodePreview; |
7 changes: 7 additions & 0 deletions
7
webui/src/Containers/Project/MainContent/Composer/CodePreview/CodePreviewState.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,7 @@ | ||
import { atom } from "recoil"; | ||
import { code } from "./mocks"; | ||
|
||
export const CodePreviewState = atom<string>({ | ||
key: "CodePreviewState", | ||
default: code, | ||
}); |
35 changes: 35 additions & 0 deletions
35
webui/src/Containers/Project/MainContent/Composer/CodePreview/CodePreviewWithData.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,35 @@ | ||
import { FC, useEffect } from "react"; | ||
import CodePreview from "./CodePreview"; | ||
import { useRecoilState, useRecoilValue } from "recoil"; | ||
import { CodePreviewState } from "./CodePreviewState"; | ||
import { PlateformSelectState } from "./PlateformSelect/PlateformSelectState"; | ||
import { useParams } from "react-router-dom"; | ||
import { useExportActionsLazyQuery } from "../../../../../Hooks/GraphQL"; | ||
|
||
const CodePreviewWithData: FC = () => { | ||
const { id } = useParams(); | ||
const plateform = useRecoilValue(PlateformSelectState); | ||
const [code, setCode] = useRecoilState(CodePreviewState); | ||
const [exportActions] = useExportActionsLazyQuery({ | ||
variables: { | ||
projectId: id!, | ||
plateform: plateform[0].id, | ||
}, | ||
}); | ||
|
||
useEffect(() => { | ||
exportActions({ | ||
variables: { | ||
projectId: id!, | ||
plateform: plateform[0].id, | ||
}, | ||
}).then(({ data }) => { | ||
setCode(data?.exportActions || ""); | ||
}); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [plateform]); | ||
|
||
return <CodePreview code={code} />; | ||
}; | ||
|
||
export default CodePreviewWithData; |
24 changes: 24 additions & 0 deletions
24
webui/src/Containers/Project/MainContent/Composer/CodePreview/Menu/Menu.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,24 @@ | ||
import { FC } from "react"; | ||
import { Download } from "@styled-icons/bootstrap"; | ||
import { Copy } from "@styled-icons/ionicons-outline"; | ||
import { Button, Container } from "./styles"; | ||
|
||
export type MenuProps = { | ||
onDownload: () => void; | ||
onCopy: () => void; | ||
}; | ||
|
||
const Menu: FC<MenuProps> = ({ onCopy, onDownload }) => { | ||
return ( | ||
<Container> | ||
<Button onClick={onCopy}> | ||
<Copy size={18} /> | ||
</Button> | ||
<Button onClick={onDownload}> | ||
<Download size={18} /> | ||
</Button> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default Menu; |
30 changes: 30 additions & 0 deletions
30
webui/src/Containers/Project/MainContent/Composer/CodePreview/Menu/MenuWithData.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,30 @@ | ||
import Menu from "./Menu"; | ||
import { FC } from "react"; | ||
import copyToClipboard from "copy-to-clipboard"; | ||
import { useRecoilValue } from "recoil"; | ||
import { CodePreviewState } from "../CodePreviewState"; | ||
import { PlateformSelectState } from "../PlateformSelect/PlateformSelectState"; | ||
|
||
const MenuWithData: FC = () => { | ||
const [{ filename }] = useRecoilValue(PlateformSelectState); | ||
const code = useRecoilValue(CodePreviewState); | ||
const onCopy = () => { | ||
copyToClipboard(code); | ||
}; | ||
|
||
const onDownload = () => { | ||
const blob = new Blob([code], { type: "text/yaml" }); | ||
const url = URL.createObjectURL(blob); | ||
const a = document.createElement("a"); | ||
a.href = url; | ||
a.download = filename; | ||
document.body.appendChild(a); | ||
a.click(); | ||
document.body.removeChild(a); | ||
URL.revokeObjectURL(url); | ||
}; | ||
|
||
return <Menu onCopy={onCopy} onDownload={onDownload} />; | ||
}; | ||
|
||
export default MenuWithData; |
3 changes: 3 additions & 0 deletions
3
webui/src/Containers/Project/MainContent/Composer/CodePreview/Menu/index.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,3 @@ | ||
import Menu from "./MenuWithData"; | ||
|
||
export default Menu; |
16 changes: 16 additions & 0 deletions
16
webui/src/Containers/Project/MainContent/Composer/CodePreview/Menu/styles.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,16 @@ | ||
import styled from "@emotion/styled"; | ||
|
||
export const Container = styled.div` | ||
position: absolute; | ||
right: 20px; | ||
`; | ||
|
||
export const Button = styled.button` | ||
background-color: initial; | ||
border: none; | ||
cursor: pointer; | ||
color: #ffffffa3; | ||
&:hover { | ||
color: #fff; | ||
} | ||
`; |
31 changes: 31 additions & 0 deletions
31
...c/Containers/Project/MainContent/Composer/CodePreview/PlateformSelect/PlateformSelect.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 { FC } from "react"; | ||
import { PlateformItem } from "./PlateformSelectState"; | ||
import { Select } from "baseui/select"; | ||
import styles, { Container } from "./styles"; | ||
|
||
export type PlateformSelectProps = { | ||
current: PlateformItem[]; | ||
onSelect: (plateform: PlateformItem[]) => void; | ||
plateforms: PlateformItem[]; | ||
}; | ||
|
||
const PlateformSelect: FC<PlateformSelectProps> = (props) => { | ||
const { current, plateforms, onSelect } = props; | ||
return ( | ||
<Container> | ||
<Select | ||
overrides={styles.Select} | ||
clearable={false} | ||
options={plateforms} | ||
value={current} | ||
placeholder="Select color" | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
onChange={(params: { value: any }) => { | ||
onSelect(params.value); | ||
}} | ||
/> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default PlateformSelect; |
15 changes: 15 additions & 0 deletions
15
...tainers/Project/MainContent/Composer/CodePreview/PlateformSelect/PlateformSelectState.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,15 @@ | ||
import { atom } from "recoil"; | ||
|
||
export type PlateformItem = { id: Plateform; label: string; filename: string }; | ||
export type Plateform = "github" | "gitlab" | "aws" | "circleci" | "azure"; | ||
|
||
export const PlateformSelectState = atom<PlateformItem[]>({ | ||
key: "PlateformSelectState", | ||
default: [ | ||
{ | ||
id: "github", | ||
label: "Github Actions", | ||
filename: "ci.yml", | ||
}, | ||
], | ||
}); |
20 changes: 20 additions & 0 deletions
20
...ners/Project/MainContent/Composer/CodePreview/PlateformSelect/PlateformSelectWithData.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,20 @@ | ||
import { FC } from "react"; | ||
import PlateformSelect from "./PlateformSelect"; | ||
import { plateforms } from "./consts"; | ||
import { useRecoilState } from "recoil"; | ||
import { PlateformSelectState } from "./PlateformSelectState"; | ||
|
||
const PlateformSelectWithData: FC = () => { | ||
const [currentPlateform, setCurrentPlateform] = | ||
useRecoilState(PlateformSelectState); | ||
|
||
return ( | ||
<PlateformSelect | ||
current={currentPlateform} | ||
plateforms={plateforms} | ||
onSelect={setCurrentPlateform} | ||
/> | ||
); | ||
}; | ||
|
||
export default PlateformSelectWithData; |
29 changes: 29 additions & 0 deletions
29
webui/src/Containers/Project/MainContent/Composer/CodePreview/PlateformSelect/consts.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,29 @@ | ||
import { PlateformItem } from "./PlateformSelectState"; | ||
|
||
export const plateforms: PlateformItem[] = [ | ||
{ | ||
label: "Azure Pipelines", | ||
id: "azure", | ||
filename: "azure-pipelines.yml", | ||
}, | ||
{ | ||
label: "AWS CodePipeline", | ||
id: "aws", | ||
filename: "buildspec.yml", | ||
}, | ||
{ | ||
label: "Circle CI", | ||
id: "circleci", | ||
filename: "config.yml", | ||
}, | ||
{ | ||
label: "Github Actions", | ||
id: "github", | ||
filename: "ci.yml", | ||
}, | ||
{ | ||
label: "GitLab CI", | ||
id: "gitlab", | ||
filename: ".gitlab-ci.yml", | ||
}, | ||
]; |
3 changes: 3 additions & 0 deletions
3
webui/src/Containers/Project/MainContent/Composer/CodePreview/PlateformSelect/index.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,3 @@ | ||
import PlateformSelect from "./PlateformSelectWithData"; | ||
|
||
export default PlateformSelect; |
26 changes: 26 additions & 0 deletions
26
webui/src/Containers/Project/MainContent/Composer/CodePreview/PlateformSelect/styles.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,26 @@ | ||
import styled from "@emotion/styled"; | ||
|
||
export const Container = styled.div` | ||
width: 250px; | ||
margin-top: 20px; | ||
`; | ||
|
||
export default { | ||
Select: { | ||
Root: { | ||
style: { | ||
fontFamily: "Lexend", | ||
}, | ||
}, | ||
DropdownListItem: { | ||
style: { | ||
fontFamily: "Lexend", | ||
}, | ||
}, | ||
ControlContainer: { | ||
style: { | ||
border: "1px solid #ffffff45", | ||
}, | ||
}, | ||
}, | ||
}; |
3 changes: 3 additions & 0 deletions
3
webui/src/Containers/Project/MainContent/Composer/CodePreview/index.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,3 @@ | ||
import CodePreview from "./CodePreviewWithData"; | ||
|
||
export default CodePreview; |
Oops, something went wrong.