consumerGroups.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { ConsumerGroupsApi, Configuration } from 'generated-sources';
  2. import {
  3. ConsumerGroupID,
  4. PromiseThunkResult,
  5. ClusterName,
  6. } from 'redux/interfaces';
  7. import { BASE_PARAMS } from 'lib/constants';
  8. import * as actions from 'redux/actions/actions';
  9. const apiClientConf = new Configuration(BASE_PARAMS);
  10. export const consumerGroupsApiClient = new ConsumerGroupsApi(apiClientConf);
  11. export const fetchConsumerGroupsList =
  12. (clusterName: ClusterName): PromiseThunkResult =>
  13. async (dispatch) => {
  14. dispatch(actions.fetchConsumerGroupsAction.request());
  15. try {
  16. const consumerGroups = await consumerGroupsApiClient.getConsumerGroups({
  17. clusterName,
  18. });
  19. dispatch(actions.fetchConsumerGroupsAction.success(consumerGroups));
  20. } catch (e) {
  21. dispatch(actions.fetchConsumerGroupsAction.failure());
  22. }
  23. };
  24. export const fetchConsumerGroupDetails =
  25. (
  26. clusterName: ClusterName,
  27. consumerGroupID: ConsumerGroupID
  28. ): PromiseThunkResult =>
  29. async (dispatch) => {
  30. dispatch(actions.fetchConsumerGroupDetailsAction.request());
  31. try {
  32. const consumerGroupDetails =
  33. await consumerGroupsApiClient.getConsumerGroup({
  34. clusterName,
  35. id: consumerGroupID,
  36. });
  37. dispatch(
  38. actions.fetchConsumerGroupDetailsAction.success({
  39. consumerGroupID,
  40. details: consumerGroupDetails,
  41. })
  42. );
  43. } catch (e) {
  44. dispatch(actions.fetchConsumerGroupDetailsAction.failure());
  45. }
  46. };