fix: отображение множественного выбора справочника + переименование типа в Справочник
This commit is contained in:
@@ -256,13 +256,16 @@ function LinkedTaskDisplay({ linkedFormId, taskId, relationType }: { linkedFormI
|
||||
// Компонент для отображения значения из справочника
|
||||
type DirectoryData = { table: { rows: Array<{ id: number; values: string[] }>; columns: Array<{ name: string }> } };
|
||||
|
||||
function TableValueDisplay({ tableId, displayColumn, rowId }: { tableId: number; displayColumn?: string; rowId: string | number }) {
|
||||
function TableValueDisplay({ tableId, displayColumn, rowId }: { tableId: number; displayColumn?: string; rowId: string | number | Array<string | number> }) {
|
||||
const { isOnline } = useOfflineSyncContext();
|
||||
const [offlineData, setOfflineData] = useState<DirectoryData | null>(null);
|
||||
|
||||
const isArray = Array.isArray(rowId);
|
||||
const rowIds = isArray ? rowId.map(String) : [String(rowId)];
|
||||
|
||||
const { data: tableData, isLoading } = useQuery<DirectoryData>({
|
||||
queryKey: ['/api/directories', tableId],
|
||||
enabled: !!tableId && !!rowId && isOnline,
|
||||
enabled: !!tableId && rowIds.length > 0 && isOnline,
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
|
||||
@@ -275,12 +278,12 @@ function TableValueDisplay({ tableId, displayColumn, rowId }: { tableId: number;
|
||||
|
||||
// Load from IDB when offline and live data is unavailable
|
||||
useEffect(() => {
|
||||
if (!isOnline && !tableData && tableId && rowId) {
|
||||
if (!isOnline && !tableData && tableId && rowIds.length > 0) {
|
||||
getDirectory(tableId).then(cached => {
|
||||
if (cached) setOfflineData(cached.data as DirectoryData);
|
||||
}).catch(() => {});
|
||||
}
|
||||
}, [isOnline, tableData, tableId, rowId]);
|
||||
}, [isOnline, tableData, tableId, rowIds]);
|
||||
|
||||
const effectiveData = tableData ?? offlineData;
|
||||
|
||||
@@ -289,18 +292,26 @@ function TableValueDisplay({ tableId, displayColumn, rowId }: { tableId: number;
|
||||
const table = effectiveData?.table;
|
||||
if (!table) return <span className="text-muted-foreground">Таблица не найдена</span>;
|
||||
|
||||
const row = table.rows?.find(r => r.id.toString() === rowId?.toString());
|
||||
if (!row) return <span className="text-muted-foreground">Запись не найдена</span>;
|
||||
|
||||
let displayColumnIndex = table.columns?.findIndex(c => c.name === displayColumn);
|
||||
if (displayColumnIndex === undefined || displayColumnIndex < 0) {
|
||||
displayColumnIndex = 0;
|
||||
}
|
||||
|
||||
const rows = table.rows || [];
|
||||
const labels = rowIds
|
||||
.map((id) => {
|
||||
const row = rows.find((r) => r.id.toString() === id);
|
||||
if (!row) return null;
|
||||
return row.values[displayColumnIndex] || row.values[0] || `#${id}`;
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
||||
if (labels.length === 0) return <span className="text-muted-foreground">Запись не найдена</span>;
|
||||
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1">
|
||||
<Table className="w-3 h-3 text-muted-foreground" />
|
||||
{row.values[displayColumnIndex] || row.values[0]}
|
||||
{labels.join(', ')}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user