Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'Refresh All App Repositories' button #1091

Merged
merged 3 commits into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions dashboard/src/actions/repos.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,6 @@ describe("deleteRepo", () => {
});

describe("resyncRepo", () => {
it("dispatches requestRepos and receiveRepos if no error", async () => {
const expectedActions = [
{
type: getType(repoActions.requestRepos),
},
{
type: getType(repoActions.receiveRepos),
payload: { foo: "bar" },
},
];

await store.dispatch(repoActions.resyncRepo("foo"));
expect(store.getActions()).toEqual(expectedActions);
});

it("dispatches errorRepos if error on #get", async () => {
AppRepository.get = jest.fn().mockImplementationOnce(() => {
throw new Error("Boom!");
Expand Down Expand Up @@ -158,25 +143,6 @@ describe("resyncRepo", () => {
await store.dispatch(repoActions.resyncRepo("foo"));
expect(store.getActions()).toEqual(expectedActions);
});

it("dispatches requestRepos and errorRepos if error on #list", async () => {
AppRepository.list = jest.fn().mockImplementationOnce(() => {
throw new Error("Boom!");
});

const expectedActions = [
{
type: getType(repoActions.requestRepos),
},
{
type: getType(repoActions.errorRepos),
payload: { err: new Error("Boom!"), op: "update" },
},
];

await store.dispatch(repoActions.resyncRepo("foo"));
expect(store.getActions()).toEqual(expectedActions);
});
});

describe("fetchRepos", () => {
Expand Down
13 changes: 10 additions & 3 deletions dashboard/src/actions/repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,22 @@ export const resyncRepo = (
repo.spec.resyncRequests++;
await AppRepository.update(name, namespace, repo);
// TODO: Do something to show progress
dispatch(requestRepos());
const repos = await AppRepository.list(namespace);
dispatch(receiveRepos(repos.items));
} catch (e) {
dispatch(errorRepos(e, "update"));
}
};
};

export const resyncAllRepos = (
repoNames: string[],
): ThunkAction<Promise<void>, IStoreState, null, AppReposAction> => {
return async (dispatch, getState) => {
repoNames.forEach(name => {
dispatch(resyncRepo(name));
});
};
};

export const fetchRepos = (): ThunkAction<Promise<void>, IStoreState, null, AppReposAction> => {
return async (dispatch, getState) => {
dispatch(requestRepos());
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/components/Config/AppRepoList/AppRepoButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class AppRepoAddButton extends React.Component<
public render() {
const { redirectTo } = this.props;
return (
<div className="AppRepoAddButton">
<React.Fragment>
<button className="button button-primary" onClick={this.openModal}>
Add App Repository
</button>
Expand All @@ -64,7 +64,7 @@ export class AppRepoAddButton extends React.Component<
<AppRepoForm install={this.install} onAfterInstall={this.closeModal} />
</Modal>
{redirectTo && <Redirect to={redirectTo} />}
</div>
</React.Fragment>
);
}

Expand Down
17 changes: 16 additions & 1 deletion dashboard/src/components/Config/AppRepoList/AppRepoList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IAppRepository, IRBACRole } from "../../../shared/types";
import ErrorSelector from "../../ErrorAlert/ErrorSelector";
import { AppRepoAddButton } from "./AppRepoButton";
import { AppRepoListItem } from "./AppRepoListItem";
import { AppRepoRefreshAllButton } from "./AppRepoRefreshAllButton";

export interface IAppRepoListProps {
errors: {
Expand All @@ -16,6 +17,7 @@ export interface IAppRepoListProps {
fetchRepos: () => void;
deleteRepo: (name: string) => Promise<boolean>;
resyncRepo: (name: string) => void;
resyncAllRepos: (names: string[]) => void;
install: (name: string, url: string, authHeader: string, customCA: string) => Promise<boolean>;
kubeappsNamespace: string;
}
Expand Down Expand Up @@ -61,7 +63,15 @@ class AppRepoList extends React.Component<IAppRepoListProps> {
}

public render() {
const { errors, repos, install, deleteRepo, resyncRepo, kubeappsNamespace } = this.props;
const {
errors,
repos,
install,
deleteRepo,
resyncRepo,
resyncAllRepos,
kubeappsNamespace,
} = this.props;
return (
<div className="app-repo-list">
<h1>App Repositories</h1>
Expand Down Expand Up @@ -92,6 +102,11 @@ class AppRepoList extends React.Component<IAppRepoListProps> {
install={install}
kubeappsNamespace={kubeappsNamespace}
/>
<AppRepoRefreshAllButton
resyncAllRepos={resyncAllRepos}
repos={repos}
kubeappsNamespace={kubeappsNamespace}
/>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as React from "react";

import { IAppRepository } from "shared/types";
import "./AppRepo.css";

interface IAppRepoRefreshAllButtonProps {
resyncAllRepos: (names: string[]) => void;
repos: IAppRepository[];
kubeappsNamespace: string;
}

export class AppRepoRefreshAllButton extends React.Component<IAppRepoRefreshAllButtonProps> {
public render() {
return (
<button
className="button button-primary margin-l-big"
onClick={this.handleResyncAllClick}
title="Refresh All App Repositories"
>
Refresh All
</button>
);
}

private handleResyncAllClick = async () => {
if (this.props.repos) {
const repoNames = this.props.repos.map(repo => {
return repo.metadata.name;
});
this.props.resyncAllRepos(repoNames);
}
};
}
Loading