diff --git a/src/actions/repos.ts b/src/actions/repos.ts index 85224763fb5..9d7304716d3 100644 --- a/src/actions/repos.ts +++ b/src/actions/repos.ts @@ -57,6 +57,20 @@ export const deleteRepo = (name: string, namespace: string = "kubeapps") => { }; }; +export const resyncRepo = (name: string, namespace: string = "kubeapps") => { + return async (dispatch: Dispatch) => { + const repo = await AppRepository.get(name, namespace); + repo.spec.resyncRequests = repo.spec.resyncRequests || 0; + repo.spec.resyncRequests++; + await AppRepository.update(name, namespace, repo); + // TODO: Do something to show progress + dispatch(requestRepos()); + const repos = await AppRepository.list(); + dispatch(receiveRepos(repos.items)); + return repos; + }; +}; + export const fetchRepos = () => { return async (dispatch: Dispatch) => { dispatch(requestRepos()); diff --git a/src/components/AppRepoList/index.tsx b/src/components/AppRepoList/index.tsx index dc5da7c6d76..3addaf38305 100644 --- a/src/components/AppRepoList/index.tsx +++ b/src/components/AppRepoList/index.tsx @@ -7,6 +7,7 @@ export interface IAppRepoListProps { repos: IAppRepository[]; fetchRepos: () => Promise; deleteRepo: (name: string) => Promise; + resyncRepo: (name: string) => Promise; install: (name: string, url: string) => Promise; } @@ -41,6 +42,12 @@ export class AppRepoList extends React.Component { > Delete + ); @@ -53,4 +60,5 @@ export class AppRepoList extends React.Component { } private handleDeleteClick = (repoName: string) => () => this.props.deleteRepo(repoName); + private handleResyncClick = (repoName: string) => () => this.props.resyncRepo(repoName); } diff --git a/src/containers/RepoListContainer.ts b/src/containers/RepoListContainer.ts index 2ecc43c6c87..2d0ccb141ba 100644 --- a/src/containers/RepoListContainer.ts +++ b/src/containers/RepoListContainer.ts @@ -22,6 +22,9 @@ function mapDispatchToProps(dispatch: Dispatch) { install: async (name: string, url: string, namespace: string = "kubeapps") => { return dispatch(actions.repos.installRepo(name, url, namespace)); }, + resyncRepo: async (name: string, namespace: string = "kubeapps") => { + return dispatch(actions.repos.resyncRepo(name, namespace)); + }, }; } diff --git a/src/shared/AppRepository.ts b/src/shared/AppRepository.ts index 625849dc72f..51d6535ca5a 100644 --- a/src/shared/AppRepository.ts +++ b/src/shared/AppRepository.ts @@ -10,6 +10,16 @@ export class AppRepository { return data; } + public static async get(name: string, namespace: string = "default") { + const { data } = await axios.get(AppRepository.getSelfLink(name, namespace)); + return data; + } + + public static async update(name: string, namespace: string = "default", newApp: IAppRepository) { + const { data } = await axios.put(AppRepository.getSelfLink(name, namespace), newApp); + return data; + } + public static async delete(name: string, namespace: string = "default") { const { data } = await axios.delete(AppRepository.getSelfLink(name, namespace)); return data;