Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions gateway/sds_gateway/api_methods/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from blake3 import blake3 as Blake3 # noqa: N812
from django.conf import settings
from django.core.cache import cache
from django.db import models
from django.db.models import ProtectedError
from django.db.models import QuerySet
Expand Down Expand Up @@ -1386,7 +1387,14 @@ def handle_dataset_soft_delete(sender, instance: Dataset, **kwargs) -> None:
"""
Handle soft deletion of datasets by also
soft deleting related share permissions.
Also invalidates keywords autocomplete cache when datasets are created/updated.
"""
# Invalidate global keywords cache (since keywords are now from all users)
# This ensures autocomplete shows latest keywords when datasets change
# Cache key matches KeywordsAutocompleteView.CACHE_KEY in users/views.py
cache_key = "keywords_autocomplete_all_users"
cache.delete(cache_key)

if instance.is_deleted:
# This is a soft delete, so we need to soft delete related share permissions
# Soft delete all UserSharePermission records for this dataset
Expand Down
32 changes: 32 additions & 0 deletions gateway/sds_gateway/api_methods/serializers/dataset_serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Dataset serializers for the API methods."""

import json

from rest_framework import serializers

from sds_gateway.api_methods.models import Dataset
Expand All @@ -13,10 +15,40 @@ class DatasetGetSerializer(serializers.ModelSerializer[Dataset]):
is_shared_with_me = serializers.SerializerMethodField()
is_owner = serializers.SerializerMethodField()
status_display = serializers.CharField(source="get_status_display", read_only=True)
keywords = serializers.SerializerMethodField()

def get_authors(self, obj):
return obj.authors[0] if obj.authors else None

def get_keywords(self, obj):
"""
Return keywords as a clean list of strings, ready for frontend display.
Handles all formats: JSON string, list, or empty.
"""
if not obj.keywords:
return []

# If it's already a list (from from_db deserialization), return it
if isinstance(obj.keywords, list):
return [str(k).strip() for k in obj.keywords if k and str(k).strip()]

# If it's a string, try to parse it
if isinstance(obj.keywords, str):
trimmed = obj.keywords.strip()
if not trimmed:
return []

# Try to parse as JSON
try:
parsed = json.loads(trimmed)
if isinstance(parsed, list):
return [str(k).strip() for k in parsed if k and str(k).strip()]
except (json.JSONDecodeError, TypeError):
# If JSON parsing fails, treat as comma-separated string
return [k.strip() for k in trimmed.split(",") if k.strip()]

return []

def get_is_shared_with_me(self, obj):
"""Check if the dataset is shared with the current user."""
request = self.context.get("request")
Expand Down
56 changes: 56 additions & 0 deletions gateway/sds_gateway/static/css/components.css
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use css variables for colors; there's a file that defines them

Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,62 @@ body {
color: #000;
}

/* Keywords Autocomplete Dropdown */
.keywords-autocomplete-dropdown {
position: absolute;
top: 100%;
left: 0;
right: 0;
z-index: 9999;
background: white;
border: 1px solid #dee2e6;
border-radius: 0.375rem;
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
max-height: 200px;
overflow-y: auto;
margin-top: 0.25rem;
}

.keywords-autocomplete-dropdown .list-group-item {
border: none;
border-bottom: 1px solid #dee2e6;
cursor: pointer;
padding: 0.75rem 1.25rem;
}

.keywords-autocomplete-dropdown .list-group-item:last-child {
border-bottom: none;
}

.keywords-autocomplete-dropdown .list-group-item:hover {
background-color: #f8f9fa;
}

.keywords-autocomplete-dropdown .list-group-item:active {
background-color: #e9ecef;
}

.keywords-autocomplete-dropdown .list-group-item.selected {
background-color: #0d6efd;
color: white;
}

.keywords-autocomplete-dropdown .list-group-item.no-results {
padding: 0.75rem 1rem;
color: #6c757d;
font-style: italic;
text-align: center;
cursor: default;
}

.keywords-autocomplete-dropdown .list-group-item.no-results:hover {
background-color: transparent;
}

.keywords-suggestion {
font-size: 0.875rem;
}

/* Share Group Manager Specific Styles */
.selected-users-chips {
gap: 0.5rem;
Expand Down
17 changes: 17 additions & 0 deletions gateway/sds_gateway/static/js/actions/DetailsActionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ class DetailsActionManager {
".dataset-details-description",
datasetData.description || "No description provided",
);

// Update keywords display
// Keywords are now returned as a clean list from the backend
const keywordsValue =
Array.isArray(datasetData.keywords) && datasetData.keywords.length > 0
? datasetData.keywords.join(", ")
: "No keywords provided";
this.updateElementText(modal, ".dataset-details-keywords", keywordsValue);

this.updateElementText(
modal,
".dataset-details-status",
Expand Down Expand Up @@ -930,6 +939,14 @@ class DetailsActionManager {
}
}

/**
* Format keywords for display
* @param {Array|string} keywords - Keywords as array or string
* @returns {string} Formatted keywords as comma-separated string
*/
// formatKeywords method removed - keywords are now formatted on the backend
// Backend returns keywords as a clean array of strings, so we just join them

/**
* Initialize details buttons for dynamically loaded content
* @param {Element} container - Container element to search within
Expand Down
Loading