Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,5 @@ docker/*local*
test-report.html
superset/static/stats/statistics.html
.aider*

.cursor
25 changes: 16 additions & 9 deletions superset-frontend/src/components/Tags/TagsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,29 @@ const TagsList = ({

const collapse = () => setTempMaxTags(maxTags);

// Sort tags alphabetically by name (case-insensitive) with memoization
const sortedTags = useMemo(() => {
return [...tags].sort((a, b) =>
a.name.toLowerCase().localeCompare(b.name.toLowerCase())
);
}, [tags]);

const tagsIsLong: boolean | null = useMemo(
() => (tempMaxTags ? tags.length > tempMaxTags : null),
[tags.length, tempMaxTags],
() => (tempMaxTags ? sortedTags.length > tempMaxTags : null),
[sortedTags.length, tempMaxTags],
);

const extraTags: number | null = useMemo(
() =>
typeof tempMaxTags === 'number' ? tags.length - tempMaxTags + 1 : null,
[tagsIsLong, tags.length, tempMaxTags],
typeof tempMaxTags === 'number' ? sortedTags.length - tempMaxTags + 1 : null,
[tagsIsLong, sortedTags.length, tempMaxTags],
);

return (
<TagsDiv className="tag-list">
{tagsIsLong && typeof tempMaxTags === 'number' ? (
<>
{tags.slice(0, tempMaxTags - 1).map((tag: TagType, index) => (
{sortedTags.slice(0, tempMaxTags - 1).map((tag: TagType, index) => (
<Tag
id={tag.id}
key={tag.id}
Expand All @@ -82,17 +89,17 @@ const TagsList = ({
editable={editable}
/>
))}
{tags.length > tempMaxTags ? (
{sortedTags.length > tempMaxTags ? (
<Tag
name={`+${extraTags}...`}
onClick={expand}
toolTipTitle={tags.map(t => t.name).join(', ')}
toolTipTitle={sortedTags.map(t => t.name).join(', ')}
/>
) : null}
</>
) : (
<>
{tags.map((tag: TagType, index) => (
{sortedTags.map((tag: TagType, index) => (
<Tag
id={tag.id}
key={tag.id}
Expand All @@ -103,7 +110,7 @@ const TagsList = ({
/>
))}
{maxTags ? (
tags.length > maxTags ? (
sortedTags.length > maxTags ? (
<Tag name="..." onClick={collapse} />
) : null
) : null}
Expand Down