fetch indexResources at beginning

This commit is contained in:
Maren Süwer
2018-10-05 13:14:33 +02:00
parent 3fd88f6166
commit a5f4d9713e
3 changed files with 31 additions and 6 deletions

View File

@@ -19,16 +19,23 @@ import {
Footer,
Header
} from "@scm-manager/ui-components";
import type { Me } from "@scm-manager/ui-types";
import type { Me, IndexResources } from "@scm-manager/ui-types";
import {
fetchIndexResources,
getFetchIndexResourcesFailure,
isFetchIndexResourcesPending
} from "../modules/indexResource";
type Props = {
me: Me,
authenticated: boolean,
error: Error,
loading: boolean,
indexResources: IndexResources,
// dispatcher functions
fetchMe: () => void,
fetchIndexResources: () => void,
// context props
t: string => string
@@ -36,6 +43,7 @@ type Props = {
class App extends Component<Props> {
componentDidMount() {
this.props.fetchIndexResources();
this.props.fetchMe();
}
@@ -70,15 +78,18 @@ class App extends Component<Props> {
const mapDispatchToProps = (dispatch: any) => {
return {
fetchMe: () => dispatch(fetchMe())
fetchMe: () => dispatch(fetchMe()),
fetchIndexResources: () => dispatch(fetchIndexResources())
};
};
const mapStateToProps = state => {
const authenticated = isAuthenticated(state);
const me = getMe(state);
const loading = isFetchMePending(state);
const error = getFetchMeFailure(state);
const loading =
isFetchMePending(state) || isFetchIndexResourcesPending(state);
const error =
getFetchMeFailure(state) || getFetchIndexResourcesFailure(state);
return {
authenticated,
me,

View File

@@ -8,7 +8,7 @@ import { getFailure } from "./failure";
// Action
export const FETCH_INDEXRESOURCES = "scm/indexResource";
export const FETCH_INDEXRESOURCES = "scm/INDEXRESOURCES";
export const FETCH_INDEXRESOURCES_PENDING = `${FETCH_INDEXRESOURCES}_${
types.PENDING_SUFFIX
}`;
@@ -86,6 +86,10 @@ export function getFetchIndexResourcesFailure(state: Object) {
return getFailure(state, FETCH_INDEXRESOURCES);
}
export function getLinks(state: Object){
return state.indexResources.links;
}
export function getUiPluginsLink(state: Object) {
return state.indexResources.links["uiPlugins"].href;
}

View File

@@ -19,7 +19,8 @@ import reducer, {
getRepositoriesLink,
getHgConfigLink,
getGitConfigLink,
getSvnConfigLink
getSvnConfigLink,
getLinks
} from "./indexResource";
const indexResourcesUnauthenticated = {
@@ -187,6 +188,15 @@ describe("index resources selectors", () => {
expect(getFetchIndexResourcesFailure({})).toBe(undefined);
});
it("should return all links", () => {
const state = {
indexResources: {
links: indexResourcesAuthenticated._links
}
};
expect(getLinks(state)).toBe(indexResourcesAuthenticated._links);
});
// ui plugins link
it("should return ui plugins link when authenticated and has permission to see it", () => {
const state = {