return attribute labels in /all/attributes endpoint
parent
b6e5368a6c
commit
376d929232
|
@ -565,9 +565,36 @@ pub async fn delete_object(
|
|||
#[get("/api/all/attributes")]
|
||||
pub async fn get_all_attributes(state: web::Data<State>) -> Result<HttpResponse, Error> {
|
||||
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
|
||||
let result = web::block(move || connection.get_all_attributes())
|
||||
let attributes = web::block(move || connection.get_all_attributes())
|
||||
.await
|
||||
.map_err(ErrorInternalServerError)?;
|
||||
|
||||
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
|
||||
let result: serde_json::Value = attributes
|
||||
.into_iter()
|
||||
.map(|attribute| {
|
||||
json!({
|
||||
"name": attribute,
|
||||
"labels": connection
|
||||
.retrieve_object(&Address::Attribute(attribute))
|
||||
.unwrap_or_else(|_| vec![])
|
||||
.into_iter()
|
||||
.filter_map(|e| {
|
||||
if e.attribute == LABEL_ATTR {
|
||||
if let EntryValue::String(label) = e.value {
|
||||
Some(label)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<Vec<String>>(),
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(HttpResponse::Ok().json(result))
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,11 @@ export type PutResult = [string | undefined, string];
|
|||
|
||||
// export type OrderedListing = [Address, IEntry][];
|
||||
|
||||
export type AttributeListingResult = Array<{
|
||||
name: string;
|
||||
labels: string[];
|
||||
}>;
|
||||
|
||||
export interface IFile {
|
||||
hash: string;
|
||||
path: string;
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
case "attribute": {
|
||||
const allAttributes = await fetchAllAttributes();
|
||||
options = allAttributes
|
||||
.map((attr) => attr.name)
|
||||
.filter((attr) => attr.toLowerCase().includes(query.toLowerCase()))
|
||||
.map((attribute) => {
|
||||
return {
|
||||
|
|
|
@ -9,6 +9,7 @@ import type {
|
|||
PutResult,
|
||||
VaultInfo,
|
||||
StoreInfo,
|
||||
AttributeListingResult,
|
||||
} from "upend/types";
|
||||
import type { EntityListing } from "./entity";
|
||||
|
||||
|
@ -117,7 +118,7 @@ export async function fetchJobs(): Promise<IJob[]> {
|
|||
return await response.json();
|
||||
}
|
||||
|
||||
export async function fetchAllAttributes(): Promise<string[]> {
|
||||
export async function fetchAllAttributes(): Promise<AttributeListingResult> {
|
||||
const response = await fetch("api/all/attributes");
|
||||
return await response.json();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue