Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
7f379e1c68
commit
f5b5d0d6f8
@@ -806,16 +806,27 @@ function ImportPage() {
|
||||
ctx.caseByExt.clear();
|
||||
ctx.caseByNumber.clear();
|
||||
ctx.caseByTitle.clear();
|
||||
ctx.caseByClientAndTitle.clear();
|
||||
ctx.activeCaseIds.clear();
|
||||
const cases = await fetchAllPaginated<{ id: string; case_number: string | null; title: string | null; external_id: string | null; status: string | null; archived_at: string | null }>(
|
||||
const cases = await fetchAllPaginated<{ id: string; case_number: string | null; title: string | null; external_id: string | null; status: string | null; archived_at: string | null; client_id: string | null }>(
|
||||
"cases",
|
||||
"id, case_number, title, external_id, status, archived_at",
|
||||
"id, case_number, title, external_id, status, archived_at, client_id",
|
||||
);
|
||||
// Build id → client_name lookup from already-loaded clients
|
||||
const clientNameById = new Map<string, string>();
|
||||
for (const [name, id] of ctx.clientByName.entries()) clientNameById.set(id, name);
|
||||
const CLOSED_STATUSES = new Set(["closed", "closed_won", "closed_lost"]);
|
||||
for (const r of cases) {
|
||||
if (r.external_id) ctx.caseByExt.set(r.external_id, r.id);
|
||||
if (r.case_number) ctx.caseByNumber.set(r.case_number, r.id);
|
||||
if (r.title) ctx.caseByTitle.set(r.title.toLowerCase().trim(), r.id);
|
||||
if (r.title) {
|
||||
const titleKey = r.title.toLowerCase().trim();
|
||||
ctx.caseByTitle.set(titleKey, r.id);
|
||||
if (r.client_id) {
|
||||
const cname = clientNameById.get(r.client_id);
|
||||
if (cname) ctx.caseByClientAndTitle.set(`${cname}||${titleKey}`, r.id);
|
||||
}
|
||||
}
|
||||
if (!r.archived_at && !CLOSED_STATUSES.has(String(r.status ?? "").toLowerCase())) {
|
||||
ctx.activeCaseIds.add(r.id);
|
||||
}
|
||||
@@ -827,7 +838,7 @@ function ImportPage() {
|
||||
if (p.full_name) ctx.userByName.set(p.full_name.toLowerCase().trim(), p.id);
|
||||
if (p.email) ctx.userByEmail.set(p.email.toLowerCase().trim(), p.id);
|
||||
}
|
||||
console.info(`[import] lookups loaded: clients=${ctx.clientByExt.size}/${ctx.clientByName.size} cases=${ctx.caseByExt.size}/${ctx.caseByNumber.size}/${ctx.caseByTitle.size} users=${ctx.userByName.size}`);
|
||||
console.info(`[import] lookups loaded: clients=${ctx.clientByExt.size}/${ctx.clientByName.size} cases=${ctx.caseByExt.size}/${ctx.caseByNumber.size}/${ctx.caseByTitle.size}/${ctx.caseByClientAndTitle.size} users=${ctx.userByName.size}`);
|
||||
};
|
||||
|
||||
const handleFile = async (cfg: ImporterConfig, source: File | string) => {
|
||||
|
||||
Reference in New Issue
Block a user