mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 08:52:26 +00:00
Enhancement: Extend useEnterprise hook by an enabled
boolean flag
This commit is contained in:
parent
3117d9f99e
commit
b88b9e8af8
@ -54,3 +54,8 @@ if (!Component) {
|
||||
return;
|
||||
}
|
||||
```
|
||||
|
||||
### `enabled`
|
||||
|
||||
Similar to react-query this boolean flag allows disabling the EE import, e.g. when more than one condition needs to be applied. If `enabled`
|
||||
is set to false, the first argument (CE_DATA) will be returned.
|
||||
|
@ -54,6 +54,14 @@ describe('useEnterprise (EE)', () => {
|
||||
await waitFor(() => expect(result.current).toStrictEqual(EE_DATA_FIXTURE));
|
||||
});
|
||||
|
||||
test('Returns CE data, when enabled is set to false', async () => {
|
||||
const { result } = setup(CE_DATA_FIXTURE, async () => EE_DATA_FIXTURE, {
|
||||
enabled: false,
|
||||
});
|
||||
|
||||
await waitFor(() => expect(result.current).toStrictEqual(CE_DATA_FIXTURE));
|
||||
});
|
||||
|
||||
test('Returns a custom defaultValue on first render followed by the EE data', async () => {
|
||||
const { result } = setup(CE_DATA_FIXTURE, async () => EE_DATA_FIXTURE, {
|
||||
defaultValue: false,
|
||||
|
@ -9,7 +9,7 @@ function isEnterprise() {
|
||||
export function useEnterprise(
|
||||
ceData,
|
||||
eeCallback,
|
||||
{ defaultValue = null, combine = (ceData, eeData) => eeData } = {}
|
||||
{ defaultValue = null, combine = (ceData, eeData) => eeData, enabled = true } = {}
|
||||
) {
|
||||
const eeCallbackRef = useCallbackRef(eeCallback);
|
||||
const combineCallbackRef = useCallbackRef(combine);
|
||||
@ -17,7 +17,7 @@ export function useEnterprise(
|
||||
// We have to use a nested object here, because functions (e.g. Components)
|
||||
// can not be stored as value directly
|
||||
const [{ data }, setData] = React.useState({
|
||||
data: isEnterprise() ? defaultValue : ceData,
|
||||
data: isEnterprise() && enabled ? defaultValue : ceData,
|
||||
});
|
||||
|
||||
React.useEffect(() => {
|
||||
@ -27,10 +27,10 @@ export function useEnterprise(
|
||||
setData({ data: combineCallbackRef(ceData, eeData) });
|
||||
}
|
||||
|
||||
if (isEnterprise()) {
|
||||
if (isEnterprise() && enabled) {
|
||||
importEE();
|
||||
}
|
||||
}, [ceData, eeCallbackRef, combineCallbackRef]);
|
||||
}, [ceData, eeCallbackRef, combineCallbackRef, enabled]);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user