9e6bea681f
Añade funciones Go stub para la API de Metabase en dominio infra: auth, CRUD de cards, dashboards y users, execute_query y execute_card. Incluye tipo MetabaseClient y helper HTTP compartido. Todas las funciones son impuras con stubs not-implemented.
3.5 KiB
3.5 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | tested | tests | test_file_path | file_path | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| metabase_update_dashboard | function | go | infra | 1.0.0 | impure | func MetabaseUpdateDashboard(client MetabaseClient, dashboardID int, fields map[string]any) (map[string]any, error) | Actualiza un dashboard en Metabase incluyendo metadata, cards y tabs. El campo dashcards representa el estado completo deseado: cards nuevas con ID negativo, existentes con ID positivo, omitidas se eliminan. Endpoint: PUT /api/dashboard/:id. |
|
|
false | error_go_core |
|
false | functions/infra/metabase_update_dashboard.go |
Ejemplo
// Cambiar nombre
MetabaseUpdateDashboard(client, 1, map[string]any{
"name": "Updated Dashboard",
})
// Agregar una card al dashboard
// Primero obtener las dashcards existentes
dash, _ := MetabaseGetDashboard(client, 1)
existingCards := dash["dashcards"].([]any)
// Construir nuevo array con las existentes + la nueva
dashcards := make([]map[string]any, 0)
for _, dc := range existingCards {
dashcards = append(dashcards, dc.(map[string]any))
}
// Agregar nueva card (ID negativo = nueva)
dashcards = append(dashcards, map[string]any{
"id": -1, "card_id": 55, "size_x": 6, "size_y": 4, "col": 0, "row": 0,
})
MetabaseUpdateDashboard(client, 1, map[string]any{
"dashcards": dashcards,
})
// Archivar dashboard (soft-delete)
MetabaseUpdateDashboard(client, 1, map[string]any{"archived": true})
Notas
Gestion de dashcards (IMPORTANTE)
El array dashcards representa el estado completo deseado del dashboard:
| Accion | Como hacerlo |
|---|---|
| Agregar card | Incluir con ID negativo (-1, -2, etc.) |
| Actualizar card | Incluir con su ID positivo existente |
| Eliminar card | Omitir del array |
| No cambiar cards | No incluir el campo dashcards |
Flujo tipico para agregar una card:
MetabaseGetDashboardpara obtener dashcards existentes- Copiar las existentes al nuevo array
- Agregar la nueva con ID negativo
- Enviar el array completo
Estructura de una dashcard
map[string]any{
"id": -1, // negativo = nueva, positivo = existente
"card_id": 42, // ID de la card/pregunta
"size_x": 6, // ancho (1-18)
"size_y": 4, // alto
"col": 0, // columna (0-based)
"row": 0, // fila (0-based)
"dashboard_tab_id": nil, // tab (nil = sin tabs)
"parameter_mappings": []map[string]any{}, // mapeo de filtros
"visualization_settings": map[string]any{}, // settings custom
}
Gestion de tabs
map[string]any{
"tabs": []map[string]any{
{"id": 1, "name": "Overview"}, // tab existente
{"id": -1, "name": "Details"}, // tab nuevo (ID negativo)
},
}
Campos actualizables
| Campo | Tipo | Descripcion |
|---|---|---|
| name | string | Nombre del dashboard |
| description | string | Descripcion |
| archived | bool | Archivar/desarchivar |
| dashcards | []map | Estado completo de cards |
| tabs | []map | Tabs del dashboard |
| parameters | []map | Filtros del dashboard |
| collection_id | int | Mover a otra coleccion |