Skip to content

Commit fa2134a

Browse files
authored
Merge pull request #61 from gitcomteam/feature/56-import-project-flow
project import flow updated
2 parents a5d944c + aa67a63 commit fa2134a

6 files changed

Lines changed: 77 additions & 156 deletions

File tree

src/Routes.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import HomeIntegrationsLayout from "./layouts/home/integrations/HomeIntegrations
1010
import LoginWithGitLabLayout from "./layouts/auth/external/gitlab/logInWith/LoginWithGitLabLayout";
1111
import LoginWithGitHubLayout from "./layouts/auth/external/github/loginWith/LoginWithGitHubLayout";
1212
import ExternalRepoLayout from "./layouts/repos/external/default/ExternalRepoLayout";
13-
import ProjectImportLayout from "./layouts/import/project/ProjectImportLayout";
1413
import ProjectPage from "./layouts/entity/project/view/ProjectPage";
1514
import BoardPage from "./layouts/entity/board/page/BoardPage";
1615
import SubscriptionLayout from "./layouts/account/subscription/SubscriptionLayout";
@@ -62,10 +61,6 @@ class Routes extends React.Component {
6261
<Route path="/auth/external/github/login" exact component={LoginWithGitHubLayout}/>
6362
<Route path="/auth/external/gitlab/login" exact component={LoginWithGitLabLayout}/>
6463

65-
{/* External import routes */}
66-
67-
<Route path="/user/repository/import" exact component={ProjectImportLayout}/>
68-
6964
{/* Project */}
7065

7166
<Route path="/:owner/:alias" exact component={ProjectPage}/>

src/components/external/external_repo/card/ExternalRepoCard.tsx

Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,105 @@
11
import React from "react";
2-
import {Button, Card, Col, Row} from "antd";
2+
import {Button, Card, Col, notification, Row} from "antd";
3+
import {ServiceType1} from "../../../../client/models";
4+
import {ProjectModel} from "../../../../client/bindings";
35
import {Link} from "react-router-dom";
4-
import {buildQuery} from "../../../../classes/utils/url/QueryBuilder";
56

67
interface IProps {
78
repo: {
89
name: string,
910
description: string,
10-
serviceType: string,
11+
serviceType: ServiceType1,
1112
originId: string
1213
}
1314
}
1415

15-
interface IState {}
16+
interface IState {
17+
importButton: {
18+
isLoading: boolean,
19+
label: string
20+
},
21+
importedProject: ProjectModel|null
22+
}
1623

1724
class ExternalRepoCard extends React.Component<IProps, IState> {
18-
getImportUrl(): string {
19-
return "/user/repository/import?" + buildQuery({
20-
origin_id: this.props.repo.originId,
21-
service_type: this.props.repo.serviceType
22-
});
25+
constructor(props: IProps) {
26+
super(props);
27+
this.state = {
28+
importButton: {
29+
isLoading: false,
30+
label: "Import"
31+
},
32+
importedProject: null
33+
}
2334
}
2435

36+
/* TODO: get repo status and if already imported - show 'go to project' button */
37+
2538
getExternalUrl(): string {
2639
let repo = this.props.repo;
2740
return `https://${repo.serviceType}.com/${repo.name}`;
2841
}
2942

43+
sendImportRequest() {
44+
this.setState({
45+
importButton: {
46+
label: 'Importing...',
47+
isLoading: true
48+
}
49+
});
50+
51+
const repo = this.props.repo;
52+
window.App.apiClient.postImportRepository(
53+
window.App.apiToken,
54+
repo.originId,
55+
repo.serviceType
56+
)
57+
.then((res) => {
58+
const project = JSON.parse(res._response.bodyAsText).data.project;
59+
if (!project.base_uri) return;
60+
notification['success']({
61+
message: `Project '${project.name}' imported successfully!`
62+
});
63+
this.setState({
64+
importedProject: project
65+
});
66+
})
67+
.catch((err) => {
68+
const project = JSON.parse(err.response.body).metadata.project;
69+
if (!project.base_uri) return;
70+
this.setState({
71+
importedProject: project
72+
});
73+
});
74+
}
75+
3076
render() {
77+
let importButton = this.state.importButton;
78+
const importedProject = this.state.importedProject;
79+
3180
return <Card className="text-left">
3281
<Row>
3382
<Col xs={16}>
3483
<b> {this.props.repo.name} </b> <br/>
35-
<b>Description:</b> <p className="inline"> description here </p> <br/>
36-
<b>Status:</b> <p className="inline"> unknown </p>
84+
<b>Description:</b> <p className="inline"> {this.props.repo.description} </p> <br/>
3785
</Col>
3886
<Col xs={8} className="text-center">
3987
<Row>
40-
<Link to={this.getImportUrl()}><Button type={"primary"}>Import</Button></Link>
88+
{
89+
importedProject ?
90+
<div>
91+
<p>Project imported</p>
92+
<Link to={`/${importedProject!.base_uri}`}>
93+
<Button type={"primary"}>Open page</Button>
94+
</Link>
95+
</div>
96+
:
97+
<Button
98+
onClick={() => this.sendImportRequest()}
99+
loading={importButton.isLoading}
100+
type={"primary"}
101+
>{importButton.label}</Button>
102+
}
41103
</Row>
42104
<Row className="margin-sm-top">
43105
<a target="_blank" rel="noopener noreferrer" href={this.getExternalUrl()}><Button

src/layouts/auth/external/github/loginWith/LoginWithGitHubLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class LoginWithGitHubLayout extends React.Component<IProps, IState> {
5757
});
5858
setTimeout(() => {
5959
this.setState({
60-
redirectBlock: <Redirect to={"/home/integrations"}/>
60+
redirectBlock: <Redirect to={"/home"}/>
6161
});
6262
}, 1000);
6363
}

src/layouts/auth/external/gitlab/logInWith/LoginWithGitLabLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class LoginWithGitLabLayout extends React.Component<IProps, IState> {
5757
});
5858
setTimeout(() => {
5959
this.setState({
60-
redirectBlock: <Redirect to={"/home/integrations"}/>
60+
redirectBlock: <Redirect to={"/home"}/>
6161
});
6262
}, 1000);
6363
}

src/layouts/import/project/ProjectImportLayout.tsx

Lines changed: 0 additions & 136 deletions
This file was deleted.

src/layouts/repos/external/default/ExternalRepoLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ExternalRepoLayout extends React.Component<IProps, IState> {
7373

7474
{!this.state.isLoaded ? <Icon type="loading" style={{fontSize: "2em"}}/> : null}
7575

76-
<Row>
76+
<Row type={"flex"}>
7777
{this.state.repositories.map((item: any, i: number) => {
7878
return <Col key={i} md={12} xs={24} className="padding-sm">
7979
<ExternalRepoCard repo={{

0 commit comments

Comments
 (0)