mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
correct getting failure function and is loading
This commit is contained in:
@@ -59,6 +59,7 @@ export function getFailure(
|
|||||||
itemId?: string | number
|
itemId?: string | number
|
||||||
) {
|
) {
|
||||||
if (state.failure) {
|
if (state.failure) {
|
||||||
|
console.log(state.failure);
|
||||||
let identifier = actionType;
|
let identifier = actionType;
|
||||||
if (itemId) {
|
if (itemId) {
|
||||||
identifier += "/" + itemId;
|
identifier += "/" + itemId;
|
||||||
|
|||||||
@@ -36,8 +36,7 @@ class Permissions extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { namespace, name, loading, error, permissions, t } = this.props;
|
const { loading, error, permissions, t } = this.props;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
<ErrorPage
|
<ErrorPage
|
||||||
@@ -62,8 +61,8 @@ class Permissions extends React.Component<Props> {
|
|||||||
const mapStateToProps = (state, ownProps) => {
|
const mapStateToProps = (state, ownProps) => {
|
||||||
const namespace = ownProps.namespace;
|
const namespace = ownProps.namespace;
|
||||||
const name = ownProps.name;
|
const name = ownProps.name;
|
||||||
const error = getFetchPermissionsFailure(state);
|
const error = getFetchPermissionsFailure(state, namespace, name);
|
||||||
const loading = isFetchPermissionsPending(state);
|
const loading = isFetchPermissionsPending(state, namespace, name);
|
||||||
const permissions = getPermissionsOfRepo(state, namespace, name);
|
const permissions = getPermissionsOfRepo(state, namespace, name);
|
||||||
return {
|
return {
|
||||||
namespace,
|
namespace,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import type { PermissionCollection } from "../types/Permissions";
|
|||||||
import { isPending } from "../../modules/pending";
|
import { isPending } from "../../modules/pending";
|
||||||
import { getFailure } from "../../modules/failure";
|
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}_${
|
export const FETCH_PERMISSIONS_PENDING = `${FETCH_PERMISSIONS}_${
|
||||||
types.PENDING_SUFFIX
|
types.PENDING_SUFFIX
|
||||||
}`;
|
}`;
|
||||||
@@ -112,10 +112,18 @@ export function getPermissionsOfRepo(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isFetchPermissionsPending(state: Object) {
|
export function isFetchPermissionsPending(
|
||||||
return isPending(state, FETCH_PERMISSIONS);
|
state: Object,
|
||||||
|
namespace: string,
|
||||||
|
name: string
|
||||||
|
) {
|
||||||
|
return isPending(state, FETCH_PERMISSIONS, namespace + "/" + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFetchPermissionsFailure(state: Object) {
|
export function getFetchPermissionsFailure(
|
||||||
return getFailure(state, FETCH_PERMISSIONS);
|
state: Object,
|
||||||
|
namespace: string,
|
||||||
|
name: string
|
||||||
|
) {
|
||||||
|
return getFailure(state, FETCH_PERMISSIONS, namespace + "/" + name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,26 +168,34 @@ describe("permissions selectors", () => {
|
|||||||
it("should return true, when fetch permissions is pending", () => {
|
it("should return true, when fetch permissions is pending", () => {
|
||||||
const state = {
|
const state = {
|
||||||
pending: {
|
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", () => {
|
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", () => {
|
it("should return error when fetch permissions did fail", () => {
|
||||||
const state = {
|
const state = {
|
||||||
failure: {
|
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", () => {
|
it("should return undefined when fetch permissions did not fail", () => {
|
||||||
expect(getFetchPermissionsFailure({})).toBe(undefined);
|
expect(getFetchPermissionsFailure({}, "hitchhiker", "puzzle42")).toBe(
|
||||||
|
undefined
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user