Skip to content

Commit

Permalink
automaticly sort
Browse files Browse the repository at this point in the history
  • Loading branch information
BaseMax committed Nov 30, 2024
1 parent f22e839 commit 8cc83ef
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions config/admin/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,37 @@


def get_dynamic_columns(data):
""" Extract unique keys from the YAML structure for dynamic columns """
"""
Extract unique keys from the YAML structure for dynamic columns.
Ensure:
- 'id' is the first item if it exists.
- 'text' is the last item if it exists.
- The resulting list contains unique values in the desired order.
"""
columns = set()

if isinstance(data, dict):
for item in data.get('items', []):
for key in item:
columns.add(key)
if isinstance(item, dict):
columns.update(item.keys())

columns = list(columns)

start = 0
if 'id' in columns:
columns.remove('id')
columns.insert(0, 'id')
start += 1

return list(columns)
if 'type' in columns:
columns.remove('type')
columns.insert(start, 'type')

if 'text' in columns:
columns.remove('text')
columns.append('text')

return columns


def get_language_keys() -> list[str]:
Expand Down

0 comments on commit 8cc83ef

Please sign in to comment.