Revert "feat: add text & numeric filters to insights routing responses (#18016)"
This reverts commit a7e7561efa.
This commit is contained in:
1 parent
237fea0a41
commit
49070b96ae
36 files changed
+482
-1162
No files matched your search
@@ -7,7 +7,6 @@ import { useQueryState, parseAsBoolean } from "nuqs";
|
||||
import { useMemo, useReducer, useRef, useState } from "react";
|
||||
|
||||
import {
|
||||
DataTableProvider,
|
||||
DataTable,
|
||||
DataTableToolbar,
|
||||
DataTableFilters,
|
||||
@@ -17,8 +16,6 @@ import {
|
||||
useFetchMoreOnBottomReached,
|
||||
textFilter,
|
||||
isTextFilterValue,
|
||||
isSelectFilterValue,
|
||||
selectFilter,
|
||||
} from "@calcom/features/data-table";
|
||||
import { useOrgBranding } from "@calcom/features/ee/organizations/context/provider";
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
@@ -100,14 +97,6 @@ function reducer(state: UserTableState, action: UserTableAction): UserTableState
|
||||
}
|
||||
|
||||
export function UserListTable() {
|
||||
return (
|
||||
<DataTableProvider>
|
||||
<UserListTableContent />
|
||||
</DataTableProvider>
|
||||
);
|
||||
}
|
||||
|
||||
function UserListTableContent() {
|
||||
const [dynamicLinkVisible, setDynamicLinkVisible] = useQueryState("dynamicLink", parseAsBoolean);
|
||||
const orgBranding = useOrgBranding();
|
||||
const domain = orgBranding?.fullDomain ?? WEBAPP_URL;
|
||||
@@ -175,75 +164,62 @@ function UserListTableContent() {
|
||||
return [];
|
||||
}
|
||||
return (
|
||||
(attributes?.map((attribute) => {
|
||||
// TODO: We need to normalize AttributeOption table first
|
||||
// so that we can have `number_value` column for numeric operations.
|
||||
// Currently, `value` column is used for both text and number attributes.
|
||||
//
|
||||
// const isNumber = attribute.type === "NUMBER";
|
||||
const isNumber = false;
|
||||
const isText = attribute.type === "TEXT";
|
||||
const filterType = isNumber ? "number" : isText ? "text" : "select";
|
||||
(attributes?.map((attribute) => ({
|
||||
id: attribute.id,
|
||||
header: attribute.name,
|
||||
meta: {
|
||||
filterType: attribute.type.toLowerCase() === "text" ? "text" : "select",
|
||||
},
|
||||
size: 120,
|
||||
accessorFn: (data) => data.attributes.find((attr) => attr.attributeId === attribute.id)?.value,
|
||||
cell: ({ row }) => {
|
||||
const attributeValues = row.original.attributes.filter(
|
||||
(attr) => attr.attributeId === attribute.id
|
||||
);
|
||||
if (attributeValues.length === 0) return null;
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
attribute.type === "NUMBER" ? "flex w-full justify-center" : "flex flex-wrap"
|
||||
)}>
|
||||
{attributeValues.map((attributeValue, index) => {
|
||||
const isAGroupOption = attributeValue.contains?.length > 0;
|
||||
const suffix = attribute.isWeightsEnabled ? `${attributeValue.weight || 100}%` : undefined;
|
||||
return (
|
||||
<div className="mr-1 inline-flex shrink-0" key={attributeValue.id}>
|
||||
<Badge
|
||||
variant={isAGroupOption ? "orange" : "gray"}
|
||||
className={classNames(suffix && "rounded-r-none")}>
|
||||
{attributeValue.value}
|
||||
</Badge>
|
||||
|
||||
return {
|
||||
id: attribute.id,
|
||||
header: attribute.name,
|
||||
meta: {
|
||||
filter: { type: filterType },
|
||||
},
|
||||
size: 120,
|
||||
accessorFn: (data) => data.attributes.find((attr) => attr.attributeId === attribute.id)?.value,
|
||||
cell: ({ row }) => {
|
||||
const attributeValues = row.original.attributes.filter(
|
||||
(attr) => attr.attributeId === attribute.id
|
||||
);
|
||||
if (attributeValues.length === 0) return null;
|
||||
return (
|
||||
<div className={classNames(isNumber ? "flex w-full justify-center" : "flex flex-wrap")}>
|
||||
{attributeValues.map((attributeValue) => {
|
||||
const isAGroupOption = attributeValue.contains?.length > 0;
|
||||
const suffix = attribute.isWeightsEnabled
|
||||
? `${attributeValue.weight || 100}%`
|
||||
: undefined;
|
||||
return (
|
||||
<div className="mr-1 inline-flex shrink-0" key={attributeValue.id}>
|
||||
{suffix ? (
|
||||
<Badge
|
||||
variant={isAGroupOption ? "orange" : "gray"}
|
||||
className={classNames(suffix && "rounded-r-none")}>
|
||||
{attributeValue.value}
|
||||
style={{
|
||||
backgroundColor: "color-mix(in hsl, var(--cal-bg-emphasis), black 5%)",
|
||||
}}
|
||||
className="rounded-l-none">
|
||||
{suffix}
|
||||
</Badge>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
filterFn: (row, id, filterValue) => {
|
||||
const attributeValues = row.original.attributes.filter((attr) => attr.attributeId === id);
|
||||
|
||||
{suffix ? (
|
||||
<Badge
|
||||
variant={isAGroupOption ? "orange" : "gray"}
|
||||
style={{
|
||||
backgroundColor: "color-mix(in hsl, var(--cal-bg-emphasis), black 5%)",
|
||||
}}
|
||||
className="rounded-l-none">
|
||||
{suffix}
|
||||
</Badge>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
filterFn: (row, id, filterValue) => {
|
||||
const attributeValues = row.original.attributes.filter((attr) => attr.attributeId === id);
|
||||
if (isTextFilterValue(filterValue)) {
|
||||
return attributeValues.some((attr) => textFilter(attr.value, filterValue));
|
||||
}
|
||||
|
||||
if (isTextFilterValue(filterValue)) {
|
||||
return attributeValues.some((attr) => textFilter(attr.value, filterValue));
|
||||
} else if (isSelectFilterValue(filterValue)) {
|
||||
return selectFilter(
|
||||
attributeValues.map((attr) => attr.value),
|
||||
filterValue
|
||||
);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
};
|
||||
}) as ColumnDef<UserTableUser>[]) ?? []
|
||||
if (attributeValues.length === 0) return false;
|
||||
return attributeValues.some((attr) => filterValue.includes(attr.value));
|
||||
},
|
||||
})) as ColumnDef<UserTableUser>[]) ?? []
|
||||
);
|
||||
};
|
||||
const cols: ColumnDef<UserTableUser>[] = [
|
||||
@@ -536,7 +512,7 @@ function UserListTableContent() {
|
||||
table={table}
|
||||
tableContainerRef={tableContainerRef}
|
||||
isPending={isPending}
|
||||
enableColumnResizing={true}
|
||||
enableColumnResizing={{ name: "UserListTable" }}
|
||||
onScroll={(e) => fetchMoreOnBottomReached(e.target as HTMLDivElement)}>
|
||||
<DataTableToolbar.Root className="lg:max-w-screen-2xl">
|
||||
<div className="flex w-full flex-col gap-2 sm:flex-row">
|
||||
@@ -558,7 +534,7 @@ function UserListTableContent() {
|
||||
{t("download")}
|
||||
</DataTableToolbar.CTA>
|
||||
{/* We have to omit member because we don't want the filter to show but we can't disable filtering as we need that for the search bar */}
|
||||
<DataTableFilters.AddFilterButton table={table} omit={["member"]} />
|
||||
<DataTableFilters.FilterButton table={table} omit={["member"]} />
|
||||
<DataTableFilters.ColumnVisibilityButton table={table} />
|
||||
{adminOrOwner && (
|
||||
<DataTableToolbar.CTA
|
||||
|
||||
Reference in new issue
Block a user