diff --git a/client/src/components/Commits.js b/client/src/components/Commits.js index 4167675..88c3c10 100644 --- a/client/src/components/Commits.js +++ b/client/src/components/Commits.js @@ -8,8 +8,8 @@ import Loading from './Loading'; class Commits extends React.Component { componentDidMount() { - this.props.loadBuildSets(); this.props.loadCommits(); + this.props.loadBuildSets(); } renderBsid = id => { @@ -22,10 +22,41 @@ class Commits extends React.Component { return obj; }) .filter(item => item.sourcestamps[0].revision === commit.sha); + let BSID = filteredBs.map(id => { + return id.bsid; + }); + console.log(BSID); + if (BSID) { + var filterBReq = []; + BSID.forEach(val => { + filterBReq.push( + this.props.bsid + .map(obj => { + return obj; + }) + .filter(item => item.buildsetid === val) + ); + }); + var mergedBsID = [].concat.apply([], filterBReq); + var filterBuild = []; + mergedBsID.forEach(val => { + filterBuild.push( + this.props.build + .map(obj => { + return obj; + }) + .filter(item => item.buildrequestid === val.buildrequestid) + ); + }); + var mergedBuild = [].concat.apply([], filterBuild); + console.log(mergedBsID); + console.log(mergedBuild); + } + return (
- {filteredBs.map(bsid => 'buildsetid__contain=' + bsid.bsid).join('&')} + {filteredBs.map(this.renderBsid)}
); }; @@ -87,13 +118,15 @@ class Commits extends React.Component { } // prettier-ignore -const mapStateToProps = ({ isLoading, commits, error, branch,page,buildData}) => ({ +const mapStateToProps = ({ isLoading, commits, error, branch,page,buildData,bsid,build}) => ({ isLoading, commits, error, branch, page, - buildData + buildData, + bsid, + build }); const mapDispatchToProps = dispatch => ({ diff --git a/client/src/redux/api/index.js b/client/src/redux/api/index.js index dd5ce77..d8c834a 100644 --- a/client/src/redux/api/index.js +++ b/client/src/redux/api/index.js @@ -26,6 +26,7 @@ export const fetchBuildReq = async str => { }; export const fetchBuilds = async str => { + console.log(str); const response = await fetch(`/api/builds?${str}`); const data = await response.json(); if (response.status >= 400) { diff --git a/client/src/redux/sagas/buildReqSaga.js b/client/src/redux/sagas/buildReqSaga.js deleted file mode 100644 index eb05b9a..0000000 --- a/client/src/redux/sagas/buildReqSaga.js +++ /dev/null @@ -1,49 +0,0 @@ -import { takeEvery, call, select, put } from 'redux-saga/effects'; -import { COMMITS } from '../constants'; -import { fetchBuildReq } from '../api'; -import { setBuildSetsError, setBsID } from '../actions'; -const commitSha = state => state.commits; -const buildData = state => state.buildData; - -function matchSha(commits, buildData) { - let cs = commits.map(commit => { - return commit.sha; - }); - let bs = buildData.map(builds => { - return builds; - }); - var filterBs = []; - cs.forEach(val => { - filterBs.push( - bs - .map(obj => { - return obj; - }) - .filter(item => item.sourcestamps[0].revision === val) - ); - }); - - var merged = [].concat.apply([], filterBs); - - let str = merged.map(bsid => 'buildsetid__contains=' + bsid.bsid).join('&'); - return str; -} - -function* handleBuildReqLoad() { - try { - const commit = yield select(commitSha); - const build = yield select(buildData); - var str = matchSha(commit, build); - if (str) { - let bsID = yield call(fetchBuildReq, str); - yield put(setBsID(bsID)); - //console.log(bsID); - } - } catch (error) { - yield put(setBuildSetsError(error.toString())); - } -} - -export default function* watchBuildsLoad() { - yield takeEvery(COMMITS.LOAD_SUCCESS, handleBuildReqLoad); -} diff --git a/client/src/redux/sagas/buildSetSaga.js b/client/src/redux/sagas/buildSetSaga.js index e763b75..588eed2 100644 --- a/client/src/redux/sagas/buildSetSaga.js +++ b/client/src/redux/sagas/buildSetSaga.js @@ -1,16 +1,72 @@ -import { takeEvery, call, put } from 'redux-saga/effects'; -import { BUILD_DATA } from '../constants'; -import { fetchBuildSets } from '../api'; -import { setBuildSets, setBuildSetsError } from '../actions'; +import { takeEvery, call, put, select } from 'redux-saga/effects'; +import { COMMITS } from '../constants'; +import { fetchBuildSets, fetchBuildReq, fetchBuilds } from '../api'; +import { + setBuildSets, + setBuildSetsError, + setBsID, + setBuilds +} from '../actions'; + +const commitSha = state => state.commits; +const buildData = state => state.buildData; +const bsid = state => state.bsid; + +function buildStr(build) { + let str = build + .map(build => 'buildrequestid__contains=' + build.buildrequestid) + .join('&'); + return str; +} + +function matchSha(commits, buildData) { + let cs = commits.map(commit => { + return commit.sha; + }); + let bs = buildData.map(builds => { + return builds; + }); + var filterBs = []; + cs.forEach(val => { + filterBs.push( + bs + .map(obj => { + return obj; + }) + .filter(item => item.sourcestamps[0].revision === val) + ); + }); + // console.log(filterBs); + + var merged = [].concat.apply([], filterBs); + //console.log(merged); + let str = merged.map(bsid => 'buildsetid__contains=' + bsid.bsid).join('&'); + return str; +} + function* handleBuildsLoad() { try { const buildSets = yield call(fetchBuildSets); yield put(setBuildSets(buildSets)); + const commit = yield select(commitSha); + const build = yield select(buildData); + var str = matchSha(commit, build); + if (str) { + let bsID = yield call(fetchBuildReq, str); + yield put(setBsID(bsID)); + //console.log(bsID); + } + const build1 = yield select(bsid); + var str1 = buildStr(build1); + if (str1) { + let build2 = yield call(fetchBuilds, str1); + yield put(setBuilds(build2)); + } } catch (error) { yield put(setBuildSetsError(error.toString())); } } export default function* watchBuildsLoad() { - yield takeEvery(BUILD_DATA.LOAD, handleBuildsLoad); + yield takeEvery(COMMITS.LOAD_SUCCESS, handleBuildsLoad); } diff --git a/client/src/redux/sagas/buildsSaga.js b/client/src/redux/sagas/buildsSaga.js deleted file mode 100644 index 86cda4b..0000000 --- a/client/src/redux/sagas/buildsSaga.js +++ /dev/null @@ -1,28 +0,0 @@ -import { takeEvery, call, select, put } from 'redux-saga/effects'; -import { fetchBuilds } from '../api'; -import { setBuildSetsError, setBuilds } from '../actions'; -const bsid = state => state.bsid; - -function buildStr(build) { - let str = build - .map(build => 'buildrequestid__contains=' + build.buildrequestid) - .join('&'); - return str; -} - -function* handleBuildsLoad() { - try { - const build = yield select(bsid); - var str = buildStr(build); - if (str) { - let build = yield call(fetchBuilds, str); - yield put(setBuilds(build)); - } - } catch (error) { - yield put(setBuildSetsError(error.toString())); - } -} - -export default function* watchBuildsLoad() { - yield takeEvery('BUILD_SET_ID_SUCCESS', handleBuildsLoad); -} diff --git a/client/src/redux/sagas/index.js b/client/src/redux/sagas/index.js index 5acd125..ea04870 100644 --- a/client/src/redux/sagas/index.js +++ b/client/src/redux/sagas/index.js @@ -4,16 +4,7 @@ import commitsSaga from './commitsSaga'; import branchesSaga from './branchesSaga'; import pullsSaga from './pullsSaga'; import buildSetSaga from './buildSetSaga'; -import buildReqSaga from './buildReqSaga'; -import buildsSaga from './buildsSaga'; export default function* rootSaga() { - yield all([ - commitsSaga(), - branchesSaga(), - pullsSaga(), - buildSetSaga(), - buildReqSaga(), - buildsSaga() - ]); + yield all([commitsSaga(), branchesSaga(), pullsSaga(), buildSetSaga()]); }