Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

call useHistory in EmptyState and remove history from props #729

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/lib/components/emptystate/Emptystate.component.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import styled, { css } from 'styled-components';

import { spacing } from '../../spacing';
import { Button } from '../buttonv2/Buttonv2.component';
import { Icon, IconName } from '../icon/Icon.component';
import { LargeText } from '../text/Text.component';
import { CoreUITheme } from '../../style/theme';
type Props = {
import { useHistory } from 'react-router';

export type Props = {
listedResource: {
singular: string;
plural: string;
};
icon: IconName;
link?: string;
history?: Record<string, any>;
backgroundColor?: keyof CoreUITheme;
/**
* The resource to create before browsing the listed resource
Expand Down Expand Up @@ -46,14 +46,9 @@ export const ActionWrapper = styled.div`
`;

function EmptyState(props: Props) {
const {
icon,
listedResource,
link,
history,
resourceToCreate,
backgroundColor,
} = props;
const { icon, listedResource, link, resourceToCreate, backgroundColor } =
props;
const history = useHistory();
return (
<EmptystateContainer
className="sc-emptystate"
Expand All @@ -72,7 +67,7 @@ function EmptyState(props: Props) {
: `Before browsing your ${listedResource.plural}, create your first ${resourceToCreate}.`}
</LargeText>
</EmptyStateRow>
{history && (
{link && (
<ActionWrapper>
<Button
label={`Create ${resourceToCreate || listedResource.singular}`}
Expand Down
23 changes: 15 additions & 8 deletions stories/emptystate.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import { EmptyState } from '../src/lib/components/emptystate/Emptystate.component';
import { Meta, StoryObj } from '@storybook/react';
import {
EmptyState,
Props,
} from '../src/lib/components/emptystate/Emptystate.component';
type Story = StoryObj<Props>;

export default {
const meta: Meta<Props> = {
title: 'Components/Data Display/EmptyState',
component: EmptyState,
args: {
icon: 'Node-backend',
label: 'Node',
listedResource: {
singular: 'resource',
plural: 'resources',
},
},
};

export const Default = {};
export default meta;

export const Default: Story = {};

export const WithLink = {
export const WithLink: Story = {
args: {
link: '',
history: {
push: () => {},
},
},
};
Loading