-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ChartDisabled in frontend when disabled in conf
- Loading branch information
Showing
9 changed files
with
98 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
|
||
function ChartDisabledBox() { | ||
return ( | ||
<div | ||
className="mt-4 bg-white shadow rounded-lg py-4 px-8 mx-auto" | ||
data-testid="chart-disabled-box" | ||
> | ||
<h2 className="font-bold text-center text-xl"> | ||
Charts are disabled, please check documentation for further details | ||
</h2> | ||
</div> | ||
); | ||
} | ||
|
||
export default ChartDisabledBox; |
10 changes: 10 additions & 0 deletions
10
assets/js/common/ChartDisabledBox/ChartDisabledBox.stories.jsx
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,10 @@ | ||
import ChartDisabledBox from '.'; | ||
|
||
export default { | ||
title: 'Components/ChartDisabledBox', | ||
component: ChartDisabledBox, | ||
}; | ||
|
||
export const Default = { | ||
args: {}, | ||
}; |
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,3 @@ | ||
import ChartDisabledBox from './ChartDisabledBox'; | ||
|
||
export default ChartDisabledBox; |
10 changes: 10 additions & 0 deletions
10
assets/js/common/ChartFeatureWrapper/ChartFeatureWrapper.jsx
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,10 @@ | ||
import React from 'react'; | ||
import ChartDisabledBox from '@common/ChartDisabledBox'; | ||
|
||
function ChartFeatureWrapper({ children }) { | ||
// eslint-disable-next-line no-undef | ||
if (!config.chartsEnabled) return <ChartDisabledBox />; | ||
return children; | ||
} | ||
|
||
export default ChartFeatureWrapper; |
31 changes: 31 additions & 0 deletions
31
assets/js/common/ChartFeatureWrapper/ChartFeatureWrapper.test.jsx
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,31 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import ChartFeatureWrapper from './ChartFeatureWrapper'; | ||
|
||
describe('ChartFeatureWrapper', () => { | ||
afterEach(() => { | ||
global.config = { chartsEnabled: false }; | ||
}); | ||
|
||
it('should render ChartDisabledBox if the chart feature is disabled', () => { | ||
global.config = { chartsEnabled: false }; | ||
|
||
render(<ChartFeatureWrapper />); | ||
expect(screen.getByTestId('chart-disabled-box')).toHaveTextContent( | ||
'disabled' | ||
); | ||
}); | ||
|
||
it('should render children if the chart feature is enabled', () => { | ||
global.config = { chartsEnabled: true }; | ||
|
||
render( | ||
<ChartFeatureWrapper> | ||
{' '} | ||
<div data-testid="child">child</div>{' '} | ||
</ChartFeatureWrapper> | ||
); | ||
expect(screen.getByTestId('child')).toHaveTextContent('child'); | ||
}); | ||
}); |
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,3 @@ | ||
import ChartFeatureWrapper from './ChartFeatureWrapper'; | ||
|
||
export default ChartFeatureWrapper; |
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