removed migration code now that migration is complete
This commit is contained in:
@@ -13,7 +13,7 @@ export const NotesSidebar: Component<{
|
|||||||
}> = (props) => {
|
}> = (props) => {
|
||||||
const currentUserId = pb.authStore.model?.id;
|
const currentUserId = pb.authStore.model?.id;
|
||||||
const [accessibleJobs] = createResource(currentUserId, async (userId) => {
|
const [accessibleJobs] = createResource(currentUserId, async (userId) => {
|
||||||
if (!userId) return { ids: new Set<string>(), numbers: new Set<string>() };
|
if (!userId) return new Set<string>();
|
||||||
try {
|
try {
|
||||||
const items = await pb.collection('Job_Info_Prod').getFullList({
|
const items = await pb.collection('Job_Info_Prod').getFullList({
|
||||||
filter: [
|
filter: [
|
||||||
@@ -24,21 +24,13 @@ export const NotesSidebar: Component<{
|
|||||||
`Office_Rep = "${userId}"`,
|
`Office_Rep = "${userId}"`,
|
||||||
`Project_Manager = "${userId}"`
|
`Project_Manager = "${userId}"`
|
||||||
].join(" || "),
|
].join(" || "),
|
||||||
fields: "id,Job_Number",
|
fields: "id",
|
||||||
requestKey: null
|
requestKey: null
|
||||||
});
|
});
|
||||||
const ids = new Set<string>();
|
return new Set(items.map((r: any) => String(r.id)));
|
||||||
const numbers = new Set<string>();
|
|
||||||
items.forEach((r: any) => {
|
|
||||||
if (r.id) ids.add(String(r.id));
|
|
||||||
if (r.Job_Number !== undefined && r.Job_Number !== null && r.Job_Number !== "") {
|
|
||||||
numbers.add(String(r.Job_Number));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return { ids, numbers };
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("Failed to load job access list for notes filter:", e);
|
console.warn("Failed to load job access list for notes filter:", e);
|
||||||
return { ids: new Set<string>(), numbers: new Set<string>() };
|
return new Set<string>();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -90,12 +82,9 @@ export const NotesSidebar: Component<{
|
|||||||
if (note.tags?.includes("prism_job")) {
|
if (note.tags?.includes("prism_job")) {
|
||||||
if (!accessible) return false;
|
if (!accessible) return false;
|
||||||
const jobIdTag = note.tags.find(t => t.startsWith("job_id:"));
|
const jobIdTag = note.tags.find(t => t.startsWith("job_id:"));
|
||||||
const jobRef = jobIdTag?.split(":")[1]?.trim();
|
const jobId = jobIdTag?.split(":")[1]?.trim();
|
||||||
if (!jobRef) return false;
|
if (!jobId) return false;
|
||||||
const isLegacyNumber = /^\d{4}$/.test(jobRef);
|
return accessible.has(jobId);
|
||||||
return isLegacyNumber
|
|
||||||
? accessible.numbers.has(jobRef)
|
|
||||||
: accessible.ids.has(jobRef);
|
|
||||||
}
|
}
|
||||||
return note.user === currentUserId;
|
return note.user === currentUserId;
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-100
@@ -1095,104 +1095,6 @@ const runLegacyTagMigration = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const runLegacyJobIdTagMigration = async () => {
|
|
||||||
const currentUserId = pb.authStore.model?.id;
|
|
||||||
if (!currentUserId) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const userRec = await pb.collection('users').getOne(currentUserId, { requestKey: null });
|
|
||||||
const prefs = userRec.Taskgrid_pref || {};
|
|
||||||
|
|
||||||
if (prefs.migratedLegacyJobIdTagsV1) return;
|
|
||||||
|
|
||||||
// Fetch all Notes (all users)
|
|
||||||
const notes = await pb.collection(NOTES_COLLECTION).getFullList({
|
|
||||||
requestKey: null
|
|
||||||
});
|
|
||||||
|
|
||||||
const extractLegacyJobNumbers = (tags: string[] | undefined) => {
|
|
||||||
if (!tags || tags.length === 0) return [];
|
|
||||||
const nums: string[] = [];
|
|
||||||
tags.forEach(t => {
|
|
||||||
if (!t.startsWith("job_id:")) return;
|
|
||||||
const val = t.split(":")[1]?.trim();
|
|
||||||
if (val && /^\d{4}$/.test(val)) nums.push(val);
|
|
||||||
});
|
|
||||||
return nums;
|
|
||||||
};
|
|
||||||
|
|
||||||
const legacyNumbers = new Set<string>();
|
|
||||||
notes.forEach(n => extractLegacyJobNumbers(n.tags).forEach(nm => legacyNumbers.add(nm)));
|
|
||||||
|
|
||||||
if (legacyNumbers.size > 0) {
|
|
||||||
const allNumbers = Array.from(legacyNumbers);
|
|
||||||
const jobMap = new Map<string, string>(); // jobNumber -> jobId
|
|
||||||
const chunkSize = 50;
|
|
||||||
|
|
||||||
for (let i = 0; i < allNumbers.length; i += chunkSize) {
|
|
||||||
const chunk = allNumbers.slice(i, i + chunkSize);
|
|
||||||
const filter = chunk.map(n => `Job_Number = "${n}"`).join(" || ");
|
|
||||||
const jobs = await pb.collection('Job_Info_Prod').getFullList({
|
|
||||||
filter,
|
|
||||||
fields: "id,Job_Number",
|
|
||||||
requestKey: null
|
|
||||||
});
|
|
||||||
jobs.forEach((j: any) => {
|
|
||||||
if (j.Job_Number !== undefined && j.Job_Number !== null && j.Job_Number !== "") {
|
|
||||||
jobMap.set(String(j.Job_Number), String(j.id));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let migratedNotes = 0;
|
|
||||||
for (const n of notes) {
|
|
||||||
if (!n.tags || n.tags.length === 0) continue;
|
|
||||||
let changed = false;
|
|
||||||
const newTags = n.tags.map((tag: string) => {
|
|
||||||
if (!tag.startsWith("job_id:")) return tag;
|
|
||||||
const val = tag.split(":")[1]?.trim();
|
|
||||||
if (!val || !/^\d{4}$/.test(val)) return tag;
|
|
||||||
const mappedId = jobMap.get(val);
|
|
||||||
if (!mappedId) return tag;
|
|
||||||
changed = true;
|
|
||||||
return `job_id:${mappedId}`;
|
|
||||||
});
|
|
||||||
if (changed) {
|
|
||||||
await pb.collection(NOTES_COLLECTION).update(n.id, { tags: newTags }, { requestKey: null });
|
|
||||||
migratedNotes++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (migratedNotes > 0) {
|
|
||||||
setStore("notes", (items) => items.map(n => {
|
|
||||||
if (!n.tags || n.tags.length === 0) return n;
|
|
||||||
let localChanged = false;
|
|
||||||
const nt = n.tags.map(tag => {
|
|
||||||
if (!tag.startsWith("job_id:")) return tag;
|
|
||||||
const val = tag.split(":")[1]?.trim();
|
|
||||||
if (!val || !/^\d{4}$/.test(val)) return tag;
|
|
||||||
const mappedId = jobMap.get(val);
|
|
||||||
if (!mappedId) return tag;
|
|
||||||
localChanged = true;
|
|
||||||
return `job_id:${mappedId}`;
|
|
||||||
});
|
|
||||||
return localChanged ? { ...n, tags: nt } : n;
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`[MIGRATION] Job tag migration complete. Updated ${migratedNotes} notes.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
prefs.migratedLegacyJobIdTagsV1 = true;
|
|
||||||
await pb.collection('users').update(currentUserId, { Taskgrid_pref: prefs }, { requestKey: null });
|
|
||||||
|
|
||||||
if (pb.authStore.model) {
|
|
||||||
pb.authStore.model.Taskgrid_pref = prefs;
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error("[MIGRATION] Job tag migration failed:", err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const initStore = async () => {
|
export const initStore = async () => {
|
||||||
if (!pb.authStore.isValid || store.isInitializing) return;
|
if (!pb.authStore.isValid || store.isInitializing) return;
|
||||||
@@ -1537,9 +1439,8 @@ export const initStore = async () => {
|
|||||||
// Fire off background sync
|
// Fire off background sync
|
||||||
await backgroundSync();
|
await backgroundSync();
|
||||||
|
|
||||||
// Run one-time migrations
|
// Run one-time migration for legacy tags
|
||||||
await runLegacyTagMigration();
|
await runLegacyTagMigration();
|
||||||
await runLegacyJobIdTagMigration();
|
|
||||||
|
|
||||||
// Separate Templates load (less critical)
|
// Separate Templates load (less critical)
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user