mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-22 01:45:59 +00:00
SYNC: autodetect data grid cell
This commit is contained in:
committed by
Diflow
parent
af9701feb8
commit
ff0157e624
@@ -278,6 +278,9 @@
|
|||||||
if (onPublishedCellsChanged) {
|
if (onPublishedCellsChanged) {
|
||||||
onPublishedCellsChanged(value);
|
onPublishedCellsChanged(value);
|
||||||
}
|
}
|
||||||
|
if (value[0]?.isSelectedFullRow && !isFormView) {
|
||||||
|
cellDataViewVisible = true;
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
onChangeSelectedColumns={cols => {
|
onChangeSelectedColumns={cols => {
|
||||||
if (domColumnManager) domColumnManager.setSelectedColumns(cols);
|
if (domColumnManager) domColumnManager.setSelectedColumns(cols);
|
||||||
|
|||||||
@@ -217,7 +217,7 @@
|
|||||||
registerCommand({
|
registerCommand({
|
||||||
id: 'dataGrid.filterSelected',
|
id: 'dataGrid.filterSelected',
|
||||||
category: __t('command.datagrid', { defaultMessage: 'Data grid' }),
|
category: __t('command.datagrid', { defaultMessage: 'Data grid' }),
|
||||||
name: __t('command.datagrid.filterSelected', { defaultMessage : 'Filter selected value'}),
|
name: __t('command.datagrid.filterSelected', { defaultMessage: 'Filter selected value' }),
|
||||||
keyText: 'CtrlOrCommand+Shift+F',
|
keyText: 'CtrlOrCommand+Shift+F',
|
||||||
testEnabled: () => getCurrentDataGrid()?.getDisplay().filterable,
|
testEnabled: () => getCurrentDataGrid()?.getDisplay().filterable,
|
||||||
onClick: () => getCurrentDataGrid().filterSelectedValue(),
|
onClick: () => getCurrentDataGrid().filterSelectedValue(),
|
||||||
@@ -225,7 +225,7 @@
|
|||||||
registerCommand({
|
registerCommand({
|
||||||
id: 'dataGrid.findColumn',
|
id: 'dataGrid.findColumn',
|
||||||
category: __t('command.datagrid', { defaultMessage: 'Data grid' }),
|
category: __t('command.datagrid', { defaultMessage: 'Data grid' }),
|
||||||
name: __t('command.datagrid.findColumn', { defaultMessage: 'Find column'}),
|
name: __t('command.datagrid.findColumn', { defaultMessage: 'Find column' }),
|
||||||
keyText: 'CtrlOrCommand+F',
|
keyText: 'CtrlOrCommand+F',
|
||||||
testEnabled: () => getCurrentDataGrid() != null,
|
testEnabled: () => getCurrentDataGrid() != null,
|
||||||
getSubCommands: () => getCurrentDataGrid().buildFindMenu(),
|
getSubCommands: () => getCurrentDataGrid().buildFindMenu(),
|
||||||
@@ -241,7 +241,7 @@
|
|||||||
registerCommand({
|
registerCommand({
|
||||||
id: 'dataGrid.clearFilter',
|
id: 'dataGrid.clearFilter',
|
||||||
category: __t('command.datagrid', { defaultMessage: 'Data grid' }),
|
category: __t('command.datagrid', { defaultMessage: 'Data grid' }),
|
||||||
name: __t('command.datagrid.clearFilter', { defaultMessage : 'Clear filter'}),
|
name: __t('command.datagrid.clearFilter', { defaultMessage: 'Clear filter' }),
|
||||||
keyText: 'CtrlOrCommand+Shift+E',
|
keyText: 'CtrlOrCommand+Shift+E',
|
||||||
testEnabled: () => getCurrentDataGrid()?.clearFilterEnabled(),
|
testEnabled: () => getCurrentDataGrid()?.clearFilterEnabled(),
|
||||||
onClick: () => getCurrentDataGrid().clearFilter(),
|
onClick: () => getCurrentDataGrid().clearFilter(),
|
||||||
@@ -249,7 +249,7 @@
|
|||||||
registerCommand({
|
registerCommand({
|
||||||
id: 'dataGrid.generateSqlFromData',
|
id: 'dataGrid.generateSqlFromData',
|
||||||
category: __t('command.datagrid', { defaultMessage: 'Data grid' }),
|
category: __t('command.datagrid', { defaultMessage: 'Data grid' }),
|
||||||
name: __t('command.datagrid.generateSql', { defaultMessage: 'Generate SQL'}),
|
name: __t('command.datagrid.generateSql', { defaultMessage: 'Generate SQL' }),
|
||||||
keyText: 'CtrlOrCommand+G',
|
keyText: 'CtrlOrCommand+G',
|
||||||
testEnabled: () => getCurrentDataGrid()?.generateSqlFromDataEnabled(),
|
testEnabled: () => getCurrentDataGrid()?.generateSqlFromDataEnabled(),
|
||||||
onClick: () => getCurrentDataGrid().generateSqlFromData(),
|
onClick: () => getCurrentDataGrid().generateSqlFromData(),
|
||||||
@@ -257,14 +257,14 @@
|
|||||||
registerCommand({
|
registerCommand({
|
||||||
id: 'dataGrid.openFreeTable',
|
id: 'dataGrid.openFreeTable',
|
||||||
category: __t('command.datagrid', { defaultMessage: 'Data grid' }),
|
category: __t('command.datagrid', { defaultMessage: 'Data grid' }),
|
||||||
name: __t('command.datagrid.editSelection', { defaultMessage: 'Edit selection as table'}),
|
name: __t('command.datagrid.editSelection', { defaultMessage: 'Edit selection as table' }),
|
||||||
testEnabled: () => getCurrentDataGrid() != null,
|
testEnabled: () => getCurrentDataGrid() != null,
|
||||||
onClick: () => getCurrentDataGrid().openFreeTable(),
|
onClick: () => getCurrentDataGrid().openFreeTable(),
|
||||||
});
|
});
|
||||||
registerCommand({
|
registerCommand({
|
||||||
id: 'dataGrid.newJson',
|
id: 'dataGrid.newJson',
|
||||||
category: __t('command.datagrid', { defaultMessage: 'Data grid' }),
|
category: __t('command.datagrid', { defaultMessage: 'Data grid' }),
|
||||||
name: __t('command.datagrid.addJsonDocument', { defaultMessage: 'Add JSON document'}),
|
name: __t('command.datagrid.addJsonDocument', { defaultMessage: 'Add JSON document' }),
|
||||||
testEnabled: () => getCurrentDataGrid()?.addJsonDocumentEnabled(),
|
testEnabled: () => getCurrentDataGrid()?.addJsonDocumentEnabled(),
|
||||||
onClick: () => getCurrentDataGrid().addJsonDocument(),
|
onClick: () => getCurrentDataGrid().addJsonDocument(),
|
||||||
});
|
});
|
||||||
@@ -759,7 +759,7 @@
|
|||||||
|
|
||||||
export function saveCellToFileEnabled() {
|
export function saveCellToFileEnabled() {
|
||||||
const value = getSelectedExportableCell();
|
const value = getSelectedExportableCell();
|
||||||
return _.isString(value) || (value?.type == 'Buffer' && _.isArray(value?.data)) || (value?.$binary?.base64);
|
return _.isString(value) || (value?.type == 'Buffer' && _.isArray(value?.data)) || value?.$binary?.base64;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveCellToFile() {
|
export async function saveCellToFile() {
|
||||||
@@ -1243,23 +1243,45 @@
|
|||||||
|
|
||||||
function getCellsPublished(cells) {
|
function getCellsPublished(cells) {
|
||||||
const regular = cellsToRegularCells(cells);
|
const regular = cellsToRegularCells(cells);
|
||||||
const res = regular
|
|
||||||
.map(cell => {
|
const commonInfo = {
|
||||||
const row = cell[0];
|
engine: display?.driver,
|
||||||
|
editable: grider.editable,
|
||||||
|
editorTypes: display?.driver?.dataEditorTypesBehaviour,
|
||||||
|
};
|
||||||
|
|
||||||
|
const rowIndexes = _.sortBy(_.uniq(regular.map(x => x[0])));
|
||||||
|
const fullRowIndexes = new Set(cells.filter(x => x[1] == 'header').map(x => x[0]));
|
||||||
|
const rowInfos = rowIndexes.map(row => {
|
||||||
const rowData = grider.getRowData(row);
|
const rowData = grider.getRowData(row);
|
||||||
const column = realColumnUniqueNames[cell[1]];
|
|
||||||
return {
|
return {
|
||||||
row,
|
row,
|
||||||
rowData,
|
rowData,
|
||||||
column,
|
|
||||||
value: rowData && rowData[column],
|
|
||||||
engine: display?.driver,
|
|
||||||
condition: display?.getChangeSetCondition(rowData),
|
condition: display?.getChangeSetCondition(rowData),
|
||||||
insertedRowIndex: grider?.getInsertedRowIndex(row),
|
insertedRowIndex: grider?.getInsertedRowIndex(row),
|
||||||
rowStatus: grider.getRowStatus(row),
|
rowStatus: grider.getRowStatus(row),
|
||||||
|
isSelectedFullRow: fullRowIndexes.has(row),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const rowInfoByIndex = _.zipObject(
|
||||||
|
rowIndexes.map(x => x.toString()),
|
||||||
|
rowInfos
|
||||||
|
);
|
||||||
|
|
||||||
|
const res = regular
|
||||||
|
.map(cell => {
|
||||||
|
const row = cell[0];
|
||||||
|
const column = realColumnUniqueNames[cell[1]];
|
||||||
|
const rowData = rowInfoByIndex[row].rowData;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...commonInfo,
|
||||||
|
...rowInfoByIndex[row],
|
||||||
|
column,
|
||||||
|
value: rowData && rowData[column],
|
||||||
onSetValue: value => grider.setCellValue(row, column, value),
|
onSetValue: value => grider.setCellValue(row, column, value),
|
||||||
editable: grider.editable,
|
|
||||||
editorTypes: display?.driver?.dataEditorTypesBehaviour,
|
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.filter(x => x.column);
|
.filter(x => x.column);
|
||||||
@@ -1813,7 +1835,7 @@
|
|||||||
{ command: 'dataGrid.refresh' },
|
{ command: 'dataGrid.refresh' },
|
||||||
{ placeTag: 'copy' },
|
{ placeTag: 'copy' },
|
||||||
{
|
{
|
||||||
text: _t('datagrid.copyAdvanced', { defaultMessage: 'Copy advanced'}),
|
text: _t('datagrid.copyAdvanced', { defaultMessage: 'Copy advanced' }),
|
||||||
submenu: [
|
submenu: [
|
||||||
_.keys(copyRowsFormatDefs).map(format => ({
|
_.keys(copyRowsFormatDefs).map(format => ({
|
||||||
text: _tval(copyRowsFormatDefs[format].label),
|
text: _tval(copyRowsFormatDefs[format].label),
|
||||||
@@ -1821,7 +1843,7 @@
|
|||||||
})),
|
})),
|
||||||
{ divider: true },
|
{ divider: true },
|
||||||
_.keys(copyRowsFormatDefs).map(format => ({
|
_.keys(copyRowsFormatDefs).map(format => ({
|
||||||
text: _t('datagrid.setFormat', { defaultMessage: 'Set format: ' }) + (_tval(copyRowsFormatDefs[format].name)),
|
text: _t('datagrid.setFormat', { defaultMessage: 'Set format: ' }) + _tval(copyRowsFormatDefs[format].name),
|
||||||
onClick: () => ($copyRowsFormat = format),
|
onClick: () => ($copyRowsFormat = format),
|
||||||
})),
|
})),
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
<script lang="ts" context="module">
|
<script lang="ts" context="module">
|
||||||
|
|
||||||
const formats = [
|
const formats = [
|
||||||
{
|
{
|
||||||
type: 'textWrap',
|
type: 'textWrap',
|
||||||
@@ -64,10 +63,13 @@
|
|||||||
];
|
];
|
||||||
|
|
||||||
function autodetect(selection) {
|
function autodetect(selection) {
|
||||||
|
if (selection[0]?.isSelectedFullRow) {
|
||||||
|
return 'table';
|
||||||
|
}
|
||||||
|
|
||||||
if (selectionCouldBeShownOnMap(selection)) {
|
if (selectionCouldBeShownOnMap(selection)) {
|
||||||
return 'map';
|
return 'map';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selection[0]?.engine?.databaseEngineTypes?.includes('document')) {
|
if (selection[0]?.engine?.databaseEngineTypes?.includes('document')) {
|
||||||
return 'jsonRow';
|
return 'jsonRow';
|
||||||
}
|
}
|
||||||
@@ -121,7 +123,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<WidgetTitle {onClose}>{_t('cellDataWidget.title', { defaultMessage: "Cell data view" })}</WidgetTitle>
|
<WidgetTitle {onClose}>{_t('cellDataWidget.title', { defaultMessage: 'Cell data view' })}</WidgetTitle>
|
||||||
<div class="main">
|
<div class="main">
|
||||||
<div class="toolbar">
|
<div class="toolbar">
|
||||||
Format:<span> </span>
|
Format:<span> </span>
|
||||||
@@ -131,18 +133,30 @@
|
|||||||
on:change={e => (selectedFormatType = e.detail)}
|
on:change={e => (selectedFormatType = e.detail)}
|
||||||
data-testid="CellDataWidget_selectFormat"
|
data-testid="CellDataWidget_selectFormat"
|
||||||
options={[
|
options={[
|
||||||
{ value: 'autodetect', label: _t('cellDataWidget.autodetect', { defaultMessage: "Autodetect - {autoDetectTitle}", values : { autoDetectTitle: autodetectFormat.title } }) },
|
{
|
||||||
|
value: 'autodetect',
|
||||||
|
label: _t('cellDataWidget.autodetect', {
|
||||||
|
defaultMessage: 'Autodetect - {autoDetectTitle}',
|
||||||
|
values: { autoDetectTitle: autodetectFormat.title },
|
||||||
|
}),
|
||||||
|
},
|
||||||
...formats.map(fmt => ({ label: fmt.title, value: fmt.type })),
|
...formats.map(fmt => ({ label: fmt.title, value: fmt.type })),
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="data">
|
<div class="data">
|
||||||
{#if usedFormat.single && selection?.length != 1}
|
{#if usedFormat.single && selection?.length != 1}
|
||||||
<ErrorInfo message={_t('cellDataWidget.mustSelectOneCell', { defaultMessage: "Must be selected one cell" })} alignTop />
|
<ErrorInfo
|
||||||
|
message={_t('cellDataWidget.mustSelectOneCell', { defaultMessage: 'Must be selected one cell' })}
|
||||||
|
alignTop
|
||||||
|
/>
|
||||||
{:else if usedFormat == null}
|
{:else if usedFormat == null}
|
||||||
<ErrorInfo message={_t('cellDataWidget.formatNotSelected', { defaultMessage: "Format not selected" })} alignTop />
|
<ErrorInfo
|
||||||
|
message={_t('cellDataWidget.formatNotSelected', { defaultMessage: 'Format not selected' })}
|
||||||
|
alignTop
|
||||||
|
/>
|
||||||
{:else if !selection || selection.length == 0}
|
{:else if !selection || selection.length == 0}
|
||||||
<ErrorInfo message={_t('cellDataWidget.noDataSelected', { defaultMessage: "No data selected" })} alignTop />
|
<ErrorInfo message={_t('cellDataWidget.noDataSelected', { defaultMessage: 'No data selected' })} alignTop />
|
||||||
{:else}
|
{:else}
|
||||||
<svelte:component this={usedFormat?.component} {selection} />
|
<svelte:component this={usedFormat?.component} {selection} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user