Skip to content

Commit

Permalink
feat: finish table structure
Browse files Browse the repository at this point in the history
  • Loading branch information
invm committed Aug 25, 2023
1 parent f6d1207 commit 9cf248e
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 40 deletions.
2 changes: 2 additions & 0 deletions src-tauri/src/database/engine/mysql/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub async fn get_columns(
let mut _conn = pool.get_conn()?;
let query = format!(
"SELECT
TABLE_SCHEMA,
TABLE_NAME,
COLUMN_NAME,
COLUMN_TYPE,
DATA_TYPE,
Expand Down
23 changes: 22 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,32 @@ import "tabulator-tables/dist/css/tabulator_midnight.min.css";
import "solid-command-palette/pkg-dist/style.css";
import { Main } from "components/Screens/Main";
import { CommandPaletteContext } from "components/CommandPalette/CommandPaletteContext";
import { Loader } from "components/UI";
import { createEffect, createSignal, onMount } from "solid-js";

function App() {
const [loading, setLoading] = createSignal(true);

createEffect(() => {
setTimeout(() => {
setLoading(false);
}, 500);
});

onMount(async () => {
const theme = localStorage.getItem("theme") || "dark";
document.documentElement.dataset.theme = theme;
});

return (
<CommandPaletteContext>
<Main />
{loading() ? (
<div class="flex justify-center items-center h-full bg-base-100 w-full">
<Loader />
</div>
) : (
<Main />
)}
</CommandPaletteContext>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/CommandPalette/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const focusQueryTextArea = defineAction({
title: t("command_palette.focus_query_text_area"),
parentActionId: focusOn.id,
/* Condition for allowing action */
// shortcut: "$mod+e", // $mod = Command on Mac & Control on Windows.
shortcut: "$mod+d", // $mod = Command on Mac & Control on Windows.
run: () => {
commandPaletteEmitter.emit("focus-query-text-area", true);
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/Screens/Console/Content/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useAppSelector } from "services/Context";
import { AddIcon, CloseIcon } from "components/UI/Icons";
import { t } from "utils/i18n";
import { QueryTab } from "./QueryTab/QueryTab";
import { TableStructureTab } from "./TableStructureTab";
import { TableStructureTab } from "./TableStructure/TableStructureTab"
import { ContentComponent, newContentTab} from "services/ConnectionTabs";

export const Content = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Screens/Console/Content/QueryTab/QueryTab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Table } from "./Table";
import { ResultsTable } from "./ResultesTable";
import { QueryContentTabData } from "services/ConnectionTabs";
import { useAppSelector } from "services/Context";
import { createEffect, createSignal, onCleanup, Show } from "solid-js";
Expand Down Expand Up @@ -38,7 +38,7 @@ export const QueryTab = () => {
</div>
<div id="results">
<Show when={data().length}>
<Table data={data()} />
<ResultsTable data={data()} />
</Show>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const QueryTextArea = () => {
} catch (error) {
setActiveContentQueryTabMessage("error", error);
}
updateStore()
};

createEffect(() => {
Expand All @@ -93,7 +94,7 @@ export const QueryTextArea = () => {
const handleKeyDown = async (e: KeyboardEvent) => {
if (e.key === "f" && e.ctrlKey) {
onFormat();
} else if (e.key === "e" && e.ctrlKey) {
} else if ((e.metaKey || e.ctrlKey) && (e.key === 'Enter' || e.key === "e")) {
await onExecute();
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createEffect } from "solid-js";
import { TabulatorFull as Tabulator } from "tabulator-tables";

export const Table = (props: { data: Record<string, any>[] }) => {
export const ResultsTable = (props: { data: Record<string, any>[] }) => {
createEffect(() => {
if (!props.data.length) return;
const columns = Object.keys(props.data[0]).map((k) => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
import { useAppSelector } from "services/Context";
import {
createEffect,
createSignal,
For,
Match,
onMount,
Switch,
} from "solid-js";
import { createSignal, For, Match, onMount, Switch } from "solid-js";
import { invoke } from "@tauri-apps/api";
import { TableStructureResult } from "interfaces";
import { t } from "utils/i18n";
import { Loader } from "components/UI";
import { createStore } from "solid-js/store";
import { Table } from "./TableStructure/Tabs/Table";
import { StructureTable } from "./Tabs/StructureTable";
import { TableStructureContentTabData } from "services/ConnectionTabs";

export const TableStructureTab = () => {
const {
connectionsService: {
getActiveConnection,
getActiveContentTab
},
connectionsService: { getActiveConnection, getActiveContentTab },
errorService: { addError },
} = useAppSelector();
const [loading, setLoading] = createSignal(true);
Expand All @@ -31,13 +22,12 @@ export const TableStructureTab = () => {

onMount(async () => {
const activeConnection = getActiveConnection();
const activeTab = getActiveContentTab()
console.log(activeTab)
const activeTab = getActiveContentTab();
try {
const { columns, indices, triggers, constraints } =
await invoke<TableStructureResult>("get_table_structure", {
connId: activeConnection.id,
tableName: "app",
tableName: (activeTab.data as TableStructureContentTabData).table,
});
setData({ columns, indices, triggers, constraints });
} catch (error) {
Expand Down Expand Up @@ -73,7 +63,7 @@ export const TableStructureTab = () => {
<For each={tabs}>
{(item, idx) => (
<Match when={tabIdx() === idx()}>
<Table data={data[item]} />
<StructureTable data={data[item]} />
</Match>
)}
</For>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export const Table = (props: { data: Record<string, any>[] }) => {
console.log(props.data);
const columns = Object.keys(props.data[0]);
export const StructureTable = (props: { data: Record<string, any>[] }) => {
const columns = props.data.length ? Object.keys(props.data[0]) : [];
const rows = props.data.map((row) => Object.values(row));
return (
<div class="overflow-x-auto">
Expand Down
5 changes: 3 additions & 2 deletions src/components/Screens/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const Main = () => {
const {
connectionsService: {
removeTab,
// clearStore,
clearStore,
connectionStore,
setConnectionStore,
},
Expand Down Expand Up @@ -61,7 +61,8 @@ export const Main = () => {
</For>
</div>
<div>
{/*<button onClick={async () => await clearStore()}>Reset store</button> */}
{/**/}
<button onClick={async () => await clearStore()}>Reset store</button>
<ThemeSwitch />
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/UI/Loader.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const Loader = () => {
return <span class="loading text-primary loading-bars loading-lg"></span>;
return <span class="loading text-primary loading-bars loading-xl"></span>;
};
6 changes: 0 additions & 6 deletions src/components/UI/ThemeSwitch.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
import { For, Show } from "solid-js";
import { titleCase } from "../../utils/formatters";
const THEMES = [
"light",
"dark",
"aqua",
"synthwave",
"dracula",
"night",
"cupcake",
] as const;
import { onMount } from "solid-js";
import { t } from "i18next";
import { useAppSelector } from "services/Context";

export const ThemeSwitch = () => {
const {
appService: { appStore },
} = useAppSelector();
onMount(async () => {
const theme = localStorage.getItem("theme") || "dark";
document.documentElement.dataset.theme = theme;
});

const select = (theme: (typeof THEMES)[number]) => {
document.documentElement.dataset.theme = theme;
Expand Down
4 changes: 4 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,7 @@ dialog {
.solid-contextmenu {
box-shadow: none;
}

.loading-xl {
width: 6rem;
}
19 changes: 16 additions & 3 deletions src/services/ConnectionTabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,16 @@ export const ConnectionTabsService = () => {

const updateStore = debounce(async () => {
await store.set(CONNECTIONS_TABS_KEY, JSON.stringify(connectionStore));
await store.set(CONTENT_TABS_KEY, JSON.stringify(contentStore));
const contentStoreTabs = contentStore.tabs.map((t) => {
if (t.key === ContentComponent.QueryTab) {
return { ...t, data: { ...t.data, results: [] } };
}
return t;
});
await store.set(
CONTENT_TABS_KEY,
JSON.stringify({ ...contentStore, tabs: contentStoreTabs })
);
await store.save();
}, 1000);

Expand Down Expand Up @@ -177,7 +186,9 @@ export const ConnectionTabsService = () => {
return contentStore.tabs[contentStore.idx];
};

const setActiveContentTableStructureTabData = (data: TableStructureContentTabData) => {
const setActiveContentTableStructureTabData = (
data: TableStructureContentTabData
) => {
const tab = getActiveContentTab();
if (!tab) return;
setContentStore(
Expand Down Expand Up @@ -223,7 +234,9 @@ export const ConnectionTabsService = () => {
setContentStore(
"tabs",
contentStore.tabs.map((t, i) =>
i === contentStore.idx ? { ...t, error: { type, message: String(message) } } : t
i === contentStore.idx
? { ...t, error: { type, message: String(message) } }
: t
)
);
};
Expand Down
2 changes: 1 addition & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default {
require("daisyui")
],
daisyui: {
themes: ["light", "dark", "aqua", "synthwave", "dracula", "night", "cupcake"], // true: all themes | false: only light + dark | array: specific themes like this ["light", "dark", "cupcake"]
themes: ["dark", "aqua", "synthwave", "dracula", "night", "cupcake"], // true: all themes | false: only + dark | array: specific themes like this ["light", "dark", "cupcake"]
darkTheme: "dark", // name of one of the included themes for dark mode
base: true, // applies background color and foreground color for root element by default
styled: true, // include daisyUI colors and design decisions for all components
Expand Down

0 comments on commit 9cf248e

Please sign in to comment.