improve typing and fixed import

This commit is contained in:
Sebastian Sdorra
2018-08-06 13:55:54 +02:00
parent dec6b3f17d
commit a3c00b9e12
3 changed files with 49 additions and 39 deletions

View File

@@ -2,7 +2,7 @@
import React from "react";
import InputField from "../../components/forms/InputField";
import { SubmitButton, Button } from "../../components/buttons";
import { SubmitButton } from "../../components/buttons";
import { translate } from "react-i18next";
import type { Group } from "../types/Group";
import * as validator from "./groupValidation";
@@ -117,8 +117,7 @@ class GroupForm extends React.Component<Props, State> {
members: usernames
}
});
}
};
addUser = (username: string) => {
if (this.isMember(username)) {

View File

@@ -1,3 +1,4 @@
// @flow
import { apiClient } from "../../apiclient";
import { isPending } from "../../modules/pending";
import { getFailure } from "../../modules/failure";
@@ -5,7 +6,7 @@ import * as types from "../../modules/types";
import { combineReducers, Dispatch } from "redux";
import type { Action } from "../../types/Action";
import type { PagedCollection } from "../../types/Collection";
import type { Groups } from "../types/Groups";
import type { Group } from "../types/Group";
export const FETCH_GROUPS = "scm/groups/FETCH_GROUPS";
export const FETCH_GROUPS_PENDING = `${FETCH_GROUPS}_${types.PENDING_SUFFIX}`;
@@ -139,10 +140,11 @@ export function createGroup(group: Group, callback?: () => void) {
return apiClient
.postWithContentType(GROUPS_URL, group, CONTENT_TYPE_GROUP)
.then(() => {
dispatch(createGroupSuccess())
dispatch(createGroupSuccess());
if (callback) {
callback();
}})
}
})
.catch(error => {
dispatch(
createGroupFailure(
@@ -175,7 +177,7 @@ export function createGroupFailure(error: Error) {
export function createGroupReset() {
return {
type: CREATE_GROUP_RESET
}
};
}
// modify group
@@ -185,14 +187,19 @@ export function modifyGroup(group: Group, callback?: () => void) {
return apiClient
.putWithContentType(group._links.update.href, group, CONTENT_TYPE_GROUP)
.then(() => {
dispatch(modifyGroupSuccess(group))
dispatch(modifyGroupSuccess(group));
if (callback) {
callback()
callback();
}
})
.catch(cause => {
dispatch(modifyGroupFailure(group, new Error(`could not modify group ${group.name}: ${cause.message}`)))
})
dispatch(
modifyGroupFailure(
group,
new Error(`could not modify group ${group.name}: ${cause.message}`)
)
);
});
};
}
@@ -201,7 +208,7 @@ export function modifyGroupPending(group: Group): Action {
type: MODIFY_GROUP_PENDING,
payload: group,
itemId: group.name
}
};
}
export function modifyGroupSuccess(group: Group): Action {
@@ -209,7 +216,7 @@ export function modifyGroupSuccess(group: Group): Action {
type: MODIFY_GROUP_SUCCESS,
payload: group,
itemId: group.name
}
};
}
export function modifyGroupFailure(group: Group, error: Error): Action {
@@ -220,7 +227,7 @@ export function modifyGroupFailure(group: Group, error: Error): Action {
group
},
itemId: group.name
}
};
}
//delete group
@@ -274,7 +281,7 @@ export function deleteGroupFailure(group: Group, error: Error): Action {
//reducer
function extractGroupsByNames(
groups: Groups[],
groups: Group[],
groupNames: string[],
oldGroupsByNames: Object
) {
@@ -436,11 +443,11 @@ export function getCreateGroupFailure(state: Object) {
}
export function isModifyGroupPending(state: Object, name: string) {
return(isPending(state, MODIFY_GROUP, name))
return isPending(state, MODIFY_GROUP, name);
}
export function getModifyGroupFailure(state: Object, name: string) {
return(getFailure(state, MODIFY_GROUP, name))
return getFailure(state, MODIFY_GROUP, name);
}
export function getGroupByName(state: Object, name: string) {

View File

@@ -1,14 +1,18 @@
//@flow
import type { Collection } from "../../types/Collection";
import type { Links } from "../../types/hal";
import type { User } from "../../users/types/User";
export type Group = {
export type Member = {
name: string,
_links: Links
};
export type Group = Collection & {
name: string,
description: string,
type: string,
members: string[],
_links: Links,
_embedded: {
members: User[]
members: Member[]
}
};