-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using ipc for "server" side requests
- Loading branch information
1 parent
13a7f76
commit 58ca20f
Showing
17 changed files
with
241 additions
and
33 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import styles from './data.container.scss'; | ||
|
||
import { getDatasetList } from '../../store/actions/data.actions'; | ||
|
||
class Data extends Component { | ||
componentDidMount() { | ||
const { dispatch } = this.props; | ||
dispatch(getDatasetList('name', 50, 0)); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className={styles.dataContainer}> | ||
<h1>Datacenter</h1> | ||
{ | ||
this.props.isLoading | ||
? 'Loading...' | ||
: <ul>{ this.props.datasets.map(ds => <li key={ds.id}>{ds.name}</li>)}</ul> | ||
} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
Data.propTypes = { | ||
isLoading: PropTypes.bool.isRequired, | ||
datasets: PropTypes.arrayOf(PropTypes.shape).isRequired, | ||
dispatch: PropTypes.func.isRequired, | ||
}; | ||
|
||
const mapStateToProps = (state) => { | ||
const { data } = state; | ||
|
||
return data; | ||
}; | ||
|
||
export default connect(mapStateToProps)(Data); |
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,14 @@ | ||
.container { | ||
position: absolute; | ||
top: 30%; | ||
left: 10px; | ||
text-align: center; | ||
} | ||
|
||
.container h2 { | ||
font-size: 5rem; | ||
} | ||
|
||
.container a { | ||
font-size: 1.4rem; | ||
} |
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,19 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { shallow } from 'enzyme'; | ||
import Container from './home.container'; | ||
|
||
|
||
function setup() { | ||
const component = shallow(<Container />); | ||
return { | ||
component | ||
}; | ||
} | ||
|
||
describe('(Container): Home', () => { | ||
it('should render', () => { | ||
const { component } = setup(); | ||
expect(component.first().type()).to.equal('h1'); | ||
}); | ||
}); |
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 Data from './data.container'; | ||
|
||
export default Data; |
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,9 +1,16 @@ | ||
import React, { Component } from 'react'; | ||
import { NavLink } from 'react-router-dom'; | ||
import styles from './home.container.scss'; | ||
|
||
export default class Home extends Component { | ||
render() { | ||
return ( | ||
<h1>Hello World</h1> | ||
<div className={styles.homeContainer}> | ||
<h1>Hello World</h1> | ||
<ul> | ||
<li><NavLink to="/datasets">Datasets</NavLink></li> | ||
</ul> | ||
</div> | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ipcRenderer } from 'electron'; | ||
|
||
export const actions = { | ||
DATASET_LIST_REQUESTED: 'DATASETS:LIST', | ||
DATASET_LIST_RETRIEVED: 'DATASETS:LIST:SUCCESS', | ||
DATASET_LIST_FAILED: 'DATASETS:LIST:FAILED' | ||
}; | ||
|
||
export function listRequested() { | ||
return { type: actions.DATASET_LIST_REQUESTED }; | ||
} | ||
|
||
export function listRetrieved(res) { | ||
return { | ||
type: actions.DATASET_LIST_RETRIEVED, | ||
datasets: res.data ? res.data : res | ||
}; | ||
} | ||
|
||
export function listFailed(error) { | ||
return { | ||
type: actions.DATASET_LIST_FAILED, | ||
error, | ||
}; | ||
} | ||
|
||
export const getDatasetList = (sort, limit, offset) => (dispatch) => { | ||
dispatch(listRequested()); | ||
|
||
ipcRenderer.send(actions.DATASET_LIST_REQUESTED, { sort, limit, offset }); | ||
ipcRenderer.on(actions.DATASET_LIST_RETRIEVED, (event, args) => dispatch(listRetrieved(args))); | ||
ipcRenderer.on(actions.DATASET_LIST_FAILED, (event, err) => dispatch(listFailed(err))); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { actions } from '../../actions/data.actions'; | ||
|
||
const { DATASET_LIST_REQUESTED, DATASET_LIST_RETRIEVED, DATASET_LIST_FAILED } = actions; | ||
|
||
function handleListFailed(state, action) { | ||
return { | ||
...state, | ||
isLoading: false, | ||
error: action.error, | ||
}; | ||
} | ||
|
||
function handleListRequested(state) { | ||
return { | ||
...state, | ||
isLoading: true, | ||
}; | ||
} | ||
|
||
function handleListRetrieved(state, action) { | ||
return { | ||
...state, | ||
isLoading: false, | ||
datasets: action.datasets, | ||
}; | ||
} | ||
|
||
const actionHandlers = new Map([ | ||
[DATASET_LIST_REQUESTED, handleListRequested], | ||
[DATASET_LIST_RETRIEVED, handleListRetrieved], | ||
[DATASET_LIST_FAILED, handleListFailed], | ||
]); | ||
|
||
export const INITIAL_STATE = { | ||
datasets: [], | ||
isLoading: false, | ||
}; | ||
|
||
export function dataReducer(state = INITIAL_STATE, action) { | ||
return (actionHandlers.has(action.type) ? actionHandlers.get(action.type)(state, action) : state); | ||
} |
File renamed without changes.
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,10 +1,13 @@ | ||
import { combineReducers } from 'redux'; | ||
import { loginReducer, INITIAL_STATE as loginState } from './login/login.reducer'; | ||
import { dataReducer, INITIAL_STATE as dataState } from './data/data.reducer'; | ||
|
||
export default combineReducers({ | ||
login: loginReducer, | ||
data: dataReducer, | ||
}); | ||
|
||
export const INITIAL_STATE = { | ||
...loginState, | ||
...dataState, | ||
}; |
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,5 +1 @@ | ||
import IOService from './io/io.service'; | ||
|
||
export default { | ||
IOService, | ||
}; | ||
export default {}; |
This file was deleted.
Oops, something went wrong.
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,11 +1,59 @@ | ||
/* eslint no-param-reassign: ["error", { "props": false }] */ | ||
const Domo = require('domo-sdk'); | ||
|
||
module.exports = { | ||
getLogins: (event) => { | ||
event.returnValue = [ | ||
{ type: 'basic', user: '[email protected]', instance: 'anthem.domo.com', sid: '', token: '' }, | ||
{ type: 'basic', user: '[email protected]', instance: 'anthem.domo.com', sid: '', token: '' }, | ||
{ type: 'oauth', token: '', secret: '' } | ||
]; | ||
const logins = [ | ||
{ type: 'basic', user: '[email protected]', instance: 'anthem', sid: '', token: '' }, | ||
{ type: 'basic', user: '[email protected]', instance: 'domo', sid: '', token: '' }, | ||
{ type: 'oauth', token: '', secret: '', instance: 'domo-sentinel.beta' } | ||
]; | ||
|
||
|
||
const service = { | ||
getLogins: () => logins, | ||
|
||
getActiveSession: () => new Domo(process.env.DOMO_CLIENT_ID, process.env.DOMO_CLIENT_SECRET, 'api.domo.com'), | ||
|
||
storeLogin: (login) => { | ||
// todo | ||
logins.push(login); | ||
}, | ||
|
||
getLoginHistory: (event) => { | ||
try { | ||
const history = service.getLogins().map(i => i.instance); | ||
event.sender.send('LOGINS:LIST:SUCCESS', history); | ||
} catch (e) { | ||
event.sender.send('LOGINS:LIST:FAILED', e); | ||
} | ||
}, | ||
|
||
loginWithAPI: ({ instance, token, secret }) => { | ||
service.storeLogin({ type: 'oauth', instance, token, secret }); | ||
service.setActiveSession(instance); | ||
}, | ||
|
||
loginWithUsername: ({ instance, username, password }) => { | ||
// todo | ||
service.storeLogin({ type: 'basic', instance, username, sid: '' }); | ||
service.setActiveSession(instance); | ||
}, | ||
|
||
loginWithDevToken: ({ instance, token }) => { | ||
// todo | ||
service.storeLogin({ type: 'basic', instance, token }); | ||
service.setActiveSession(instance); | ||
}, | ||
|
||
listDatasets: (event, { sort, limit, offset }) => { | ||
service.getActiveSession().datasets | ||
.list(sort, limit, offset) | ||
.then(res => { | ||
console.log('ListDataset', res); | ||
event.sender.send('DATASETS:LIST:SUCCESS', res); | ||
return res; | ||
}) | ||
.catch(err => event.sender.send('DATASETS:LIST:FAILED', err)); | ||
} | ||
}; | ||
|
||
module.exports = service; |