fetch changeset correct

This commit is contained in:
Maren Süwer
2018-09-25 14:11:18 +02:00
parent e3c7f50797
commit 5463796741
3 changed files with 11 additions and 11 deletions

View File

@@ -11,7 +11,6 @@ type Props = {
repository: Repository,
repositories: Repository[],
fetchChangesetIfNeeded: (
state: Object,
namespace: string,
repoName: string,
id: string
@@ -28,7 +27,7 @@ class ChangesetView extends React.Component<State, Props> {
const { fetchChangesetIfNeeded, repository } = this.props;
const id = this.props.match.params.id;
//state macht keinen Sinn?! repositories holen!
fetchChangesetIfNeeded(null, repository.namespace, repository.name, id);
fetchChangesetIfNeeded(repository.namespace, repository.name, id);
}
render() {
@@ -45,12 +44,11 @@ const mapStateToProps = (state, ownProps: Props) => {
const mapDispatchToProps = dispatch => {
return {
fetchChangesetIfNeeded: (
state: Object,
namespace: string,
repoName: string,
id: string
) => {
dispatch(fetchChangesetIfNeeded(state, namespace, repoName, id));
dispatch(fetchChangesetIfNeeded(namespace, repoName, id));
}
};
};

View File

@@ -32,13 +32,11 @@ const REPO_URL = "repositories";
//********added for detailed view of changesets
export function fetchChangesetIfNeeded(
state: Object,
namespace: string,
repoName: string,
id: string
) {
return (dispatch: any, getState: any) => {
console.log(getState());
if (shouldFetchChangeset(getState(), namespace, repoName, id)) {
return dispatch(fetchChangeset(namespace, repoName, id));
}
@@ -59,6 +57,7 @@ export function fetchChangeset(
dispatch(fetchChangesetSuccess(data, namespace, repoName, id))
)
.catch(err => {
console.log(err);
dispatch(fetchChangesetFailure(namespace, repoName, id, err));
});
};
@@ -276,7 +275,7 @@ function listReducer(
//********added for detailed view of changesets
case FETCH_CHANGESET_SUCCESS:
const changesetId = action.payload.changeset.id;
const stateEntries = state.entries;
const stateEntries = state.entries ? state.entries : [];
stateEntries.push(changesetId);
return {
entries: stateEntries,
@@ -359,7 +358,10 @@ export function getChangeset(
branch?: string
) {
const key = createItemId(namespace, name, branch);
const changesets = state.changesets.byKey[key].byId;
const changesets =
state.changesets && state.changesets.byKey && state.changesets.byKey[key]
? state.changesets.byKey[key].byId
: null;
if (changesets != null && changesets[id]) {
return changesets[id];
}

View File

@@ -145,7 +145,7 @@ describe("changesets", () => {
const store = mockStore({});
return store
.dispatch(fetchChangesetIfNeeded(state, "foo", "bar", "id3"))
.dispatch(fetchChangesetIfNeeded("foo", "bar", "id3"))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
@@ -169,9 +169,9 @@ describe("changesets", () => {
const expectedActions = [];
const store = mockStore({});
const store = mockStore(state);
return expect(
store.dispatch(fetchChangesetIfNeeded(state, "foo", "bar", "id1"))
store.dispatch(fetchChangesetIfNeeded("foo", "bar", "id1"))
).toEqual(undefined);
});