correct getting failure function and is loading

This commit is contained in:
Maren Süwer
2018-08-23 12:25:00 +02:00
parent d784109326
commit 80aad7ccc1
4 changed files with 31 additions and 15 deletions

View File

@@ -59,6 +59,7 @@ export function getFailure(
itemId?: string | number
) {
if (state.failure) {
console.log(state.failure);
let identifier = actionType;
if (itemId) {
identifier += "/" + itemId;

View File

@@ -36,8 +36,7 @@ class Permissions extends React.Component<Props> {
}
render() {
const { namespace, name, loading, error, permissions, t } = this.props;
const { loading, error, permissions, t } = this.props;
if (error) {
return (
<ErrorPage
@@ -62,8 +61,8 @@ class Permissions extends React.Component<Props> {
const mapStateToProps = (state, ownProps) => {
const namespace = ownProps.namespace;
const name = ownProps.name;
const error = getFetchPermissionsFailure(state);
const loading = isFetchPermissionsPending(state);
const error = getFetchPermissionsFailure(state, namespace, name);
const loading = isFetchPermissionsPending(state, namespace, name);
const permissions = getPermissionsOfRepo(state, namespace, name);
return {
namespace,

View File

@@ -6,7 +6,7 @@ import type { PermissionCollection } from "../types/Permissions";
import { isPending } from "../../modules/pending";
import { getFailure } from "../../modules/failure";
export const FETCH_PERMISSIONS = "scm/repos/FETCH_PERMISSIONS";
export const FETCH_PERMISSIONS = "scm/permissions/FETCH_PERMISSIONS";
export const FETCH_PERMISSIONS_PENDING = `${FETCH_PERMISSIONS}_${
types.PENDING_SUFFIX
}`;
@@ -112,10 +112,18 @@ export function getPermissionsOfRepo(
}
}
export function isFetchPermissionsPending(state: Object) {
return isPending(state, FETCH_PERMISSIONS);
export function isFetchPermissionsPending(
state: Object,
namespace: string,
name: string
) {
return isPending(state, FETCH_PERMISSIONS, namespace + "/" + name);
}
export function getFetchPermissionsFailure(state: Object) {
return getFailure(state, FETCH_PERMISSIONS);
export function getFetchPermissionsFailure(
state: Object,
namespace: string,
name: string
) {
return getFailure(state, FETCH_PERMISSIONS, namespace + "/" + name);
}

View File

@@ -168,26 +168,34 @@ describe("permissions selectors", () => {
it("should return true, when fetch permissions is pending", () => {
const state = {
pending: {
[FETCH_PERMISSIONS]: true
[FETCH_PERMISSIONS + "/hitchhiker/puzzle42"]: true
}
};
expect(isFetchPermissionsPending(state)).toEqual(true);
expect(isFetchPermissionsPending(state, "hitchhiker", "puzzle42")).toEqual(
true
);
});
it("should return false, when fetch permissions is not pending", () => {
expect(isFetchPermissionsPending({})).toEqual(false);
expect(isFetchPermissionsPending({}, "hitchiker", "puzzle42")).toEqual(
false
);
});
it("should return error when fetch permissions did fail", () => {
const state = {
failure: {
[FETCH_PERMISSIONS]: error
[FETCH_PERMISSIONS + "/hitchhiker/puzzle42"]: error
}
};
expect(getFetchPermissionsFailure(state)).toEqual(error);
expect(getFetchPermissionsFailure(state, "hitchhiker", "puzzle42")).toEqual(
error
);
});
it("should return undefined when fetch permissions did not fail", () => {
expect(getFetchPermissionsFailure({})).toBe(undefined);
expect(getFetchPermissionsFailure({}, "hitchhiker", "puzzle42")).toBe(
undefined
);
});
});