Skip to content

Commit

Permalink
Basic dashboard components (#562)
Browse files Browse the repository at this point in the history
* Case sensitive renaming

* Update `cvat-js` lib.

* Add `.env` file

* Add basic redux capabilities

* Remove `setTimeout` as it was fixes in `cvat-js`

* Remove redundant state field
  • Loading branch information
zankevich authored and nmanovic committed Jul 10, 2019
1 parent 0efd665 commit 9651a19
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 68 deletions.
8 changes: 8 additions & 0 deletions cvat-ui/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
REACT_APP_VERSION=${npm_package_version}
REACT_APP_API_PROTOCOL=http
REACT_APP_API_HOST=localhost
REACT_APP_API_PORT=7000
REACT_APP_API_HOST_URL=${REACT_APP_API_PROTOCOL}://${REACT_APP_API_HOST}:${REACT_APP_API_PORT}
REACT_APP_API_FULL_URL=${REACT_APP_API_PROTOCOL}://${REACT_APP_API_HOST}:${REACT_APP_API_PORT}/api/v1
REACT_APP_LOGIN=admin
REACT_APP_PASSWORD=admin
4 changes: 4 additions & 0 deletions cvat-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@types/node": "^12.0.3",
"@types/react": "16.8.19",
"@types/react-dom": "16.8.4",
"@types/react-redux": "^7.1.1",
"@types/react-router-dom": "^4.3.4",
"antd": "^3.19.1",
"babel-plugin-import": "^1.11.2",
Expand All @@ -18,8 +19,11 @@
"react": "^16.8.6",
"react-app-rewired": "^2.1.3",
"react-dom": "^16.8.6",
"react-redux": "^7.1.0",
"react-router-dom": "^5.0.1",
"react-scripts": "3.0.1",
"redux": "^4.0.3",
"redux-thunk": "^2.3.0",
"source-map-explorer": "^1.8.0",
"typescript": "3.4.5"
},
Expand Down
8 changes: 4 additions & 4 deletions cvat-ui/public/cvat.min.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions cvat-ui/src/actions/authentication-action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const loginAction = () => (dispatch: any) => {
dispatch({
type: 'LOGIN',
payload: true,
})
}

export const logoutAction = () => (dispatch: any) => {
dispatch({
type: 'LOGOUT',
payload: false,
})
}
46 changes: 0 additions & 46 deletions cvat-ui/src/components/app/App.tsx

This file was deleted.

File renamed without changes.
46 changes: 46 additions & 0 deletions cvat-ui/src/components/app/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, { PureComponent } from 'react';
import { BrowserRouter as Router, Route, Redirect } from 'react-router-dom';
import { connect } from 'react-redux';

import Dashboard from '../dashboard/dashboard';

import { loginAction, logoutAction } from '../../actions/authentication-action';

import './app.scss';

declare const window: any;

const mapDispatchToProps = (dispatch: any) => ({
login: () => { dispatch(loginAction()) },
logout: () => { dispatch(logoutAction()) },
})

const mapStateToProps = (state: any) => ({
...state.authenticateReducer,
})

class App extends PureComponent<any, any> {
componentDidMount() {
window.cvat.server.login(process.env.REACT_APP_LOGIN, process.env.REACT_APP_PASSWORD).then(
(_response: any) => {
this.props.login();
},
(_error: any) => {
this.props.logout();
}
);
}

render() {
return(
<Router>
<div>
<Redirect from="/" to="dashboard" />
<Route path="/dashboard" component={ Dashboard } />
</div>
</Router>
);
}
}

export default connect(mapStateToProps, mapDispatchToProps)(App);
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ interface DashboardContentAction {
}

