mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 17:00:55 +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;
|
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));
|
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 () => {
|
test('Returns a custom defaultValue on first render followed by the EE data', async () => {
|
||||||
const { result } = setup(CE_DATA_FIXTURE, async () => EE_DATA_FIXTURE, {
|
const { result } = setup(CE_DATA_FIXTURE, async () => EE_DATA_FIXTURE, {
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
|
@ -9,7 +9,7 @@ function isEnterprise() {
|
|||||||
export function useEnterprise(
|
export function useEnterprise(
|
||||||
ceData,
|
ceData,
|
||||||
eeCallback,
|
eeCallback,
|
||||||
{ defaultValue = null, combine = (ceData, eeData) => eeData } = {}
|
{ defaultValue = null, combine = (ceData, eeData) => eeData, enabled = true } = {}
|
||||||
) {
|
) {
|
||||||
const eeCallbackRef = useCallbackRef(eeCallback);
|
const eeCallbackRef = useCallbackRef(eeCallback);
|
||||||
const combineCallbackRef = useCallbackRef(combine);
|
const combineCallbackRef = useCallbackRef(combine);
|
||||||
@ -17,7 +17,7 @@ export function useEnterprise(
|
|||||||
// We have to use a nested object here, because functions (e.g. Components)
|
// We have to use a nested object here, because functions (e.g. Components)
|
||||||
// can not be stored as value directly
|
// can not be stored as value directly
|
||||||
const [{ data }, setData] = React.useState({
|
const [{ data }, setData] = React.useState({
|
||||||
data: isEnterprise() ? defaultValue : ceData,
|
data: isEnterprise() && enabled ? defaultValue : ceData,
|
||||||
});
|
});
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
@ -27,10 +27,10 @@ export function useEnterprise(
|
|||||||
setData({ data: combineCallbackRef(ceData, eeData) });
|
setData({ data: combineCallbackRef(ceData, eeData) });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEnterprise()) {
|
if (isEnterprise() && enabled) {
|
||||||
importEE();
|
importEE();
|
||||||
}
|
}
|
||||||
}, [ceData, eeCallbackRef, combineCallbackRef]);
|
}, [ceData, eeCallbackRef, combineCallbackRef, enabled]);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user