Compareware/src/models/item.rs
ryan 486bf9cbad feat(typeahead): update structure and enhance Typeahead integration and logging:
- Bloodhound Initialization:
  - Changed the suggestion object structure to a flattened format for Typeahead compatibility.
  - Removed nested `display` structure in favor of direct `displayLabel` and `displayDescription` fields.
  - Simplified the construction of suggestion objects by directly setting flattened fields.

- Typeahead Initialization:
  - Enhanced logging in the JavaScript initialization script for better debugging.
  - Updated the `display` function in Typeahead to use flattened fields (`displayLabel` and `displayDescription`) instead of nested `display` objects.
  - Improved error handling and logging for cases where suggestions are not arrays or are empty.

- Selection Handling:
  - Added detailed logging for selected suggestions in both Rust and JavaScript.
  - Ensured the input field is updated with the selected suggestion's label.

- Code Cleanup:
  - Removed redundant nested object creation for `display` fields in Bloodhound initialization.
  - Streamlined the JavaScript initialization script for better readability and maintainability.
  - Consolidated logging statements for consistent debugging output.
2025-04-14 17:42:04 +03:00

49 lines
No EOL
1.4 KiB
Rust

/// Represents an Item in CompareWare.
/// Each item has metadata and key-value tags for categorization.
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Item {
pub id: String,
pub name: String,
pub description: String,
pub wikidata_id: Option<String>,
pub custom_properties: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct WikidataSuggestion {
pub id: String,
#[serde(default)]
pub label: String,
#[serde(default)]
pub description: String,
#[serde(default)]
pub title: String,
#[serde(default, rename = "display")]
pub display: DisplayInfo,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
pub struct DisplayInfo {
#[serde(default, rename = "label")]
pub label: LabelInfo,
#[serde(default, rename = "description")]
pub description: DescriptionInfo,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
pub struct LabelInfo {
#[serde(default, rename = "value")]
pub value: String,
#[serde(default, rename = "language")]
pub language: String,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
pub struct DescriptionInfo {
#[serde(default, rename = "value")]
pub value: String,
#[serde(default, rename = "language")]
pub language: String,
}