Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

Expose a clear button on the account manager picker

Jerome2e0b694db7d7
diff --git a/e2e/adminAccountManagerFilter.spec.ts b/e2e/adminAccountManagerFilter.spec.ts
index 5b19f935..23b61773 100644
--- a/e2e/adminAccountManagerFilter.spec.ts
+++ b/e2e/adminAccountManagerFilter.spec.ts
@@ -60,6 +60,11 @@ test.describe("admin filtering by account manager", () => {
await expect(page.getByText("Grace Hopper")).toBeVisible();
await expect(page.getByText("Ada Lovelace")).toBeHidden();
+
+ await page.getByRole("button", { name: "Clear value" }).click();
+
+ await expect(page.getByText("Ada Lovelace")).toBeVisible();
+ await expect(page.getByText("Grace Hopper")).toBeVisible();
});
test("a non-admin user gets no account manager picker", async ({
diff --git a/registry.json b/registry.json
index a8337a71..bc2f9f28 100644
--- a/registry.json
+++ b/registry.json
@@ -161,6 +161,10 @@
"path": "src/components/atomic-crm/sales/useGetSalesName.ts",
"type": "registry:component"
},
+ {
+ "path": "src/components/atomic-crm/sales/useCanFilterByAccountManager.ts",
+ "type": "registry:component"
+ },
{
"path": "src/components/atomic-crm/sales/index.ts",
"type": "registry:component"
@@ -181,6 +185,10 @@
"path": "src/components/atomic-crm/sales/SalesCreate.tsx",
"type": "registry:component"
},
+ {
+ "path": "src/components/atomic-crm/sales/AccountManagerInput.tsx",
+ "type": "registry:component"
+ },
{
"path": "src/components/atomic-crm/root/useConfigurationLoader.ts",
"type": "registry:component"
@@ -481,6 +489,10 @@
"path": "src/components/atomic-crm/misc/ActiveFilterButton.tsx",
"type": "registry:component"
},
+ {
+ "path": "src/components/atomic-crm/login/authConfig.ts",
+ "type": "registry:component"
+ },
{
"path": "src/components/atomic-crm/login/StartPage.tsx",
"type": "registry:component"
diff --git a/src/components/admin/autocomplete-input.tsx b/src/components/admin/autocomplete-input.tsx
index d24fd813..f62f8c6f 100644
--- a/src/components/admin/autocomplete-input.tsx
+++ b/src/components/admin/autocomplete-input.tsx
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as React from "react";
import { useCallback } from "react";
-import { Check, ChevronsUpDown } from "lucide-react";
+import { Check, ChevronsUpDown, X } from "lucide-react";
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
import {
@@ -179,6 +179,15 @@ export const AutocompleteInput = (
],
);
+ const handleReset = useEvent((event: React.MouseEvent<HTMLDivElement>) => {
+ event.stopPropagation();
+ field.onChange("");
+ setFilterValue("");
+ if (isFromReference) {
+ setFilters(filterToQuery(""));
+ }
+ });
+
const {
getCreateItem,
handleChange: handleChangeWithCreateSupport,
@@ -234,7 +243,18 @@ export const AutocompleteInput = (
) : (
<span className="text-muted-foreground">{placeholder}</span>
)}
- <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
+ {selectedChoice && !isRequired ? (
+ <div
+ role="button"
+ aria-label={translate("ra.action.clear_input_value")}
+ className="ml-2 shrink-0 pointer-events-auto text-muted-foreground opacity-50 hover:opacity-100"
+ onClick={handleReset}
+ >
+ <X className="h-4 w-4" />
+ </div>
+ ) : (
+ <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
+ )}
</Button>
</PopoverTrigger>
<PopoverContent className="w-full max-w-(--radix-popover-trigger-width) p-0">
diff --git a/src/components/atomic-crm/deals/DealList.stories.tsx b/src/components/atomic-crm/deals/DealList.stories.tsx
index 2d154a24..377f5507 100644
--- a/src/components/atomic-crm/deals/DealList.stories.tsx
+++ b/src/components/atomic-crm/deals/DealList.stories.tsx
@@ -35,7 +35,10 @@ const buildDeal = (overrides: Partial<Deal> = {}): Deal => ({
const dataForAccountManagerFilter = {
companies: [buildCompany()],
- deals: [buildDeal()],
+ deals: [
+ buildDeal({ id: 1, name: "Jane deal", sales_id: 0 }),
+ buildDeal({ id: 2, index: 1, name: "Marie deal", sales_id: 1 }),
+ ],
sales: [
buildSale({ administrator: true, first_name: "Jane", id: 0 }),
buildSale({
diff --git a/src/components/atomic-crm/deals/DealList.test.tsx b/src/components/atomic-crm/deals/DealList.test.tsx
index 321d9e96..78362392 100644
--- a/src/components/atomic-crm/deals/DealList.test.tsx
+++ b/src/components/atomic-crm/deals/DealList.test.tsx
@@ -22,6 +22,23 @@ describe("DealList", () => {
.not.toBeInTheDocument();
});
+ it("returns to every deal after an admin clears the account manager", async () => {
+ const screen = await render(<AdminAccountManagerFilter />);
+
+ await expect.element(screen.getByText("Jane deal")).toBeVisible();
+ await expect.element(screen.getByText("Marie deal")).toBeVisible();
+
+ await screen.getByRole("combobox", { name: "Account manager" }).click();
+ await screen.getByRole("option", { name: "Marie Curie" }).click();
+
+ await expect.element(screen.getByText("Jane deal")).not.toBeInTheDocument();
+
+ await screen.getByRole("button", { name: "Clear value" }).click();
+
+ await expect.element(screen.getByText("Jane deal")).toBeVisible();
+ await expect.element(screen.getByText("Marie deal")).toBeVisible();
+ });
+
it("keeps the only-mine switch for a user who is not an admin", async () => {
const screen = await render(<NonAdminAccountManagerFilter />);