Skip to content

Commit

Permalink
feat: context menu to copy queries from console
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Jul 18, 2022
1 parent 44647f5 commit c21bd60
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/renderer/components/Workspace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ watch(queryTabs, (newVal, oldVal) => {
});
const addQueryTab = () => {
newTab({ uid: props.connection.uid, type: 'query' });
newTab({ uid: props.connection.uid, type: 'query', schema: workspace.value.breadcrumbs.schema });
};
const getSelectedTab = () => {
Expand Down
25 changes: 25 additions & 0 deletions src/renderer/components/WorkspaceQueryConsole.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,30 @@
:key="i"
class="query-console-log"
tabindex="0"
@contextmenu.prevent="contextMenu($event, wLog)"
>
<span class="type-datetime">{{ moment(wLog.date).format('YYYY-MM-DD HH:mm:ss') }}</span>: <span class="type-string">{{ wLog.sql }}</span>
</div>
</div>
</div>
</div>
<BaseContextMenu
v-if="isContext"
:context-event="contextEvent"
@close-context="isContext = false"
>
<div class="context-element" @click="copyQuery">
<span class="d-flex"><i class="mdi mdi-18px mdi-content-copy text-light pr-1" /> {{ $t('word.copy') }}</span>
</div>
</BaseContextMenu>
</template>
<script setup lang="ts">
import { computed, nextTick, onMounted, ref, Ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import * as moment from 'moment';
import { useConsoleStore } from '@/stores/console';
import { storeToRefs } from 'pinia';
import BaseContextMenu from '@/components/BaseContextMenu.vue';
const { t } = useI18n();
Expand All @@ -53,6 +64,9 @@ const queryConsoleBody: Ref<HTMLInputElement> = ref(null);
const resizer: Ref<HTMLInputElement> = ref(null);
const localHeight = ref(250);
const isHover = ref(false);
const isContext = ref(false);
const contextQuery: Ref<string> = ref(null);
const contextEvent: Ref<MouseEvent> = ref(null);
const resize = (e: MouseEvent) => {
const el = queryConsole.value;
Expand All @@ -72,6 +86,17 @@ const stopResize = () => {
window.removeEventListener('mouseup', stopResize);
};
const contextMenu = (event: MouseEvent, wLog: {date: Date; sql: string}) => {
contextEvent.value = event;
contextQuery.value = wLog.sql;
isContext.value = true;
};
const copyQuery = () => {
navigator.clipboard.writeText(contextQuery.value);
isContext.value = false;
};
watch(workspaceLogs, async () => {
if (!isHover.value) {
await nextTick();
Expand Down

0 comments on commit c21bd60

Please sign in to comment.