fix: apply routing form filter by default on /insights/routing (#19535)
* fix: mandate routing form filter on /insights/routing * add e2e test * update e2e test * fix e2e test * add comment
This commit is contained in:
1 parent
52662b3375
commit
d44d74d2fc
4 files changed
+58
-4
No files matched your search
@@ -0,0 +1,40 @@
|
|||||||
|
import { test } from "./lib/fixtures";
|
||||||
|
|
||||||
|
test.afterEach(({ users }) => users.deleteAll());
|
||||||
|
|
||||||
|
test.describe("Insights > Routing", () => {
|
||||||
|
test("applies routing form filter by default", async ({ page, users, routingForms }) => {
|
||||||
|
const owner = await users.create(undefined, {
|
||||||
|
hasTeam: true,
|
||||||
|
isUnpublished: true,
|
||||||
|
isOrg: true,
|
||||||
|
hasSubteam: true,
|
||||||
|
});
|
||||||
|
await owner.apiLogin();
|
||||||
|
|
||||||
|
const membership = await owner.getOrgMembership();
|
||||||
|
|
||||||
|
const formName = "Test Form 1234";
|
||||||
|
await routingForms.create({
|
||||||
|
name: formName,
|
||||||
|
userId: owner.id,
|
||||||
|
teamId: membership.teamId,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
type: "text",
|
||||||
|
label: "Name",
|
||||||
|
identifier: "name",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.goto(`/insights/routing`);
|
||||||
|
await page.locator('[data-testid="filter-popover-trigger-formId"]').getByText(formName).waitFor();
|
||||||
|
|
||||||
|
// The routing form filter is persisted
|
||||||
|
// even if user tries to clear it.
|
||||||
|
await page.locator('[data-testid="clear-filters-button"]').click();
|
||||||
|
await page.locator('[data-testid="filter-popover-trigger-formId"]').getByText(formName).waitFor();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -31,7 +31,7 @@ export function MultiSelectFilterOptions({ column }: MultiSelectFilterOptionsPro
|
|||||||
<Command data-testid={`multi-select-options-${column.id}`}>
|
<Command data-testid={`multi-select-options-${column.id}`}>
|
||||||
<CommandInput placeholder={t("search")} />
|
<CommandInput placeholder={t("search")} />
|
||||||
<CommandList>
|
<CommandList>
|
||||||
<CommandEmpty>{t("no_options_found")}</CommandEmpty>
|
<CommandEmpty>{t("no_options_available")}</CommandEmpty>
|
||||||
{column.options.map((option, index) => {
|
{column.options.map((option, index) => {
|
||||||
if (!option) return null;
|
if (!option) return null;
|
||||||
const {
|
const {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export function SingleSelectFilterOptions({ column }: SingleSelectFilterOptionsP
|
|||||||
<Command data-testid={`single-select-options-${column.id}`}>
|
<Command data-testid={`single-select-options-${column.id}`}>
|
||||||
<CommandInput placeholder={t("search")} />
|
<CommandInput placeholder={t("search")} />
|
||||||
<CommandList>
|
<CommandList>
|
||||||
<CommandEmpty>{t("no_options_found")}</CommandEmpty>
|
<CommandEmpty>{t("no_options_available")}</CommandEmpty>
|
||||||
{column.options.map((option, index) => {
|
{column.options.map((option, index) => {
|
||||||
if (!option) return null;
|
if (!option) return null;
|
||||||
const {
|
const {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
getSortedRowModel,
|
getSortedRowModel,
|
||||||
} from "@tanstack/react-table";
|
} from "@tanstack/react-table";
|
||||||
// eslint-disable-next-line no-restricted-imports
|
// eslint-disable-next-line no-restricted-imports
|
||||||
import { useMemo } from "react";
|
import { useMemo, useEffect } from "react";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DataTableWrapper,
|
DataTableWrapper,
|
||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
useDataTable,
|
useDataTable,
|
||||||
DateRangeFilter,
|
DateRangeFilter,
|
||||||
ColumnFilterType,
|
ColumnFilterType,
|
||||||
|
convertMapToFacetedValues,
|
||||||
type FilterableColumn,
|
type FilterableColumn,
|
||||||
} from "@calcom/features/data-table";
|
} from "@calcom/features/data-table";
|
||||||
import { trpc } from "@calcom/trpc";
|
import { trpc } from "@calcom/trpc";
|
||||||
@@ -54,7 +55,7 @@ export function RoutingFormResponsesTable() {
|
|||||||
|
|
||||||
const getInsightsFacetedUniqueValues = useInsightsFacetedUniqueValues({ headers, userId, teamId, isAll });
|
const getInsightsFacetedUniqueValues = useInsightsFacetedUniqueValues({ headers, userId, teamId, isAll });
|
||||||
|
|
||||||
const { sorting } = useDataTable();
|
const { sorting, updateFilter } = useDataTable();
|
||||||
|
|
||||||
const { data, fetchNextPage, isFetching, isPending, hasNextPage, isLoading } =
|
const { data, fetchNextPage, isFetching, isPending, hasNextPage, isLoading } =
|
||||||
trpc.viewer.insights.routingFormResponses.useInfiniteQuery(
|
trpc.viewer.insights.routingFormResponses.useInfiniteQuery(
|
||||||
@@ -104,6 +105,19 @@ export function RoutingFormResponsesTable() {
|
|||||||
getFacetedUniqueValues: getInsightsFacetedUniqueValues,
|
getFacetedUniqueValues: getInsightsFacetedUniqueValues,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (routingFormId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const routingForms = convertMapToFacetedValues(getInsightsFacetedUniqueValues(table, "formId")());
|
||||||
|
const newRoutingFormId = routingForms?.[0]?.value;
|
||||||
|
if (newRoutingFormId) {
|
||||||
|
// if routing form filter is not set, set it to the first form
|
||||||
|
// this also prevents user from clearing the routing form filter
|
||||||
|
updateFilter("formId", { type: ColumnFilterType.SINGLE_SELECT, data: newRoutingFormId });
|
||||||
|
}
|
||||||
|
}, [table, getInsightsFacetedUniqueValues, routingFormId]);
|
||||||
|
|
||||||
if ((isHeadersLoading && !headers) || ((isFetching || isLoading) && !data)) {
|
if ((isHeadersLoading && !headers) || ((isFetching || isLoading) && !data)) {
|
||||||
return <DataTableSkeleton columns={4} columnWidths={[200, 200, 250, 250]} />;
|
return <DataTableSkeleton columns={4} columnWidths={[200, 200, 250, 250]} />;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user