Skip to content

Commit

Permalink
fix: sorting the table by name
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed Oct 1, 2024
1 parent 58226fe commit b6cb386
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/components/gui/schema-sidebar-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ function groupByFtsTable(items: ListViewItem<DatabaseSchemaItem>[]) {
return items.filter((item) => !excludes.has(item.data.name));
}

function sortTable(items: ListViewItem<DatabaseSchemaItem>[]) {
return items.sort((a, b) => a.name.localeCompare(b.name));
}

function flattenSchemaGroup(
schemaGroup: ListViewItem<DatabaseSchemaItem>[]
): ListViewItem<DatabaseSchemaItem>[] {
Expand Down Expand Up @@ -154,17 +158,19 @@ export default function SchemaList({ search }: Readonly<SchemaListProps>) {
);

const listViewItems = useMemo(() => {
const r = Object.entries(schema).map(([s, tables]) => {
return {
data: { type: "schema", schemaName: s },
icon: LucideDatabase,
name: s,
key: s.toString(),
children: groupByFtsTable(
groupTriggerByTable(prepareListViewItem(tables))
),
} as ListViewItem<DatabaseSchemaItem>;
});
const r = sortTable(
Object.entries(schema).map(([s, tables]) => {
return {
data: { type: "schema", schemaName: s },
icon: LucideDatabase,
name: s,
key: s.toString(),
children: sortTable(
groupByFtsTable(groupTriggerByTable(prepareListViewItem(tables)))
),
} as ListViewItem<DatabaseSchemaItem>;
})
);

if (databaseDriver.getFlags().optionalSchema) {
// For SQLite, the default schema is main and
Expand Down

0 comments on commit b6cb386

Please sign in to comment.