Skip to content

Database diagrams editor that allows you to visualize and design your DB with a single query.

fix: show default schema first (#854)

Guy Ben-Aharon1759b0b9f271
diff --git a/src/context/chartdb-context/chartdb-provider.tsx b/src/context/chartdb-context/chartdb-provider.tsx
index 58a3b20f..78d5404a 100644
--- a/src/context/chartdb-context/chartdb-provider.tsx
+++ b/src/context/chartdb-context/chartdb-provider.tsx
@@ -89,7 +89,10 @@ export const ChartDBProvider: React.FC<
diffEvents.useSubscription(diffCalculatedHandler);
- const defaultSchemaName = defaultSchemas[databaseType];
+ const defaultSchemaName = useMemo(
+ () => defaultSchemas[databaseType],
+ [databaseType]
+ );
const readonly = useMemo(
() => readonlyProp ?? hasDiff ?? false,
@@ -110,9 +113,11 @@ export const ChartDBProvider: React.FC<
.filter((schema) => !!schema) as string[]
),
]
- .sort((a, b) =>
- a === defaultSchemaName ? -1 : a.localeCompare(b)
- )
+ .sort((a, b) => {
+ if (a === defaultSchemaName) return -1;
+ if (b === defaultSchemaName) return 1;
+ return a.localeCompare(b);
+ })
.map(
(schema): DBSchema => ({
id: schemaNameToSchemaId(schema),