-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- get feature flag from AppConfig - add Feature component and useFeature hook - this change replace the environement variable based feature flag (#6367)
- Loading branch information
Showing
3 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
graylog2-web-interface/src/components/features/Feature.tsx
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,48 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import useFeature from 'hooks/useFeature'; | ||
|
||
type Props = { | ||
name: string; | ||
fallback?: React.ReactNode, | ||
children: React.ReactNode, | ||
} | ||
|
||
const Feature = ({ name, fallback, children }: Props) => { | ||
const hasFeature = useFeature(name); | ||
|
||
if (hasFeature) { | ||
return children; | ||
} | ||
|
||
return fallback; | ||
}; | ||
|
||
Feature.propTypes = { | ||
name: PropTypes.string.isRequired, | ||
fallback: PropTypes.node, | ||
children: PropTypes.node.isRequired, | ||
}; | ||
|
||
Feature.defaultProps = { | ||
fallback: null, | ||
}; | ||
|
||
export default Feature; |
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,29 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
import PropTypes from 'prop-types'; | ||
|
||
import AppConfig from 'util/AppConfig'; | ||
|
||
const useFeature = (name: string) => { | ||
return AppConfig.isFeatureEnabled(name); | ||
}; | ||
|
||
useFeature.propTypes = { | ||
name: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default useFeature; |
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