mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 04:16:00 +00:00
open as data sheet, readonly - remember last use
This commit is contained in:
@@ -43,7 +43,6 @@
|
||||
export const extractKey = data => data.fileName;
|
||||
export const createMatcher = ({ fileName }) => filter => filterName(filter, fileName);
|
||||
const ARCHIVE_ICONS = {
|
||||
jsonl: 'img archive',
|
||||
'table.yaml': 'img table',
|
||||
'view.sql': 'img view',
|
||||
'proc.sql': 'img procedure',
|
||||
@@ -51,6 +50,15 @@
|
||||
'trigger.sql': 'img sql-file',
|
||||
'matview.sql': 'img view',
|
||||
};
|
||||
|
||||
function getArchiveIcon(archiveFilesAsDataSheets, data) {
|
||||
if (data.fileType == 'jsonl') {
|
||||
return isArchiveFileMarkedAsDataSheet(archiveFilesAsDataSheets, data.folderName, data.fileName)
|
||||
? 'img free-table'
|
||||
: 'img archive';
|
||||
}
|
||||
return ARCHIVE_ICONS[data.fileType];
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
@@ -59,7 +67,7 @@
|
||||
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
||||
import { showModal } from '../modals/modalTools';
|
||||
|
||||
import { currentArchive, extensions, getCurrentDatabase } from '../stores';
|
||||
import { archiveFilesAsDataSheets, currentArchive, extensions, getCurrentDatabase } from '../stores';
|
||||
|
||||
import axiosInstance from '../utility/axiosInstance';
|
||||
import createQuickExportMenu from '../utility/createQuickExportMenu';
|
||||
@@ -69,6 +77,11 @@
|
||||
import getConnectionLabel from '../utility/getConnectionLabel';
|
||||
import InputTextModal from '../modals/InputTextModal.svelte';
|
||||
import ConfirmModal from '../modals/ConfirmModal.svelte';
|
||||
import {
|
||||
isArchiveFileMarkedAsDataSheet,
|
||||
markArchiveFileAsDataSheet,
|
||||
markArchiveFileAsReadonly,
|
||||
} from '../utility/archiveTools';
|
||||
|
||||
export let data;
|
||||
|
||||
@@ -101,9 +114,11 @@
|
||||
});
|
||||
};
|
||||
const handleOpenRead = () => {
|
||||
markArchiveFileAsReadonly(data.folderName, data.fileName);
|
||||
openArchive(data.fileName, data.folderName);
|
||||
};
|
||||
const handleOpenWrite = () => {
|
||||
markArchiveFileAsDataSheet(data.folderName, data.fileName);
|
||||
openNewTab({
|
||||
title: data.fileName,
|
||||
icon: 'img free-table',
|
||||
@@ -122,7 +137,13 @@
|
||||
});
|
||||
};
|
||||
const handleClick = () => {
|
||||
if (data.fileType == 'jsonl') openArchive(data.fileName, data.folderName);
|
||||
if (data.fileType == 'jsonl') {
|
||||
if (isArchiveFileMarkedAsDataSheet($archiveFilesAsDataSheets, data.folderName, data.fileName)) {
|
||||
handleOpenWrite();
|
||||
} else {
|
||||
handleOpenRead();
|
||||
}
|
||||
}
|
||||
if (data.fileType.endsWith('.sql')) {
|
||||
handleOpenSqlFile();
|
||||
}
|
||||
@@ -179,7 +200,7 @@
|
||||
{...$$restProps}
|
||||
{data}
|
||||
title={data.fileLabel}
|
||||
icon={ARCHIVE_ICONS[data.fileType]}
|
||||
icon={getArchiveIcon($archiveFilesAsDataSheets, data)}
|
||||
menu={createMenu}
|
||||
on:click={handleClick}
|
||||
/>
|
||||
|
||||
@@ -46,6 +46,7 @@ export const pinnedDatabases = writableWithStorage([], 'pinnedDatabases');
|
||||
export const pinnedTables = writableWithStorage([], 'pinnedTables');
|
||||
export const commandsSettings = derived(useSettings(), (config: any) => (config || {}).commands || {});
|
||||
export const allResultsInOneTabDefault = writableWithStorage(false, 'allResultsInOneTabDefault');
|
||||
export const archiveFilesAsDataSheets = writableWithStorage([], 'archiveFilesAsDataSheets');
|
||||
export const commandsCustomized = derived([commands, commandsSettings], ([$commands, $commandsSettings]) =>
|
||||
_.mapValues($commands, (v, k) => ({
|
||||
// @ts-ignore
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
import { showModal } from '../modals/modalTools';
|
||||
import SaveArchiveModal from '../modals/SaveArchiveModal.svelte';
|
||||
import useEditorData from '../query/useEditorData';
|
||||
import { markArchiveFileAsDataSheet } from '../utility/archiveTools';
|
||||
import axiosInstance from '../utility/axiosInstance';
|
||||
import { changeTab } from '../utility/common';
|
||||
import { registerMenu } from '../utility/contextMenu';
|
||||
@@ -93,6 +94,7 @@
|
||||
}));
|
||||
archiveFile = file;
|
||||
archiveFolder = folder;
|
||||
markArchiveFileAsDataSheet(folder, file);
|
||||
};
|
||||
|
||||
function handleRunMacro(macro, params, cells) {
|
||||
|
||||
15
packages/web/src/utility/archiveTools.ts
Normal file
15
packages/web/src/utility/archiveTools.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { archiveFilesAsDataSheets } from '../stores';
|
||||
|
||||
export function markArchiveFileAsDataSheet(folder, file) {
|
||||
archiveFilesAsDataSheets.update(ar =>
|
||||
ar.find(x => x.folder == folder && x.file == file) ? ar : [...ar, { folder, file }]
|
||||
);
|
||||
}
|
||||
|
||||
export function markArchiveFileAsReadonly(folder, file) {
|
||||
archiveFilesAsDataSheets.update(ar => ar.filter(x => x.folder != folder || x.file != file));
|
||||
}
|
||||
|
||||
export function isArchiveFileMarkedAsDataSheet(store, folder, file) {
|
||||
return !!store.find(x => x.folder == folder && x.file == file);
|
||||
}
|
||||
Reference in New Issue
Block a user