mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 17:24:00 +00:00
open JSON from data grid
This commit is contained in:
@@ -111,14 +111,30 @@
|
|||||||
id: 'dataGrid.viewJsonDocument',
|
id: 'dataGrid.viewJsonDocument',
|
||||||
category: 'Data grid',
|
category: 'Data grid',
|
||||||
name: 'View row as JSON document',
|
name: 'View row as JSON document',
|
||||||
testEnabled: () => getCurrentDataGrid()?.viewJsonEnabled(),
|
testEnabled: () => getCurrentDataGrid()?.viewJsonDocumentEnabled(),
|
||||||
onClick: () => getCurrentDataGrid().viewJsonDocument(),
|
onClick: () => getCurrentDataGrid().viewJsonDocument(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
registerCommand({
|
||||||
|
id: 'dataGrid.viewJsonValue',
|
||||||
|
category: 'Data grid',
|
||||||
|
name: 'View cell as JSON document',
|
||||||
|
testEnabled: () => getCurrentDataGrid()?.viewJsonValueEnabled(),
|
||||||
|
onClick: () => getCurrentDataGrid().viewJsonValue(),
|
||||||
|
});
|
||||||
|
|
||||||
|
registerCommand({
|
||||||
|
id: 'dataGrid.openJsonArrayInSheet',
|
||||||
|
category: 'Data grid',
|
||||||
|
name: 'Open array as data sheet',
|
||||||
|
testEnabled: () => getCurrentDataGrid()?.openJsonArrayInSheetEnabled(),
|
||||||
|
onClick: () => getCurrentDataGrid().openJsonArrayInSheet(),
|
||||||
|
});
|
||||||
|
|
||||||
registerCommand({
|
registerCommand({
|
||||||
id: 'dataGrid.copyJsonDocument',
|
id: 'dataGrid.copyJsonDocument',
|
||||||
category: 'Data grid',
|
category: 'Data grid',
|
||||||
name: 'Copy JSON document',
|
name: 'Copy row as JSON document',
|
||||||
testEnabled: () => getCurrentDataGrid()?.copyJsonEnabled(),
|
testEnabled: () => getCurrentDataGrid()?.copyJsonEnabled(),
|
||||||
onClick: () => getCurrentDataGrid().copyJsonDocument(),
|
onClick: () => getCurrentDataGrid().copyJsonDocument(),
|
||||||
});
|
});
|
||||||
@@ -462,7 +478,7 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function viewJsonEnabled() {
|
export function viewJsonDocumentEnabled() {
|
||||||
return isDynamicStructure && _.uniq(selectedCells.map(x => x[0])).length == 1;
|
return isDynamicStructure && _.uniq(selectedCells.map(x => x[0])).length == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,6 +488,44 @@
|
|||||||
openJsonDocument(json);
|
openJsonDocument(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSelectedDataJson(forceArray = false) {
|
||||||
|
const cells = cellsToRegularCells(selectedCells);
|
||||||
|
const data = cells.map(cell => grider.getRowData(cell[0])[realColumnUniqueNames[cell[1]]]);
|
||||||
|
if (!data.every(x => _.isArray(x) || _.isPlainObject(x))) return null;
|
||||||
|
if (data.length == 0) return null;
|
||||||
|
if (data.length == 1 && _.isPlainObject(data[0]) && !forceArray) return data[0];
|
||||||
|
return _.flatten(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function viewJsonValueEnabled() {
|
||||||
|
return getSelectedDataJson() != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function viewJsonValue() {
|
||||||
|
openJsonDocument(getSelectedDataJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
export function openJsonArrayInSheetEnabled() {
|
||||||
|
return getSelectedDataJson() != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function openJsonArrayInSheet() {
|
||||||
|
openNewTab(
|
||||||
|
{
|
||||||
|
title: 'Data #',
|
||||||
|
icon: 'img free-table',
|
||||||
|
tabComponent: 'FreeTableTab',
|
||||||
|
props: {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
editor: {
|
||||||
|
rows: getSelectedDataJson(true),
|
||||||
|
structure: { __isDynamicStructure: true, columns: [] },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function editJsonEnabled() {
|
export function editJsonEnabled() {
|
||||||
return grider.editable && isDynamicStructure && _.uniq(selectedCells.map(x => x[0])).length == 1;
|
return grider.editable && isDynamicStructure && _.uniq(selectedCells.map(x => x[0])).length == 1;
|
||||||
}
|
}
|
||||||
@@ -1178,7 +1232,6 @@
|
|||||||
// { text: 'Copy as JSON', onClick: () => copyToClipboardCore('json') },
|
// { text: 'Copy as JSON', onClick: () => copyToClipboardCore('json') },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{ command: 'dataGrid.copyJsonDocument', hideDisabled: true },
|
|
||||||
{ placeTag: 'switch' },
|
{ placeTag: 'switch' },
|
||||||
{ divider: true },
|
{ divider: true },
|
||||||
{ placeTag: 'save' },
|
{ placeTag: 'save' },
|
||||||
@@ -1197,6 +1250,9 @@
|
|||||||
{ command: 'dataGrid.redo', hideDisabled: true },
|
{ command: 'dataGrid.redo', hideDisabled: true },
|
||||||
{ command: 'dataGrid.editJsonDocument', hideDisabled: true },
|
{ command: 'dataGrid.editJsonDocument', hideDisabled: true },
|
||||||
{ command: 'dataGrid.viewJsonDocument', hideDisabled: true },
|
{ command: 'dataGrid.viewJsonDocument', hideDisabled: true },
|
||||||
|
{ command: 'dataGrid.viewJsonValue', hideDisabled: true },
|
||||||
|
{ command: 'dataGrid.openJsonArrayInSheet', hideDisabled: true },
|
||||||
|
{ command: 'dataGrid.copyJsonDocument', hideDisabled: true },
|
||||||
{ divider: true },
|
{ divider: true },
|
||||||
{ placeTag: 'export' },
|
{ placeTag: 'export' },
|
||||||
{ command: 'dataGrid.generateSqlFromData' },
|
{ command: 'dataGrid.generateSqlFromData' },
|
||||||
|
|||||||
Reference in New Issue
Block a user