-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SharedUX] Migrate PageTemplate > NoDataPage > NoDataCard (#127025)
* [SharedUX] Migrate PageTemplate > NoData > NoDataCard * Add deprecation warning * Fix directory structure * Fix i18n * Applying Caroline's suggestions * Fix types * Fix typescripting * Update src/plugins/shared_ux/public/components/page_template/no_data_page/no_data_card/no_data_card.stories.tsx Co-authored-by: Caroline Horn <[email protected]> Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Caroline Horn <[email protected]>
- Loading branch information
1 parent
2da341c
commit 8782ced
Showing
8 changed files
with
336 additions
and
0 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
9 changes: 9 additions & 0 deletions
9
src/plugins/shared_ux/public/components/page_template/index.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,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { NoDataCard } from './no_data_page/no_data_card'; |
155 changes: 155 additions & 0 deletions
155
...mponents/page_template/no_data_page/no_data_card/__snapshots__/no_data_card.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
src/plugins/shared_ux/public/components/page_template/no_data_page/no_data_card/index.ts
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,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
export { NoDataCard } from './no_data_card'; |
45 changes: 45 additions & 0 deletions
45
...red_ux/public/components/page_template/no_data_page/no_data_card/no_data_card.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,45 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { NoDataCard } from './no_data_card'; | ||
import type { NoDataCardProps } from './types'; | ||
|
||
export default { | ||
title: 'No Data Card', | ||
description: 'A wrapper around EuiCard, to be used on NoData page', | ||
}; | ||
|
||
type Params = Pick<NoDataCardProps, 'recommended' | 'button' | 'description'>; | ||
|
||
export const PureComponent = (params: Params) => { | ||
return ( | ||
<div style={{ width: '50%' }}> | ||
<NoDataCard title={'Add data'} {...params} /> | ||
</div> | ||
); | ||
}; | ||
|
||
PureComponent.argTypes = { | ||
recommended: { | ||
control: 'boolean', | ||
defaultValue: false, | ||
}, | ||
button: { | ||
control: { | ||
type: 'text', | ||
}, | ||
defaultValue: 'Button text', | ||
}, | ||
description: { | ||
control: { | ||
type: 'text', | ||
}, | ||
defaultValue: 'This is a description', | ||
}, | ||
}; |
41 changes: 41 additions & 0 deletions
41
...shared_ux/public/components/page_template/no_data_page/no_data_card/no_data_card.test.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,41 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { render } from 'enzyme'; | ||
import React from 'react'; | ||
import { NoDataCard } from './no_data_card'; | ||
|
||
describe('NoDataCard', () => { | ||
test('renders', () => { | ||
const component = render(<NoDataCard title="Card title" description="Description" />); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
describe('props', () => { | ||
test('recommended', () => { | ||
const component = render( | ||
<NoDataCard recommended title="Card title" description="Description" /> | ||
); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
test('button', () => { | ||
const component = render( | ||
<NoDataCard button="Button" title="Card title" description="Description" /> | ||
); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
test('href', () => { | ||
const component = render( | ||
<NoDataCard href="#" button="Button" title="Card title" description="Description" /> | ||
); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
...gins/shared_ux/public/components/page_template/no_data_page/no_data_card/no_data_card.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 Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import React, { FunctionComponent } from 'react'; | ||
import { EuiButton, EuiCard } from '@elastic/eui'; | ||
import type { NoDataCardProps } from './types'; | ||
|
||
const recommendedLabel = i18n.translate('sharedUX.pageTemplate.noDataPage.recommendedLabel', { | ||
defaultMessage: 'Recommended', | ||
}); | ||
|
||
const defaultDescription = i18n.translate('sharedUX.pageTemplate.noDataCard.description', { | ||
defaultMessage: `Proceed without collecting data`, | ||
}); | ||
|
||
export const NoDataCard: FunctionComponent<NoDataCardProps> = ({ | ||
recommended, | ||
title, | ||
button, | ||
description, | ||
...cardRest | ||
}) => { | ||
const footer = () => { | ||
if (typeof button !== 'string') { | ||
return button; | ||
} | ||
return <EuiButton fill>{button || title}</EuiButton>; | ||
}; | ||
const label = recommended ? recommendedLabel : undefined; | ||
const cardDescription = description || defaultDescription; | ||
|
||
return ( | ||
<EuiCard | ||
paddingSize="l" | ||
title={title!} | ||
description={cardDescription} | ||
betaBadgeProps={{ label }} | ||
footer={footer()} | ||
{...cardRest} | ||
/> | ||
); | ||
}; |
29 changes: 29 additions & 0 deletions
29
src/plugins/shared_ux/public/components/page_template/no_data_page/no_data_card/types.ts
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 Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { EuiCardProps } from '@elastic/eui'; | ||
import { MouseEventHandler, ReactNode } from 'react'; | ||
|
||
export type NoDataCardProps = Partial<Omit<EuiCardProps, 'layout'>> & { | ||
/** | ||
* Applies the `Recommended` beta badge and makes the button `fill` | ||
*/ | ||
recommended?: boolean; | ||
/** | ||
* Provide just a string for the button's label, or a whole component | ||
*/ | ||
button?: string | ReactNode; | ||
/** | ||
* Remapping `onClick` to any element | ||
*/ | ||
onClick?: MouseEventHandler<HTMLElement>; | ||
/** | ||
* Description for the card. If not provided, the default will be used. | ||
*/ | ||
description?: string; | ||
}; |