Skip to content

Commit

Permalink
AppRepo resync button (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmgot authored and prydonius committed Feb 13, 2018
1 parent 95c6c61 commit bda522f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/actions/repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ export const deleteRepo = (name: string, namespace: string = "kubeapps") => {
};
};

export const resyncRepo = (name: string, namespace: string = "kubeapps") => {
return async (dispatch: Dispatch<IStoreState>) => {
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<IStoreState>) => {
dispatch(requestRepos());
Expand Down
8 changes: 8 additions & 0 deletions src/components/AppRepoList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface IAppRepoListProps {
repos: IAppRepository[];
fetchRepos: () => Promise<any>;
deleteRepo: (name: string) => Promise<any>;
resyncRepo: (name: string) => Promise<any>;
install: (name: string, url: string) => Promise<any>;
}

Expand Down Expand Up @@ -41,6 +42,12 @@ export class AppRepoList extends React.Component<IAppRepoListProps> {
>
Delete
</button>
<button
className="button button-secondary"
onClick={this.handleResyncClick(repo.metadata.name)}
>
Refresh
</button>
</td>
</tr>
);
Expand All @@ -53,4 +60,5 @@ export class AppRepoList extends React.Component<IAppRepoListProps> {
}

private handleDeleteClick = (repoName: string) => () => this.props.deleteRepo(repoName);
private handleResyncClick = (repoName: string) => () => this.props.resyncRepo(repoName);
}
3 changes: 3 additions & 0 deletions src/containers/RepoListContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function mapDispatchToProps(dispatch: Dispatch<IStoreState>) {
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));
},
};
}

Expand Down
10 changes: 10 additions & 0 deletions src/shared/AppRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bda522f

Please sign in to comment.