Skip to content

Commit

Permalink
Implement the group detail reducer and add new API
Browse files Browse the repository at this point in the history
  • Loading branch information
gkarat committed Feb 21, 2023
1 parent c716c74 commit 8eec311
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/components/InventoryGroups/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export const validateGroupName = (name) => {
.then((resp) => resp?.results.some((group) => group.name === name));
};

export const getGroupDetail = (groupId) => {
return instance.get(`${INVENTORY_API_BASE}/groups/${groupId}`);
};

getGroups.propTypes = {
search: PropTypes.shape({
// eslint-disable-next-line camelcase
Expand All @@ -35,3 +39,7 @@ getGroups.propTypes = {
page: PropTypes.number
})
};

getGroupDetail.propTypes = {
groupId: PropTypes.string.isRequired
};
3 changes: 2 additions & 1 deletion src/store/action-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export const asyncInventory = [
'LOAD_TAGS',
'ALL_TAGS',
'OPERATING_SYSTEMS',
'GROUPS'
'GROUPS',
'GROUP_DETAIL'
];

export const systemIssues = [
Expand Down
45 changes: 45 additions & 0 deletions src/store/groupDetail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

import { applyReducerHash } from '@redhat-cloud-services/frontend-components-utilities/ReducerRegistry';
import { ACTION_TYPES } from './action-types';

export const initialState = {
loading: false,
rejected: false,
fulfilled: false,
uninitialized: true,
error: null,
data: null
};

export default applyReducerHash(
{
[ACTION_TYPES.GROUP_DETAIL_PENDING]: (state) => {
return {
...state,
loading: true,
uninitialized: false
};
},
[ACTION_TYPES.GROUP_DETAIL_FULFILLED]: (state, { payload }) => {
return {
...state,
loading: false,
rejected: false,
uninitialized: false,
fulfilled: true,
data: payload
};
},
[ACTION_TYPES.GROUP_DETAIL_REJECTED]: (state, { payload }) => {
return {
...state,
loading: false,
rejected: true,
uninitialized: false,
fulfilled: false,
error: payload
};
}
},
initialState
);
7 changes: 6 additions & 1 deletion src/store/inventory-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
filtersReducer,
getOperatingSystems
} from '../api';
import { getGroups } from '../components/InventoryGroups/utils/api';
import { getGroupDetail, getGroups } from '../components/InventoryGroups/utils/api';

export const loadEntities = (items = [], { filters, ...config }, { showTags } = {}, getEntities = defaultGetEntities) => {
const itemIds = items.reduce((acc, curr) => (
Expand Down Expand Up @@ -184,6 +184,11 @@ export const fetchGroups = (search, pagination) => ({
payload: getGroups(search, pagination)
});

export const fetchGroupDetail = (groupId) => ({
type: ACTION_TYPES.GROUP_DETAIL,
payload: getGroupDetail(groupId)
});

export const fetchOperatingSystems = (params = []) => ({
type: ACTION_TYPES.OPERATING_SYSTEMS,
payload: getOperatingSystems(params)
Expand Down
4 changes: 3 additions & 1 deletion src/store/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { notificationsReducer } from '@redhat-cloud-services/frontend-components
import entitiesReducer, { defaultState as entitiesDefault } from './entities';
import entityDetailsReducer, { entityDefaultState as entityDefault, updateEntity } from './entityDetails';
import groups from './groups';
import groupDetail from './groupDetail';

export { entitiesReducer, entityDetailsReducer };

Expand Down Expand Up @@ -114,7 +115,8 @@ function onSetPagination(state, { payload }) {
let reducers = {
notifications: notificationsReducer,
systemProfileStore,
groups
groups,
groupDetail
};

export const tableReducer = applyReducerHash(
Expand Down

0 comments on commit 8eec311

Please sign in to comment.