@salesforce/ui-bundle-template-app-react-template-b2e 1.117.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +82 -0
- package/README.md +52 -0
- package/dist/.forceignore +15 -0
- package/dist/.husky/pre-commit +4 -0
- package/dist/.prettierignore +11 -0
- package/dist/.prettierrc +17 -0
- package/dist/AGENT.md +193 -0
- package/dist/CHANGELOG.md +2128 -0
- package/dist/README.md +52 -0
- package/dist/config/project-scratch-def.json +13 -0
- package/dist/eslint.config.js +7 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/.forceignore +15 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/.graphqlrc.yml +2 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/.prettierignore +9 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/.prettierrc +11 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/CHANGELOG.md +10 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/README.md +35 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/codegen.yml +95 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/components.json +18 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/e2e/app.spec.ts +17 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/eslint.config.js +169 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/index.html +12 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/package.json +69 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/playwright.config.ts +24 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/reactinternalapp.uibundle-meta.xml +7 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/scripts/get-graphql-schema.mjs +68 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/scripts/rewrite-e2e-assets.mjs +23 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/api/account/accountSearchService.ts +46 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/api/account/query/distinctAccountIndustries.graphql +19 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/api/account/query/distinctAccountTypes.graphql +19 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/api/account/query/getAccountDetail.graphql +121 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/api/account/query/searchAccounts.graphql +51 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/api/graphql-operations-types.ts +11260 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/api/graphqlClient.ts +25 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/app.tsx +17 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/appLayout.tsx +85 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/assets/icons/book.svg +3 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/assets/icons/copy.svg +4 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/assets/icons/rocket.svg +3 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/assets/icons/star.svg +3 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/assets/images/codey-1.png +0 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/assets/images/codey-2.png +0 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/assets/images/codey-3.png +0 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/assets/images/vibe-codey.svg +194 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/AgentforceConversationClient.tsx +168 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/__inherit_AgentforceConversationClient.tsx +3 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/alerts/status-alert.tsx +49 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/layouts/card-layout.tsx +29 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/alert.tsx +76 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/badge.tsx +48 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/breadcrumb.tsx +109 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/button.tsx +67 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/calendar.tsx +232 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/card.tsx +103 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/checkbox.tsx +32 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/collapsible.tsx +33 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/datePicker.tsx +127 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/dialog.tsx +162 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/field.tsx +237 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/index.ts +84 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/input.tsx +19 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/label.tsx +22 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/pagination.tsx +132 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/popover.tsx +89 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/select.tsx +193 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/separator.tsx +26 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/skeleton.tsx +14 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/sonner.tsx +20 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/spinner.tsx +16 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/table.tsx +114 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/components/ui/tabs.tsx +88 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/__examples__/api/accountSearchService.ts +46 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/__examples__/api/query/distinctAccountIndustries.graphql +19 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/__examples__/api/query/distinctAccountTypes.graphql +19 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/__examples__/api/query/getAccountDetail.graphql +121 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/__examples__/api/query/searchAccounts.graphql +51 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/__examples__/pages/AccountObjectDetailPage.tsx +357 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/__examples__/pages/AccountSearch.tsx +312 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/__examples__/pages/Home.tsx +34 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/api/objectSearchService.ts +84 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/ActiveFilters.tsx +89 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/FilterContext.tsx +83 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/ObjectBreadcrumb.tsx +66 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/PaginationControls.tsx +109 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/SearchBar.tsx +41 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/SortControl.tsx +143 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/filters/BooleanFilter.tsx +78 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/filters/DateFilter.tsx +128 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/filters/DateRangeFilter.tsx +70 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/filters/FilterFieldWrapper.tsx +33 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/filters/MultiSelectFilter.tsx +97 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/filters/NumericRangeFilter.tsx +163 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/filters/SearchFilter.tsx +50 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/filters/SelectFilter.tsx +97 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/components/filters/TextFilter.tsx +91 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/hooks/useAsyncData.ts +54 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/hooks/useCachedAsyncData.ts +184 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/hooks/useDebouncedCallback.ts +34 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/hooks/useObjectSearchParams.ts +252 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/utils/debounce.ts +25 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/utils/fieldUtils.ts +29 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/utils/filterUtils.ts +395 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/features/object-search/utils/sortUtils.ts +38 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/index.ts +6 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/lib/utils.ts +6 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/navigationMenu.tsx +80 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/pages/AccountObjectDetailPage.tsx +361 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/pages/AccountSearch.tsx +305 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/pages/Home.tsx +34 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/pages/NotFound.tsx +18 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/router-utils.tsx +35 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/routes.tsx +32 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/styles/global.css +135 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/src/types/conversation.ts +33 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/tsconfig.json +42 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/tsconfig.node.json +13 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/ui-bundle.json +7 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/vite-env.d.ts +1 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/vite.config.ts +106 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/vitest-env.d.ts +2 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/vitest.config.ts +11 -0
- package/dist/force-app/main/default/uiBundles/reactinternalapp/vitest.setup.ts +1 -0
- package/dist/jest.config.js +6 -0
- package/dist/package-lock.json +9995 -0
- package/dist/package.json +40 -0
- package/dist/scripts/apex/hello.apex +10 -0
- package/dist/scripts/graphql-search.sh +191 -0
- package/dist/scripts/prepare-import-unique-fields.js +122 -0
- package/dist/scripts/setup-cli.mjs +563 -0
- package/dist/scripts/sf-project-setup.mjs +66 -0
- package/dist/scripts/soql/account.soql +6 -0
- package/dist/sfdx-project.json +12 -0
- package/package.json +40 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Select,
|
|
3
|
+
SelectContent,
|
|
4
|
+
SelectItem,
|
|
5
|
+
SelectTrigger,
|
|
6
|
+
SelectValue,
|
|
7
|
+
} from "../../../../components/ui/select";
|
|
8
|
+
import { cn } from "../../../../lib/utils";
|
|
9
|
+
import { useFilterField } from "../FilterContext";
|
|
10
|
+
import { FilterFieldWrapper } from "./FilterFieldWrapper";
|
|
11
|
+
import type { ActiveFilterValue } from "../../utils/filterUtils";
|
|
12
|
+
|
|
13
|
+
const ALL_VALUE = "__all__";
|
|
14
|
+
|
|
15
|
+
interface BooleanFilterProps extends Omit<React.ComponentProps<"div">, "onChange"> {
|
|
16
|
+
field: string;
|
|
17
|
+
label: string;
|
|
18
|
+
helpText?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function BooleanFilter({ field, label, helpText, className, ...props }: BooleanFilterProps) {
|
|
22
|
+
const { value, onChange } = useFilterField(field);
|
|
23
|
+
return (
|
|
24
|
+
<FilterFieldWrapper
|
|
25
|
+
label={label}
|
|
26
|
+
htmlFor={`filter-${field}`}
|
|
27
|
+
helpText={helpText}
|
|
28
|
+
className={className}
|
|
29
|
+
{...props}
|
|
30
|
+
>
|
|
31
|
+
<BooleanFilterSelect field={field} label={label} value={value} onChange={onChange} />
|
|
32
|
+
</FilterFieldWrapper>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface BooleanFilterSelectProps {
|
|
37
|
+
field: string;
|
|
38
|
+
label: string;
|
|
39
|
+
value: ActiveFilterValue | undefined;
|
|
40
|
+
onChange: (value: ActiveFilterValue | undefined) => void;
|
|
41
|
+
triggerProps?: React.ComponentProps<typeof SelectTrigger>;
|
|
42
|
+
contentProps?: React.ComponentProps<typeof SelectContent>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function BooleanFilterSelect({
|
|
46
|
+
field,
|
|
47
|
+
label,
|
|
48
|
+
value,
|
|
49
|
+
onChange,
|
|
50
|
+
triggerProps,
|
|
51
|
+
contentProps,
|
|
52
|
+
}: BooleanFilterSelectProps) {
|
|
53
|
+
return (
|
|
54
|
+
<Select
|
|
55
|
+
value={value?.value ?? ALL_VALUE}
|
|
56
|
+
onValueChange={(v) => {
|
|
57
|
+
if (v === ALL_VALUE) {
|
|
58
|
+
onChange(undefined);
|
|
59
|
+
} else {
|
|
60
|
+
onChange({ field, label, type: "boolean", value: v });
|
|
61
|
+
}
|
|
62
|
+
}}
|
|
63
|
+
>
|
|
64
|
+
<SelectTrigger
|
|
65
|
+
id={`filter-${field}`}
|
|
66
|
+
{...triggerProps}
|
|
67
|
+
className={cn("w-full", triggerProps?.className)}
|
|
68
|
+
>
|
|
69
|
+
<SelectValue />
|
|
70
|
+
</SelectTrigger>
|
|
71
|
+
<SelectContent {...contentProps}>
|
|
72
|
+
<SelectItem value={ALL_VALUE}>All</SelectItem>
|
|
73
|
+
<SelectItem value="true">Yes</SelectItem>
|
|
74
|
+
<SelectItem value="false">No</SelectItem>
|
|
75
|
+
</SelectContent>
|
|
76
|
+
</Select>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { parseISO } from "date-fns";
|
|
3
|
+
import {
|
|
4
|
+
DatePicker,
|
|
5
|
+
DatePickerTrigger,
|
|
6
|
+
DatePickerContent,
|
|
7
|
+
DatePickerCalendar,
|
|
8
|
+
} from "../../../../components/ui/datePicker";
|
|
9
|
+
|
|
10
|
+
import { useFilterField } from "../FilterContext";
|
|
11
|
+
import { FilterFieldWrapper } from "./FilterFieldWrapper";
|
|
12
|
+
import type { FilterFieldType } from "../../utils/filterUtils";
|
|
13
|
+
import {
|
|
14
|
+
Select,
|
|
15
|
+
SelectContent,
|
|
16
|
+
SelectItem,
|
|
17
|
+
SelectTrigger,
|
|
18
|
+
SelectValue,
|
|
19
|
+
} from "../../../../components/ui/select";
|
|
20
|
+
|
|
21
|
+
type DateOperator = "gt" | "lt";
|
|
22
|
+
|
|
23
|
+
const OPERATOR_OPTIONS: { value: DateOperator; label: string }[] = [
|
|
24
|
+
{ value: "gt", label: "After" },
|
|
25
|
+
{ value: "lt", label: "Before" },
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
function operatorToField(op: DateOperator): "min" | "max" {
|
|
29
|
+
return op === "gt" ? "min" : "max";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface DateFilterProps extends Omit<React.ComponentProps<"div">, "onChange"> {
|
|
33
|
+
field: string;
|
|
34
|
+
label: string;
|
|
35
|
+
helpText?: string;
|
|
36
|
+
filterType?: FilterFieldType;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function DateFilter({
|
|
40
|
+
field,
|
|
41
|
+
label,
|
|
42
|
+
helpText,
|
|
43
|
+
filterType = "date",
|
|
44
|
+
className,
|
|
45
|
+
...props
|
|
46
|
+
}: DateFilterProps) {
|
|
47
|
+
const { value, onChange } = useFilterField(field);
|
|
48
|
+
|
|
49
|
+
const initialOp: DateOperator = value?.min ? "gt" : "lt";
|
|
50
|
+
const [operator, setOperator] = useState<DateOperator>(initialOp);
|
|
51
|
+
|
|
52
|
+
const currentDate = toDate(value?.min ?? value?.max);
|
|
53
|
+
|
|
54
|
+
function handleOperatorChange(op: DateOperator) {
|
|
55
|
+
setOperator(op);
|
|
56
|
+
if (currentDate) {
|
|
57
|
+
emitChange(op, currentDate);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function handleDateChange(date: Date | undefined) {
|
|
62
|
+
if (!date) {
|
|
63
|
+
onChange(undefined);
|
|
64
|
+
} else {
|
|
65
|
+
emitChange(operator, date);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function emitChange(op: DateOperator, date: Date) {
|
|
70
|
+
const dateStr = toDateString(date);
|
|
71
|
+
const f = operatorToField(op);
|
|
72
|
+
onChange({
|
|
73
|
+
field,
|
|
74
|
+
label,
|
|
75
|
+
type: filterType,
|
|
76
|
+
value: op,
|
|
77
|
+
min: f === "min" ? dateStr : undefined,
|
|
78
|
+
max: f === "max" ? dateStr : undefined,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<FilterFieldWrapper label={label} helpText={helpText} className={className} {...props}>
|
|
84
|
+
<div className="flex gap-2">
|
|
85
|
+
<Select value={operator} onValueChange={(v) => handleOperatorChange(v as DateOperator)}>
|
|
86
|
+
<SelectTrigger className="w-full flex-1">
|
|
87
|
+
<SelectValue />
|
|
88
|
+
</SelectTrigger>
|
|
89
|
+
<SelectContent>
|
|
90
|
+
{OPERATOR_OPTIONS.map((opt) => (
|
|
91
|
+
<SelectItem key={opt.value} value={opt.value}>
|
|
92
|
+
{opt.label}
|
|
93
|
+
</SelectItem>
|
|
94
|
+
))}
|
|
95
|
+
</SelectContent>
|
|
96
|
+
</Select>
|
|
97
|
+
<DatePicker>
|
|
98
|
+
<DatePickerTrigger
|
|
99
|
+
className="w-full flex-2"
|
|
100
|
+
date={currentDate}
|
|
101
|
+
dateFormat="MMM do, yyyy"
|
|
102
|
+
placeholder="Pick a date"
|
|
103
|
+
aria-label={label}
|
|
104
|
+
/>
|
|
105
|
+
<DatePickerContent>
|
|
106
|
+
<DatePickerCalendar
|
|
107
|
+
mode="single"
|
|
108
|
+
captionLayout="dropdown"
|
|
109
|
+
selected={currentDate}
|
|
110
|
+
onSelect={handleDateChange}
|
|
111
|
+
/>
|
|
112
|
+
</DatePickerContent>
|
|
113
|
+
</DatePicker>
|
|
114
|
+
</div>
|
|
115
|
+
</FilterFieldWrapper>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function toDate(value: string | undefined): Date | undefined {
|
|
120
|
+
if (!value) return undefined;
|
|
121
|
+
const parsed = parseISO(value);
|
|
122
|
+
return isNaN(parsed.getTime()) ? undefined : parsed;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function toDateString(date: Date | undefined): string {
|
|
126
|
+
if (!date) return "";
|
|
127
|
+
return date.toISOString().split("T")[0];
|
|
128
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { DateRange } from "react-day-picker";
|
|
2
|
+
import {
|
|
3
|
+
DatePicker,
|
|
4
|
+
DatePickerRangeTrigger,
|
|
5
|
+
DatePickerContent,
|
|
6
|
+
DatePickerCalendar,
|
|
7
|
+
} from "../../../../components/ui/datePicker";
|
|
8
|
+
|
|
9
|
+
import { useFilterField } from "../FilterContext";
|
|
10
|
+
import { FilterFieldWrapper } from "./FilterFieldWrapper";
|
|
11
|
+
import type { FilterFieldType } from "../../utils/filterUtils";
|
|
12
|
+
import { toDate, toDateString } from "./DateFilter";
|
|
13
|
+
|
|
14
|
+
interface DateRangeFilterProps extends Omit<React.ComponentProps<"div">, "onChange"> {
|
|
15
|
+
field: string;
|
|
16
|
+
label: string;
|
|
17
|
+
helpText?: string;
|
|
18
|
+
filterType?: FilterFieldType;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function DateRangeFilter({
|
|
22
|
+
field,
|
|
23
|
+
label,
|
|
24
|
+
helpText,
|
|
25
|
+
filterType = "daterange",
|
|
26
|
+
className,
|
|
27
|
+
...props
|
|
28
|
+
}: DateRangeFilterProps) {
|
|
29
|
+
const { value, onChange } = useFilterField(field);
|
|
30
|
+
|
|
31
|
+
const dateRange: DateRange | undefined =
|
|
32
|
+
value?.min || value?.max ? { from: toDate(value?.min), to: toDate(value?.max) } : undefined;
|
|
33
|
+
|
|
34
|
+
function handleRangeSelect(range: DateRange | undefined) {
|
|
35
|
+
if (!range?.from && !range?.to) {
|
|
36
|
+
onChange(undefined);
|
|
37
|
+
} else {
|
|
38
|
+
onChange({
|
|
39
|
+
field,
|
|
40
|
+
label,
|
|
41
|
+
type: filterType,
|
|
42
|
+
min: toDateString(range?.from),
|
|
43
|
+
max: toDateString(range?.to),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<FilterFieldWrapper label={label} helpText={helpText} className={className} {...props}>
|
|
50
|
+
<DatePicker>
|
|
51
|
+
<DatePickerRangeTrigger
|
|
52
|
+
className="w-full"
|
|
53
|
+
dateRange={dateRange}
|
|
54
|
+
placeholder="Pick a date range"
|
|
55
|
+
aria-label={label}
|
|
56
|
+
/>
|
|
57
|
+
<DatePickerContent align="start">
|
|
58
|
+
<DatePickerCalendar
|
|
59
|
+
mode="range"
|
|
60
|
+
captionLayout="dropdown"
|
|
61
|
+
defaultMonth={dateRange?.from}
|
|
62
|
+
selected={dateRange}
|
|
63
|
+
onSelect={handleRangeSelect}
|
|
64
|
+
numberOfMonths={2}
|
|
65
|
+
/>
|
|
66
|
+
</DatePickerContent>
|
|
67
|
+
</DatePicker>
|
|
68
|
+
</FilterFieldWrapper>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Label } from "../../../../components/ui/label";
|
|
2
|
+
import { cn } from "../../../../lib/utils";
|
|
3
|
+
|
|
4
|
+
interface FilterFieldWrapperProps extends React.ComponentProps<"div"> {
|
|
5
|
+
label: string;
|
|
6
|
+
htmlFor?: string;
|
|
7
|
+
helpText?: string;
|
|
8
|
+
error?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function FilterFieldWrapper({
|
|
12
|
+
label,
|
|
13
|
+
htmlFor,
|
|
14
|
+
helpText,
|
|
15
|
+
error,
|
|
16
|
+
className,
|
|
17
|
+
children,
|
|
18
|
+
...props
|
|
19
|
+
}: FilterFieldWrapperProps) {
|
|
20
|
+
return (
|
|
21
|
+
<div className={cn("space-y-1", className)} {...props}>
|
|
22
|
+
<Label htmlFor={htmlFor}>{label}</Label>
|
|
23
|
+
{children}
|
|
24
|
+
<div className="min-h-4">
|
|
25
|
+
{error ? (
|
|
26
|
+
<p className="text-xs text-destructive">{error}</p>
|
|
27
|
+
) : (
|
|
28
|
+
helpText && <p className="text-xs text-muted-foreground">{helpText}</p>
|
|
29
|
+
)}
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Popover,
|
|
3
|
+
PopoverContent,
|
|
4
|
+
PopoverTrigger,
|
|
5
|
+
} from "../../../../components/ui/popover";
|
|
6
|
+
import { Checkbox } from "../../../../components/ui/checkbox";
|
|
7
|
+
import { Button } from "../../../../components/ui/button";
|
|
8
|
+
import { cn } from "../../../../lib/utils";
|
|
9
|
+
import { Label } from "../../../../components/ui/label";
|
|
10
|
+
import { ChevronDown } from "lucide-react";
|
|
11
|
+
import { useFilterField } from "../FilterContext";
|
|
12
|
+
import { FilterFieldWrapper } from "./FilterFieldWrapper";
|
|
13
|
+
|
|
14
|
+
interface MultiSelectFilterProps extends Omit<React.ComponentProps<"div">, "onChange"> {
|
|
15
|
+
field: string;
|
|
16
|
+
label: string;
|
|
17
|
+
options: Array<{ value: string; label: string }>;
|
|
18
|
+
helpText?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function MultiSelectFilter({
|
|
22
|
+
field,
|
|
23
|
+
label,
|
|
24
|
+
options,
|
|
25
|
+
helpText,
|
|
26
|
+
className,
|
|
27
|
+
...props
|
|
28
|
+
}: MultiSelectFilterProps) {
|
|
29
|
+
const { value, onChange } = useFilterField(field);
|
|
30
|
+
const selected = value?.value ? value.value.split(",") : [];
|
|
31
|
+
|
|
32
|
+
const triggerLabel =
|
|
33
|
+
selected.length === 0
|
|
34
|
+
? `Select ${label.toLowerCase()}`
|
|
35
|
+
: selected.length === 1
|
|
36
|
+
? (options.find((o) => o.value === selected[0])?.label ?? selected[0])
|
|
37
|
+
: `${selected.length} selected`;
|
|
38
|
+
|
|
39
|
+
function handleToggle(optionValue: string) {
|
|
40
|
+
const next = selected.includes(optionValue)
|
|
41
|
+
? selected.filter((v) => v !== optionValue)
|
|
42
|
+
: [...selected, optionValue];
|
|
43
|
+
|
|
44
|
+
if (next.length === 0) {
|
|
45
|
+
onChange(undefined);
|
|
46
|
+
} else {
|
|
47
|
+
onChange({
|
|
48
|
+
field,
|
|
49
|
+
label,
|
|
50
|
+
type: "multipicklist",
|
|
51
|
+
value: next.join(","),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<FilterFieldWrapper label={label} helpText={helpText} className={className} {...props}>
|
|
58
|
+
<Popover>
|
|
59
|
+
<PopoverTrigger asChild>
|
|
60
|
+
<Button
|
|
61
|
+
variant="outline"
|
|
62
|
+
role="combobox"
|
|
63
|
+
className={cn(
|
|
64
|
+
"w-full justify-between font-normal",
|
|
65
|
+
selected.length === 0 && "text-muted-foreground",
|
|
66
|
+
)}
|
|
67
|
+
>
|
|
68
|
+
<span className="truncate">{triggerLabel}</span>
|
|
69
|
+
<ChevronDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
|
70
|
+
</Button>
|
|
71
|
+
</PopoverTrigger>
|
|
72
|
+
<PopoverContent className="p-2" align="start">
|
|
73
|
+
<div className="max-h-48 overflow-y-auto space-y-1">
|
|
74
|
+
{options.map((opt) => {
|
|
75
|
+
const id = `filter-${field}-${opt.value}`;
|
|
76
|
+
return (
|
|
77
|
+
<div
|
|
78
|
+
key={opt.value}
|
|
79
|
+
className="flex items-center gap-2 rounded px-1 py-0.5 hover:bg-accent"
|
|
80
|
+
>
|
|
81
|
+
<Checkbox
|
|
82
|
+
id={id}
|
|
83
|
+
checked={selected.includes(opt.value)}
|
|
84
|
+
onCheckedChange={() => handleToggle(opt.value)}
|
|
85
|
+
/>
|
|
86
|
+
<Label htmlFor={id} className="text-sm font-normal cursor-pointer w-full">
|
|
87
|
+
{opt.label}
|
|
88
|
+
</Label>
|
|
89
|
+
</div>
|
|
90
|
+
);
|
|
91
|
+
})}
|
|
92
|
+
</div>
|
|
93
|
+
</PopoverContent>
|
|
94
|
+
</Popover>
|
|
95
|
+
</FilterFieldWrapper>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { Input } from "../../../../components/ui/input";
|
|
3
|
+
|
|
4
|
+
import { useFilterField } from "../FilterContext";
|
|
5
|
+
import { useDebouncedCallback } from "../../hooks/useDebouncedCallback";
|
|
6
|
+
import { FilterFieldWrapper } from "./FilterFieldWrapper";
|
|
7
|
+
import type { ActiveFilterValue } from "../../utils/filterUtils";
|
|
8
|
+
|
|
9
|
+
interface NumericRangeFilterProps extends Omit<React.ComponentProps<"div">, "onChange"> {
|
|
10
|
+
field: string;
|
|
11
|
+
label: string;
|
|
12
|
+
helpText?: string;
|
|
13
|
+
min?: number;
|
|
14
|
+
max?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function NumericRangeFilter({
|
|
18
|
+
field,
|
|
19
|
+
label,
|
|
20
|
+
helpText,
|
|
21
|
+
min,
|
|
22
|
+
max,
|
|
23
|
+
className,
|
|
24
|
+
...props
|
|
25
|
+
}: NumericRangeFilterProps) {
|
|
26
|
+
const { value, onChange } = useFilterField(field);
|
|
27
|
+
return (
|
|
28
|
+
<NumericRangeFilterInputs
|
|
29
|
+
field={field}
|
|
30
|
+
label={label}
|
|
31
|
+
helpText={helpText}
|
|
32
|
+
value={value}
|
|
33
|
+
onChange={onChange}
|
|
34
|
+
min={min}
|
|
35
|
+
max={max}
|
|
36
|
+
className={className}
|
|
37
|
+
{...props}
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface NumericRangeFilterInputsProps extends Omit<React.ComponentProps<"div">, "onChange"> {
|
|
43
|
+
field: string;
|
|
44
|
+
label: string;
|
|
45
|
+
helpText?: string;
|
|
46
|
+
value: ActiveFilterValue | undefined;
|
|
47
|
+
onChange: (value: ActiveFilterValue | undefined) => void;
|
|
48
|
+
min?: number;
|
|
49
|
+
max?: number;
|
|
50
|
+
minInputProps?: React.ComponentProps<typeof Input>;
|
|
51
|
+
maxInputProps?: React.ComponentProps<typeof Input>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function NumericRangeFilterInputs({
|
|
55
|
+
field,
|
|
56
|
+
label,
|
|
57
|
+
helpText,
|
|
58
|
+
value,
|
|
59
|
+
onChange,
|
|
60
|
+
min: boundMin,
|
|
61
|
+
max: boundMax,
|
|
62
|
+
className,
|
|
63
|
+
...props
|
|
64
|
+
}: NumericRangeFilterInputsProps) {
|
|
65
|
+
const [localMin, setLocalMin] = useState(value?.min ?? "");
|
|
66
|
+
const [localMax, setLocalMax] = useState(value?.max ?? "");
|
|
67
|
+
|
|
68
|
+
const externalMin = value?.min ?? "";
|
|
69
|
+
const externalMax = value?.max ?? "";
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
setLocalMin(externalMin);
|
|
72
|
+
}, [externalMin]);
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
setLocalMax(externalMax);
|
|
75
|
+
}, [externalMax]);
|
|
76
|
+
|
|
77
|
+
const isOutOfBounds = (v: string) => {
|
|
78
|
+
if (v === "") return false;
|
|
79
|
+
const n = Number(v);
|
|
80
|
+
return (boundMin != null && n < boundMin) || (boundMax != null && n > boundMax);
|
|
81
|
+
};
|
|
82
|
+
const minOutOfBounds = isOutOfBounds(localMin);
|
|
83
|
+
const maxOutOfBounds = isOutOfBounds(localMax);
|
|
84
|
+
const isRangeInverted = localMin !== "" && localMax !== "" && Number(localMin) > Number(localMax);
|
|
85
|
+
const hasError = minOutOfBounds || maxOutOfBounds || isRangeInverted;
|
|
86
|
+
|
|
87
|
+
const debouncedOnChange = useDebouncedCallback((min: string, max: string) => {
|
|
88
|
+
if (!min && !max) {
|
|
89
|
+
onChange(undefined);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const minNum = min !== "" ? Number(min) : null;
|
|
93
|
+
const maxNum = max !== "" ? Number(max) : null;
|
|
94
|
+
if (minNum != null && maxNum != null && minNum > maxNum) return;
|
|
95
|
+
if (
|
|
96
|
+
minNum != null &&
|
|
97
|
+
((boundMin != null && minNum < boundMin) || (boundMax != null && minNum > boundMax))
|
|
98
|
+
)
|
|
99
|
+
return;
|
|
100
|
+
if (
|
|
101
|
+
maxNum != null &&
|
|
102
|
+
((boundMin != null && maxNum < boundMin) || (boundMax != null && maxNum > boundMax))
|
|
103
|
+
)
|
|
104
|
+
return;
|
|
105
|
+
onChange({ field, label, type: "numeric" as const, min, max });
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const boundsLabel =
|
|
109
|
+
boundMin != null && boundMax != null
|
|
110
|
+
? `${boundMin}–${boundMax}`
|
|
111
|
+
: boundMin != null
|
|
112
|
+
? `${boundMin} or more`
|
|
113
|
+
: boundMax != null
|
|
114
|
+
? `${boundMax} or less`
|
|
115
|
+
: null;
|
|
116
|
+
|
|
117
|
+
const errorMessage = isRangeInverted
|
|
118
|
+
? "Min must not exceed max"
|
|
119
|
+
: (minOutOfBounds || maxOutOfBounds) && boundsLabel
|
|
120
|
+
? `Value must be between ${boundsLabel}`
|
|
121
|
+
: undefined;
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<FilterFieldWrapper
|
|
125
|
+
label={label}
|
|
126
|
+
helpText={helpText}
|
|
127
|
+
error={errorMessage}
|
|
128
|
+
className={className}
|
|
129
|
+
{...props}
|
|
130
|
+
>
|
|
131
|
+
<div className="flex gap-2">
|
|
132
|
+
<Input
|
|
133
|
+
type="number"
|
|
134
|
+
placeholder="Min"
|
|
135
|
+
value={localMin}
|
|
136
|
+
min={boundMin}
|
|
137
|
+
max={boundMax}
|
|
138
|
+
onChange={(e) => {
|
|
139
|
+
const v = e.target.value;
|
|
140
|
+
setLocalMin(v);
|
|
141
|
+
debouncedOnChange(v, localMax);
|
|
142
|
+
}}
|
|
143
|
+
aria-label={`${label} minimum`}
|
|
144
|
+
aria-invalid={hasError || undefined}
|
|
145
|
+
/>
|
|
146
|
+
<Input
|
|
147
|
+
type="number"
|
|
148
|
+
placeholder="Max"
|
|
149
|
+
value={localMax}
|
|
150
|
+
min={boundMin}
|
|
151
|
+
max={boundMax}
|
|
152
|
+
onChange={(e) => {
|
|
153
|
+
const v = e.target.value;
|
|
154
|
+
setLocalMax(v);
|
|
155
|
+
debouncedOnChange(localMin, v);
|
|
156
|
+
}}
|
|
157
|
+
aria-label={`${label} maximum`}
|
|
158
|
+
aria-invalid={hasError || undefined}
|
|
159
|
+
/>
|
|
160
|
+
</div>
|
|
161
|
+
</FilterFieldWrapper>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { SearchBar } from "../SearchBar";
|
|
4
|
+
import { useFilterField } from "../FilterContext";
|
|
5
|
+
import { FilterFieldWrapper } from "./FilterFieldWrapper";
|
|
6
|
+
import { useDebouncedCallback } from "../../hooks/useDebouncedCallback";
|
|
7
|
+
|
|
8
|
+
interface SearchFilterProps extends Omit<React.ComponentProps<"div">, "onChange"> {
|
|
9
|
+
field: string;
|
|
10
|
+
label: string;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function SearchFilter({
|
|
15
|
+
field,
|
|
16
|
+
label,
|
|
17
|
+
placeholder,
|
|
18
|
+
className,
|
|
19
|
+
...props
|
|
20
|
+
}: SearchFilterProps) {
|
|
21
|
+
const { value, onChange } = useFilterField(field);
|
|
22
|
+
const [localValue, setLocalValue] = useState(value?.value ?? "");
|
|
23
|
+
|
|
24
|
+
const externalValue = value?.value ?? "";
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
setLocalValue(externalValue);
|
|
27
|
+
}, [externalValue]);
|
|
28
|
+
|
|
29
|
+
const debouncedOnChange = useDebouncedCallback((v: string) => {
|
|
30
|
+
if (v) {
|
|
31
|
+
onChange({ field, label, type: "search", value: v });
|
|
32
|
+
} else {
|
|
33
|
+
onChange(undefined);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<FilterFieldWrapper label={label} htmlFor={`filter-${field}`} className={className} {...props}>
|
|
39
|
+
<SearchBar
|
|
40
|
+
value={localValue}
|
|
41
|
+
handleChange={(v) => {
|
|
42
|
+
setLocalValue(v);
|
|
43
|
+
debouncedOnChange(v);
|
|
44
|
+
}}
|
|
45
|
+
placeholder={placeholder}
|
|
46
|
+
inputProps={{ id: `filter-${field}` }}
|
|
47
|
+
/>
|
|
48
|
+
</FilterFieldWrapper>
|
|
49
|
+
);
|
|
50
|
+
}
|