@aglyn/plugins-crm 1.0.0-beta.187 → 1.0.0-beta.188
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/package.json +13 -13
- package/src/lib/components/companies-section.js +6 -6
- package/src/lib/components/companies-section.js.map +1 -1
- package/src/lib/components/contacts-section.js +7 -7
- package/src/lib/components/contacts-section.js.map +1 -1
- package/src/lib/components/deals-section.js +7 -7
- package/src/lib/components/deals-section.js.map +1 -1
- package/src/lib/components/leads-section.js +6 -6
- package/src/lib/components/leads-section.js.map +1 -1
- package/src/lib/components/tasks-section.js +7 -7
- package/src/lib/components/tasks-section.js.map +1 -1
- package/src/lib/model/lead-filters.d.ts +4 -4
- package/src/lib/model/lead-filters.js +5 -5
- package/src/lib/model/lead-filters.js.map +1 -1
- package/src/lib/components/crm-filter-bar.d.ts +0 -55
- package/src/lib/components/crm-filter-bar.js +0 -93
- package/src/lib/components/crm-filter-bar.js.map +0 -1
- package/src/lib/hooks/use-crm-grid-filter.d.ts +0 -77
- package/src/lib/hooks/use-crm-grid-filter.js +0 -143
- package/src/lib/hooks/use-crm-grid-filter.js.map +0 -1
- package/src/lib/model/crm-grid-filter.d.ts +0 -64
- package/src/lib/model/crm-grid-filter.js +0 -144
- package/src/lib/model/crm-grid-filter.js.map +0 -1
|
@@ -15,7 +15,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/ import { EMAIL_STATE_LABELS, EMAIL_STATE_STATUSES, CRM_LEAD_STATUS_LABELS, emailStateForbidsEmail, crmLeadStatus, isCrmLeadOpen, normalizeCrmPicklistLabel, readCampaignIds, readEmailState } from "@aglyn/aglyn";
|
|
18
|
-
import {
|
|
18
|
+
import { listSelectCodec, listRowMatchesSearch } from "@aglyn/shared-ui-jsx/const/list-grid-filter";
|
|
19
19
|
export const LEAD_FILTERS = [
|
|
20
20
|
'open',
|
|
21
21
|
'new',
|
|
@@ -88,7 +88,7 @@ export const LEAD_EMAIL_FILTER_LABELS = _extends({
|
|
|
88
88
|
*/ export function leadMatchesSearch(lead, term) {
|
|
89
89
|
// Tags are a list; a stray string there is no tag of the lead's.
|
|
90
90
|
const tags = Array.isArray(lead['tags']) ? lead['tags'] : undefined;
|
|
91
|
-
return
|
|
91
|
+
return listRowMatchesSearch(_extends({}, lead, {
|
|
92
92
|
tags
|
|
93
93
|
}), LEAD_SEARCH_FIELDS, term.trim().split(/\s+/));
|
|
94
94
|
}
|
|
@@ -254,7 +254,7 @@ const listed = (clause)=>clause.op === 'isAnyOf' ? clause.value.split(',').map((
|
|
|
254
254
|
value: clause.value
|
|
255
255
|
} : null,
|
|
256
256
|
toClause: (item)=>{
|
|
257
|
-
const clause =
|
|
257
|
+
const clause = listSelectCodec.toClause(item);
|
|
258
258
|
return clause && clause.op === 'equals' ? _extends({}, clause, {
|
|
259
259
|
op: 'contains'
|
|
260
260
|
}) : null;
|
|
@@ -264,9 +264,9 @@ const listed = (clause)=>clause.op === 'isAnyOf' ? clause.value.split(',').map((
|
|
|
264
264
|
toItem: (clause)=>clause.op === 'isEmpty' ? {
|
|
265
265
|
operator: 'is',
|
|
266
266
|
value: LEAD_SOURCE_FILTER_NONE
|
|
267
|
-
} :
|
|
267
|
+
} : listSelectCodec.toItem(clause),
|
|
268
268
|
toClause: (item)=>{
|
|
269
|
-
const clause =
|
|
269
|
+
const clause = listSelectCodec.toClause(item);
|
|
270
270
|
if ((clause == null ? void 0 : clause.op) === 'equals' && clause.value === LEAD_SOURCE_FILTER_NONE) {
|
|
271
271
|
return {
|
|
272
272
|
field: clause.field,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/model/lead-filters.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 {\n EMAIL_STATE_LABELS,\n EMAIL_STATE_STATUSES,\n CRM_LEAD_STATUS_LABELS,\n type EmailStateStatus,\n type CrmLeadFields,\n type CrmLeadStatus,\n emailStateForbidsEmail,\n crmLeadStatus,\n isCrmLeadOpen,\n normalizeCrmPicklistLabel,\n readCampaignIds,\n readEmailState,\n} from '@aglyn/aglyn'\nimport type { CrmViewFilterClause } from '@aglyn/aglyn'\nimport type { ListFilterField } from '@aglyn/shared-ui-jsx/const/list-filter'\nimport { type CrmGridFilterCodec, crmSelectCodec, crmRowMatchesSearch } from './crm-grid-filter'\n\n/**\n * What the Leads section's `Show` control offers (AGL-2608): the two\n * aggregate views and each status on its own. `open` is the default — the\n * list opens on the work — and it is the one view a Firestore query cannot\n * express, because a lead nobody has touched carries no status field at all;\n * see the section for why the filter runs over a loaded window.\n */\nexport type LeadFilter = 'open' | 'all' | CrmLeadStatus\n\nexport const LEAD_FILTERS: readonly LeadFilter[] = [\n 'open',\n 'new',\n 'working',\n 'qualified',\n 'unqualified',\n 'all',\n]\n\nexport const LEAD_FILTER_LABELS: Record<LeadFilter, string> = {\n open: 'Open',\n all: 'All',\n new: CRM_LEAD_STATUS_LABELS.new,\n working: CRM_LEAD_STATUS_LABELS.working,\n qualified: CRM_LEAD_STATUS_LABELS.qualified,\n unqualified: CRM_LEAD_STATUS_LABELS.unqualified,\n}\n\n/** Whether a lead belongs in a filter's view. An absent status is `new`. */\nexport function leadMatchesFilter(\n lead: Pick<CrmLeadFields, 'status'>,\n filter: LeadFilter,\n): boolean {\n if (filter === 'all') return true\n if (filter === 'open') return isCrmLeadOpen(lead)\n return crmLeadStatus(lead) === filter\n}\n\n/**\n * The Leads section's `Email` control (AGL-3245): every lead, the ones a\n * member must not email — any verdict but `ok` — the ones nothing has been\n * said about, or one verdict on its own. Beside `Show`, not inside it: a\n * bounce does not move a lead out of Open, and a queue of bounced leads is\n * a queue of people to reach some other way.\n */\nexport type LeadEmailFilter = 'any' | 'problem' | 'none' | EmailStateStatus\n\nexport const LEAD_EMAIL_FILTERS: readonly LeadEmailFilter[] = [\n 'any',\n 'problem',\n ...EMAIL_STATE_STATUSES,\n 'none',\n]\n\nexport const LEAD_EMAIL_FILTER_LABELS: Record<LeadEmailFilter, string> = {\n any: 'Any',\n problem: 'Cannot be emailed',\n none: 'Nothing known',\n ...EMAIL_STATE_LABELS,\n}\n\n/** Whether a lead belongs in an email filter's view. */\nexport function leadMatchesEmailFilter(\n lead: Readonly<Record<string, unknown>>,\n filter: LeadEmailFilter,\n): boolean {\n if (filter === 'any') return true\n const state = readEmailState(lead)\n if (filter === 'none') return state === null\n if (filter === 'problem') return emailStateForbidsEmail(state)\n return state?.status === filter\n}\n\n/**\n * The Leads section's `Campaign` control (AGL-3254): every lead, or the\n * ones filed under one campaign — read off the lead's own `campaignIds`,\n * the field every campaign member carries. `''` is every lead, which is\n * what the control opens on; the ids are the site's containers', and the\n * section resolves their names for the menu.\n */\nexport function leadMatchesCampaignFilter(\n lead: Readonly<Record<string, unknown>>,\n campaignId: string,\n): boolean {\n if (!campaignId) return true\n return readCampaignIds(lead).includes(campaignId)\n}\n\n/**\n * The fields the Leads section's search box reads (AGL-3246): who the lead\n * is and where they work — the words a person types to find one — plus the\n * tags, which are how an import names its batch (`sal-15`). `name` and\n * `email` are the capture door's fields rather than the CRM's, so the row is\n * read as a record rather than through `CrmLeadFields`.\n */\nexport const LEAD_SEARCH_FIELDS = ['name', 'email', 'company', 'jobTitle', 'tags'] as const\n\n/**\n * Whether a lead answers a search term.\n *\n * Case-insensitive, and every whitespace-separated word of the term must\n * appear in SOME searched field: `morgan lamphere` and `lamphere sal-15`\n * both find Morgan Lamphere, `morgan smith` does not. A blank term matches\n * every lead, so the box emptied is the list unfiltered.\n */\nexport function leadMatchesSearch(\n lead: Readonly<Record<string, unknown>>,\n term: string,\n): boolean {\n // Tags are a list; a stray string there is no tag of the lead's.\n const tags = Array.isArray(lead['tags']) ? lead['tags'] : undefined\n return crmRowMatchesSearch({ ...lead, tags }, LEAD_SEARCH_FIELDS, term.trim().split(/\\s+/))\n}\n\n/**\n * The `Lead source` control's \"no lead source\" choice (AGL-3298). Held in\n * the saved view as an `isEmpty` clause, never as this string; it is only\n * the select's own value for the choice.\n */\nexport const LEAD_SOURCE_FILTER_NONE = '\\u0000none'\n\n/**\n * The Leads section's `Lead source` control (AGL-3298): every lead (`''`),\n * the ones holding one value — compared the way the picklist compares\n * labels, so a value typed in another case before the list existed is\n * still found — or the ones holding none.\n */\nexport function leadMatchesLeadSourceFilter(\n lead: Readonly<Record<string, unknown>>,\n filter: string,\n): boolean {\n if (!filter) return true\n const held = normalizeCrmPicklistLabel(lead['leadSource']).toLowerCase()\n if (filter === LEAD_SOURCE_FILTER_NONE) return held === ''\n return held === normalizeCrmPicklistLabel(filter).toLowerCase()\n}\n\n/*==========================================\n * THE LEADS GRID'S FILTERS (AGL-3313).\n *\n * The Show, Email, Campaign and Lead source dropdowns became columns of the\n * grid's own Filters panel. Their clauses keep the shape the dropdowns\n * stored, so every saved view of leads reads as it did:\n *\n * status `equals <filter>`; none at all is Open, `all` is every lead\n * emailState `equals <filter>`\n * campaignIds `contains <campaign id>`\n * leadSource `equals <label>`, or `isEmpty` for the leads holding none\n *\n * Every one narrows the loaded window, never the query — see the section's\n * `LEADS_WINDOW` for why a status cannot be asked of Firestore.\n *=========================================*/\n\n/** The fields the grid's panel offers on Leads. */\nexport const LEAD_LIST_FILTER_FIELDS: readonly ListFilterField[] = [\n { column: 'status', kind: 'exact', path: 'status', operators: ['equals', 'isAnyOf'] },\n { column: 'emailState', kind: 'exact', path: 'emailState', operators: ['equals', 'isAnyOf'] },\n { column: 'ownerUid', kind: 'exact', path: 'ownerUid', operators: ['equals', 'isAnyOf'] },\n { column: 'leadSource', kind: 'exact', path: 'leadSource', operators: ['equals', 'isAnyOf'] },\n { column: 'campaignIds', kind: 'exact', path: 'campaignIds', operators: ['equals'] },\n]\n\n/** What each filter field reads as on a chip. */\nexport const LEAD_LIST_FILTER_HEADERS: Readonly<Record<string, string>> = {\n status: 'Status',\n emailState: 'Email',\n ownerUid: 'Owner',\n leadSource: 'Lead source',\n campaignIds: 'Campaign',\n}\n\n/** The choices for Status: Open (new or working) and each status on its own. */\nexport const LEAD_STATUS_FILTER_OPTIONS = LEAD_FILTERS.filter(\n (option) => option !== 'all',\n).map((option) => ({\n value: option,\n label: option === 'open' ? 'Open (new or working)' : LEAD_FILTER_LABELS[option],\n}))\n\n/** The choices for Email: every verdict, plus the two aggregates. */\nexport const LEAD_EMAIL_FILTER_OPTIONS = LEAD_EMAIL_FILTERS.filter(\n (option) => option !== 'any',\n).map((option) => ({ value: option, label: LEAD_EMAIL_FILTER_LABELS[option] }))\n\nconst STATUS_OPEN: CrmViewFilterClause = { field: 'status', op: 'equals', value: 'open' }\nconst STATUS_ALL: CrmViewFilterClause = { field: 'status', op: 'equals', value: 'all' }\n\n/**\n * The clauses the grid shows for a view's stored ones. A stored list with\n * no status clause is Open, which the list opened on before views existed,\n * so it is shown as the clause it means; `status equals all` is every lead\n * and so no clause at all.\n */\nexport function leadClausesForGrid(\n stored: readonly CrmViewFilterClause[],\n): CrmViewFilterClause[] {\n const status = stored.find((clause) => clause.field === 'status')\n if (!status) return [STATUS_OPEN, ...stored]\n if (status.op === 'equals' && status.value === 'all') {\n return stored.filter((clause) => clause.field !== 'status')\n }\n return [...stored]\n}\n\n/** The inverse of {@link leadClausesForGrid}: what the view stores. */\nexport function leadClausesToStore(\n shown: readonly CrmViewFilterClause[],\n): CrmViewFilterClause[] {\n const status = shown.find((clause) => clause.field === 'status')\n if (!status) return [...shown, STATUS_ALL]\n if (status.op === 'equals' && status.value === 'open') {\n return shown.filter((clause) => clause.field !== 'status')\n }\n return [...shown]\n}\n\nconst listed = (clause: CrmViewFilterClause): string[] =>\n clause.op === 'isAnyOf'\n ? clause.value.split(',').map((entry) => entry.trim()).filter(Boolean)\n : [clause.value]\n\n/** Whether a lead answers every clause the grid shows. */\nexport function leadMatchesClauses(\n lead: Readonly<Record<string, unknown>> & Pick<CrmLeadFields, 'status'>,\n clauses: readonly CrmViewFilterClause[],\n): boolean {\n return clauses.every((clause) => {\n switch (clause.field) {\n case 'status':\n return listed(clause).some((value) =>\n (LEAD_FILTERS as readonly string[]).includes(value)\n ? leadMatchesFilter(lead, value as LeadFilter)\n : true,\n )\n case 'emailState':\n return listed(clause).some((value) =>\n (LEAD_EMAIL_FILTERS as readonly string[]).includes(value)\n ? leadMatchesEmailFilter(lead, value as LeadEmailFilter)\n : true,\n )\n case 'campaignIds':\n return listed(clause).some((value) => leadMatchesCampaignFilter(lead, value))\n case 'leadSource':\n return clause.op === 'isEmpty'\n ? leadMatchesLeadSourceFilter(lead, LEAD_SOURCE_FILTER_NONE)\n : listed(clause).some((value) => leadMatchesLeadSourceFilter(lead, value))\n case 'ownerUid':\n return listed(clause).includes(String(lead['ownerUid'] ?? ''))\n default:\n // A clause on a field this list does not answer narrows nothing,\n // rather than emptying the list.\n return true\n }\n })\n}\n\n/** Campaign clauses were stored as `contains`; the panel's select says `is`. */\nexport const LEAD_CAMPAIGN_CODEC: CrmGridFilterCodec = {\n toItem: (clause) =>\n clause.op === 'contains' || clause.op === 'equals'\n ? { operator: 'is', value: clause.value }\n : null,\n toClause: (item) => {\n const clause = crmSelectCodec.toClause(item)\n return clause && clause.op === 'equals' ? { ...clause, op: 'contains' } : null\n },\n}\n\n/** \"No lead source\" is an `isEmpty` clause, shown as a choice of the select. */\nexport const LEAD_SOURCE_CODEC: CrmGridFilterCodec = {\n toItem: (clause) =>\n clause.op === 'isEmpty'\n ? { operator: 'is', value: LEAD_SOURCE_FILTER_NONE }\n : crmSelectCodec.toItem(clause),\n toClause: (item) => {\n const clause = crmSelectCodec.toClause(item)\n if (clause?.op === 'equals' && clause.value === LEAD_SOURCE_FILTER_NONE) {\n return { field: clause.field, op: 'isEmpty', value: '' }\n }\n return clause\n },\n}\n\n/** The Leads fields whose stored clauses translate their own way. */\nexport const LEAD_FILTER_CODECS: Readonly<Record<string, CrmGridFilterCodec>> = {\n campaignIds: LEAD_CAMPAIGN_CODEC,\n leadSource: LEAD_SOURCE_CODEC,\n}\n"],"names":["EMAIL_STATE_LABELS","EMAIL_STATE_STATUSES","CRM_LEAD_STATUS_LABELS","emailStateForbidsEmail","crmLeadStatus","isCrmLeadOpen","normalizeCrmPicklistLabel","readCampaignIds","readEmailState","crmSelectCodec","crmRowMatchesSearch","LEAD_FILTERS","LEAD_FILTER_LABELS","open","all","new","working","qualified","unqualified","leadMatchesFilter","lead","filter","LEAD_EMAIL_FILTERS","LEAD_EMAIL_FILTER_LABELS","any","problem","none","leadMatchesEmailFilter","state","status","leadMatchesCampaignFilter","campaignId","includes","LEAD_SEARCH_FIELDS","leadMatchesSearch","term","tags","Array","isArray","undefined","trim","split","LEAD_SOURCE_FILTER_NONE","leadMatchesLeadSourceFilter","held","toLowerCase","LEAD_LIST_FILTER_FIELDS","column","kind","path","operators","LEAD_LIST_FILTER_HEADERS","emailState","ownerUid","leadSource","campaignIds","LEAD_STATUS_FILTER_OPTIONS","option","map","value","label","LEAD_EMAIL_FILTER_OPTIONS","STATUS_OPEN","field","op","STATUS_ALL","leadClausesForGrid","stored","find","clause","leadClausesToStore","shown","listed","entry","Boolean","leadMatchesClauses","clauses","every","some","String","LEAD_CAMPAIGN_CODEC","toItem","operator","toClause","item","LEAD_SOURCE_CODEC","LEAD_FILTER_CODECS"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,kBAAkB,EAClBC,oBAAoB,EACpBC,sBAAsB,EAItBC,sBAAsB,EACtBC,aAAa,EACbC,aAAa,EACbC,yBAAyB,EACzBC,eAAe,EACfC,c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BAAwC;IACnDJ,QAAQ,CAACZ,SACPA,OAAOL,EAAE,KAAK,YACV;YAAEkB,UAAU;YAAMvB,OAAOjB;QAAwB,IACjDjC,eAAewE,MAAM,CAACZ;IAC5Bc,UAAU,CAACC;QACT,MAAMf,SAAS5D,eAAe0E,QAAQ,CAACC;QACvC,IAAIf,CAAAA,0BAAAA,OAAQL,EAAE,MAAK,YAAYK,OAAOV,KAAK,KAAKjB,yBAAyB;YACvE,OAAO;gBAAEqB,OAAOM,OAAON,KAAK;gBAAEC,IAAI;gBAAWL,OAAO;YAAG;QACzD;QACA,OAAOU;IACT;AACF,EAAC;AAED,mEAAmE,GACnE,OAAO,MAAMiB,qBAAmE;IAC9E/B,aAAayB;IACb1B,YAAY+B;AACd,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/model/lead-filters.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 {\n EMAIL_STATE_LABELS,\n EMAIL_STATE_STATUSES,\n CRM_LEAD_STATUS_LABELS,\n type EmailStateStatus,\n type CrmLeadFields,\n type CrmLeadStatus,\n emailStateForbidsEmail,\n crmLeadStatus,\n isCrmLeadOpen,\n normalizeCrmPicklistLabel,\n readCampaignIds,\n readEmailState,\n} from '@aglyn/aglyn'\nimport type { CrmViewFilterClause } from '@aglyn/aglyn'\nimport type { ListFilterField } from '@aglyn/shared-ui-jsx/const/list-filter'\nimport { type ListGridFilterCodec, listSelectCodec, listRowMatchesSearch } from '@aglyn/shared-ui-jsx/const/list-grid-filter'\n\n/**\n * What the Leads section's `Show` control offers (AGL-2608): the two\n * aggregate views and each status on its own. `open` is the default — the\n * list opens on the work — and it is the one view a Firestore query cannot\n * express, because a lead nobody has touched carries no status field at all;\n * see the section for why the filter runs over a loaded window.\n */\nexport type LeadFilter = 'open' | 'all' | CrmLeadStatus\n\nexport const LEAD_FILTERS: readonly LeadFilter[] = [\n 'open',\n 'new',\n 'working',\n 'qualified',\n 'unqualified',\n 'all',\n]\n\nexport const LEAD_FILTER_LABELS: Record<LeadFilter, string> = {\n open: 'Open',\n all: 'All',\n new: CRM_LEAD_STATUS_LABELS.new,\n working: CRM_LEAD_STATUS_LABELS.working,\n qualified: CRM_LEAD_STATUS_LABELS.qualified,\n unqualified: CRM_LEAD_STATUS_LABELS.unqualified,\n}\n\n/** Whether a lead belongs in a filter's view. An absent status is `new`. */\nexport function leadMatchesFilter(\n lead: Pick<CrmLeadFields, 'status'>,\n filter: LeadFilter,\n): boolean {\n if (filter === 'all') return true\n if (filter === 'open') return isCrmLeadOpen(lead)\n return crmLeadStatus(lead) === filter\n}\n\n/**\n * The Leads section's `Email` control (AGL-3245): every lead, the ones a\n * member must not email — any verdict but `ok` — the ones nothing has been\n * said about, or one verdict on its own. Beside `Show`, not inside it: a\n * bounce does not move a lead out of Open, and a queue of bounced leads is\n * a queue of people to reach some other way.\n */\nexport type LeadEmailFilter = 'any' | 'problem' | 'none' | EmailStateStatus\n\nexport const LEAD_EMAIL_FILTERS: readonly LeadEmailFilter[] = [\n 'any',\n 'problem',\n ...EMAIL_STATE_STATUSES,\n 'none',\n]\n\nexport const LEAD_EMAIL_FILTER_LABELS: Record<LeadEmailFilter, string> = {\n any: 'Any',\n problem: 'Cannot be emailed',\n none: 'Nothing known',\n ...EMAIL_STATE_LABELS,\n}\n\n/** Whether a lead belongs in an email filter's view. */\nexport function leadMatchesEmailFilter(\n lead: Readonly<Record<string, unknown>>,\n filter: LeadEmailFilter,\n): boolean {\n if (filter === 'any') return true\n const state = readEmailState(lead)\n if (filter === 'none') return state === null\n if (filter === 'problem') return emailStateForbidsEmail(state)\n return state?.status === filter\n}\n\n/**\n * The Leads section's `Campaign` control (AGL-3254): every lead, or the\n * ones filed under one campaign — read off the lead's own `campaignIds`,\n * the field every campaign member carries. `''` is every lead, which is\n * what the control opens on; the ids are the site's containers', and the\n * section resolves their names for the menu.\n */\nexport function leadMatchesCampaignFilter(\n lead: Readonly<Record<string, unknown>>,\n campaignId: string,\n): boolean {\n if (!campaignId) return true\n return readCampaignIds(lead).includes(campaignId)\n}\n\n/**\n * The fields the Leads section's search box reads (AGL-3246): who the lead\n * is and where they work — the words a person types to find one — plus the\n * tags, which are how an import names its batch (`sal-15`). `name` and\n * `email` are the capture door's fields rather than the CRM's, so the row is\n * read as a record rather than through `CrmLeadFields`.\n */\nexport const LEAD_SEARCH_FIELDS = ['name', 'email', 'company', 'jobTitle', 'tags'] as const\n\n/**\n * Whether a lead answers a search term.\n *\n * Case-insensitive, and every whitespace-separated word of the term must\n * appear in SOME searched field: `morgan lamphere` and `lamphere sal-15`\n * both find Morgan Lamphere, `morgan smith` does not. A blank term matches\n * every lead, so the box emptied is the list unfiltered.\n */\nexport function leadMatchesSearch(\n lead: Readonly<Record<string, unknown>>,\n term: string,\n): boolean {\n // Tags are a list; a stray string there is no tag of the lead's.\n const tags = Array.isArray(lead['tags']) ? lead['tags'] : undefined\n return listRowMatchesSearch({ ...lead, tags }, LEAD_SEARCH_FIELDS, term.trim().split(/\\s+/))\n}\n\n/**\n * The `Lead source` control's \"no lead source\" choice (AGL-3298). Held in\n * the saved view as an `isEmpty` clause, never as this string; it is only\n * the select's own value for the choice.\n */\nexport const LEAD_SOURCE_FILTER_NONE = '\\u0000none'\n\n/**\n * The Leads section's `Lead source` control (AGL-3298): every lead (`''`),\n * the ones holding one value — compared the way the picklist compares\n * labels, so a value typed in another case before the list existed is\n * still found — or the ones holding none.\n */\nexport function leadMatchesLeadSourceFilter(\n lead: Readonly<Record<string, unknown>>,\n filter: string,\n): boolean {\n if (!filter) return true\n const held = normalizeCrmPicklistLabel(lead['leadSource']).toLowerCase()\n if (filter === LEAD_SOURCE_FILTER_NONE) return held === ''\n return held === normalizeCrmPicklistLabel(filter).toLowerCase()\n}\n\n/*==========================================\n * THE LEADS GRID'S FILTERS (AGL-3313).\n *\n * The Show, Email, Campaign and Lead source dropdowns became columns of the\n * grid's own Filters panel. Their clauses keep the shape the dropdowns\n * stored, so every saved view of leads reads as it did:\n *\n * status `equals <filter>`; none at all is Open, `all` is every lead\n * emailState `equals <filter>`\n * campaignIds `contains <campaign id>`\n * leadSource `equals <label>`, or `isEmpty` for the leads holding none\n *\n * Every one narrows the loaded window, never the query — see the section's\n * `LEADS_WINDOW` for why a status cannot be asked of Firestore.\n *=========================================*/\n\n/** The fields the grid's panel offers on Leads. */\nexport const LEAD_LIST_FILTER_FIELDS: readonly ListFilterField[] = [\n { column: 'status', kind: 'exact', path: 'status', operators: ['equals', 'isAnyOf'] },\n { column: 'emailState', kind: 'exact', path: 'emailState', operators: ['equals', 'isAnyOf'] },\n { column: 'ownerUid', kind: 'exact', path: 'ownerUid', operators: ['equals', 'isAnyOf'] },\n { column: 'leadSource', kind: 'exact', path: 'leadSource', operators: ['equals', 'isAnyOf'] },\n { column: 'campaignIds', kind: 'exact', path: 'campaignIds', operators: ['equals'] },\n]\n\n/** What each filter field reads as on a chip. */\nexport const LEAD_LIST_FILTER_HEADERS: Readonly<Record<string, string>> = {\n status: 'Status',\n emailState: 'Email',\n ownerUid: 'Owner',\n leadSource: 'Lead source',\n campaignIds: 'Campaign',\n}\n\n/** The choices for Status: Open (new or working) and each status on its own. */\nexport const LEAD_STATUS_FILTER_OPTIONS = LEAD_FILTERS.filter(\n (option) => option !== 'all',\n).map((option) => ({\n value: option,\n label: option === 'open' ? 'Open (new or working)' : LEAD_FILTER_LABELS[option],\n}))\n\n/** The choices for Email: every verdict, plus the two aggregates. */\nexport const LEAD_EMAIL_FILTER_OPTIONS = LEAD_EMAIL_FILTERS.filter(\n (option) => option !== 'any',\n).map((option) => ({ value: option, label: LEAD_EMAIL_FILTER_LABELS[option] }))\n\nconst STATUS_OPEN: CrmViewFilterClause = { field: 'status', op: 'equals', value: 'open' }\nconst STATUS_ALL: CrmViewFilterClause = { field: 'status', op: 'equals', value: 'all' }\n\n/**\n * The clauses the grid shows for a view's stored ones. A stored list with\n * no status clause is Open, which the list opened on before views existed,\n * so it is shown as the clause it means; `status equals all` is every lead\n * and so no clause at all.\n */\nexport function leadClausesForGrid(\n stored: readonly CrmViewFilterClause[],\n): CrmViewFilterClause[] {\n const status = stored.find((clause) => clause.field === 'status')\n if (!status) return [STATUS_OPEN, ...stored]\n if (status.op === 'equals' && status.value === 'all') {\n return stored.filter((clause) => clause.field !== 'status')\n }\n return [...stored]\n}\n\n/** The inverse of {@link leadClausesForGrid}: what the view stores. */\nexport function leadClausesToStore(\n shown: readonly CrmViewFilterClause[],\n): CrmViewFilterClause[] {\n const status = shown.find((clause) => clause.field === 'status')\n if (!status) return [...shown, STATUS_ALL]\n if (status.op === 'equals' && status.value === 'open') {\n return shown.filter((clause) => clause.field !== 'status')\n }\n return [...shown]\n}\n\nconst listed = (clause: CrmViewFilterClause): string[] =>\n clause.op === 'isAnyOf'\n ? clause.value.split(',').map((entry) => entry.trim()).filter(Boolean)\n : [clause.value]\n\n/** Whether a lead answers every clause the grid shows. */\nexport function leadMatchesClauses(\n lead: Readonly<Record<string, unknown>> & Pick<CrmLeadFields, 'status'>,\n clauses: readonly CrmViewFilterClause[],\n): boolean {\n return clauses.every((clause) => {\n switch (clause.field) {\n case 'status':\n return listed(clause).some((value) =>\n (LEAD_FILTERS as readonly string[]).includes(value)\n ? leadMatchesFilter(lead, value as LeadFilter)\n : true,\n )\n case 'emailState':\n return listed(clause).some((value) =>\n (LEAD_EMAIL_FILTERS as readonly string[]).includes(value)\n ? leadMatchesEmailFilter(lead, value as LeadEmailFilter)\n : true,\n )\n case 'campaignIds':\n return listed(clause).some((value) => leadMatchesCampaignFilter(lead, value))\n case 'leadSource':\n return clause.op === 'isEmpty'\n ? leadMatchesLeadSourceFilter(lead, LEAD_SOURCE_FILTER_NONE)\n : listed(clause).some((value) => leadMatchesLeadSourceFilter(lead, value))\n case 'ownerUid':\n return listed(clause).includes(String(lead['ownerUid'] ?? ''))\n default:\n // A clause on a field this list does not answer narrows nothing,\n // rather than emptying the list.\n return true\n }\n })\n}\n\n/** Campaign clauses were stored as `contains`; the panel's select says `is`. */\nexport const LEAD_CAMPAIGN_CODEC: ListGridFilterCodec = {\n toItem: (clause) =>\n clause.op === 'contains' || clause.op === 'equals'\n ? { operator: 'is', value: clause.value }\n : null,\n toClause: (item) => {\n const clause = listSelectCodec.toClause(item)\n return clause && clause.op === 'equals' ? { ...clause, op: 'contains' } : null\n },\n}\n\n/** \"No lead source\" is an `isEmpty` clause, shown as a choice of the select. */\nexport const LEAD_SOURCE_CODEC: ListGridFilterCodec = {\n toItem: (clause) =>\n clause.op === 'isEmpty'\n ? { operator: 'is', value: LEAD_SOURCE_FILTER_NONE }\n : listSelectCodec.toItem(clause),\n toClause: (item) => {\n const clause = listSelectCodec.toClause(item)\n if (clause?.op === 'equals' && clause.value === LEAD_SOURCE_FILTER_NONE) {\n return { field: clause.field, op: 'isEmpty', value: '' }\n }\n return clause\n },\n}\n\n/** The Leads fields whose stored clauses translate their own way. */\nexport const LEAD_FILTER_CODECS: Readonly<Record<string, ListGridFilterCodec>> = {\n campaignIds: LEAD_CAMPAIGN_CODEC,\n leadSource: LEAD_SOURCE_CODEC,\n}\n"],"names":["EMAIL_STATE_LABELS","EMAIL_STATE_STATUSES","CRM_LEAD_STATUS_LABELS","emailStateForbidsEmail","crmLeadStatus","isCrmLeadOpen","normalizeCrmPicklistLabel","readCampaignIds","readEmailState","listSelectCodec","listRowMatchesSearch","LEAD_FILTERS","LEAD_FILTER_LABELS","open","all","new","working","qualified","unqualified","leadMatchesFilter","lead","filter","LEAD_EMAIL_FILTERS","LEAD_EMAIL_FILTER_LABELS","any","problem","none","leadMatchesEmailFilter","state","status","leadMatchesCampaignFilter","campaignId","includes","LEAD_SEARCH_FIELDS","leadMatchesSearch","term","tags","Array","isArray","undefined","trim","split","LEAD_SOURCE_FILTER_NONE","leadMatchesLeadSourceFilter","held","toLowerCase","LEAD_LIST_FILTER_FIELDS","column","kind","path","operators","LEAD_LIST_FILTER_HEADERS","emailState","ownerUid","leadSource","campaignIds","LEAD_STATUS_FILTER_OPTIONS","option","map","value","label","LEAD_EMAIL_FILTER_OPTIONS","STATUS_OPEN","field","op","STATUS_ALL","leadClausesForGrid","stored","find","clause","leadClausesToStore","shown","listed","entry","Boolean","leadMatchesClauses","clauses","every","some","String","LEAD_CAMPAIGN_CODEC","toItem","operator","toClause","item","LEAD_SOURCE_CODEC","LEAD_FILTER_CODECS"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,kBAAkB,EAClBC,oBAAoB,EACpBC,sBAAsB,EAItBC,sBAAsB,EACtBC,aAAa,EACbC,aAAa,EACbC,yBAAyB,EACzBC,eAAe,EACfC,cAAc,QACT,eAAc;AAGrB,SAAmCC,eAAe,EAAEC,oBAAoB,QAAQ,8CAA6C;AAW7H,OAAO,MAAMC,eAAsC;IACjD;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED,OAAO,MAAMC,qBAAiD;IAC5DC,MAAM;IACNC,KAAK;IACLC,KAAKb,uBAAuBa,GAAG;IAC/BC,SAASd,uBAAuBc,OAAO;IACvCC,WAAWf,uBAAuBe,SAAS;IAC3CC,aAAahB,uBAAuBgB,WAAW;AACjD,EAAC;AAED,0EAA0E,GAC1E,OAAO,SAASC,kBACdC,IAAmC,EACnCC,MAAkB;IAElB,IAAIA,WAAW,OAAO,OAAO;IAC7B,IAAIA,WAAW,QAAQ,OAAOhB,cAAce;IAC5C,OAAOhB,cAAcgB,UAAUC;AACjC;AAWA,OAAO,MAAMC,qBAAiD;IAC5D;IACA;OACGrB;IACH;CACD,CAAA;AAED,OAAO,MAAMsB,2BAA4D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-
*
|
|
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
|
-
*/
|
|
17
|
-
import type { CrmViewFilterClause } from '@aglyn/aglyn';
|
|
18
|
-
import { type ListFilterField } from '@aglyn/shared-ui-jsx/const/list-filter';
|
|
19
|
-
import type { CrmFilterOption } from '../model/crm-grid-filter';
|
|
20
|
-
export type { CrmFilterOption } from '../model/crm-grid-filter';
|
|
21
|
-
export interface CrmFilterBarProps {
|
|
22
|
-
/** The list's grammar — every field a clause may name. */
|
|
23
|
-
fields: readonly ListFilterField[];
|
|
24
|
-
/** How a field reads on a chip; a field without one reads as its column. */
|
|
25
|
-
headers: Readonly<Record<string, string>>;
|
|
26
|
-
clauses: readonly CrmViewFilterClause[];
|
|
27
|
-
onChange: (clauses: CrmViewFilterClause[]) => void;
|
|
28
|
-
/** Choices per field, so a chip names a picked value by its label. */
|
|
29
|
-
options?: Readonly<Record<string, readonly CrmFilterOption[]>>;
|
|
30
|
-
/**
|
|
31
|
-
* The field the query is serving, marked so the reader knows which reached
|
|
32
|
-
* everything. Omitted on a list whose every clause narrows the same rows.
|
|
33
|
-
*/
|
|
34
|
-
servedField?: string | null;
|
|
35
|
-
/** Whether chips carry the served / loaded-window distinction at all. */
|
|
36
|
-
marksServed?: boolean;
|
|
37
|
-
disabled?: boolean;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Every clause a CRM list is narrowed by, as chips over the grid (AGL-2617,
|
|
41
|
-
* AGL-3313).
|
|
42
|
-
*
|
|
43
|
-
* The clauses are ADDED through the grid's own Filters panel; this bar is
|
|
44
|
-
* what shows the SET. The free DataGrid's panel holds one item at a time
|
|
45
|
-
* and a saved view holds several, so without it a view narrowed by lead
|
|
46
|
-
* source and status would show one of the two and hide the other. Each
|
|
47
|
-
* chip reads as a sentence — "Owner is Dana", "Created on or after 1 Jan"
|
|
48
|
-
* — and removes its clause; where some clauses reach the query and others
|
|
49
|
-
* narrow the loaded rows, the served one is marked.
|
|
50
|
-
*/
|
|
51
|
-
export declare function CrmFilterBar(props: CrmFilterBarProps): import("react").JSX.Element;
|
|
52
|
-
export declare namespace CrmFilterBar {
|
|
53
|
-
var displayName: string;
|
|
54
|
-
}
|
|
55
|
-
export default CrmFilterBar;
|
|
@@ -1,93 +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
|
-
*/ 'use client';
|
|
17
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
|
-
import { listFilterOperatorLabel } from "@aglyn/shared-ui-jsx/const/list-filter";
|
|
19
|
-
import { Chip, Stack, Tooltip } from "@mui/material";
|
|
20
|
-
/** Operators that carry no value. */ const VALUELESS = new Set([
|
|
21
|
-
'isEmpty',
|
|
22
|
-
'isNotEmpty'
|
|
23
|
-
]);
|
|
24
|
-
/** Operators that take several values, comma-joined the way the grammar splits them. */ const MULTI = new Set([
|
|
25
|
-
'isAnyOf'
|
|
26
|
-
]);
|
|
27
|
-
const dayLabel = (raw)=>{
|
|
28
|
-
const at = new Date(raw);
|
|
29
|
-
return Number.isNaN(at.getTime()) ? raw : at.toLocaleDateString();
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Every clause a CRM list is narrowed by, as chips over the grid (AGL-2617,
|
|
33
|
-
* AGL-3313).
|
|
34
|
-
*
|
|
35
|
-
* The clauses are ADDED through the grid's own Filters panel; this bar is
|
|
36
|
-
* what shows the SET. The free DataGrid's panel holds one item at a time
|
|
37
|
-
* and a saved view holds several, so without it a view narrowed by lead
|
|
38
|
-
* source and status would show one of the two and hide the other. Each
|
|
39
|
-
* chip reads as a sentence — "Owner is Dana", "Created on or after 1 Jan"
|
|
40
|
-
* — and removes its clause; where some clauses reach the query and others
|
|
41
|
-
* narrow the loaded rows, the served one is marked.
|
|
42
|
-
*/ export function CrmFilterBar(props) {
|
|
43
|
-
const { fields, headers, clauses, onChange, options = {}, servedField = null, marksServed = true, disabled = false } = props;
|
|
44
|
-
const header = (column)=>{
|
|
45
|
-
var _headers_column;
|
|
46
|
-
return (_headers_column = headers[column]) != null ? _headers_column : column;
|
|
47
|
-
};
|
|
48
|
-
/** How a clause reads: its header, its operator, and its value by label. */ const sentence = (clause)=>{
|
|
49
|
-
var _clause_label;
|
|
50
|
-
const field = fields.find((entry)=>entry.column === clause.field);
|
|
51
|
-
const choices = options[clause.field];
|
|
52
|
-
const named = (value)=>{
|
|
53
|
-
var _ref;
|
|
54
|
-
var _choices_find;
|
|
55
|
-
return (_ref = choices == null ? void 0 : (_choices_find = choices.find((option)=>option.value === value)) == null ? void 0 : _choices_find.label) != null ? _ref : value;
|
|
56
|
-
};
|
|
57
|
-
const value = VALUELESS.has(clause.op) ? '' : MULTI.has(clause.op) ? clause.value.split(',').map((entry)=>entry.trim()).filter(Boolean).map(named).join(', ') : (_clause_label = clause.label) != null ? _clause_label : (field == null ? void 0 : field.kind) === 'date' ? dayLabel(clause.value) : named(clause.value);
|
|
58
|
-
return `${header(clause.field)} ${listFilterOperatorLabel(clause.op)}${value ? ` ${value}` : ''}`;
|
|
59
|
-
};
|
|
60
|
-
if (!clauses.length) return null;
|
|
61
|
-
return /*#__PURE__*/ _jsx(Stack, {
|
|
62
|
-
direction: "row",
|
|
63
|
-
spacing: 1,
|
|
64
|
-
useFlexGap: true,
|
|
65
|
-
sx: {
|
|
66
|
-
alignItems: 'center',
|
|
67
|
-
flexWrap: 'wrap'
|
|
68
|
-
},
|
|
69
|
-
role: "list",
|
|
70
|
-
"aria-label": "Filters",
|
|
71
|
-
children: clauses.map((clause, index)=>{
|
|
72
|
-
const served = marksServed && servedField !== null && clause.field === servedField;
|
|
73
|
-
const key = `${clause.field}-${clause.op}-${index}`;
|
|
74
|
-
const chip = /*#__PURE__*/ _jsx(Chip, {
|
|
75
|
-
role: "listitem",
|
|
76
|
-
size: "small",
|
|
77
|
-
variant: served ? 'filled' : 'outlined',
|
|
78
|
-
color: served ? 'primary' : 'default',
|
|
79
|
-
label: sentence(clause),
|
|
80
|
-
disabled: disabled,
|
|
81
|
-
onDelete: ()=>onChange(clauses.filter((_entry, at)=>at !== index))
|
|
82
|
-
}, key);
|
|
83
|
-
return marksServed ? /*#__PURE__*/ _jsx(Tooltip, {
|
|
84
|
-
title: served ? 'Searched across every record' : 'Narrows the records already loaded',
|
|
85
|
-
children: chip
|
|
86
|
-
}, key) : chip;
|
|
87
|
-
})
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
CrmFilterBar.displayName = 'CrmFilterBar';
|
|
91
|
-
export default CrmFilterBar;
|
|
92
|
-
|
|
93
|
-
//# sourceMappingURL=crm-filter-bar.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/components/crm-filter-bar.tsx"],"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\n'use client'\n\nimport type { CrmViewFilterClause } from '@aglyn/aglyn'\nimport {\n type ListFilterField,\n listFilterOperatorLabel,\n} from '@aglyn/shared-ui-jsx/const/list-filter'\nimport { Chip, Stack, Tooltip } from '@mui/material'\nimport type { CrmFilterOption } from '../model/crm-grid-filter'\n\nexport type { CrmFilterOption } from '../model/crm-grid-filter'\n\nexport interface CrmFilterBarProps {\n /** The list's grammar — every field a clause may name. */\n fields: readonly ListFilterField[]\n /** How a field reads on a chip; a field without one reads as its column. */\n headers: Readonly<Record<string, string>>\n clauses: readonly CrmViewFilterClause[]\n onChange: (clauses: CrmViewFilterClause[]) => void\n /** Choices per field, so a chip names a picked value by its label. */\n options?: Readonly<Record<string, readonly CrmFilterOption[]>>\n /**\n * The field the query is serving, marked so the reader knows which reached\n * everything. Omitted on a list whose every clause narrows the same rows.\n */\n servedField?: string | null\n /** Whether chips carry the served / loaded-window distinction at all. */\n marksServed?: boolean\n disabled?: boolean\n}\n\n/** Operators that carry no value. */\nconst VALUELESS = new Set(['isEmpty', 'isNotEmpty'])\n/** Operators that take several values, comma-joined the way the grammar splits them. */\nconst MULTI = new Set(['isAnyOf'])\n\nconst dayLabel = (raw: string): string => {\n const at = new Date(raw)\n return Number.isNaN(at.getTime()) ? raw : at.toLocaleDateString()\n}\n\n/**\n * Every clause a CRM list is narrowed by, as chips over the grid (AGL-2617,\n * AGL-3313).\n *\n * The clauses are ADDED through the grid's own Filters panel; this bar is\n * what shows the SET. The free DataGrid's panel holds one item at a time\n * and a saved view holds several, so without it a view narrowed by lead\n * source and status would show one of the two and hide the other. Each\n * chip reads as a sentence — \"Owner is Dana\", \"Created on or after 1 Jan\"\n * — and removes its clause; where some clauses reach the query and others\n * narrow the loaded rows, the served one is marked.\n */\nexport function CrmFilterBar(props: CrmFilterBarProps) {\n const {\n fields,\n headers,\n clauses,\n onChange,\n options = {},\n servedField = null,\n marksServed = true,\n disabled = false,\n } = props\n const header = (column: string) => headers[column] ?? column\n\n /** How a clause reads: its header, its operator, and its value by label. */\n const sentence = (clause: CrmViewFilterClause): string => {\n const field = fields.find((entry) => entry.column === clause.field)\n const choices = options[clause.field]\n const named = (value: string) =>\n choices?.find((option) => option.value === value)?.label ?? value\n const value = VALUELESS.has(clause.op)\n ? ''\n : MULTI.has(clause.op)\n ? clause.value\n .split(',')\n .map((entry) => entry.trim())\n .filter(Boolean)\n .map(named)\n .join(', ')\n : clause.label ?? (field?.kind === 'date' ? dayLabel(clause.value) : named(clause.value))\n return `${header(clause.field)} ${listFilterOperatorLabel(clause.op)}${value ? ` ${value}` : ''}`\n }\n\n if (!clauses.length) return null\n return (\n <Stack\n direction=\"row\"\n spacing={1}\n useFlexGap\n sx={{ alignItems: 'center', flexWrap: 'wrap' }}\n role=\"list\"\n aria-label=\"Filters\"\n >\n {clauses.map((clause, index) => {\n const served = marksServed && servedField !== null && clause.field === servedField\n const key = `${clause.field}-${clause.op}-${index}`\n const chip = (\n <Chip\n key={key}\n role=\"listitem\"\n size=\"small\"\n variant={served ? 'filled' : 'outlined'}\n color={served ? 'primary' : 'default'}\n label={sentence(clause)}\n disabled={disabled}\n onDelete={() => onChange(clauses.filter((_entry, at) => at !== index))}\n />\n )\n return marksServed ? (\n <Tooltip\n key={key}\n title={served ? 'Searched across every record' : 'Narrows the records already loaded'}\n >\n {chip}\n </Tooltip>\n ) : (\n chip\n )\n })}\n </Stack>\n )\n}\nCrmFilterBar.displayName = 'CrmFilterBar'\n\nexport default CrmFilterBar\n"],"names":["listFilterOperatorLabel","Chip","Stack","Tooltip","VALUELESS","Set","MULTI","dayLabel","raw","at","Date","Number","isNaN","getTime","toLocaleDateString","CrmFilterBar","props","fields","headers","clauses","onChange","options","servedField","marksServed","disabled","header","column","sentence","clause","field","find","entry","choices","named","value","option","label","has","op","split","map","trim","filter","Boolean","join","kind","length","direction","spacing","useFlexGap","sx","alignItems","flexWrap","role","aria-label","index","served","key","chip","size","variant","color","onDelete","_entry","title","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;AAGA,SAEEA,uBAAuB,QAClB,yCAAwC;AAC/C,SAASC,IAAI,EAAEC,KAAK,EAAEC,OAAO,QAAQ,gBAAe;AAwBpD,mCAAmC,GACnC,MAAMC,YAAY,IAAIC,IAAI;IAAC;IAAW;CAAa;AACnD,sFAAsF,GACtF,MAAMC,QAAQ,IAAID,IAAI;IAAC;CAAU;AAEjC,MAAME,WAAW,CAACC;IAChB,MAAMC,KAAK,IAAIC,KAAKF;IACpB,OAAOG,OAAOC,KAAK,CAACH,GAAGI,OAAO,MAAML,MAAMC,GAAGK,kBAAkB;AACjE;AAEA;;;;;;;;;;;CAWC,GACD,OAAO,SAASC,aAAaC,KAAwB;IACnD,MAAM,EACJC,MAAM,EACNC,OAAO,EACPC,OAAO,EACPC,QAAQ,EACRC,UAAU,CAAC,CAAC,EACZC,cAAc,IAAI,EAClBC,cAAc,IAAI,EAClBC,WAAW,KAAK,EACjB,GAAGR;IACJ,MAAMS,SAAS,CAACC;YAAmBR;gBAAAA,kBAAAA,OAAO,CAACQ,OAAO,YAAfR,kBAAmBQ;;IAEtD,0EAA0E,GAC1E,MAAMC,WAAW,CAACC;YAcVA;QAbN,MAAMC,QAAQZ,OAAOa,IAAI,CAAC,CAACC,QAAUA,MAAML,MAAM,KAAKE,OAAOC,KAAK;QAClE,MAAMG,UAAUX,OAAO,CAACO,OAAOC,KAAK,CAAC;QACrC,MAAMI,QAAQ,CAACC;;gBACbF;2BAAAA,4BAAAA,gBAAAA,QAASF,IAAI,CAAC,CAACK,SAAW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B;gBAEC6D,OAAOR,SAAS,iCAAiC;0BAEhDE;eAHID,OAMPC;QAEJ;;AAGN;AACA3C,aAAakD,WAAW,GAAG;AAE3B,eAAelD,aAAY"}
|
|
@@ -1,77 +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
|
-
*/
|
|
17
|
-
import type { CrmViewFilterClause } from '@aglyn/aglyn';
|
|
18
|
-
import type { GridFilterModel } from '@mui/x-data-grid';
|
|
19
|
-
import { type CrmGridFilterCodec } from '../model/crm-grid-filter';
|
|
20
|
-
export interface CrmGridFilterOptions {
|
|
21
|
-
/** The clauses the list is narrowed by — the saved view's working filters. */
|
|
22
|
-
clauses: readonly CrmViewFilterClause[];
|
|
23
|
-
onChange: (clauses: CrmViewFilterClause[]) => void;
|
|
24
|
-
/** Fields whose values are picked, which the panel shows as a select. */
|
|
25
|
-
selectFields?: readonly string[];
|
|
26
|
-
/** A field whose stored clauses predate the panel, translated its own way. */
|
|
27
|
-
codecs?: Readonly<Record<string, CrmGridFilterCodec>>;
|
|
28
|
-
/**
|
|
29
|
-
* The query serves ONE clause, so the panel's replaces every other — a
|
|
30
|
-
* server-paged list, which has no loaded window to narrow further.
|
|
31
|
-
* `keepAlongside` names the clauses that do narrow the loaded page and so
|
|
32
|
-
* may stand beside it ("No next activity").
|
|
33
|
-
*/
|
|
34
|
-
single?: boolean;
|
|
35
|
-
keepAlongside?: (clause: CrmViewFilterClause) => boolean;
|
|
36
|
-
/**
|
|
37
|
-
* The quick search's words, held by the list when it needs them before
|
|
38
|
-
* the grid's columns exist; the hook holds them itself otherwise.
|
|
39
|
-
*/
|
|
40
|
-
search?: {
|
|
41
|
-
words: string[];
|
|
42
|
-
onChange: (words: string[]) => void;
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
/** What the grid is handed, and what the list filters its rows by. */
|
|
46
|
-
export interface CrmGridFilter {
|
|
47
|
-
/** Controlled: the panel's one item, and the quick search's words. */
|
|
48
|
-
filterModel: GridFilterModel;
|
|
49
|
-
onFilterModelChange: (model: GridFilterModel) => void;
|
|
50
|
-
/** The quick search's words, for the list to match its rows against. */
|
|
51
|
-
searchWords: string[];
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* The grid's Filters panel and quick search, bound to a list's view clauses
|
|
55
|
-
* (AGL-3313). See `model/crm-grid-filter.ts` for the shape both sides keep.
|
|
56
|
-
*
|
|
57
|
-
* ## One field, one clause; the panel edits one at a time
|
|
58
|
-
*
|
|
59
|
-
* The free DataGrid's panel holds a single item, while a saved view
|
|
60
|
-
* holds several clauses. So each FIELD holds one clause, and the panel is a
|
|
61
|
-
* window onto whichever field was last filtered: setting a value writes
|
|
62
|
-
* that field's clause, clearing it or deleting the row removes it, and
|
|
63
|
-
* choosing another column in the panel moves the window without touching
|
|
64
|
-
* the clause the reader just set. Filtering Lead source and then Status is
|
|
65
|
-
* therefore both, which is what a reader who does it means; the chips over
|
|
66
|
-
* the grid (`CrmFilterBar`) show every clause and remove any of them.
|
|
67
|
-
*
|
|
68
|
-
* ## The list answers, never the grid
|
|
69
|
-
*
|
|
70
|
-
* Every list passes `filterMode="server"`: the grid holds one page, or a
|
|
71
|
-
* window the query already narrowed, so a filter the grid ran itself would
|
|
72
|
-
* answer "no match" for a row on the next page. The list reads the clauses
|
|
73
|
-
* — onto its query where it can, over its loaded rows where it cannot —
|
|
74
|
-
* and the quick search's words, and hands the grid the rows that answer.
|
|
75
|
-
*/
|
|
76
|
-
export declare function useCrmGridFilter(options: CrmGridFilterOptions): CrmGridFilter;
|
|
77
|
-
export default useCrmGridFilter;
|
|
@@ -1,143 +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
|
-
*/ 'use client';
|
|
17
|
-
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
18
|
-
import { useCallback, useMemo, useState } from "react";
|
|
19
|
-
import { crmPlainCodec, crmSelectCodec, crmUpsertClause } from "../model/crm-grid-filter.js";
|
|
20
|
-
/**
|
|
21
|
-
* The grid's Filters panel and quick search, bound to a list's view clauses
|
|
22
|
-
* (AGL-3313). See `model/crm-grid-filter.ts` for the shape both sides keep.
|
|
23
|
-
*
|
|
24
|
-
* ## One field, one clause; the panel edits one at a time
|
|
25
|
-
*
|
|
26
|
-
* The free DataGrid's panel holds a single item, while a saved view
|
|
27
|
-
* holds several clauses. So each FIELD holds one clause, and the panel is a
|
|
28
|
-
* window onto whichever field was last filtered: setting a value writes
|
|
29
|
-
* that field's clause, clearing it or deleting the row removes it, and
|
|
30
|
-
* choosing another column in the panel moves the window without touching
|
|
31
|
-
* the clause the reader just set. Filtering Lead source and then Status is
|
|
32
|
-
* therefore both, which is what a reader who does it means; the chips over
|
|
33
|
-
* the grid (`CrmFilterBar`) show every clause and remove any of them.
|
|
34
|
-
*
|
|
35
|
-
* ## The list answers, never the grid
|
|
36
|
-
*
|
|
37
|
-
* Every list passes `filterMode="server"`: the grid holds one page, or a
|
|
38
|
-
* window the query already narrowed, so a filter the grid ran itself would
|
|
39
|
-
* answer "no match" for a row on the next page. The list reads the clauses
|
|
40
|
-
* — onto its query where it can, over its loaded rows where it cannot —
|
|
41
|
-
* and the quick search's words, and hands the grid the rows that answer.
|
|
42
|
-
*/ export function useCrmGridFilter(options) {
|
|
43
|
-
var _ref, _ref1;
|
|
44
|
-
var _options_search, _options_search1;
|
|
45
|
-
const { clauses, onChange, selectFields = [], codecs = {}, single = false, keepAlongside } = options;
|
|
46
|
-
const codecFor = useCallback((field)=>{
|
|
47
|
-
var _codecs_field;
|
|
48
|
-
return (_codecs_field = codecs[field]) != null ? _codecs_field : selectFields.includes(field) ? crmSelectCodec : crmPlainCodec;
|
|
49
|
-
}, [
|
|
50
|
-
codecs,
|
|
51
|
-
selectFields
|
|
52
|
-
]);
|
|
53
|
-
/** The field the panel shows, once the reader has pointed it anywhere. */ const [focus, setFocus] = useState(null);
|
|
54
|
-
/** The panel's row while it holds no value yet — a column chosen, a value not. */ const [pending, setPending] = useState(null);
|
|
55
|
-
const [ownWords, setOwnWords] = useState([]);
|
|
56
|
-
const searchWords = (_ref = (_options_search = options.search) == null ? void 0 : _options_search.words) != null ? _ref : ownWords;
|
|
57
|
-
const setSearchWords = (_ref1 = (_options_search1 = options.search) == null ? void 0 : _options_search1.onChange) != null ? _ref1 : setOwnWords;
|
|
58
|
-
/** Whatever the panel last pointed at, else the newest clause it can show. */ const shownField = useMemo(()=>{
|
|
59
|
-
if (focus) return focus;
|
|
60
|
-
for(let at = clauses.length - 1; at >= 0; at -= 1){
|
|
61
|
-
if (codecFor(clauses[at].field).toItem(clauses[at])) return clauses[at].field;
|
|
62
|
-
}
|
|
63
|
-
return null;
|
|
64
|
-
}, [
|
|
65
|
-
focus,
|
|
66
|
-
clauses,
|
|
67
|
-
codecFor
|
|
68
|
-
]);
|
|
69
|
-
const filterModel = useMemo(()=>{
|
|
70
|
-
const clause = shownField ? clauses.find((entry)=>entry.field === shownField) : undefined;
|
|
71
|
-
const shown = clause ? codecFor(clause.field).toItem(clause) : null;
|
|
72
|
-
const item = pending && pending.field === shownField ? pending : clause && shown ? _extends({
|
|
73
|
-
id: 'crm',
|
|
74
|
-
field: clause.field
|
|
75
|
-
}, shown) : null;
|
|
76
|
-
return {
|
|
77
|
-
items: item ? [
|
|
78
|
-
item
|
|
79
|
-
] : [],
|
|
80
|
-
quickFilterValues: searchWords
|
|
81
|
-
};
|
|
82
|
-
}, [
|
|
83
|
-
shownField,
|
|
84
|
-
clauses,
|
|
85
|
-
codecFor,
|
|
86
|
-
pending,
|
|
87
|
-
searchWords
|
|
88
|
-
]);
|
|
89
|
-
const onFilterModelChange = useCallback((model)=>{
|
|
90
|
-
var _model_quickFilterValues;
|
|
91
|
-
const words = ((_model_quickFilterValues = model.quickFilterValues) != null ? _model_quickFilterValues : []).map((word)=>String(word));
|
|
92
|
-
if (words.join(' ') !== searchWords.join(' ')) setSearchWords(words);
|
|
93
|
-
const item = model.items[0];
|
|
94
|
-
// The row deleted: the field it showed is no longer filtered.
|
|
95
|
-
if (!item) {
|
|
96
|
-
if (shownField && clauses.some((clause)=>clause.field === shownField)) {
|
|
97
|
-
onChange(crmUpsertClause(clauses, shownField, null));
|
|
98
|
-
}
|
|
99
|
-
setPending(null);
|
|
100
|
-
setFocus(null);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const field = String(item.field);
|
|
104
|
-
const moved = field !== shownField;
|
|
105
|
-
setFocus(field);
|
|
106
|
-
const clause = codecFor(field).toClause(item);
|
|
107
|
-
if (!clause) {
|
|
108
|
-
// No value yet. A value cleared on the field already shown removes
|
|
109
|
-
// its clause; a column just chosen leaves the last one standing.
|
|
110
|
-
setPending(_extends({}, item, {
|
|
111
|
-
id: 'crm'
|
|
112
|
-
}));
|
|
113
|
-
if (!moved && clauses.some((entry)=>entry.field === field)) {
|
|
114
|
-
onChange(crmUpsertClause(clauses, field, null));
|
|
115
|
-
}
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
setPending(null);
|
|
119
|
-
// A clause that stands alongside the served one is added beside it;
|
|
120
|
-
// any other replaces whatever the query was serving.
|
|
121
|
-
const base = single && !(keepAlongside == null ? void 0 : keepAlongside(clause)) ? clauses.filter((entry)=>entry.field === field || (keepAlongside == null ? void 0 : keepAlongside(entry))) : clauses;
|
|
122
|
-
const next = crmUpsertClause(base, field, clause);
|
|
123
|
-
const same = next.length === clauses.length && next.every((entry, at)=>entry.field === clauses[at].field && entry.op === clauses[at].op && entry.value === clauses[at].value);
|
|
124
|
-
if (!same) onChange(next);
|
|
125
|
-
}, [
|
|
126
|
-
searchWords,
|
|
127
|
-
setSearchWords,
|
|
128
|
-
shownField,
|
|
129
|
-
clauses,
|
|
130
|
-
onChange,
|
|
131
|
-
codecFor,
|
|
132
|
-
single,
|
|
133
|
-
keepAlongside
|
|
134
|
-
]);
|
|
135
|
-
return {
|
|
136
|
-
filterModel,
|
|
137
|
-
onFilterModelChange,
|
|
138
|
-
searchWords
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
export default useCrmGridFilter;
|
|
142
|
-
|
|
143
|
-
//# sourceMappingURL=use-crm-grid-filter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/hooks/use-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\n'use client'\n\nimport type { CrmViewFilterClause } from '@aglyn/aglyn'\nimport type { GridFilterItem, GridFilterModel } from '@mui/x-data-grid'\nimport { useCallback, useMemo, useState } from 'react'\nimport {\n type CrmGridFilterCodec,\n crmPlainCodec,\n crmSelectCodec,\n crmUpsertClause,\n} from '../model/crm-grid-filter'\n\nexport interface CrmGridFilterOptions {\n /** The clauses the list is narrowed by — the saved view's working filters. */\n clauses: readonly CrmViewFilterClause[]\n onChange: (clauses: CrmViewFilterClause[]) => void\n /** Fields whose values are picked, which the panel shows as a select. */\n selectFields?: readonly string[]\n /** A field whose stored clauses predate the panel, translated its own way. */\n codecs?: Readonly<Record<string, CrmGridFilterCodec>>\n /**\n * The query serves ONE clause, so the panel's replaces every other — a\n * server-paged list, which has no loaded window to narrow further.\n * `keepAlongside` names the clauses that do narrow the loaded page and so\n * may stand beside it (\"No next activity\").\n */\n single?: boolean\n keepAlongside?: (clause: CrmViewFilterClause) => boolean\n /**\n * The quick search's words, held by the list when it needs them before\n * the grid's columns exist; the hook holds them itself otherwise.\n */\n search?: { words: string[]; onChange: (words: string[]) => void }\n}\n\n/** What the grid is handed, and what the list filters its rows by. */\nexport interface CrmGridFilter {\n /** Controlled: the panel's one item, and the quick search's words. */\n filterModel: GridFilterModel\n onFilterModelChange: (model: GridFilterModel) => void\n /** The quick search's words, for the list to match its rows against. */\n searchWords: string[]\n}\n\n/**\n * The grid's Filters panel and quick search, bound to a list's view clauses\n * (AGL-3313). See `model/crm-grid-filter.ts` for the shape both sides keep.\n *\n * ## One field, one clause; the panel edits one at a time\n *\n * The free DataGrid's panel holds a single item, while a saved view\n * holds several clauses. So each FIELD holds one clause, and the panel is a\n * window onto whichever field was last filtered: setting a value writes\n * that field's clause, clearing it or deleting the row removes it, and\n * choosing another column in the panel moves the window without touching\n * the clause the reader just set. Filtering Lead source and then Status is\n * therefore both, which is what a reader who does it means; the chips over\n * the grid (`CrmFilterBar`) show every clause and remove any of them.\n *\n * ## The list answers, never the grid\n *\n * Every list passes `filterMode=\"server\"`: the grid holds one page, or a\n * window the query already narrowed, so a filter the grid ran itself would\n * answer \"no match\" for a row on the next page. The list reads the clauses\n * — onto its query where it can, over its loaded rows where it cannot —\n * and the quick search's words, and hands the grid the rows that answer.\n */\nexport function useCrmGridFilter(options: CrmGridFilterOptions): CrmGridFilter {\n const { clauses, onChange, selectFields = [], codecs = {}, single = false, keepAlongside } =\n options\n\n const codecFor = useCallback(\n (field: string): CrmGridFilterCodec =>\n codecs[field] ?? (selectFields.includes(field) ? crmSelectCodec : crmPlainCodec),\n [codecs, selectFields],\n )\n\n /** The field the panel shows, once the reader has pointed it anywhere. */\n const [focus, setFocus] = useState<string | null>(null)\n /** The panel's row while it holds no value yet — a column chosen, a value not. */\n const [pending, setPending] = useState<GridFilterItem | null>(null)\n const [ownWords, setOwnWords] = useState<string[]>([])\n const searchWords = options.search?.words ?? ownWords\n const setSearchWords = options.search?.onChange ?? setOwnWords\n\n /** Whatever the panel last pointed at, else the newest clause it can show. */\n const shownField = useMemo(() => {\n if (focus) return focus\n for (let at = clauses.length - 1; at >= 0; at -= 1) {\n if (codecFor(clauses[at].field).toItem(clauses[at])) return clauses[at].field\n }\n return null\n }, [focus, clauses, codecFor])\n\n const filterModel = useMemo<GridFilterModel>(() => {\n const clause = shownField\n ? clauses.find((entry) => entry.field === shownField)\n : undefined\n const shown = clause ? codecFor(clause.field).toItem(clause) : null\n const item: GridFilterItem | null =\n pending && pending.field === shownField\n ? pending\n : clause && shown\n ? { id: 'crm', field: clause.field, ...shown }\n : null\n return { items: item ? [item] : [], quickFilterValues: searchWords }\n }, [shownField, clauses, codecFor, pending, searchWords])\n\n const onFilterModelChange = useCallback(\n (model: GridFilterModel) => {\n const words = (model.quickFilterValues ?? []).map((word) => String(word))\n if (words.join(' ') !== searchWords.join(' ')) setSearchWords(words)\n\n const item = model.items[0]\n // The row deleted: the field it showed is no longer filtered.\n if (!item) {\n if (shownField && clauses.some((clause) => clause.field === shownField)) {\n onChange(crmUpsertClause(clauses, shownField, null))\n }\n setPending(null)\n setFocus(null)\n return\n }\n const field = String(item.field)\n const moved = field !== shownField\n setFocus(field)\n const clause = codecFor(field).toClause(item)\n if (!clause) {\n // No value yet. A value cleared on the field already shown removes\n // its clause; a column just chosen leaves the last one standing.\n setPending({ ...item, id: 'crm' })\n if (!moved && clauses.some((entry) => entry.field === field)) {\n onChange(crmUpsertClause(clauses, field, null))\n }\n return\n }\n setPending(null)\n // A clause that stands alongside the served one is added beside it;\n // any other replaces whatever the query was serving.\n const base =\n single && !keepAlongside?.(clause)\n ? clauses.filter((entry) => entry.field === field || keepAlongside?.(entry))\n : clauses\n const next = crmUpsertClause(base, field, clause)\n const same =\n next.length === clauses.length &&\n next.every(\n (entry, at) =>\n entry.field === clauses[at].field &&\n entry.op === clauses[at].op &&\n entry.value === clauses[at].value,\n )\n if (!same) onChange(next)\n },\n [searchWords, setSearchWords, shownField, clauses, onChange, codecFor, single, keepAlongside],\n )\n\n return { filterModel, onFilterModelChange, searchWords }\n}\n\nexport default useCrmGridFilter\n"],"names":["useCallback","useMemo","useState","crmPlainCodec","crmSelectCodec","crmUpsertClause","useCrmGridFilter","options","clauses","onChange","selectFields","codecs","single","keepAlongside","codecFor","field","includes","focus","setFocus","pending","setPending","ownWords","setOwnWords","searchWords","search","words","setSearchWords","shownField","at","length","toItem","filterModel","clause","find","entry","undefined","shown","item","id","items","quickFilterValues","onFilterModelChange","model","map","word","String","join","some","moved","toClause","base","filter","next","same","every","op","value"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;AAIA,SAASA,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACtD,SAEEC,aAAa,EACbC,cAAc,EACdC,eAAe,QACV,8BAA0B;AAkCjC;;;;;;;;;;;;;;;;;;;;;;CAsBC,GACD,OAAO,SAASC,iBAAiBC,O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,KAAK,KAAKA,UAASF,iCAAAA,cAAgBqB,WACnE1B;QACN,MAAM4C,OAAO/C,gBAAgB6C,MAAMnC,OAAOiB;QAC1C,MAAMqB,OACJD,KAAKvB,MAAM,KAAKrB,QAAQqB,MAAM,IAC9BuB,KAAKE,KAAK,CACR,CAACpB,OAAON,KACNM,MAAMnB,KAAK,KAAKP,OAAO,CAACoB,GAAG,CAACb,KAAK,IACjCmB,MAAMqB,EAAE,KAAK/C,OAAO,CAACoB,GAAG,CAAC2B,EAAE,IAC3BrB,MAAMsB,KAAK,KAAKhD,OAAO,CAACoB,GAAG,CAAC4B,KAAK;QAEvC,IAAI,CAACH,MAAM5C,SAAS2C;IACtB,GACA;QAAC7B;QAAaG;QAAgBC;QAAYnB;QAASC;QAAUK;QAAUF;QAAQC;KAAc;IAG/F,OAAO;QAAEkB;QAAaU;QAAqBlB;IAAY;AACzD;AAEA,eAAejB,iBAAgB"}
|
|
@@ -1,64 +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
|
-
*/
|
|
17
|
-
import type { CrmViewFilterClause } from '@aglyn/aglyn';
|
|
18
|
-
import { type ListFilterField } from '@aglyn/shared-ui-jsx/const/list-filter';
|
|
19
|
-
import { type GridColDef, type GridFilterItem } from '@mui/x-data-grid';
|
|
20
|
-
/** A choice for a field whose value is picked rather than typed. */
|
|
21
|
-
export interface CrmFilterOption {
|
|
22
|
-
value: string;
|
|
23
|
-
label: string;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* How one field's stored clause and the panel's item translate. A field
|
|
27
|
-
* with choices uses {@link crmSelectCodec}; a typed one, {@link crmPlainCodec}.
|
|
28
|
-
* A list whose clauses predate the panel supplies its own.
|
|
29
|
-
*/
|
|
30
|
-
export interface CrmGridFilterCodec {
|
|
31
|
-
toItem: (clause: CrmViewFilterClause) => Pick<GridFilterItem, 'operator' | 'value'> | null;
|
|
32
|
-
toClause: (item: GridFilterItem) => CrmViewFilterClause | null;
|
|
33
|
-
}
|
|
34
|
-
/** A typed field: the stored operator IS the grid's. */
|
|
35
|
-
export declare const crmPlainCodec: CrmGridFilterCodec;
|
|
36
|
-
/** A picked field: `equals` shows as `is`, and `isAnyOf` holds a comma list. */
|
|
37
|
-
export declare const crmSelectCodec: CrmGridFilterCodec;
|
|
38
|
-
/** The select operators a field's allowed clause operators map to. */
|
|
39
|
-
export declare function crmSelectOperators(allowed: readonly string[]): import("@mui/x-data-grid").GridFilterOperator<any, any, any, import("@mui/x-data-grid").GridFilterInputValueProps>[];
|
|
40
|
-
/**
|
|
41
|
-
* The list's columns, each made filterable exactly as far as its field is
|
|
42
|
-
* declared, and every declared field that is not a column added as a
|
|
43
|
-
* permanently hidden one — the panel lists columns, so a field with none
|
|
44
|
-
* could not be reached (`hiddenFilterColumns`).
|
|
45
|
-
*
|
|
46
|
-
* A field with choices becomes a `singleSelect` over them, whatever the
|
|
47
|
-
* column rendered before; one without keeps the grammar's operators; a
|
|
48
|
-
* column no field declares offers no filter, because the list, not the
|
|
49
|
-
* grid, answers every filter and would have nothing to answer it with.
|
|
50
|
-
*/
|
|
51
|
-
export declare function crmFilterColumns(columns: readonly GridColDef[], fields: readonly ListFilterField[], options?: Readonly<Record<string, readonly CrmFilterOption[]>>, headers?: Readonly<Record<string, string>>): GridColDef[];
|
|
52
|
-
/**
|
|
53
|
-
* Whether a row answers a quick search: every whitespace-separated word
|
|
54
|
-
* appears, case-insensitively, in SOME of the row's searched values. A
|
|
55
|
-
* blank search matches every row, so an emptied box is the list unfiltered.
|
|
56
|
-
* An array value (tags) is searched member by member.
|
|
57
|
-
*/
|
|
58
|
-
export declare function crmRowMatchesSearch(row: object, paths: readonly string[], words: readonly string[]): boolean;
|
|
59
|
-
/**
|
|
60
|
-
* The clauses with one field's clause set: replaced in place where the field
|
|
61
|
-
* already had one, appended where it did not, removed when `next` is null.
|
|
62
|
-
* A field holds ONE clause, which is what the panel edits.
|
|
63
|
-
*/
|
|
64
|
-
export declare function crmUpsertClause(clauses: readonly CrmViewFilterClause[], field: string, next: CrmViewFilterClause | null): CrmViewFilterClause[];
|