-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #351 from ashik-75/work
Add github automation issue
- Loading branch information
Showing
21 changed files
with
432 additions
and
36 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
### [6.4.0] - 2023-10-11 | ||
|
||
- Add github automation | ||
|
||
### [6.3.0] - 2023-10-03 | ||
|
||
- Fix Test | ||
|
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
35 changes: 35 additions & 0 deletions
35
ui/src/pages/Automation/GithubIssue/components/CsvTable.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 React from "react"; | ||
import { Table } from "antd"; | ||
import { IssueType } from "pages/Automation/GithubIssue/types"; | ||
|
||
interface CsvTableProps { | ||
data: IssueType[]; | ||
} | ||
|
||
type DataColumn = { | ||
title: string; | ||
dataIndex: string; | ||
key: string; | ||
}; | ||
|
||
const CsvTable: React.FC<CsvTableProps> = ({ data }) => { | ||
const columns: DataColumn[] = []; | ||
|
||
if (data.length > 0) { | ||
const headers = Object.keys(data[0]); | ||
|
||
headers.forEach((header) => { | ||
columns.push({ | ||
title: header, | ||
dataIndex: header, | ||
key: header, | ||
}); | ||
}); | ||
} | ||
|
||
return ( | ||
<Table scroll={{ x: "400px" }} dataSource={data} columns={columns} /> | ||
); | ||
}; | ||
|
||
export default CsvTable; |
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,168 @@ | ||
import { Alert, Button, Card, Form, Progress, Steps, Upload } from "antd"; | ||
import { ResponsiveInputWithLabel } from "components/General/FormComponents"; | ||
import InputGrid from "components/Layouts/InputGrid"; | ||
import PageGrid from "components/Layouts/PageGrid"; | ||
import React, { useState } from "react"; | ||
import Papa from "papaparse"; | ||
import CsvTable from "./components/CsvTable"; | ||
import { CSVLink } from "react-csv"; | ||
import { calculateSteps, createGitHubIssue } from "./utils/helper"; | ||
import { steps } from "./utils/constants"; | ||
import { IssueType, SavedIssueType } from "./types"; | ||
|
||
const GithubIssue: React.FC = () => { | ||
//? input state | ||
const [owner, setOwner] = useState(""); | ||
const [repo, setRepo] = useState(""); | ||
const [token, setToken] = useState(""); | ||
const [fileData, setFileData] = useState<IssueType[]>([]); | ||
const [isValidInput, setIsValidInput] = useState(false); | ||
|
||
// ? output state | ||
const [progress, setProgress] = useState(0); | ||
const [isError, setIsError] = useState(false); | ||
const [savedIssues, setSavedIssues] = useState<SavedIssueType[]>([]); | ||
|
||
const handleUpload = (file: File) => { | ||
Papa.parse<IssueType[]>(file, { | ||
complete: (result) => { | ||
const responseIssue = result.data; | ||
|
||
// Convert keys to lowercase for each object in the array | ||
const formatData = responseIssue.map((issue) => { | ||
const formattedIssue: IssueType = {} as IssueType; | ||
for (const key in issue) { | ||
if (Object.prototype.hasOwnProperty.call(issue, key)) { | ||
// ts-ignore | ||
formattedIssue[key.toLowerCase()] = issue[key]; | ||
} | ||
} | ||
return formattedIssue; | ||
}); | ||
|
||
const checkValidity = formatData.every((dt) => dt?.title); | ||
setIsValidInput(checkValidity); | ||
if (checkValidity) { | ||
setFileData(formatData); | ||
} | ||
}, | ||
header: true, | ||
skipEmptyLines: true, | ||
}); | ||
}; | ||
|
||
const handleCreateGitHubIssue = () => { | ||
createGitHubIssue( | ||
owner, | ||
repo, | ||
token, | ||
fileData, | ||
setProgress, | ||
setSavedIssues, | ||
setIsError | ||
); | ||
}; | ||
|
||
const haveConfig = repo.length > 0 && token.length > 0 && owner.length > 0; | ||
const haveFileData = fileData.length > 0; | ||
|
||
return ( | ||
<PageGrid> | ||
<Card> | ||
<Steps | ||
current={calculateSteps( | ||
haveConfig, | ||
haveFileData, | ||
isValidInput | ||
)} | ||
items={steps} | ||
/> | ||
<br /> | ||
{!isValidInput && fileData.length > 0 && ( | ||
<> | ||
<Alert | ||
message="Csv file must contains a title" | ||
type="error" | ||
showIcon | ||
/> | ||
<br /> | ||
</> | ||
)} | ||
<Form layout="vertical"> | ||
<ResponsiveInputWithLabel | ||
label="Github token" | ||
placeholder="enter your github token" | ||
value={token} | ||
onChange={(e) => setToken(e.target.value)} | ||
min={0} | ||
type="text" | ||
/> | ||
|
||
<InputGrid> | ||
<ResponsiveInputWithLabel | ||
label="Owner" | ||
placeholder="owner" | ||
value={owner} | ||
onChange={(e) => setOwner(e.target.value)} | ||
min={0} | ||
type="text" | ||
/> | ||
|
||
<ResponsiveInputWithLabel | ||
label="Repositories" | ||
placeholder="repository name" | ||
value={repo} | ||
onChange={(e) => setRepo(e.target.value)} | ||
min={0} | ||
type="text" | ||
/> | ||
</InputGrid> | ||
|
||
<InputGrid> | ||
<Form.Item> | ||
<Upload beforeUpload={handleUpload}> | ||
<Button disabled={!haveConfig}> | ||
Upload csv | ||
</Button> | ||
</Upload> | ||
</Form.Item> | ||
<Button | ||
disabled={fileData.length === 0 && !isValidInput} | ||
block | ||
onClick={handleCreateGitHubIssue} | ||
> | ||
Create {fileData?.length} issue | ||
</Button> | ||
</InputGrid> | ||
</Form> | ||
|
||
<CsvTable data={fileData} /> | ||
</Card> | ||
|
||
<Card title="Saved Issue" style={{ height: "100%" }}> | ||
{isError && ( | ||
<> | ||
<Alert | ||
message="something went wrong, please try again with your valid credentials" | ||
type="error" | ||
showIcon | ||
/> | ||
<br /> | ||
</> | ||
)} | ||
|
||
{progress > 0 && <Progress percent={progress} size="small" />} | ||
|
||
<CsvTable data={savedIssues} /> | ||
<br /> | ||
<CSVLink data={savedIssues} filename={"csv_data.csv"}> | ||
<Button disabled={savedIssues.length === 0}> | ||
Download CSV | ||
</Button> | ||
</CSVLink> | ||
</Card> | ||
</PageGrid> | ||
); | ||
}; | ||
|
||
export default GithubIssue; |
Oops, something went wrong.