-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AppCatalog: Adds comp and story for AppCatalogSettings
Signed-off-by: Vincent T <[email protected]>
- Loading branch information
Showing
4 changed files
with
83 additions
and
107 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
app-catalog/src/components/settings/AppCatalogSettings.stories.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,30 @@ | ||
import { createTheme, ThemeProvider } from '@mui/material/styles'; | ||
import { Meta, Story } from '@storybook/react'; | ||
import React from 'react'; | ||
import { AppCatalogSettings, AppCatalogSettingsProps } from './AppCatalogSettings'; | ||
|
||
export default { | ||
title: 'Components/AppCatalogSettings', | ||
component: AppCatalogSettings, | ||
} as Meta | ||
|
||
const theme = createTheme(); | ||
|
||
const Template: Story<AppCatalogSettingsProps> = (args) => ( | ||
<ThemeProvider theme={theme}> | ||
<AppCatalogSettings {...args} /> | ||
</ThemeProvider> | ||
); | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = {}; | ||
|
||
export const ShowOnlyVerifiedTrue = Template.bind({}); | ||
ShowOnlyVerifiedTrue.args = { | ||
initialConfig: { showOnlyVerified: true }, | ||
}; | ||
|
||
export const ShowOnlyVerifiedFalse = Template.bind({}); | ||
ShowOnlyVerifiedFalse.args = { | ||
initialConfig: { showOnlyVerified: false }, | ||
}; |
52 changes: 52 additions & 0 deletions
52
app-catalog/src/components/settings/AppCatalogSettings.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,52 @@ | ||
import { HoverInfoLabel, NameValueTable } from '@kinvolk/headlamp-plugin/lib/components/common'; | ||
import { Box, Typography } from '@mui/material'; | ||
import { useState } from 'react'; | ||
import { store } from '../charts/List'; | ||
import { EnableSwitch } from './EnableSwitch'; | ||
|
||
export interface AppCatalogSettingsProps { | ||
initialConfig?: { showOnlyVerified: boolean }; | ||
} | ||
|
||
export function AppCatalogSettings({ initialConfig }: AppCatalogSettingsProps) { | ||
const config = initialConfig || store.get(); | ||
|
||
const [currentConfig, setCurrentConfig] = useState(config); | ||
|
||
function handleSave(value) { | ||
const updatedConfig = { showOnlyVerified: value }; | ||
store.set(updatedConfig); | ||
setCurrentConfig(store.get()); | ||
return; | ||
} | ||
|
||
function toggleShowOnlyVerified() { | ||
const newShowOnlyVerified = currentConfig?.showOnlyVerified; | ||
handleSave(!newShowOnlyVerified); | ||
} | ||
|
||
return ( | ||
<Box | ||
style={{ | ||
marginTop: '3rem', | ||
}} | ||
> | ||
<Typography variant="h5">App Catalog Settings</Typography> | ||
<NameValueTable | ||
rows={[ | ||
{ | ||
name: ( | ||
<HoverInfoLabel | ||
label="Only verified" | ||
hoverInfo="Show charts from verified publishers only" | ||
/> | ||
), | ||
value: ( | ||
<EnableSwitch checked={!!currentConfig?.showOnlyVerified} onChange={toggleShowOnlyVerified} /> | ||
), | ||
}, | ||
]} | ||
/> | ||
</Box> | ||
); | ||
} |
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 was deleted.
Oops, something went wrong.