@erxes/ui 4.0.0-v2.8 → 4.0.0-v2.9
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/README.md +8 -3
- package/dist/hooks/use-item-keys.d.ts +10 -0
- package/dist/hooks/use-item-keys.js +23 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.js +9 -2
- package/dist/lib/format.d.ts +2 -0
- package/dist/lib/format.js +6 -1
- package/dist/lib/money.d.ts +10 -0
- package/dist/lib/money.js +18 -0
- package/dist/lib/text.d.ts +7 -0
- package/dist/lib/text.js +14 -0
- package/dist/modules/conditions/ConditionValueInput.d.ts +10 -0
- package/dist/modules/conditions/ConditionValueInput.js +166 -0
- package/dist/modules/conditions/ConditionsEditor.d.ts +11 -0
- package/dist/modules/conditions/ConditionsEditor.js +209 -0
- package/dist/modules/conditions/LazyConditionsEditor.d.ts +9 -0
- package/dist/modules/conditions/LazyConditionsEditor.js +10 -0
- package/dist/modules/conditions/PathPicker.d.ts +8 -0
- package/dist/modules/conditions/PathPicker.js +51 -0
- package/dist/modules/conditions/conditions.d.ts +64 -0
- package/dist/modules/conditions/conditions.js +135 -0
- package/dist/modules/list/ListFilter.d.ts +25 -11
- package/dist/modules/list/ListFilter.js +30 -26
- package/dist/modules/list/filter/AdvancedFilterDialog.d.ts +5 -0
- package/dist/modules/list/filter/AdvancedFilterDialog.js +52 -0
- package/dist/modules/list/filter/FieldMenus.d.ts +5 -0
- package/dist/modules/list/filter/FieldMenus.js +184 -0
- package/dist/modules/list/filter/ListFilterBar.d.ts +6 -0
- package/dist/modules/list/filter/ListFilterBar.js +246 -0
- package/dist/modules/list/filter/RecordCount.d.ts +7 -0
- package/dist/modules/list/filter/RecordCount.js +22 -0
- package/dist/modules/list/filter/RuleChips.d.ts +2 -0
- package/dist/modules/list/filter/RuleChips.js +157 -0
- package/dist/modules/list/filter/fieldIcons.d.ts +7 -0
- package/dist/modules/list/filter/fieldIcons.js +16 -0
- package/dist/modules/list/filter/filterRules.d.ts +46 -0
- package/dist/modules/list/filter/filterRules.js +166 -0
- package/dist/modules/list/filter/listFilterContext.d.ts +29 -0
- package/dist/modules/list/filter/listFilterContext.js +34 -0
- package/dist/modules/list/filter/listFilterQuery.d.ts +15 -0
- package/dist/modules/list/filter/listFilterQuery.js +21 -0
- package/dist/modules/pickers/LookupPicker.d.ts +50 -0
- package/dist/modules/pickers/LookupPicker.js +83 -0
- package/dist/theme.css +2 -0
- package/package.json +2 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TConditionLookups } from "../../conditions/conditions.js";
|
|
2
|
+
import { TListFilterField } from "../ListFilter.js";
|
|
3
|
+
import { FilterPart } from "./filterRules.js";
|
|
4
|
+
/** What the filter menu, its chips and the advanced filter share. */
|
|
5
|
+
export interface ListFilterState {
|
|
6
|
+
fields: TListFilterField[];
|
|
7
|
+
/** Where `member` and `tags` fields pick from. */
|
|
8
|
+
lookups: TConditionLookups;
|
|
9
|
+
/** The list's filter as parts that must all hold (`partsOf`). */
|
|
10
|
+
parts: FilterPart[];
|
|
11
|
+
/** Changes the filter as `withPart` does. */
|
|
12
|
+
setPart: (index: number | null, next: FilterPart | null) => void;
|
|
13
|
+
/** The part a chip opened the menu on. */
|
|
14
|
+
editing: number | null;
|
|
15
|
+
/** Opens the menu on a chip's part, or the advanced filter when the menu can't show it. */
|
|
16
|
+
edit: (index: number) => void;
|
|
17
|
+
openAdvanced: () => void;
|
|
18
|
+
}
|
|
19
|
+
export declare const ListFilterContext: import("react").Context<ListFilterState | null>;
|
|
20
|
+
export declare const useListFilter: () => ListFilterState;
|
|
21
|
+
/** What a choice field picks from: its options, the team ("Me" first), or the list's tags. */
|
|
22
|
+
export declare const useFieldOptions: (field: TListFilterField) => {
|
|
23
|
+
options: {
|
|
24
|
+
value: string;
|
|
25
|
+
label: string;
|
|
26
|
+
}[];
|
|
27
|
+
loading: boolean;
|
|
28
|
+
error: Error | null;
|
|
29
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isRule } from "../../conditions/conditions.js";
|
|
2
|
+
import { useMemberOptions, useTagOptions } from "../../pickers/LookupPicker.js";
|
|
3
|
+
import { valuesOf } from "./filterRules.js";
|
|
4
|
+
import { createContext, useContext } from "react";
|
|
5
|
+
import { useTranslation } from "react-i18next";
|
|
6
|
+
// src/modules/list/filter/listFilterContext.ts
|
|
7
|
+
const ListFilterContext = createContext(null);
|
|
8
|
+
const useListFilter = () => {
|
|
9
|
+
const state = useContext(ListFilterContext);
|
|
10
|
+
if (!state) throw new Error("useListFilter is only available inside <ListFilter>");
|
|
11
|
+
return state;
|
|
12
|
+
};
|
|
13
|
+
/** What a choice field picks from: its options, the team ("Me" first), or the list's tags. */
|
|
14
|
+
const useFieldOptions = (field) => {
|
|
15
|
+
const { t } = useTranslation("views", { keyPrefix: "filter" });
|
|
16
|
+
const { lookups, parts } = useListFilter();
|
|
17
|
+
const picked = parts.flatMap((part) => isRule(part) && part.path === field.path ? valuesOf(part) : []);
|
|
18
|
+
const members = useMemberOptions(lookups.members, field.type === "member", picked);
|
|
19
|
+
const tags = useTagOptions(lookups.tags, field.type === "tags");
|
|
20
|
+
if (field.type === "member") return {
|
|
21
|
+
...members,
|
|
22
|
+
options: [{
|
|
23
|
+
value: "me",
|
|
24
|
+
label: t("me", "Me")
|
|
25
|
+
}, ...members.options]
|
|
26
|
+
};
|
|
27
|
+
if (field.type === "tags") return tags;
|
|
28
|
+
return {
|
|
29
|
+
options: field.options ?? [],
|
|
30
|
+
loading: false,
|
|
31
|
+
error: null
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export { ListFilterContext, useFieldOptions, useListFilter };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TConditionGroup } from "../../conditions/conditions.js";
|
|
2
|
+
/**
|
|
3
|
+
* Where a list's filter lives in the address, so shared links and reloads keep it: `advanced`,
|
|
4
|
+
* the condition group as JSON, and `searchValue`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const listFilterQuery: {
|
|
7
|
+
advanced: import("nuqs").SingleParserBuilder<TConditionGroup>;
|
|
8
|
+
searchValue: import("nuqs").SingleParserBuilder<string>;
|
|
9
|
+
};
|
|
10
|
+
/** The list's conditions (null without any) and search, and how the bar changes them. */
|
|
11
|
+
export declare const useListConditions: () => {
|
|
12
|
+
advanced: TConditionGroup | null;
|
|
13
|
+
search: string | null;
|
|
14
|
+
setAdvanced: (next: TConditionGroup | null) => undefined;
|
|
15
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ConditionGroup } from "../../conditions/conditions.js";
|
|
2
|
+
import { parseAsJson, parseAsString, useQueryStates } from "nuqs";
|
|
3
|
+
// src/modules/list/filter/listFilterQuery.ts
|
|
4
|
+
/**
|
|
5
|
+
* Where a list's filter lives in the address, so shared links and reloads keep it: `advanced`,
|
|
6
|
+
* the condition group as JSON, and `searchValue`.
|
|
7
|
+
*/
|
|
8
|
+
const listFilterQuery = {
|
|
9
|
+
advanced: parseAsJson((value) => ConditionGroup.safeParse(value).data ?? null),
|
|
10
|
+
searchValue: parseAsString
|
|
11
|
+
};
|
|
12
|
+
/** The list's conditions (null without any) and search, and how the bar changes them. */
|
|
13
|
+
const useListConditions = () => {
|
|
14
|
+
const [{ advanced, searchValue }, setQueries] = useQueryStates(listFilterQuery, { history: "replace" });
|
|
15
|
+
return {
|
|
16
|
+
advanced: advanced?.rules.length ? advanced : null,
|
|
17
|
+
search: searchValue,
|
|
18
|
+
setAdvanced: (next) => void setQueries({ advanced: next?.rules.length ? next : null })
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export { listFilterQuery, useListConditions };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { MemberQueries } from "./members.js";
|
|
2
|
+
import { UseQueryOptions } from "@tanstack/react-query";
|
|
3
|
+
/** A tag as the pickers show one: core's `Tag` has these fields and more. */
|
|
4
|
+
export interface Tag {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The tags of one record type, as TanStack query options: in erxes, web's query for
|
|
10
|
+
* `orpc.tags.list` with the type (`{ type: 'customer' }`).
|
|
11
|
+
*/
|
|
12
|
+
export type TagsQuery = RowsQuery<Tag>;
|
|
13
|
+
type LookupOptions = {
|
|
14
|
+
options: {
|
|
15
|
+
value: string;
|
|
16
|
+
label: string;
|
|
17
|
+
}[];
|
|
18
|
+
loading: boolean;
|
|
19
|
+
error: Error | null;
|
|
20
|
+
};
|
|
21
|
+
type RowsQuery<T> = UseQueryOptions<{
|
|
22
|
+
data: T[];
|
|
23
|
+
}, Error, {
|
|
24
|
+
data: T[];
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* The active team as picker options, plus the `picked` members outside it (a disabled member a
|
|
28
|
+
* filter still names), so their names show; none without `members`.
|
|
29
|
+
*/
|
|
30
|
+
export declare const useMemberOptions: (members: MemberQueries | undefined, enabled?: boolean, picked?: readonly string[]) => {
|
|
31
|
+
loading: boolean;
|
|
32
|
+
error: Error | null;
|
|
33
|
+
options: {
|
|
34
|
+
value: string;
|
|
35
|
+
label: string;
|
|
36
|
+
}[];
|
|
37
|
+
};
|
|
38
|
+
/** A record type's tags as picker options; none without `tags`. */
|
|
39
|
+
export declare const useTagOptions: (tags: TagsQuery | undefined, enabled?: boolean) => LookupOptions;
|
|
40
|
+
/** One option, or several with `multiple`, from members or tags, on a button. */
|
|
41
|
+
export declare const LookupPicker: ({ lookup: { options, loading, error }, value, onValueChange, multiple, placeholder, disabled, className }: {
|
|
42
|
+
lookup: LookupOptions;
|
|
43
|
+
value: string[];
|
|
44
|
+
onValueChange: (values: string[]) => void;
|
|
45
|
+
multiple?: boolean;
|
|
46
|
+
placeholder: string;
|
|
47
|
+
disabled?: boolean;
|
|
48
|
+
className?: string;
|
|
49
|
+
}) => import("react").JSX.Element;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Combobox } from "../../components/combobox.js";
|
|
2
|
+
import { Popover } from "../../components/popover.js";
|
|
3
|
+
import { EntityPicker } from "./EntityPicker.js";
|
|
4
|
+
import { memberName } from "./members.js";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { useMemo, useState } from "react";
|
|
7
|
+
import { skipToken, useQuery } from "@tanstack/react-query";
|
|
8
|
+
// src/modules/pickers/LookupPicker.tsx
|
|
9
|
+
const useLookup = (query, enabled, option) => {
|
|
10
|
+
const options = query ? {
|
|
11
|
+
...query,
|
|
12
|
+
enabled
|
|
13
|
+
} : {
|
|
14
|
+
queryKey: ["erxes-ui", "no-lookup"],
|
|
15
|
+
queryFn: skipToken
|
|
16
|
+
};
|
|
17
|
+
const result = useQuery(options);
|
|
18
|
+
return {
|
|
19
|
+
options: useMemo(() => (result.data?.data ?? []).map(option), [result.data, option]),
|
|
20
|
+
loading: enabled && !!query && result.isPending,
|
|
21
|
+
error: result.error
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
const memberOption = (member) => ({
|
|
25
|
+
value: member.id,
|
|
26
|
+
label: memberName(member)
|
|
27
|
+
});
|
|
28
|
+
const tagOption = (tag) => ({
|
|
29
|
+
value: tag.id,
|
|
30
|
+
label: tag.name
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* The active team as picker options, plus the `picked` members outside it (a disabled member a
|
|
34
|
+
* filter still names), so their names show; none without `members`.
|
|
35
|
+
*/
|
|
36
|
+
const useMemberOptions = (members, enabled = true, picked = []) => {
|
|
37
|
+
const team = useLookup(members?.team, enabled, memberOption);
|
|
38
|
+
const known = new Set(team.options.map((option) => option.value));
|
|
39
|
+
const missing = [...new Set(picked)].filter((id) => id !== "me" && !known.has(id)).toSorted((a, b) => a.localeCompare(b));
|
|
40
|
+
const others = useLookup(members && missing.length ? members.byIds(missing) : void 0, enabled && !team.loading && missing.length > 0, memberOption);
|
|
41
|
+
return {
|
|
42
|
+
...team,
|
|
43
|
+
options: [...team.options, ...others.options]
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/** A record type's tags as picker options; none without `tags`. */
|
|
47
|
+
const useTagOptions = (tags, enabled = true) => useLookup(tags, enabled, tagOption);
|
|
48
|
+
/** One option, or several with `multiple`, from members or tags, on a button. */
|
|
49
|
+
const LookupPicker = ({ lookup: { options, loading, error }, value, onValueChange, multiple, placeholder, disabled, className }) => {
|
|
50
|
+
const [open, setOpen] = useState(false);
|
|
51
|
+
const items = [...value.filter((id) => !options.some((option) => option.value === id)).map((id) => ({
|
|
52
|
+
value: id,
|
|
53
|
+
label: id
|
|
54
|
+
})), ...options];
|
|
55
|
+
const labels = value.map((id) => items.find((option) => option.value === id)?.label ?? id);
|
|
56
|
+
return /* @__PURE__ */ jsxs(Popover, {
|
|
57
|
+
open,
|
|
58
|
+
onOpenChange: setOpen,
|
|
59
|
+
children: [/* @__PURE__ */ jsx(Combobox.Trigger, {
|
|
60
|
+
disabled,
|
|
61
|
+
className,
|
|
62
|
+
children: /* @__PURE__ */ jsx(Combobox.Value, {
|
|
63
|
+
value: labels.join(", "),
|
|
64
|
+
placeholder
|
|
65
|
+
})
|
|
66
|
+
}), /* @__PURE__ */ jsx(Combobox.Content, { children: /* @__PURE__ */ jsx(EntityPicker, {
|
|
67
|
+
multiple,
|
|
68
|
+
items,
|
|
69
|
+
itemKey: (option) => ({
|
|
70
|
+
id: option.value,
|
|
71
|
+
label: option.label
|
|
72
|
+
}),
|
|
73
|
+
value,
|
|
74
|
+
onValueChange: (next) => {
|
|
75
|
+
onValueChange(next);
|
|
76
|
+
if (!multiple) setOpen(false);
|
|
77
|
+
},
|
|
78
|
+
loading,
|
|
79
|
+
error
|
|
80
|
+
}) })]
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
export { LookupPicker, useMemberOptions, useTagOptions };
|
package/dist/theme.css
CHANGED
|
@@ -126,6 +126,8 @@
|
|
|
126
126
|
--grid-template-columns-field: 6.5rem minmax(0, 1fr);
|
|
127
127
|
/* A side column of 18 to 24rem beside the content. */
|
|
128
128
|
--grid-template-columns-aside: minmax(18rem, 24rem) minmax(0, 1fr);
|
|
129
|
+
/* A condition row: field and operator, then the remove button. */
|
|
130
|
+
--grid-template-columns-condition: minmax(0, 1fr) minmax(0, 1fr) auto;
|
|
129
131
|
|
|
130
132
|
/* Panels and sidebars sliding open or shut. */
|
|
131
133
|
--ease-out-quint: cubic-bezier(0.22, 1, 0.36, 1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@erxes/ui",
|
|
3
|
-
"version": "4.0.0-v2.
|
|
3
|
+
"version": "4.0.0-v2.9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "erxes design system: UI primitives, layout, hooks and shared frontend state",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
"@types/react": "19.3.0",
|
|
75
75
|
"@types/react-dom": "19.3.0",
|
|
76
76
|
"happy-dom": "21.0.4",
|
|
77
|
+
"i18next": "^27.1.1",
|
|
77
78
|
"jotai": "^3.0.2",
|
|
78
79
|
"nuqs": "^2.10.3",
|
|
79
80
|
"react": "^19.3.1",
|