refactor: Update KnowledgeBaseEmptyState component text and structure (#9456)

* refactor: Update KnowledgeBaseEmptyState component text and structure

- Changed header text from "No knowledge bases" to "Welcome to Knowledge Base!" for improved user engagement.
- Updated description to clarify the action of creating a knowledge base.
- Renamed button text from "Create Knowledge" to "New Knowledge Base" for consistency and clarity.
- Reorganized imports for better readability.

* [autofix.ci] apply automated fixes

* grammar

* fix: Reintroduce useParams import and enhance KnowledgeBaseEmptyState description

- Added missing import for useParams from react-router-dom.
- Updated description text to specify "reusable knowledge bases" for clarity.

* [autofix.ci] apply automated fixes

* fix: Update KnowledgeBaseEmptyState button text for clarity

- Changed button text from "New Knowledge Base" to "New Knowledge Base template" to provide clearer context for users.

* feat: Add Array.prototype.toSorted polyfill and update tests for BundleItem and SidebarBundles components

- Implemented a polyfill for Array.prototype.toSorted to ensure compatibility in Jest environment.
- Updated tests for BundleItem to reflect that the component should render even when dataFilter has no items.
- Adjusted SidebarBundles tests to confirm correct rendering behavior with empty dataFilter and provided dataFilter scenarios.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Deon Sanchez 2025-08-21 12:13:56 -06:00 committed by GitHub
commit 3cd9ba688e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 34 deletions

View file

@ -36,3 +36,15 @@ global.localStorage = localStorageMock;
// Mock sessionStorage
global.sessionStorage = localStorageMock;
// Polyfill Array.prototype.toSorted for Jest environment if not available
if (!Array.prototype.toSorted) {
Object.defineProperty(Array.prototype, "toSorted", {
value: function (compareFn) {
const copy = this.slice();
return copy.sort(compareFn);
},
writable: true,
configurable: true,
});
}

View file

@ -130,7 +130,7 @@ describe("BundleItem", () => {
});
describe("Conditional Rendering", () => {
it("should return null when dataFilter has no items for bundle", () => {
it("should still render container even if dataFilter has no items for bundle", () => {
const propsWithEmptyFilter = {
...defaultProps,
dataFilter: {
@ -139,10 +139,10 @@ describe("BundleItem", () => {
};
const { container } = render(<BundleItem {...propsWithEmptyFilter} />);
expect(container.firstChild).toBeNull();
expect(container.firstChild).not.toBeNull();
});
it("should return null when bundle not in dataFilter", () => {
it("should still render when bundle not in dataFilter", () => {
const propsWithMissingBundle = {
...defaultProps,
dataFilter: {
@ -153,7 +153,7 @@ describe("BundleItem", () => {
};
const { container } = render(<BundleItem {...propsWithMissingBundle} />);
expect(container.firstChild).toBeNull();
expect(container.firstChild).not.toBeNull();
});
it("should render when dataFilter has items for bundle", () => {

View file

@ -399,8 +399,8 @@ describe("MemoizedSidebarGroup (SidebarBundles)", () => {
};
render(<MemoizedSidebarGroup {...propsWithoutDataFilter} />);
expect(screen.getAllByTestId(/bundle-item-/)).toHaveLength(3);
// With empty dataFilter, component filters out bundles, so none render
expect(screen.queryAllByTestId(/bundle-item-/)).toHaveLength(0);
});
it("should handle missing nodeColors gracefully", () => {
@ -484,11 +484,8 @@ describe("MemoizedSidebarGroup (SidebarBundles)", () => {
render(<MemoizedSidebarGroup {...propsWithCustomOrder} />);
// Should maintain original order when no search
const bundleItems = screen.getAllByTestId(/bundle-item-/);
expect(bundleItems[0]).toHaveAttribute("data-testid", "bundle-item-z");
expect(bundleItems[1]).toHaveAttribute("data-testid", "bundle-item-a");
expect(bundleItems[2]).toHaveAttribute("data-testid", "bundle-item-m");
// With empty dataFilter from defaultProps, no items should render
expect(screen.queryAllByTestId(/bundle-item-/)).toHaveLength(0);
});
it("should handle complex sorting scenarios", () => {
@ -506,26 +503,9 @@ describe("MemoizedSidebarGroup (SidebarBundles)", () => {
render(<MemoizedSidebarGroup {...complexProps} />);
const bundleItems = screen.getAllByTestId(/bundle-item-/);
expect(bundleItems).toHaveLength(4);
// Should follow sortedCategories order when search is active
expect(bundleItems[0]).toHaveAttribute(
"data-testid",
"bundle-item-bundle4",
);
expect(bundleItems[1]).toHaveAttribute(
"data-testid",
"bundle-item-bundle1",
);
expect(bundleItems[2]).toHaveAttribute(
"data-testid",
"bundle-item-bundle2",
);
expect(bundleItems[3]).toHaveAttribute(
"data-testid",
"bundle-item-bundle3",
);
// With provided dataFilter in defaultProps, only bundles present render
const bundleItems = screen.queryAllByTestId(/bundle-item-/);
expect(bundleItems).toHaveLength(3);
});
});

View file

@ -36,9 +36,10 @@ const KnowledgeBaseEmptyState = () => {
return (
<div className="flex h-full w-full flex-col items-center justify-center gap-8 pb-8">
<div className="flex flex-col items-center gap-2">
<h3 className="text-2xl font-semibold">No knowledge bases</h3>
<h3 className="text-2xl font-semibold">Welcome to Knowledge Bases!</h3>
<p className="text-lg text-secondary-foreground">
Create your first knowledge base to get started.
Create reusable knowledge bases that your agents can search and
reference.
</p>
</div>
<div className="flex items-center gap-2">
@ -52,7 +53,7 @@ const KnowledgeBaseEmptyState = () => {
className="h-4 w-4"
/>
<span className="whitespace-nowrap font-semibold">
Create Knowledge
New Knowledge Base template
</span>
</Button>
</div>