mirror of
https://github.com/sartography/spiff-arena.git
synced 2025-01-27 17:55:04 +00:00
Add support for KKV data stores to the data stores tab (#576)
This commit is contained in:
parent
ffaaf03f97
commit
16ae1d9ccd
@ -6,6 +6,7 @@ from flask import make_response
|
|||||||
|
|
||||||
from spiffworkflow_backend import db
|
from spiffworkflow_backend import db
|
||||||
from spiffworkflow_backend.exceptions.api_error import ApiError
|
from spiffworkflow_backend.exceptions.api_error import ApiError
|
||||||
|
from spiffworkflow_backend.models.kkv_data_store import KKVDataStoreModel
|
||||||
from spiffworkflow_backend.models.typeahead import TypeaheadModel
|
from spiffworkflow_backend.models.typeahead import TypeaheadModel
|
||||||
|
|
||||||
|
|
||||||
@ -13,11 +14,15 @@ def data_store_list() -> flask.wrappers.Response:
|
|||||||
"""Returns a list of the names of all the data stores."""
|
"""Returns a list of the names of all the data stores."""
|
||||||
data_stores = []
|
data_stores = []
|
||||||
|
|
||||||
# Right now the only data store we support is type ahead
|
# Right now the only data stores we support are type ahead and kkv
|
||||||
|
|
||||||
for cat in db.session.query(TypeaheadModel.category).distinct().order_by(TypeaheadModel.category): # type: ignore
|
for cat in db.session.query(TypeaheadModel.category).distinct().order_by(TypeaheadModel.category): # type: ignore
|
||||||
data_stores.append({"name": cat[0], "type": "typeahead"})
|
data_stores.append({"name": cat[0], "type": "typeahead"})
|
||||||
|
|
||||||
|
keys = db.session.query(KKVDataStoreModel.top_level_key).distinct().order_by(KKVDataStoreModel.top_level_key) # type: ignore
|
||||||
|
for key in keys:
|
||||||
|
data_stores.append({"name": key[0], "type": "kkv"})
|
||||||
|
|
||||||
return make_response(jsonify(data_stores), 200)
|
return make_response(jsonify(data_stores), 200)
|
||||||
|
|
||||||
|
|
||||||
@ -44,5 +49,27 @@ def data_store_item_list(
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
return make_response(jsonify(response_json), 200)
|
return make_response(jsonify(response_json), 200)
|
||||||
else:
|
|
||||||
|
if data_store_type == "kkv":
|
||||||
|
data_store_query = KKVDataStoreModel.query.filter_by(top_level_key=name).order_by(
|
||||||
|
KKVDataStoreModel.top_level_key, KKVDataStoreModel.secondary_key
|
||||||
|
)
|
||||||
|
data = data_store_query.paginate(page=page, per_page=per_page, error_out=False)
|
||||||
|
results = []
|
||||||
|
for kkv in data.items:
|
||||||
|
result = {
|
||||||
|
"secondary_key": kkv.secondary_key,
|
||||||
|
"value": kkv.value,
|
||||||
|
}
|
||||||
|
results.append(result)
|
||||||
|
response_json = {
|
||||||
|
"results": results,
|
||||||
|
"pagination": {
|
||||||
|
"count": len(data.items),
|
||||||
|
"total": data.total,
|
||||||
|
"pages": data.pages,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return make_response(jsonify(response_json), 200)
|
||||||
|
|
||||||
raise ApiError("unknown_data_store", f"Unknown data store type: {data_store_type}", status_code=400)
|
raise ApiError("unknown_data_store", f"Unknown data store type: {data_store_type}", status_code=400)
|
||||||
|
@ -36,7 +36,6 @@ export default function DataStoreList() {
|
|||||||
1,
|
1,
|
||||||
'datastore'
|
'datastore'
|
||||||
);
|
);
|
||||||
console.log();
|
|
||||||
const dataStoreType = searchParams.get('type') || '';
|
const dataStoreType = searchParams.get('type') || '';
|
||||||
const dataStoreName = searchParams.get('name') || '';
|
const dataStoreName = searchParams.get('name') || '';
|
||||||
|
|
||||||
@ -60,12 +59,24 @@ export default function DataStoreList() {
|
|||||||
});
|
});
|
||||||
}, [dataStores, searchParams]);
|
}, [dataStores, searchParams]);
|
||||||
|
|
||||||
|
const getCell = (value: any) => {
|
||||||
|
const valueToUse =
|
||||||
|
typeof value === 'object' ? (
|
||||||
|
<pre>
|
||||||
|
<code>{JSON.stringify(value, null, 4)}</code>
|
||||||
|
</pre>
|
||||||
|
) : (
|
||||||
|
value
|
||||||
|
);
|
||||||
|
|
||||||
|
return <TableCell>{valueToUse}</TableCell>;
|
||||||
|
};
|
||||||
|
|
||||||
const getTable = () => {
|
const getTable = () => {
|
||||||
if (results.length === 0) {
|
if (results.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const firstResult = results[0];
|
const firstResult = results[0];
|
||||||
console.log('Results', results);
|
|
||||||
const tableHeaders: any[] = [];
|
const tableHeaders: any[] = [];
|
||||||
const keys = Object.keys(firstResult);
|
const keys = Object.keys(firstResult);
|
||||||
keys.forEach((key) => tableHeaders.push(<TableHeader>{key}</TableHeader>));
|
keys.forEach((key) => tableHeaders.push(<TableHeader>{key}</TableHeader>));
|
||||||
@ -80,7 +91,7 @@ export default function DataStoreList() {
|
|||||||
return (
|
return (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
{keys.map((key) => {
|
{keys.map((key) => {
|
||||||
return <TableCell>{object[key]}</TableCell>;
|
return getCell(object[key]);
|
||||||
})}
|
})}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user