feat(0036b): NodeGroups admite kind=Group + loader entities
NodeGroupsWindowState gana un discriminador `kind` (Table | Group) y
un flag `focus_request` (lo consumira 0036c). Por defecto Table, asi
que el flujo historico (DuckDB rows tras expand de un nodo Table) no
cambia.
kind=Group lee directamente operations.db consultando
`entities WHERE group_id = container_id` con columnas fijas
(id, name, type_ref, status, updated_at) ordenadas por updated_at DESC.
Los nuevos loaders viven en node_groups.cpp:
- node_groups_count_for_group -> SELECT count(*) ...
- node_groups_page_for_group -> SELECT id,name,type_ref,status,
updated_at ... LIMIT ? OFFSET ?
Para columnas, opcion (A) del issue: pre-popular meta.columns con la
lista fija al abrir kind=Group, asi el render se mantiene generico.
NodeGroupsRow.values guarda los 5 campos en ese orden y row.id es la
key natural (= entity_id de la fila — al ser ya entidad, no hace falta
promocionarla).
Render en views.cpp ramifica por kind:
- Table: layout original [id_col + columns + promoted] con doble
click -> promote/focus.
- Group: layout [columns fijas] sin promoted. Doble click sobre la
fila ya pone want_focus_entity = id (los flujos posteriores 0036c-e
afinan UX). Right click ofrece "Focus in Inspector".
main.cpp dispatcha por kind al refrescar paginas y, al cerrar via X,
solo llama a node_groups_set_expanded para kind=Table (Group no usa
ese flag).
views_node_groups_windows_sync se hace kind-aware: solo reconcilia
entries kind=Table contra el set de Tables expandidas; no toca las
entries kind=Group (las gestiona views_node_groups_open).
Nueva API publica:
views_node_groups_open(app, container_id, kind, ops_db)
Crea o reusa la entry, setea focus_request=true y para kind=Group
pre-popula meta.columns + intenta leer `name` del Group para el
titulo. Sin caller todavia — la consume 0036c.
Tests:
- tests/test_node_groups_loader.py (6 tests) verifica el contrato
SQL via gx-cli. Nuevo subcomando `gx-cli group page <id>` espejea
el loader C++ exactamente (mismo SQL); tambien expuesto como tool
MCP `group_page` para que Echo pueda inspeccionar Groups.
Resultado:
- WSL: 89 -> 95 passed
- Windows: 78+11 -> 84+11 passed
- Build C++ Windows limpio, sin warnings nuevos.
- Regresion kind=Table: comportamiento identico (mismo render,
mismo loader DuckDB).
Refs: issues/0036b-kind-discriminator-and-group-loader.md
This commit is contained in:
@@ -807,4 +807,93 @@ bool node_groups_ingest_file(const char* duckdb_path,
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Issue 0036b — kind=Group loaders sobre operations.db
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool node_groups_count_for_group(const char* ops_db,
|
||||
const char* container_id,
|
||||
int64_t* out_total)
|
||||
{
|
||||
if (!ops_db || !container_id || !out_total) return false;
|
||||
*out_total = 0;
|
||||
sqlite3* db = nullptr;
|
||||
if (sqlite3_open_v2(ops_db, &db, SQLITE_OPEN_READONLY, nullptr) != SQLITE_OK) {
|
||||
if (db) sqlite3_close(db);
|
||||
return false;
|
||||
}
|
||||
const char* sql = "SELECT count(*) FROM entities WHERE group_id = ?";
|
||||
sqlite3_stmt* st = nullptr;
|
||||
if (sqlite3_prepare_v2(db, sql, -1, &st, nullptr) != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
return false;
|
||||
}
|
||||
sqlite3_bind_text(st, 1, container_id, -1, SQLITE_TRANSIENT);
|
||||
bool ok = false;
|
||||
if (sqlite3_step(st) == SQLITE_ROW) {
|
||||
*out_total = sqlite3_column_int64(st, 0);
|
||||
ok = true;
|
||||
}
|
||||
sqlite3_finalize(st);
|
||||
sqlite3_close(db);
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool node_groups_page_for_group(const char* ops_db,
|
||||
const char* container_id,
|
||||
int64_t offset, int64_t limit,
|
||||
std::vector<NodeGroupsRow>* out_rows)
|
||||
{
|
||||
if (!ops_db || !container_id || !out_rows) return false;
|
||||
out_rows->clear();
|
||||
if (limit < 1) limit = 1;
|
||||
if (limit > 5000) limit = 5000;
|
||||
|
||||
sqlite3* db = nullptr;
|
||||
if (sqlite3_open_v2(ops_db, &db, SQLITE_OPEN_READONLY, nullptr) != SQLITE_OK) {
|
||||
if (db) sqlite3_close(db);
|
||||
return false;
|
||||
}
|
||||
// Columnas fijas: id, name, type_ref, status, updated_at — el orden
|
||||
// espejea la lista que pre-pobla views_node_groups_open() en meta.columns
|
||||
// para que el render se mantenga generico.
|
||||
const char* sql =
|
||||
"SELECT id, name, type_ref, status, updated_at "
|
||||
"FROM entities WHERE group_id = ? "
|
||||
"ORDER BY updated_at DESC "
|
||||
"LIMIT ? OFFSET ?";
|
||||
sqlite3_stmt* st = nullptr;
|
||||
if (sqlite3_prepare_v2(db, sql, -1, &st, nullptr) != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
return false;
|
||||
}
|
||||
sqlite3_bind_text (st, 1, container_id, -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_int64(st, 2, limit);
|
||||
sqlite3_bind_int64(st, 3, offset);
|
||||
while (sqlite3_step(st) == SQLITE_ROW) {
|
||||
NodeGroupsRow row;
|
||||
auto col_text = [&](int i) -> std::string {
|
||||
const unsigned char* p = sqlite3_column_text(st, i);
|
||||
return p ? std::string((const char*)p) : std::string();
|
||||
};
|
||||
// id va en NodeGroupsRow.id (key natural) y tambien en values[0]
|
||||
// para que el render pinte la columna "id" igual que las demas.
|
||||
row.id = col_text(0);
|
||||
row.values.reserve(5);
|
||||
row.values.push_back(row.id); // id
|
||||
row.values.push_back(col_text(1)); // name
|
||||
row.values.push_back(col_text(2)); // type_ref
|
||||
row.values.push_back(col_text(3)); // status
|
||||
row.values.push_back(col_text(4)); // updated_at
|
||||
// promoted_entity_id no aplica en kind=Group — la fila YA es una
|
||||
// entidad real del grafo, asi que la dejamos vacia (el render
|
||||
// mostrara "-" en la columna 'promoted', que ocultamos para Group
|
||||
// mas abajo en views.cpp).
|
||||
out_rows->push_back(std::move(row));
|
||||
}
|
||||
sqlite3_finalize(st);
|
||||
sqlite3_close(db);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace ge
|
||||
|
||||
Reference in New Issue
Block a user