Skip to content

Commit

Permalink
feat: add keymaps component
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ionov committed Dec 28, 2023
1 parent d64ad37 commit 4761a78
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 35 deletions.
35 changes: 18 additions & 17 deletions src/components/CommandPalette/CommandPaletteContext.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
import { actions } from "./actions";
import { useAppSelector } from "services/Context";
import { CommandPalette, Root } from "solid-command-palette";
import { JSX } from "solid-js/jsx-runtime";
import { createShortcut } from "@solid-primitives/keyboard";
import { actions } from './actions';
import { useAppSelector } from 'services/Context';
import { CommandPalette, Root } from 'solid-command-palette';
import { JSX } from 'solid-js/jsx-runtime';
import { createShortcut } from '@solid-primitives/keyboard';

export interface ActionsContext {
[key: string]: unknown;
}

export const CommandPaletteContext = (props: { children: JSX.Element }) => {
const {
connections: {
addContentTab,
removeContentTab,
setContentIdx,
setConnectionIdx,
},
connections: { addContentTab, removeContentTab, setContentIdx, contentStore },
} = useAppSelector();

const actionsContext: ActionsContext = {};

for (let i = 0; i < 9; i++) {
createShortcut(["Alt", String(i)], () => setContentIdx(i - 1));
createShortcut(["Control", String(i)], () => setConnectionIdx(i - 1));
}
createShortcut(['Meta', 'w'], () => {
removeContentTab(contentStore.idx);
});

createShortcut(['Meta', 't'], () => {
addContentTab();
});

createShortcut(["Control", "T"], () => addContentTab());
createShortcut(["Control", "Shift", "T"], () => removeContentTab());
for (let i = 1; i <= 9; i++) {
createShortcut(['Meta', String(i)], () => {
setContentIdx(i - 1);
});
}

return (
<Root actions={actions} actionsContext={actionsContext}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Screens/Console/Console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const Console = () => {
createEffect(() => {
const s = Split(["#sidebar", "#main"], {
sizes: [20, 80],
minSize: [100, 200],
minSize: [200, 200],
maxSize: [400, Infinity],
gutterSize: 4,
});
Expand Down
15 changes: 0 additions & 15 deletions src/components/Screens/Console/Content/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,12 @@ import { AddIcon, CloseIcon } from 'components/UI/Icons';
import { QueryTab } from './QueryTab/QueryTab';
import { TableStructureTab } from './TableStructure/TableStructureTab';
import { ContentTab } from 'services/Connections';
import { createShortcut } from '@solid-primitives/keyboard';

export const Content = () => {
const {
connections: { contentStore, setContentIdx, addContentTab, removeContentTab },
} = useAppSelector();

createShortcut(['Meta', 'w'], () => {
removeContentTab(contentStore.idx);
});

createShortcut(['Meta', 't'], () => {
addContentTab();
});

for (let i = 1; i <= 9; i++) {
createShortcut(['Meta', String(i)], () => {
setContentIdx(i - 1);
});
}

return (
<div class="flex flex-col h-full">
<div class="bg-base-300 tabs gap-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { QueryTextArea } from "./QueryTextArea";

export const QueryTab = () => {
createEffect(() => {
// TODO: fix this, results table height changes between results sets
const q = Split(["#query", "#results"], {
sizes: [30, 70],
minSize: [200, 400],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { createCodeMirror, createEditorControlledValue } from 'solid-codemirror'
import { Pagination } from './components/Pagination';
import { useAppSelector } from 'services/Context';
import { Row } from 'interfaces';
import Keymaps from 'components/UI/Keymaps';

type TableColumn = { title: string; field: string; resizeable: boolean };

Expand Down Expand Up @@ -78,7 +79,7 @@ export const ResultsTable = () => {

createEffect(updateRows);

createEffect(async () => {
createEffect(() => {
let columns: TableColumn[] = [];
if (rows().length) {
columns = Object.keys(rows()[0]).map((k) => ({
Expand All @@ -91,6 +92,8 @@ export const ResultsTable = () => {

new Tabulator('#results-table', {
data: rows(),
placeholder: <Keymaps /> as HTMLElement,
// autoColumns: true,
columns,
columnDefaults: {
title: '',
Expand All @@ -99,8 +102,10 @@ export const ResultsTable = () => {
layout: 'fitDataStretch',
autoResize: true,
clipboard: true,
renderHorizontal: 'virtual',
pagination: false,
maxHeight: '100%',
minHeight: '100%',
height: '100%',
paginationCounter: 'rows',
debugInvalidOptions: false,
Expand Down Expand Up @@ -138,6 +143,7 @@ export const ResultsTable = () => {
// navRight: ["ctrl + shift + l", 39],
// },
});
console.log('render');
});

const onNextPage = async () => {
Expand Down
43 changes: 43 additions & 0 deletions src/components/UI/Keymaps.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { For } from 'solid-js';

const keymaps = [
// TODO:
// { action: 'Help', keys: ['F1'] },
{ action: 'Execute query', keys: ['Ctrl', 'e'] },
{ action: 'Select tab', keys: ['Meta', 'number'] },
{ action: 'New tab', keys: ['Meta', 'w'] },
{ action: 'Close current tab', keys: ['Meta', 't'] },
{ action: 'Focus on editor', keys: ['Ctrl', 'l'] },
{ action: 'Format query', keys: ['Ctrl', 'Shift', 'f'] },
{ action: 'Select next/previous result', keys: ['Ctrl', 'Shift', 'n/p'] },
{ action: 'Select next/previous page', keys: ['Ctrl', 'n/p'] },
];

const Keymaps = () => {
return (
<div class="flex items-center justify-center">
<div class="flex flex-col items-end pr-1">
<For each={keymaps}>
{({ action }) => (
<div class="h-[40px] flex items-center align-middle">
<span class="text-lg font-medium ">{action}</span>
</div>
)}
</For>
</div>
<div class="flex flex-col items-start pl-1">
<For each={keymaps}>
{({ keys }) => (
<div class="h-[40px] flex items-center">
<span class="flex gap-2">
<For each={keys}>{(key) => <kbd class="kbd kbd-sm">{key}</kbd>}</For>
</span>
</div>
)}
</For>
</div>
</div>
);
};

export default Keymaps;

0 comments on commit 4761a78

Please sign in to comment.