-
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.
* Make ChecksCatalog component storybookable * Add ChecksCatalog stories * Use concat function properly
- Loading branch information
Showing
6 changed files
with
154 additions
and
71 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
82 changes: 82 additions & 0 deletions
82
assets/js/components/ChecksCatalog/ChecksCatalog.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,82 @@ | ||
import React from 'react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { faker } from '@faker-js/faker'; | ||
|
||
import { catalogCheckFactory } from '@lib/test-utils/factories'; | ||
import ChecksCatalog from './ChecksCatalog'; | ||
|
||
const groupName1 = faker.string.uuid(); | ||
const groupName2 = faker.string.uuid(); | ||
const groupName3 = faker.string.uuid(); | ||
const group1 = catalogCheckFactory.buildList(5, { group: groupName1 }); | ||
const group2 = catalogCheckFactory.buildList(5, { group: groupName2 }); | ||
const group3 = catalogCheckFactory.buildList(5, { group: groupName3 }); | ||
const catalogData = group1.concat(group2, group3); | ||
|
||
function ContainerWrapper({ children }) { | ||
return ( | ||
<div className="max-w-7xl mx-auto px-4 sm:px-6 md:px-8">{children}</div> | ||
); | ||
} | ||
|
||
export default { | ||
title: 'Layouts/ChecksCatalog', | ||
component: ChecksCatalog, | ||
argTypes: { | ||
catalogData: { | ||
control: 'object', | ||
description: 'Catalog content', | ||
}, | ||
catalogError: { | ||
control: 'text', | ||
description: 'Error message getting catalog data', | ||
table: { | ||
type: { summary: 'string' }, | ||
}, | ||
}, | ||
loading: { | ||
control: { type: 'boolean' }, | ||
description: 'Catalog data is being loaded', | ||
table: { | ||
type: { summary: 'string' }, | ||
defaultValue: { summary: false }, | ||
}, | ||
}, | ||
updateCatalog: { | ||
action: 'Update catalog', | ||
description: 'Update catalog content', | ||
}, | ||
}, | ||
decorators: [ | ||
(Story) => ( | ||
<MemoryRouter> | ||
<Story /> | ||
</MemoryRouter> | ||
), | ||
], | ||
render: (args) => ( | ||
<ContainerWrapper> | ||
<ChecksCatalog {...args} /> | ||
</ContainerWrapper> | ||
), | ||
}; | ||
|
||
export const Default = { | ||
args: { | ||
catalogData, | ||
}, | ||
}; | ||
|
||
export const Loading = { | ||
args: { | ||
...Default.args, | ||
loading: true, | ||
}, | ||
}; | ||
|
||
export const Error = { | ||
args: { | ||
...Default.args, | ||
catalogError: 'Error loading catalog', | ||
}, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
|
||
import { getCatalog } from '@state/selectors/catalog'; | ||
import { updateCatalog } from '@state/actions/catalog'; | ||
import { checkProviderExists } from '@components/ProviderLabel/ProviderLabel'; | ||
import ChecksCatalog from './ChecksCatalog'; | ||
|
||
const buildUpdateCatalogAction = (provider) => { | ||
const payload = checkProviderExists(provider) | ||
? { provider, target_type: 'cluster' } | ||
: {}; | ||
return updateCatalog(payload); | ||
}; | ||
|
||
function ChecksCatalogPage() { | ||
const dispatch = useDispatch(); | ||
|
||
const { | ||
data: catalogData, | ||
error: catalogError, | ||
loading, | ||
} = useSelector(getCatalog()); | ||
|
||
return ( | ||
<ChecksCatalog | ||
catalogData={catalogData} | ||
catalogError={catalogError} | ||
loading={loading} | ||
updateCatalog={(selectedProvider) => | ||
dispatch(buildUpdateCatalogAction(selectedProvider)) | ||
} | ||
/> | ||
); | ||
} | ||
|
||
export default ChecksCatalogPage; |
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,3 +1,3 @@ | ||
import ChecksCatalog from './ChecksCatalog'; | ||
import ChecksCatalogPage from './ChecksCatalogPage'; | ||
|
||
export default ChecksCatalog; | ||
export default ChecksCatalogPage; |
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