mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 13:53:59 +00:00
Remove comments and apply early return pattern
This commit is contained in:
@@ -12,20 +12,14 @@
|
|||||||
|
|
||||||
export let selection;
|
export let selection;
|
||||||
|
|
||||||
// Get first row data
|
|
||||||
$: firstSelection = selection?.[0];
|
$: firstSelection = selection?.[0];
|
||||||
$: rowData = firstSelection?.rowData;
|
$: rowData = firstSelection?.rowData;
|
||||||
$: editable = firstSelection?.editable;
|
$: editable = firstSelection?.editable;
|
||||||
$: editorTypes = firstSelection?.editorTypes;
|
$: editorTypes = firstSelection?.editorTypes;
|
||||||
|
|
||||||
// Get columns in display order
|
|
||||||
$: columns = selection?.columns || [];
|
$: columns = selection?.columns || [];
|
||||||
$: realColumnUniqueNames = selection?.realColumnUniqueNames || [];
|
$: realColumnUniqueNames = selection?.realColumnUniqueNames || [];
|
||||||
|
|
||||||
// Get the general setCellValue function
|
|
||||||
$: setCellValue = selection?.setCellValue;
|
$: setCellValue = selection?.setCellValue;
|
||||||
|
|
||||||
// Build ordered columns with values
|
|
||||||
$: orderedFields = realColumnUniqueNames
|
$: orderedFields = realColumnUniqueNames
|
||||||
.map(colName => {
|
.map(colName => {
|
||||||
const col = columns.find(c => c.uniqueName === colName);
|
const col = columns.find(c => c.uniqueName === colName);
|
||||||
@@ -40,7 +34,6 @@
|
|||||||
})
|
})
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
|
|
||||||
// Editing state
|
|
||||||
let editingColumn = null;
|
let editingColumn = null;
|
||||||
let editValue = '';
|
let editValue = '';
|
||||||
let domEditor = null;
|
let domEditor = null;
|
||||||
@@ -51,31 +44,24 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (_.isArray(value)) return true;
|
if (_.isArray(value)) return true;
|
||||||
if (typeof value === 'string' && isJsonLikeLongString(value)) {
|
if (typeof value !== 'string') return false;
|
||||||
const parsed = safeJsonParse(value);
|
if (!isJsonLikeLongString(value)) return false;
|
||||||
return parsed !== null && (_.isPlainObject(parsed) || _.isArray(parsed));
|
const parsed = safeJsonParse(value);
|
||||||
}
|
return parsed !== null && (_.isPlainObject(parsed) || _.isArray(parsed));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getJsonObject(value) {
|
function getJsonObject(value) {
|
||||||
if (_.isPlainObject(value) || _.isArray(value)) return value;
|
if (_.isPlainObject(value) || _.isArray(value)) return value;
|
||||||
if (typeof value === 'string') {
|
if (typeof value === 'string') return safeJsonParse(value);
|
||||||
return safeJsonParse(value);
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleDoubleClick(field) {
|
function handleDoubleClick(field) {
|
||||||
if (!editable || !setCellValue) return;
|
if (!editable || !setCellValue) return;
|
||||||
|
|
||||||
// For JSON values, open the edit modal directly
|
|
||||||
if (isJsonValue(field.value)) {
|
if (isJsonValue(field.value)) {
|
||||||
openEditModal(field);
|
openEditModal(field);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For regular values, start inline editing
|
|
||||||
startEditing(field);
|
startEditing(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,10 +71,9 @@
|
|||||||
editValue = stringifyCellValue(field.value, 'inlineEditorIntent', editorTypes).value;
|
editValue = stringifyCellValue(field.value, 'inlineEditorIntent', editorTypes).value;
|
||||||
isChangedRef.set(false);
|
isChangedRef.set(false);
|
||||||
tick().then(() => {
|
tick().then(() => {
|
||||||
if (domEditor) {
|
if (!domEditor) return;
|
||||||
domEditor.focus();
|
domEditor.focus();
|
||||||
domEditor.select();
|
domEditor.select();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,39 +84,36 @@
|
|||||||
editingColumn = null;
|
editingColumn = null;
|
||||||
break;
|
break;
|
||||||
case keycodes.enter:
|
case keycodes.enter:
|
||||||
if (isChangedRef.get()) {
|
if (isChangedRef.get()) saveValue(field);
|
||||||
saveValue(field);
|
|
||||||
}
|
|
||||||
editingColumn = null;
|
editingColumn = null;
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
case keycodes.tab:
|
case keycodes.tab:
|
||||||
if (isChangedRef.get()) {
|
if (isChangedRef.get()) saveValue(field);
|
||||||
saveValue(field);
|
|
||||||
}
|
|
||||||
editingColumn = null;
|
editingColumn = null;
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
// Move to next field
|
moveToNextField(field, event.shiftKey);
|
||||||
const currentIndex = orderedFields.findIndex(f => f.uniqueName === field.uniqueName);
|
|
||||||
const nextIndex = event.shiftKey ? currentIndex - 1 : currentIndex + 1;
|
|
||||||
if (nextIndex >= 0 && nextIndex < orderedFields.length) {
|
|
||||||
tick().then(() => {
|
|
||||||
const nextField = orderedFields[nextIndex];
|
|
||||||
if (isJsonValue(nextField.value)) {
|
|
||||||
openEditModal(nextField);
|
|
||||||
} else {
|
|
||||||
startEditing(nextField);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function moveToNextField(field, reverse) {
|
||||||
|
const currentIndex = orderedFields.findIndex(f => f.uniqueName === field.uniqueName);
|
||||||
|
const nextIndex = reverse ? currentIndex - 1 : currentIndex + 1;
|
||||||
|
if (nextIndex < 0 || nextIndex >= orderedFields.length) return;
|
||||||
|
|
||||||
|
tick().then(() => {
|
||||||
|
const nextField = orderedFields[nextIndex];
|
||||||
|
if (isJsonValue(nextField.value)) {
|
||||||
|
openEditModal(nextField);
|
||||||
|
} else {
|
||||||
|
startEditing(nextField);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function handleBlur(field) {
|
function handleBlur(field) {
|
||||||
if (isChangedRef.get()) {
|
if (isChangedRef.get()) saveValue(field);
|
||||||
saveValue(field);
|
|
||||||
}
|
|
||||||
editingColumn = null;
|
editingColumn = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,13 +135,13 @@
|
|||||||
|
|
||||||
function openJsonInNewTab(field) {
|
function openJsonInNewTab(field) {
|
||||||
const jsonObj = getJsonObject(field.value);
|
const jsonObj = getJsonObject(field.value);
|
||||||
if (jsonObj) {
|
if (jsonObj) openJsonDocument(jsonObj, undefined, true);
|
||||||
openJsonDocument(jsonObj, undefined, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getJsonParsedValue(value) {
|
function getJsonParsedValue(value) {
|
||||||
return !editorTypes?.explicitDataType && isJsonLikeLongString(value) ? safeJsonParse(value) : null;
|
if (editorTypes?.explicitDataType) return null;
|
||||||
|
if (!isJsonLikeLongString(value)) return null;
|
||||||
|
return safeJsonParse(value);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1258,21 +1258,21 @@
|
|||||||
condition: display?.getChangeSetCondition(rowData),
|
condition: display?.getChangeSetCondition(rowData),
|
||||||
insertedRowIndex: grider?.getInsertedRowIndex(row),
|
insertedRowIndex: grider?.getInsertedRowIndex(row),
|
||||||
rowStatus: grider.getRowStatus(row),
|
rowStatus: grider.getRowStatus(row),
|
||||||
// Additional data for TableCellView editing support
|
|
||||||
onSetValue: value => grider.setCellValue(row, column, value),
|
onSetValue: value => grider.setCellValue(row, column, value),
|
||||||
editable: grider.editable,
|
editable: grider.editable,
|
||||||
editorTypes: display?.driver?.dataEditorTypesBehaviour,
|
editorTypes: display?.driver?.dataEditorTypesBehaviour,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.filter(x => x.column);
|
.filter(x => x.column);
|
||||||
// Add columns info for TableCellView (columns in display order)
|
|
||||||
res.columns = columns;
|
res.columns = columns;
|
||||||
res.realColumnUniqueNames = realColumnUniqueNames;
|
res.realColumnUniqueNames = realColumnUniqueNames;
|
||||||
// Add a general setCellValue function for editing any column in the first selected row
|
|
||||||
if (res.length > 0) {
|
if (res.length > 0) {
|
||||||
const firstRow = res[0].row;
|
const firstRow = res[0].row;
|
||||||
res.setCellValue = (columnName, value) => grider.setCellValue(firstRow, columnName, value);
|
res.setCellValue = (columnName, value) => grider.setCellValue(firstRow, columnName, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user