63 lines
2.2 KiB
TypeScript
63 lines
2.2 KiB
TypeScript
import { ConnectorCategory, ConnectorInfo, SqlEngineInfo } from '../api/api.types';
|
|
|
|
/**
|
|
* The "Obtener datos" gallery, built from what the server reports it can
|
|
* read (`GET /imports/connectors`): one tile per connector, and one per
|
|
* database engine for SQL. A new connector on the server shows up here
|
|
* without client changes.
|
|
*/
|
|
export type GalleryCategory = ConnectorCategory | 'all';
|
|
|
|
export interface GalleryEntry {
|
|
id: string;
|
|
name: string;
|
|
description: string;
|
|
icon: string;
|
|
category: ConnectorCategory;
|
|
connector: ConnectorInfo;
|
|
/** SQL tiles: the engine the connection form is for; `url` for a raw connection string. */
|
|
engine?: SqlEngineInfo | 'url';
|
|
/** False when the server lacks what this tile needs (e.g. a database driver). */
|
|
available: boolean;
|
|
}
|
|
|
|
export const GALLERY_CATEGORIES: { id: GalleryCategory; label: string; icon: string }[] = [
|
|
{ id: 'all', label: 'Todos', icon: 'apps' },
|
|
{ id: 'file', label: 'Archivo', icon: 'folder_open' },
|
|
{ id: 'database', label: 'Base de datos', icon: 'storage' },
|
|
{ id: 'document', label: 'Documento', icon: 'description' },
|
|
{ id: 'signal', label: 'Señales', icon: 'monitor_heart' },
|
|
];
|
|
|
|
export function galleryEntries(connectors: ConnectorInfo[]): GalleryEntry[] {
|
|
return connectors.flatMap((connector): GalleryEntry[] => {
|
|
if (connector.kind !== 'sql') {
|
|
return [{ ...pick(connector), id: connector.kind, name: connector.label, connector, available: true }];
|
|
}
|
|
const engines = (connector.engines ?? []).map((engine) => ({
|
|
...pick(connector),
|
|
id: `sql-${engine.id}`,
|
|
name: engine.label,
|
|
description: engine.available ? engine.description : `${engine.description} (driver no instalado en el servidor)`,
|
|
connector,
|
|
engine,
|
|
available: engine.available,
|
|
}));
|
|
const raw: GalleryEntry = {
|
|
...pick(connector),
|
|
id: 'sql-url',
|
|
name: 'Otra base de datos',
|
|
description: 'Cadena de conexión SQLAlchemy (avanzado)',
|
|
icon: 'link',
|
|
connector,
|
|
engine: 'url',
|
|
available: true,
|
|
};
|
|
return [...engines, raw];
|
|
});
|
|
}
|
|
|
|
function pick(connector: ConnectorInfo) {
|
|
return { description: connector.description, icon: connector.icon, category: connector.category };
|
|
}
|