Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update hook to use change request settings (#2406)
* Refactors the hook to use the change request settings from the API
- Loading branch information
1 parent
a425bcb
commit 4689705
Showing
10 changed files
with
63 additions
and
35 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
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
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
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
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 |
---|---|---|
@@ -1,10 +1,35 @@ | ||
import React from 'react'; | ||
import useUiConfig from './api/getters/useUiConfig/useUiConfig'; | ||
import { useChangeRequestConfig } from './api/getters/useChangeRequestConfig/useChangeRequestConfig'; | ||
|
||
export const useChangeRequestsEnabled = (environment?: string) => { | ||
// it can be swapped with proper settings instead of feature flag | ||
export const useChangeRequestsEnabled = (projectId: string) => { | ||
const { uiConfig } = useUiConfig(); | ||
return ( | ||
Boolean(uiConfig?.flags?.changeRequests) && | ||
(environment === 'production' || typeof environment === 'undefined') | ||
const { data } = useChangeRequestConfig(projectId); | ||
|
||
const isChangeRequestConfigured = React.useCallback( | ||
(environment: string): boolean => { | ||
const enabled = data.some(draft => { | ||
return ( | ||
draft.environment === environment && | ||
draft.changeRequestEnabled | ||
); | ||
}); | ||
|
||
return Boolean(uiConfig?.flags.changeRequests) && enabled; | ||
}, | ||
[data] | ||
); | ||
|
||
const isChangeRequestConfiguredInAnyEnv = React.useCallback((): boolean => { | ||
return ( | ||
Boolean(uiConfig?.flags.changeRequests) && | ||
data.some(draft => draft.changeRequestEnabled) | ||
); | ||
}, [data]); | ||
|
||
return { | ||
isChangeRequestFlagEnabled: Boolean(uiConfig?.flags.changeRequests), | ||
isChangeRequestConfigured, | ||
isChangeRequestConfiguredInAnyEnv, | ||
}; | ||
}; |