Update Prism Notes branding and OneNote sync UI
This commit is contained in:
@@ -17,6 +17,25 @@
|
||||
|
||||
// Cache for email lookups to minimize queries
|
||||
const emailLookupCache = {};
|
||||
let associationsCollectionAvailable = true;
|
||||
let associationsWarningShown = false;
|
||||
|
||||
function getAssociationEmail(record) {
|
||||
return record?.emailtext || record?.email || 'Email not found';
|
||||
}
|
||||
|
||||
function handleAssociationsError(error) {
|
||||
const statusCode = Number(error?.status || error?.response?.status || 0);
|
||||
if (statusCode === 404) {
|
||||
associationsCollectionAvailable = false;
|
||||
if (!associationsWarningShown) {
|
||||
associationsWarningShown = true;
|
||||
console.warn("'Associations' collection not found. Email hover lookup disabled.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
console.error('Associations lookup failed:', error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch email from Associations collection by first name
|
||||
@@ -31,6 +50,7 @@ const emailLookupCache = {};
|
||||
*/
|
||||
async function getEmailByFirstName(pb, firstName) {
|
||||
if (!firstName) return 'Email not found';
|
||||
if (!associationsCollectionAvailable) return 'Email lookup unavailable';
|
||||
|
||||
// Check cache first
|
||||
if (emailLookupCache[firstName]) {
|
||||
@@ -38,36 +58,22 @@ async function getEmailByFirstName(pb, firstName) {
|
||||
}
|
||||
|
||||
try {
|
||||
// First, get ALL records to inspect structure
|
||||
const allRecords = await pb.collection('Associations').getList(1, 50);
|
||||
console.log(`[Email Lookup] All Associations records:`, allRecords.items);
|
||||
if (allRecords.items.length > 0) {
|
||||
console.log(`[Email Lookup] Sample record fields:`, Object.keys(allRecords.items[0]));
|
||||
console.log(`[Email Lookup] Sample record:`, allRecords.items[0]);
|
||||
}
|
||||
|
||||
// Now try the filtered query
|
||||
const records = await pb.collection('Associations').getList(1, 50, {
|
||||
filter: `first_name = "${firstName}"`,
|
||||
});
|
||||
|
||||
console.log(`[Email Lookup] Query: first_name="${firstName}" | Filtered results:`, records.items);
|
||||
|
||||
|
||||
if (records.items.length === 0) {
|
||||
console.log(`[Email Lookup] No records found for: ${firstName}`);
|
||||
emailLookupCache[firstName] = 'Email not found';
|
||||
return 'Email not found';
|
||||
}
|
||||
|
||||
// Use first match's emailtext field
|
||||
const firstRecord = records.items[0];
|
||||
console.log(`[Email Lookup] First record:`, firstRecord);
|
||||
const email = firstRecord.emailtext || 'Email not found';
|
||||
const email = getAssociationEmail(firstRecord);
|
||||
emailLookupCache[firstName] = email;
|
||||
return email;
|
||||
} catch (error) {
|
||||
console.error(`Failed to lookup email for "${firstName}":`, error);
|
||||
console.error(`Error response:`, error.response?.data);
|
||||
handleAssociationsError(error);
|
||||
return 'Error loading email';
|
||||
}
|
||||
}
|
||||
@@ -161,6 +167,8 @@ function attachEmailLookupTooltip(pb, capsuleEl) {
|
||||
*/
|
||||
window.clearEmailLookupCache = function() {
|
||||
Object.keys(emailLookupCache).forEach(key => delete emailLookupCache[key]);
|
||||
associationsCollectionAvailable = true;
|
||||
associationsWarningShown = false;
|
||||
console.log('✓ Email lookup cache cleared');
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user