@aglyn/plugins-crm 1.0.0-beta.187 → 1.0.0-beta.189

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.
@@ -1,144 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2026 Aglyn LLC
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */ import { _ as _extends } from "@swc/helpers/_/_extends";
17
- import { gridFilterRequests, hiddenFilterColumns, listFilterColumn, listFilterOperators } from "@aglyn/shared-ui-jsx/const/list-filter";
18
- import { getGridSingleSelectOperators } from "@mui/x-data-grid";
19
- /** The grid operator each stored select operator shows as. */ const SELECT_TO_GRID = {
20
- equals: 'is',
21
- doesNotEqual: 'not',
22
- isAnyOf: 'isAnyOf'
23
- };
24
- const SELECT_FROM_GRID = {
25
- is: 'equals',
26
- not: 'doesNotEqual',
27
- isAnyOf: 'isAnyOf'
28
- };
29
- /** The panel's item as a clause, through the grammar's one notion of "usable". */ const plainClause = (item)=>{
30
- var _gridFilterRequests_;
31
- return (_gridFilterRequests_ = gridFilterRequests({
32
- items: [
33
- item
34
- ]
35
- })[0]) != null ? _gridFilterRequests_ : null;
36
- };
37
- /** A typed field: the stored operator IS the grid's. */ export const crmPlainCodec = {
38
- toItem: (clause)=>({
39
- operator: clause.op,
40
- value: clause.value === '' ? undefined : clause.value
41
- }),
42
- toClause: plainClause
43
- };
44
- /** A picked field: `equals` shows as `is`, and `isAnyOf` holds a comma list. */ export const crmSelectCodec = {
45
- toItem: (clause)=>{
46
- const operator = SELECT_TO_GRID[clause.op];
47
- if (!operator) return null;
48
- return {
49
- operator,
50
- value: operator === 'isAnyOf' ? clause.value.split(',').map((entry)=>entry.trim()).filter(Boolean) : clause.value
51
- };
52
- },
53
- toClause: (item)=>{
54
- const op = SELECT_FROM_GRID[String(item.operator)];
55
- const request = op ? plainClause(item) : null;
56
- return request && op ? _extends({}, request, {
57
- op
58
- }) : null;
59
- }
60
- };
61
- /** The select operators a field's allowed clause operators map to. */ export function crmSelectOperators(allowed) {
62
- const shown = allowed.map((op)=>SELECT_TO_GRID[op]).filter(Boolean);
63
- return getGridSingleSelectOperators().filter((operator)=>shown.includes(operator.value));
64
- }
65
- /**
66
- * The list's columns, each made filterable exactly as far as its field is
67
- * declared, and every declared field that is not a column added as a
68
- * permanently hidden one — the panel lists columns, so a field with none
69
- * could not be reached (`hiddenFilterColumns`).
70
- *
71
- * A field with choices becomes a `singleSelect` over them, whatever the
72
- * column rendered before; one without keeps the grammar's operators; a
73
- * column no field declares offers no filter, because the list, not the
74
- * grid, answers every filter and would have nothing to answer it with.
75
- */ export function crmFilterColumns(columns, fields, options = {}, headers = {}) {
76
- const selectProps = (field)=>{
77
- var _options_field_column;
78
- const choices = (_options_field_column = options[field.column]) != null ? _options_field_column : [];
79
- const operators = crmSelectOperators(listFilterOperators(field));
80
- return {
81
- type: 'singleSelect',
82
- valueOptions: choices.map((choice)=>({
83
- value: choice.value,
84
- label: choice.label
85
- })),
86
- filterable: choices.length > 0 && operators.length > 0,
87
- filterOperators: operators
88
- };
89
- };
90
- const shown = columns.map((column)=>{
91
- if (column.filterable === false && column.hideable === false) return column;
92
- const field = fields.find((entry)=>entry.column === column.field);
93
- if (!field) return _extends({}, column, {
94
- filterable: false
95
- });
96
- if (options[field.column]) return _extends({}, column, selectProps(field));
97
- return _extends({}, column, listFilterColumn(fields, field.column));
98
- });
99
- const present = columns.map((column)=>column.field);
100
- const hidden = hiddenFilterColumns(fields, present, headers).map((column)=>{
101
- const field = fields.find((entry)=>entry.column === column.field);
102
- return field && options[field.column] ? _extends({}, column, selectProps(field)) : column;
103
- });
104
- return [
105
- ...shown,
106
- ...hidden
107
- ];
108
- }
109
- /**
110
- * Whether a row answers a quick search: every whitespace-separated word
111
- * appears, case-insensitively, in SOME of the row's searched values. A
112
- * blank search matches every row, so an emptied box is the list unfiltered.
113
- * An array value (tags) is searched member by member.
114
- */ export function crmRowMatchesSearch(row, paths, words) {
115
- const asked = words.map((word)=>word.trim().toLowerCase()).filter(Boolean);
116
- if (!asked.length) return true;
117
- const values = paths.flatMap((path)=>{
118
- const value = path.split('.').reduce((at, key)=>at == null ? undefined : at[key], row);
119
- return Array.isArray(value) ? value : [
120
- value
121
- ];
122
- }).filter((value)=>typeof value === 'string' || typeof value === 'number').map((value)=>String(value).toLowerCase()).filter(Boolean);
123
- return asked.every((word)=>values.some((value)=>value.includes(word)));
124
- }
125
- /**
126
- * The clauses with one field's clause set: replaced in place where the field
127
- * already had one, appended where it did not, removed when `next` is null.
128
- * A field holds ONE clause, which is what the panel edits.
129
- */ export function crmUpsertClause(clauses, field, next) {
130
- const at = clauses.findIndex((clause)=>clause.field === field);
131
- const rest = clauses.filter((clause)=>clause.field !== field);
132
- if (!next) return rest;
133
- if (at === -1) return [
134
- ...rest,
135
- next
136
- ];
137
- return [
138
- ...rest.slice(0, at),
139
- next,
140
- ...rest.slice(at)
141
- ];
142
- }
143
-
144
- //# sourceMappingURL=crm-grid-filter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/model/crm-grid-filter.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { CrmViewFilterClause } from '@aglyn/aglyn'\nimport {\n gridFilterRequests,\n hiddenFilterColumns,\n type ListFilterField,\n listFilterColumn,\n listFilterOperators,\n} from '@aglyn/shared-ui-jsx/const/list-filter'\nimport {\n getGridSingleSelectOperators,\n type GridColDef,\n type GridFilterItem,\n} from '@mui/x-data-grid'\n\n/*\n * ONE path from a CRM list's saved-view clauses to the data grid's own\n * Filters panel and quick search, and back (AGL-3313).\n *\n * Every CRM list stores what it is narrowed by as view clauses —\n * `{ field, op, value }`, the shape saved views have held since AGL-2617 —\n * and every one of them now edits those clauses through the grid's toolbar\n * rather than a control of its own. What a list declares is its fields,\n * as the `ListFilterField` grammar the console's other paged lists speak\n * (the content entries, the staff lists), plus the choices of the fields\n * whose values are picked rather than typed. The grid then offers each as a\n * typed column: a `singleSelect` with its choices where there are choices,\n * the operators the grammar allows otherwise.\n *\n * The clauses keep their stored shape, so a view saved with the old\n * dropdowns reads unchanged: the panel shows `equals` as the select's `is`\n * and writes `is` back as `equals`, and a list whose clauses were stored in\n * some other shape (Leads' campaign `contains`, its lead source `isEmpty`)\n * says so with a codec.\n */\n\n/** A choice for a field whose value is picked rather than typed. */\nexport interface CrmFilterOption {\n value: string\n label: string\n}\n\n/** The grid operator each stored select operator shows as. */\nconst SELECT_TO_GRID: Readonly<Record<string, string>> = {\n equals: 'is',\n doesNotEqual: 'not',\n isAnyOf: 'isAnyOf',\n}\nconst SELECT_FROM_GRID: Readonly<Record<string, string>> = {\n is: 'equals',\n not: 'doesNotEqual',\n isAnyOf: 'isAnyOf',\n}\n\n/**\n * How one field's stored clause and the panel's item translate. A field\n * with choices uses {@link crmSelectCodec}; a typed one, {@link crmPlainCodec}.\n * A list whose clauses predate the panel supplies its own.\n */\nexport interface CrmGridFilterCodec {\n toItem: (clause: CrmViewFilterClause) => Pick<GridFilterItem, 'operator' | 'value'> | null\n toClause: (item: GridFilterItem) => CrmViewFilterClause | null\n}\n\n/** The panel's item as a clause, through the grammar's one notion of \"usable\". */\nconst plainClause = (item: GridFilterItem): CrmViewFilterClause | null =>\n gridFilterRequests({ items: [item] })[0] ?? null\n\n/** A typed field: the stored operator IS the grid's. */\nexport const crmPlainCodec: CrmGridFilterCodec = {\n toItem: (clause) => ({\n operator: clause.op,\n value: clause.value === '' ? undefined : clause.value,\n }),\n toClause: plainClause,\n}\n\n/** A picked field: `equals` shows as `is`, and `isAnyOf` holds a comma list. */\nexport const crmSelectCodec: CrmGridFilterCodec = {\n toItem: (clause) => {\n const operator = SELECT_TO_GRID[clause.op]\n if (!operator) return null\n return {\n operator,\n value:\n operator === 'isAnyOf'\n ? clause.value.split(',').map((entry) => entry.trim()).filter(Boolean)\n : clause.value,\n }\n },\n toClause: (item) => {\n const op = SELECT_FROM_GRID[String(item.operator)]\n const request = op ? plainClause(item) : null\n return request && op ? { ...request, op } : null\n },\n}\n\n/** The select operators a field's allowed clause operators map to. */\nexport function crmSelectOperators(allowed: readonly string[]) {\n const shown = allowed.map((op) => SELECT_TO_GRID[op]).filter(Boolean)\n return getGridSingleSelectOperators().filter((operator) =>\n shown.includes(operator.value),\n )\n}\n\n/**\n * The list's columns, each made filterable exactly as far as its field is\n * declared, and every declared field that is not a column added as a\n * permanently hidden one — the panel lists columns, so a field with none\n * could not be reached (`hiddenFilterColumns`).\n *\n * A field with choices becomes a `singleSelect` over them, whatever the\n * column rendered before; one without keeps the grammar's operators; a\n * column no field declares offers no filter, because the list, not the\n * grid, answers every filter and would have nothing to answer it with.\n */\nexport function crmFilterColumns(\n columns: readonly GridColDef[],\n fields: readonly ListFilterField[],\n options: Readonly<Record<string, readonly CrmFilterOption[]>> = {},\n headers: Readonly<Record<string, string>> = {},\n): GridColDef[] {\n const selectProps = (field: ListFilterField) => {\n const choices = options[field.column] ?? []\n const operators = crmSelectOperators(listFilterOperators(field))\n return {\n type: 'singleSelect' as const,\n valueOptions: choices.map((choice) => ({ value: choice.value, label: choice.label })),\n filterable: choices.length > 0 && operators.length > 0,\n filterOperators: operators,\n }\n }\n const shown = columns.map((column): GridColDef => {\n if (column.filterable === false && column.hideable === false) return column\n const field = fields.find((entry) => entry.column === column.field)\n if (!field) return { ...column, filterable: false }\n if (options[field.column]) return { ...column, ...selectProps(field) } as GridColDef\n return { ...column, ...listFilterColumn(fields, field.column) }\n })\n const present = columns.map((column) => column.field)\n const hidden = hiddenFilterColumns(fields, present, headers).map(\n (column): GridColDef => {\n const field = fields.find((entry) => entry.column === column.field)\n return field && options[field.column]\n ? ({ ...column, ...selectProps(field) } as GridColDef)\n : column\n },\n )\n return [...shown, ...hidden]\n}\n\n/**\n * Whether a row answers a quick search: every whitespace-separated word\n * appears, case-insensitively, in SOME of the row's searched values. A\n * blank search matches every row, so an emptied box is the list unfiltered.\n * An array value (tags) is searched member by member.\n */\nexport function crmRowMatchesSearch(\n row: object,\n paths: readonly string[],\n words: readonly string[],\n): boolean {\n const asked = words.map((word) => word.trim().toLowerCase()).filter(Boolean)\n if (!asked.length) return true\n const values = paths\n .flatMap((path) => {\n const value = path\n .split('.')\n .reduce<unknown>(\n (at, key) => (at == null ? undefined : (at as Record<string, unknown>)[key]),\n row,\n )\n return Array.isArray(value) ? value : [value]\n })\n .filter((value): value is string | number => typeof value === 'string' || typeof value === 'number')\n .map((value) => String(value).toLowerCase())\n .filter(Boolean)\n return asked.every((word) => values.some((value) => value.includes(word)))\n}\n\n/**\n * The clauses with one field's clause set: replaced in place where the field\n * already had one, appended where it did not, removed when `next` is null.\n * A field holds ONE clause, which is what the panel edits.\n */\nexport function crmUpsertClause(\n clauses: readonly CrmViewFilterClause[],\n field: string,\n next: CrmViewFilterClause | null,\n): CrmViewFilterClause[] {\n const at = clauses.findIndex((clause) => clause.field === field)\n const rest = clauses.filter((clause) => clause.field !== field)\n if (!next) return rest\n if (at === -1) return [...rest, next]\n return [...rest.slice(0, at), next, ...rest.slice(at)]\n}\n"],"names":["gridFilterRequests","hiddenFilterColumns","listFilterColumn","listFilterOperators","getGridSingleSelectOperators","SELECT_TO_GRID","equals","doesNotEqual","isAnyOf","SELECT_FROM_GRID","is","not","plainClause","item","items","crmPlainCodec","toItem","clause","operator","op","value","undefined","toClause","crmSelectCodec","split","map","entry","trim","filter","Boolean","String","request","crmSelectOperators","allowed","shown","includes","crmFilterColumns","columns","fields","options","headers","selectProps","field","choices","column","operators","type","valueOptions","choice","label","filterable","length","filterOperators","hideable","find","present","hidden","crmRowMatchesSearch","row","paths","words","asked","word","toLowerCase","values","flatMap","path","reduce","at","key","Array","isArray","every","some","crmUpsertClause","clauses","next","findIndex","rest","slice"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SACEA,kBAAkB,EAClBC,mBAAmB,EAEnBC,gBAAgB,EAChBC,mBAAmB,QACd,yCAAwC;AAC/C,SACEC,4BAA4B,QAGvB,mBAAkB;AA6BzB,4DAA4D,GAC5D,MAAMC,iBAAmD;IACvDC,QAAQ;IACRC,cAAc;IACdC,SAAS;AACX;AACA,MAAMC,mBAAqD;IACzDC,IAAI;IACJC,KAAK;IACLH,SAAS;AACX;AAYA,gFAAgF,GAChF,MAAMI,cAAc,CAACC;QACnBb;YAAAA,uBAAAA,mBAAmB;QAAEc,OAAO;YAACD;SAAK;IAAC,EAAE,CAAC,EAAE,YAAxCb,uBAA4C;;AAE9C,sDAAsD,GACtD,OAAO,MAAMe,gBAAoC;IAC/CC,QAAQ,CAACC,SAAY,CAAA;YACnBC,UAAUD,OAAOE,EAAE;YACnBC,OAAOH,OAAOG,KAAK,KAAK,KAAKC,YAAYJ,OAAOG,KAAK;QACvD,CAAA;IACAE,UAAUV;AACZ,EAAC;AAED,8EAA8E,GAC9E,OAAO,MAAMW,iBAAqC;IAChDP,QAAQ,CAACC;QACP,MAAMC,WAAWb,cAAc,CAACY,OAAOE,EAAE,CAAC;QAC1C,IAAI,CAACD,UAAU,OAAO;QACtB,OAAO;YACLA;YACAE,OACEF,aAAa,YACTD,OAAOG,KAAK,CAACI,KAAK,CAAC,KAAKC,GAAG,CAAC,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