Skip to content

Build your personal knowledge base with Trilium Notes

fix(client): SQL schemas loaded even when not needed

Elian Dorand690985b58f1
diff --git a/apps/client/src/widgets/sql_table_schemas.tsx b/apps/client/src/widgets/sql_table_schemas.tsx
index 3605c2f956..af8fd25c79 100644
--- a/apps/client/src/widgets/sql_table_schemas.tsx
+++ b/apps/client/src/widgets/sql_table_schemas.tsx
@@ -8,39 +8,44 @@ import Dropdown from "./react/Dropdown";
export default function SqlTableSchemas() {
const { note } = useNoteContext();
+
+ const isEnabled = note?.mime === "text/x-sqlite;schema=trilium";
+ return (
+ <div className={`sql-table-schemas-widget ${!isEnabled ? "hidden-ext" : ""}`}>
+ {isEnabled && <SqlTableSchemasContent />}
+ </div>
+ )
+}
+
+function SqlTableSchemasContent() {
const [ schemas, setSchemas ] = useState<SchemaResponse[]>();
useEffect(() => {
server.get<SchemaResponse[]>("sql/schema").then(setSchemas);
}, []);
- const isEnabled = note?.mime === "text/x-sqlite;schema=trilium" && schemas;
- return (
- <div className={`sql-table-schemas-widget ${!isEnabled ? "hidden-ext" : ""}`}>
- {isEnabled && (
- <>
- {t("sql_table_schemas.tables")}{": "}
+ return schemas && (
+ <>
+ {t("sql_table_schemas.tables")}{": "}
- <span class="sql-table-schemas">
- {schemas.map(({ name, columns }) => (
- <>
- <Dropdown text={name} noSelectButtonStyle hideToggleArrow
- >
- <table className="table-schema">
- {columns.map(column => (
- <tr>
- <td>{column.name}</td>
- <td>{column.type}</td>
- </tr>
- ))}
- </table>
- </Dropdown>
- {" "}
- </>
- ))}
- </span>
- </>
- )}
- </div>
+ <span className="sql-table-schemas">
+ {schemas.map(({ name, columns }) => (
+ <>
+ <Dropdown text={name} noSelectButtonStyle hideToggleArrow
+ >
+ <table className="table-schema">
+ {columns.map(column => (
+ <tr>
+ <td>{column.name}</td>
+ <td>{column.type}</td>
+ </tr>
+ ))}
+ </table>
+ </Dropdown>
+ {" "}
+ </>
+ ))}
+ </span>
+ </>
)
-}
\ No newline at end of file
+}