Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/components/Label/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from "react";
import classnames from "classnames";
import PropTypes from "prop-types";

import HelpContent from "./HelpContent";
import { HelpContent } from "components/commons";

import Button from "../Button";
import Tooltip from "../Tooltip";
Expand Down
10 changes: 9 additions & 1 deletion src/components/NoData/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PropTypes from "prop-types";
import { isEmpty, isNil, omit } from "ramda";

import Button from "components/Button";
import { HelpContent } from "components/commons";
import Tooltip from "components/Tooltip";
import Typography from "components/Typography";

Expand All @@ -20,11 +21,13 @@ const NoData = ({
secondaryButtonProps = {},
buttonSeparatorText = "",
showTooltipWhenButtonDisabled = false,
helpIconProps = {},
...otherProps
}) => {
const hasPrimaryButtonProps = !isEmpty(primaryButtonProps);
const hasSecondaryButtonProps = !isEmpty(secondaryButtonProps);
const hasButtonSeparatorText = !isEmpty(buttonSeparatorText);
const hasHelpIconProps = !isEmpty(helpIconProps);

const showButtonSeparator =
hasButtonSeparatorText && hasPrimaryButtonProps && hasSecondaryButtonProps;
Expand Down Expand Up @@ -78,12 +81,13 @@ const NoData = ({
(!showTooltipWhenButtonDisabled && primaryButtonProps?.disabled)
}
>
<div>
<div className="flex items-center gap-1">
<Button
data-cy="no-data-primary-button"
data-testid="no-data-primary-button"
{...omit(["tooltipProps"], primaryButtonProps)}
/>
{hasHelpIconProps && <HelpContent {...{ helpIconProps }} />}
</div>
</Tooltip>
)}
Expand Down Expand Up @@ -154,6 +158,10 @@ NoData.propTypes = {
* To specify the text that appears between the primary and secondary buttons.
* */
buttonSeparatorText: PropTypes.string,
/**
* To specify the props to be passed to the help popover for the disabled button.
*/
helpIconProps: PropTypes.object,
};

export default NoData;
File renamed without changes.
3 changes: 3 additions & 0 deletions src/components/commons/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import HelpContent from "./HelpContent";

export { HelpContent };
22 changes: 22 additions & 0 deletions stories/Components/NoData.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,27 @@ const WithHelpText = args => (

WithHelpText.storyName = "No Data with help text";

const WithHelpIcon = args => (
<div className="flex w-full items-center justify-center">
<NoData
{...args}
description="You can try adding a new ticket or learn more about how tickets work."
primaryButtonProps={{ label: "Add new ticket" }}
title="There are no tickets to show"
helpIconProps={{
popoverProps: {
title: "What is KB keywords?",
description:
"Keywords represent the key concepts of an article. These will be shown on the KB and will be used for SEO",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though this is a story, it would be better if the content is related. The empty state is about tickets, but the tooltip content is about keywords

helpLinkProps: { label: "View help article" },
},
}}
/>
</div>
);

WithHelpIcon.storyName = "No Data with help icon";

const WithCustomImageAsSVG = args => (
<div className="flex w-full items-center justify-center">
<NoData
Expand Down Expand Up @@ -208,6 +229,7 @@ export {
WithDescription,
WithSecondaryButton,
WithHelpText,
WithHelpIcon,
WithCustomImageAsSVG,
WithCustomImageFromURL,
CSSCustomization,
Expand Down
27 changes: 27 additions & 0 deletions tests/NoData.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,31 @@ describe("Typography", () => {
await userEvent.hover(secondaryButton);
await expect(screen.getByText("Secondary tooltip")).toBeInTheDocument();
});

it("should display help icon popover when hovered", async () => {
const { container } = render(
<NoData
primaryButtonProps={{ label: "Add new ticket" }}
title="There are no tickets to show"
helpIconProps={{
popoverProps: {
title: "About Tickets",
description: "Tickets help you track customer issues.",
helpLinkProps: { label: "Learn more" },
},
}}
/>
);

const helpIcon = container.querySelector(".neeto-ui-label__help-icon-wrap");
expect(helpIcon).toBeInTheDocument();

await userEvent.hover(helpIcon);

await expect(screen.getByText("About Tickets")).toBeInTheDocument();
await expect(
screen.getByText("Tickets help you track customer issues.")
).toBeInTheDocument();
await expect(screen.getByText("Learn more")).toBeInTheDocument();
});
});
2 changes: 2 additions & 0 deletions types/NoData.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { ButtonProps } from "./Button";
import { HelpContentProps } from "./HelpContent";

export type NoDataProps = {
title?: string;
Expand All @@ -8,6 +9,7 @@ export type NoDataProps = {
primaryButtonProps?: ButtonProps;
secondaryButtonProps?: ButtonProps;
showTooltipWhenButtonDisabled?: boolean;
helpIconProps?: HelpContentProps;
className?: string;
};

Expand Down