class DashboardContent extends Component<any, any> {
hostUrl: string;
apiUrl: string;
hostUrl: string | undefined;
apiUrl: string | undefined;
actions: DashboardContentAction[];

constructor(props: any) {
super(props);

this.state = {};
this.hostUrl = 'http://localhost:7000';
this.apiUrl = 'http://localhost:7000/api/v1';
this.hostUrl = process.env.REACT_APP_API_HOST_URL;
this.apiUrl = process.env.REACT_APP_API_FULL_URL;

this.actions = [
// {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import './dashboard.scss';

interface DashboardState {
tasks: [];
tasksCount: number;
}

class Dashboard extends Component<any, DashboardState> {
constructor(props: any) {
super(props);

this.state = { tasks: [], tasksCount: 0 };
this.state = { tasks: [] };
}

componentDidMount() {
Expand All @@ -29,7 +28,7 @@ class Dashboard extends Component<any, DashboardState> {
<Layout>
<DashboardHeader onSearch={ this.getTasks } />
<DashboardContent tasks={ this.state.tasks } deleteTask={ this.deleteTask } />
<DashboardFooter tasksCount={ this.state.tasksCount } onPageChange={ this.onPageChange } />
<DashboardFooter tasksCount={ (this.state.tasks as any)['count'] } onPageChange={ this.onPageChange } />
</Layout>
);
}
Expand All @@ -41,7 +40,7 @@ class Dashboard extends Component<any, DashboardState> {

(window as any).cvat.tasks.get(query ? queryObject : {}).then(
(tasks: any) => {
this.setState({ tasks, tasksCount: tasks.count });
this.setState({ tasks });
},
(error: any) => {
console.log(error);
Expand All @@ -63,13 +62,7 @@ class Dashboard extends Component<any, DashboardState> {
private deleteTask = (task: any) => {
task.delete().then(
(_deleted: any) => {
setTimeout(() => {

this.getTasks();
}, 1000);
// const tasks = this.state.tasks.filter((taskToDelete: any) => taskToDelete.id !== task.id) as any;

// this.setState({ tasks, tasksCount: this.state.tasksCount - 1 });
this.getTasks();
},
(error: any) => {
console.log(error);
Expand Down
4 changes: 2 additions & 2 deletions cvat-ui/src/components/dashboard/header/dashboard-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ interface DashboardHeaderAction {

class DashboardHeader extends Component<any, any> {
actions: DashboardHeaderAction[];
hostUrl: string;
hostUrl: string | undefined;

constructor(props: any) {
super(props);

this.state = {};

this.hostUrl = 'http://localhost:7000';
this.hostUrl = process.env.REACT_APP_API_HOST_URL;

this.actions = [
// {
Expand Down
10 changes: 9 additions & 1 deletion cvat-ui/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux'

import configureStore from './store';

import * as serviceWorker from './serviceWorker';

import './index.scss';
import App from './components/app/app';

ReactDOM.render(<App />, document.getElementById('root'));
ReactDOM.render(
<Provider store={ configureStore() }>
<App />
</Provider>,
document.getElementById('root')
);

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
Expand Down
10 changes: 10 additions & 0 deletions cvat-ui/src/reducers/authenticate-reducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default (state = {}, action: any) => {
switch (action.type) {
case 'LOGIN':
return { ...state, isLoggedIn: action.payload };
case 'LOGOUT':
return { ...state, isLoggedIn: action.payload };
default:
return state;
}
}
7 changes: 7 additions & 0 deletions cvat-ui/src/reducers/root-reducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { combineReducers } from 'redux';

import authenticationReducer from './authenticate-reducer';

export default combineReducers({
authenticationReducer,
});
19 changes: 19 additions & 0 deletions cvat-ui/src/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';

import rootReducer from './reducers/root-reducer';

export default function configureStore(initialState = {}) {
return createStore(
rootReducer,
initialState,
compose(
applyMiddleware(thunk),
(window as any).__REDUX_DEVTOOLS_EXTENSION__
?
(window as any).__REDUX_DEVTOOLS_EXTENSION__({ trace: true })
:
(f: any) => f
)
);
}

0 comments on commit 9651a19

Please sign in to comment.