-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e51e133
commit 1783b07
Showing
6 changed files
with
254 additions
and
146 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,11 @@ | ||
export const TEST_DASHBOARD_ACTION = 'TEST_DASHBOARD_ACTION'; | ||
export const TEST_LOGIN_ACTION = 'TEST_LOGIN_ACTION'; | ||
export const TEST_HOME_ACTION = 'TEST_HOME_ACTION'; | ||
|
||
// dashboard page | ||
export const GET_PROJECT_DETAILS_SUCCESS = 'GET_PROJECT_DETAILS_SUCCESS'; | ||
export const GET_PROJECT_DETAILS_FAILURE = 'GET_PROJECT_DETAILS_FAILURE'; | ||
export const GET_PROJECT_LOGS_SUCCESS = 'GET_PROJECT_LOGS_SUCCESS'; | ||
export const GET_PROJECT_LOGS_FAILURE = 'GET_PROJECT_LOGS_FAILURE'; | ||
export const GET_CONTAINERS_SUCCESS = 'GET_CONTAINERS_SUCCESS'; | ||
export const GET_CONTAINERS_FAILURE = 'GET_CONTAINERS_FAILURE'; |
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,13 +1,127 @@ | ||
// import InertiaAPI from '../common/API'; | ||
import { | ||
TEST_DASHBOARD_ACTION, | ||
GET_PROJECT_DETAILS_SUCCESS, | ||
// GET_PROJECT_DETAILS_FAILURE, | ||
GET_PROJECT_LOGS_SUCCESS, | ||
GET_PROJECT_LOGS_FAILURE, | ||
GET_CONTAINERS_SUCCESS, | ||
GET_CONTAINERS_FAILURE, | ||
} from './_constants'; | ||
|
||
const MOCK_DETAILS = { | ||
name: 'your-project-name', | ||
branch: 'master', | ||
commit: 'e51e133565bd0b0fda6caf69014dd2b2b24bfbaa', | ||
message: 'commit message goes here', | ||
buildType: 'docker-compose', | ||
}; | ||
|
||
const MOCK_LOGS = [ | ||
'log1asdasdasdasdasdasdasdssdasdasdssdasdasdssdasdasdssdasdasdsa', | ||
'log2asdasdasdasdsdassdasdasdssdasdasdssdasdasdssdasdasdsdsdasds', | ||
'log3dasdsdazxcxzsdasdasdssdasdasdssdasdasdssdasdasdsxxxxxxxxxx', | ||
'log4dasdsdasdsdasdasdssdasdasdssdasdasdssdasdasdsxzczxczxs', | ||
'log5dasdsdaasdsdasdasdssdasdasdssdasdasdssdasdasdsasdasdsds', | ||
'log6dasdsdaszsdasdasdssdasdasdssdasdasdssdasdasdsxczxczxczxcwqdqds', | ||
'log7dasdsdaxcsdasdasdssdasdasdssdasdasdssdasdasdszxczzxcsds', | ||
]; | ||
|
||
const MOCK_CONTAINERS = [ | ||
{ | ||
name: '/inertia-deploy-test', | ||
status: 'ACTIVE', | ||
lastUpdated: '2018-01-01 00:00', | ||
}, | ||
{ | ||
name: '/docker-compose', | ||
status: 'ACTIVE', | ||
lastUpdated: '2018-01-01 00:00', | ||
}, | ||
]; | ||
|
||
function promiseState(p) { | ||
const t = {}; | ||
|
||
return Promise.race([p, t]) | ||
.then(v => (v === t ? 'pending' : ('fulfilled', () => 'rejected'))); | ||
} | ||
|
||
export const testAction = payload => (dispatch) => { | ||
// remove later | ||
console.log('dashboard action fired!'); | ||
export const handleGetProjectDetails = () => (dispatch) => { | ||
// TODO: put fetch request here | ||
dispatch({ | ||
type: TEST_DASHBOARD_ACTION, | ||
payload, | ||
type: GET_PROJECT_DETAILS_SUCCESS, | ||
payload: { project: MOCK_DETAILS }, | ||
}); | ||
}; | ||
|
||
export const handleGetLogs = ({ container }) => (dispatch) => { | ||
try { | ||
let resp; | ||
if (!container) { | ||
resp = MOCK_LOGS; | ||
// resp = InertiaAPI.getContainerLogs(); | ||
} else { | ||
resp = MOCK_LOGS; | ||
// resp = InertiaAPI.getContainerLogs(container); | ||
} | ||
if (resp.status !== 200) { | ||
// this.setState({ | ||
// errored: true, | ||
// logEntries: [], | ||
// }); | ||
} | ||
|
||
const reader = resp.body.getReader(); | ||
// this.setState({ logReader: reader }); | ||
const decoder = new TextDecoder('utf-8'); | ||
let buffer = ''; | ||
const stream = () => promiseState(reader.closed) | ||
.then((s) => { | ||
if (s === 'pending') { | ||
return reader.read() | ||
.then((data) => { | ||
const chunk = decoder.decode(data.value); | ||
const parts = chunk.split('\n') | ||
.filter(c => c); | ||
|
||
parts[0] = buffer + parts[0]; | ||
buffer = ''; | ||
if (!chunk.endsWith('\n')) { | ||
buffer = parts.pop(); | ||
} | ||
|
||
dispatch({ | ||
type: GET_PROJECT_LOGS_SUCCESS, | ||
payload: { logs: MOCK_LOGS }, | ||
}); | ||
// this.setState({ | ||
// logEntries: this.state.logEntries.concat(parts), | ||
// }); | ||
|
||
return stream(); | ||
}); | ||
} | ||
return null; | ||
}) | ||
.catch((err) => { | ||
dispatch({ | ||
type: GET_PROJECT_LOGS_SUCCESS, | ||
payload: { logs: MOCK_LOGS }}); | ||
}); | ||
|
||
stream(); | ||
} catch (e) { | ||
dispatch({ | ||
type: GET_PROJECT_LOGS_FAILURE, | ||
payload: { logs: MOCK_LOGS }}); | ||
} | ||
}; | ||
|
||
export const handleGetContainers = () => (dispatch) => { | ||
// TODO: put fetch request here | ||
dispatch({ | ||
type: GET_CONTAINERS_SUCCESS, | ||
payload: { containers: MOCK_CONTAINERS }, | ||
}); | ||
}; | ||
|
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
Oops, something went wrong.