-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(bannerMessages): ent-4899 align hook components
- Loading branch information
Showing
12 changed files
with
95 additions
and
507 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { useShallowCompareEffect } from 'react-use'; | ||
import { reduxActions, storeHooks } from '../../redux'; | ||
import { useProduct, useProductQuery } from '../productView/productViewContext'; | ||
import { dateHelpers } from '../../common'; | ||
import { | ||
rhsmConstants, | ||
RHSM_API_QUERY_GRANULARITY_TYPES as GRANULARITY_TYPES, | ||
RHSM_API_QUERY_SET_TYPES | ||
} from '../../services/rhsm/rhsmConstants'; | ||
|
||
/** | ||
* Get app messages. | ||
* | ||
* @param {object} options | ||
* @param {Function} options.getMessageReports | ||
* @param {Function} options.useDispatch | ||
* @param {Function} options.useProduct | ||
* @param {Function} options.useProductQuery | ||
* @param {Function} options.useSelectorsResponse | ||
* @returns {object} | ||
*/ | ||
const useGetAppMessages = ({ | ||
getMessageReports = reduxActions.rhsm.getMessageReports, | ||
useDispatch: useAliasDispatch = storeHooks.reactRedux.useDispatch, | ||
useProduct: useAliasProduct = useProduct, | ||
useProductQuery: useAliasProductQuery = useProductQuery, | ||
useSelectorsResponse: useAliasSelectorsResponse = storeHooks.reactRedux.useSelectorsResponse | ||
} = {}) => { | ||
const { productId } = useAliasProduct(); | ||
const query = useAliasProductQuery(); | ||
const dispatch = useAliasDispatch(); | ||
const { error, fulfilled, pending, data } = useAliasSelectorsResponse({ | ||
id: 'messages', | ||
selector: ({ messages }) => messages?.report?.[productId] | ||
}); | ||
|
||
useShallowCompareEffect(() => { | ||
if (productId) { | ||
const { startDate, endDate } = dateHelpers.getRangedDateTime('CURRENT'); | ||
const updatedQuery = { | ||
...query, | ||
[RHSM_API_QUERY_SET_TYPES.GRANULARITY]: GRANULARITY_TYPES.DAILY, | ||
[RHSM_API_QUERY_SET_TYPES.START_DATE]: startDate.toISOString(), | ||
[RHSM_API_QUERY_SET_TYPES.END_DATE]: endDate.toISOString() | ||
}; | ||
|
||
getMessageReports(productId, updatedQuery)(dispatch); | ||
} | ||
}, [productId, query]); | ||
|
||
const updatedData = { | ||
cloudigradeMismatch: false | ||
}; | ||
|
||
if (fulfilled) { | ||
const { messages = {} } = data || {}; | ||
|
||
updatedData.cloudigradeMismatch = | ||
messages?.data | ||
?.reverse() | ||
?.find( | ||
({ [rhsmConstants.RHSM_API_RESPONSE_TALLY_META_TYPES.HAS_CLOUDIGRADE_MISMATCH]: mismatch }) => | ||
mismatch === true | ||
) !== undefined; | ||
} | ||
|
||
return { | ||
error, | ||
fulfilled, | ||
pending, | ||
data: { | ||
...updatedData | ||
} | ||
}; | ||
}; | ||
|
||
const context = { | ||
useGetAppMessages | ||
}; | ||
|
||
export { context as default, context, useGetAppMessages }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
import { reactReduxHooks } from './useReactRedux'; | ||
import { rhsmActionsHooks } from './useRhsmActions'; | ||
import { rhsmSelectorsHooks } from './useRhsmSelectors'; | ||
|
||
const storeHooks = { | ||
reactRedux: reactReduxHooks, | ||
rhsmActions: rhsmActionsHooks, | ||
rhsmSelectors: rhsmSelectorsHooks | ||
reactRedux: reactReduxHooks | ||
}; | ||
|
||
export { storeHooks as default, storeHooks, reactReduxHooks, rhsmActionsHooks, rhsmSelectorsHooks }; | ||
export { storeHooks as default, storeHooks, reactReduxHooks }; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.