This commit is contained in:
2025-11-12 17:02:27 +01:00
parent d2e27c12a2
commit b812d748ea
44 changed files with 221 additions and 356 deletions
@@ -18,7 +18,7 @@ export const sortCorrespondents = (entries = []) =>
export const buildCorrespondentOptions = (entries = []) => {
const seen = new Set();
return entries.reduce((options, entry) => {
const name = typeof entry?.name === 'string' ? entry.name.trim() : '';
const name = entry?.name?.trim?.() || '';
if (!name) {
return options;
}
@@ -38,20 +38,14 @@ const normalizeQuickAddOption = (option) => {
if (option == null) {
return null;
}
if (typeof option === 'string') {
const label = option.trim();
return label ? { id: label, label, original: option } : null;
}
const label = typeof option.label === 'string'
? option.label.trim()
: typeof option.name === 'string'
? option.name.trim()
: '';
const isObject = typeof option === 'object';
const labelSource = isObject ? option.label ?? option.name ?? '' : option;
const label = labelSource?.trim?.() || '';
if (!label) {
return null;
}
return {
id: option.id ?? label,
id: isObject && option.id ? option.id : label,
label,
original: option,
};
@@ -75,9 +69,10 @@ export const TagSection = ({
const handleSelect = useCallback(
(option) => {
if (!onAdd) return;
const label =
(option && typeof option === 'object' && option.label) ||
(typeof option === 'string' ? option : '');
const labelSource = option && typeof option === 'object'
? option.label ?? option.name ?? ''
: option;
const label = labelSource?.trim?.() || '';
if (!label) {
return;
}
@@ -117,7 +112,7 @@ export const TagSection = ({
});
tags.forEach((tag) => {
const label = typeof tag?.label === 'string' ? tag.label.trim() : '';
const label = tag?.label?.trim?.() || '';
if (!label) {
return;
}
@@ -244,7 +239,7 @@ export const CorrespondentSection = ({
});
entries.forEach((entry) => {
const label = typeof entry?.name === 'string' ? entry.name.trim() : '';
const label = entry?.name?.trim?.() || '';
if (!label) {
return;
}
@@ -274,9 +269,10 @@ export const CorrespondentSection = ({
}
const source = item.payload ?? item;
const resolvedName =
(source && typeof source.name === 'string' && source.name.trim())
|| (typeof source === 'string' ? source.trim() : '')
|| (source && typeof source.label === 'string' ? source.label.trim() : '');
source?.name?.trim?.()
|| source?.label?.trim?.()
|| source?.trim?.()
|| '';
if (!resolvedName) {
return;
}
@@ -24,7 +24,7 @@ const useLazyVisibility = (rootRef, resetKey) => {
return undefined;
}
if (typeof window === 'undefined' || typeof IntersectionObserver === 'undefined') {
if (!('IntersectionObserver' in window)) {
setIsVisible(true);
return undefined;
}
@@ -10,15 +10,24 @@ const STATE_ORDER = {
const normalizeItems = (items) =>
(Array.isArray(items) ? items : [])
.filter((item) => item && typeof item.label === 'string' && item.label.trim().length > 0)
.map((item) => ({
id: item.id ?? item.label,
label: item.label.trim(),
state: item.state === 'all' ? 'all' : item.state === 'partial' ? 'partial' : 'none',
count: typeof item.count === 'number' ? item.count : null,
total: typeof item.total === 'number' ? item.total : null,
payload: item.payload ?? item,
}));
.map((item) => {
if (!item) {
return null;
}
const trimmedLabel = item.label?.trim?.() || '';
if (!trimmedLabel) {
return null;
}
return {
id: item.id ?? trimmedLabel,
label: trimmedLabel,
state: item.state === 'all' ? 'all' : item.state === 'partial' ? 'partial' : 'none',
count: typeof item.count === 'number' ? item.count : null,
total: typeof item.total === 'number' ? item.total : null,
payload: item.payload ?? item,
};
})
.filter(Boolean);
const SelectionAssignmentMenu = ({
label,
@@ -34,9 +34,8 @@ const buildFolderTreeOptions = (tree) => {
if (!node || !node.id) {
return;
}
const name = typeof node.name === 'string' && node.name.trim().length
? node.name.trim()
: 'Folder';
const trimmedName = node?.name?.trim?.();
const name = trimmedName?.length ? trimmedName : 'Folder';
const nextSegments = parentSegments.concat([name]);
const label = nextSegments.join('/');
entries.push({ id: node.id, label });
+1 -5
View File
@@ -8,11 +8,7 @@ export const resolveCorrespondents = (doc) => {
doc.correspondents.forEach((entry = {}, index) => {
const { id, name } = entry;
if (typeof name !== 'string') {
return;
}
const trimmedName = name.trim();
const trimmedName = name?.trim?.();
if (!trimmedName) {
return;
}
@@ -16,7 +16,7 @@ const useBulkDocumentActions = ({
}) => {
const handleBulkCorrespondentAdd = useCallback(
async ({ name, input, documentIds }) => {
const trimmed = typeof name === 'string' ? name.trim() : '';
const trimmed = name?.trim?.() || '';
if (!trimmed) {
setStatusMessage('Correspondent name is required.', 'error');
return;
+1 -1
View File
@@ -10,7 +10,7 @@ export const isPrimaryPointerEvent = (event) => {
if (typeof event.button === 'number' && event.button !== 0) {
return false;
}
const type = typeof event.type === 'string' ? event.type.toLowerCase() : '';
const type = event?.type?.toLowerCase?.() ?? '';
return type === 'click' || type === 'pointerdown' || type === 'pointerup';
};
+6 -7
View File
@@ -6,15 +6,14 @@ const focusInput = (node) => {
}
const applyFocus = () => {
node.focus();
if (typeof node.select === 'function') {
node.select();
}
node.select?.();
};
if (typeof window !== 'undefined' && typeof window.requestAnimationFrame === 'function') {
window.requestAnimationFrame(applyFocus);
} else {
applyFocus();
const raf = window.requestAnimationFrame;
if (raf) {
raf(applyFocus);
return;
}
applyFocus();
};
const identity = (value) => value;