Skip to content

Commit ab2dbd3

Browse files
committed
Add location as field in db and display the same on dashboard
Design improvements
1 parent c2d7e45 commit ab2dbd3

11 files changed

Lines changed: 38 additions & 17 deletions

File tree

react-frontend/src/App/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class App extends React.Component {
2525
return (
2626
<div>
2727
{alert.message && (
28-
<div className={`alert ${alert.type}`}>{alert.message}</div>
28+
<div className={`ui ${alert.type} message`}>{alert.message}</div>
2929
)}
3030
<Router history={history}>
3131
<PrivateRoute exact path="/" component={HomePage} />

react-frontend/src/HomePage/HomePage.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { connect } from "react-redux";
55
import { userActions } from "../_actions/user.actions.js";
66
import "./HomePage.css";
77
import ServiceTable from "./ServiceTable";
8+
import { Loader } from "semantic-ui-react";
89

910
class HomePage extends React.Component {
1011
constructor(props) {
@@ -21,8 +22,11 @@ class HomePage extends React.Component {
2122
this.props.dispatch(userActions.getAll(this.state.selectedService));
2223
}
2324

24-
handleDeleteUser(id) {
25-
return e => this.props.dispatch(userActions.delete(id));
25+
handleServiceChange(serviceName) {
26+
this.setState({
27+
selectedService: serviceName
28+
});
29+
this.props.dispatch(userActions.getAll(serviceName));
2630
}
2731

2832
render() {
@@ -54,7 +58,7 @@ class HomePage extends React.Component {
5458
<div class="ui center aligned page grid" style={{ marginTop: 50 }}>
5559
<div
5660
class="three wide left floated column"
57-
onClick={() => this.setState({ selectedService: "azure" })}
61+
onClick={() => this.handleServiceChange("azure")}
5862
>
5963
<div
6064
className="serviceChooser"
@@ -76,7 +80,7 @@ class HomePage extends React.Component {
7680
</div>
7781
<div
7882
class="three wide column"
79-
onClick={() => this.setState({ selectedService: "aws" })}
83+
onClick={() => this.handleServiceChange("aws")}
8084
>
8185
<div
8286
className="serviceChooser"
@@ -98,7 +102,7 @@ class HomePage extends React.Component {
98102
</div>
99103
<div
100104
class="three wide right floated column"
101-
onClick={() => this.setState({ selectedService: "gcp" })}
105+
onClick={() => this.handleServiceChange("gcp")}
102106
>
103107
<div
104108
className="serviceChooser"
@@ -120,7 +124,11 @@ class HomePage extends React.Component {
120124
</div>
121125
</div>
122126
<div style={{ margin: 50 }}>
123-
{this.props.users.loading && <p> Data is loading</p>}
127+
{this.props.users.loading && (
128+
<Loader active inline="centered">
129+
Loading {selectedService} services...
130+
</Loader>
131+
)}
124132
{!this.props.users.loading && (
125133
<ServiceTable service={this.props.users.items} />
126134
)}

react-frontend/src/HomePage/ServiceTable.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ class ServiceTable extends Component {
55
renderTableData() {
66
if (this.props.service) {
77
return this.props.service.map((service, index) => {
8-
const { id, serviceid, name, type } = service; //destructuring
8+
const { id, serviceid, name, type, location } = service; //destructuring
99
return (
1010
<Table.Row key={id}>
1111
<Table.Cell>{id}</Table.Cell>
1212
<Table.Cell>{serviceid}</Table.Cell>
1313
<Table.Cell>{name}</Table.Cell>
1414
<Table.Cell>{type}</Table.Cell>
15+
<Table.Cell>{location}</Table.Cell>
1516
</Table.Row>
1617
);
1718
});
@@ -32,10 +33,10 @@ class ServiceTable extends Component {
3233
<div>
3334
{this.props.service && (
3435
<Table id="users">
35-
<Table.Body>
36+
<Table.Header>
3637
<Table.Row>{this.renderTableHeader()}</Table.Row>
37-
{this.renderTableData()}
38-
</Table.Body>
38+
</Table.Header>
39+
<Table.Body>{this.renderTableData()}</Table.Body>
3940
</Table>
4041
)}
4142
</div>

react-frontend/src/_actions/user.actions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ function getAll(serviceProvider) {
7575
userService.getAll(serviceProvider).then(res => {
7676
if (res.success) {
7777
dispatch(success(res.data));
78+
dispatch(alertActions.clear());
7879
} else {
7980
dispatch(failure(res.message));
8081
dispatch(alertActions.error(res.message));

react-frontend/src/_reducers/alert.reducer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ export function alert(state = {}, action) {
44
switch (action.type) {
55
case alertConstants.SUCCESS:
66
return {
7-
type: "alert-success",
7+
type: "success",
88
message: action.message
99
};
1010
case alertConstants.ERROR:
1111
return {
12-
type: "alert-danger",
12+
type: "error",
1313
message: action.message
1414
};
1515
case alertConstants.CLEAR:

react-frontend/src/_reducers/authentication.reducer.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ export function authentication(state = initialState, action) {
1111
user: action.user
1212
};
1313
case userConstants.LOGIN_SUCCESS:
14-
console.log("REDUCERS SUCCESS", action.user);
1514
return {
1615
loggedIn: true,
1716
user: action.user
1817
};
1918
case userConstants.LOGIN_FAILURE:
20-
console.log("REDUCERS FAIL", action);
2119
return {};
2220
case userConstants.LOGOUT:
2321
return {};

react-frontend/src/_services/user.services.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ function login(username, password) {
1818
body: JSON.stringify({ username, password })
1919
};
2020

21-
console.log("USERSERVICE REQUESTOPTIONS", requestOptions);
2221
return fetch(`http://localhost:4000/login`, requestOptions)
2322
.then(handleResponse)
2423
.then(user => {

server/db.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const createTableService = () => {
4545
t.string("serviceid").notNullable();
4646
t.string("name").notNullable();
4747
t.string("type").notNullable();
48+
t.string("location").notNullable();
4849
})
4950
.then(console.log("Service Table created"));
5051

server/routes/getservices.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ router.get("/home", jsonParser, function(req, response) {
6363
store.serviceList().then(res => response.json(res));
6464
}
6565
);
66+
} else if (req.query.serviceProvider === "aws") {
67+
res = {
68+
success: false,
69+
message: "AWS Services are Under development, Please try again later!"
70+
};
71+
response.json(res);
72+
} else if (req.query.serviceProvider === "gcp") {
73+
res = {
74+
success: false,
75+
message: "GCP Services are Under development, Please try again later!"
76+
};
77+
response.json(res);
6678
}
6779
});
6880
module.exports = router;

server/store.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ module.exports = {
6666
.insert({
6767
serviceId: serviceDetails.id,
6868
name: serviceDetails.name,
69-
type: serviceDetails.type
69+
type: serviceDetails.type,
70+
location: serviceDetails.location
7071
})
7172
.then(console.log("Inserted"));
7273

0 commit comments

Comments
 (0)