Skip to content

Commit

Permalink
Add 'Refresh All App Repositories' button
Browse files Browse the repository at this point in the history
Close #582. Add a button next to 'Add App Repository'
to refresh all app repositories.
  • Loading branch information
jessehu committed Jul 23, 2019
1 parent dc36837 commit 7b1b9a5
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 3 deletions.
24 changes: 24 additions & 0 deletions dashboard/src/actions/repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,30 @@ export const resyncRepo = (
};
};

export const resyncAllRepos = (): ThunkAction<Promise<void>, IStoreState, null, AppReposAction> => {
return async (dispatch, getState) => {
try {
const {
config: { namespace },
} = getState();
// TODO: Do something to show progress
const repos = await AppRepository.list(namespace);
if (repos.items.length > 0) {
repos.items.forEach(repo => {
if (repo && repo.spec) {
repo.spec.resyncRequests = repo.spec.resyncRequests || 0;
repo.spec.resyncRequests++;
const name = repo.metadata.name;
AppRepository.update(name, namespace, repo);
}
});
}
} catch (e) {
dispatch(errorRepos(e, "update"));
}
};
};

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">
<span>
<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>
</span>
);
}

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: () => 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
error={errors.update}
resyncAllRepos={resyncAllRepos}
kubeappsNamespace={kubeappsNamespace}
/>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from "react";

import "./AppRepo.css";

interface IAppRepoRefreshAllButtonProps {
error?: Error;
resyncAllRepos: () => void;
kubeappsNamespace: string;
}

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

private handleResyncAllClick() {
return () => {
this.props.resyncAllRepos();
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function mapDispatchToProps(dispatch: ThunkDispatch<IStoreState, null, Action>)
resyncRepo: async (name: string) => {
return dispatch(actions.repos.resyncRepo(name));
},
resyncAllRepos: async () => {
return dispatch(actions.repos.resyncAllRepos());
},
};
}

Expand Down
1 change: 1 addition & 0 deletions dashboard/src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export interface IAppRepository
};
};
};
resyncRequests: number;
},
undefined
> {}
Expand Down

0 comments on commit 7b1b9a5

Please sign in to comment.