mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-03 09:24:00 +00:00
next macros
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
import { FreeTableModel } from './FreeTableModel';
|
import { FreeTableModel } from './FreeTableModel';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import uuidv1 from 'uuid/v1';
|
||||||
|
import uuidv4 from 'uuid/v4';
|
||||||
|
import moment from 'moment';
|
||||||
import { MacroDefinition, MacroSelectedCell } from './MacroDefinition';
|
import { MacroDefinition, MacroSelectedCell } from './MacroDefinition';
|
||||||
|
|
||||||
const getMacroFunction = {
|
const getMacroFunction = {
|
||||||
@@ -12,6 +15,9 @@ const getMacroFunction = {
|
|||||||
|
|
||||||
const modules = {
|
const modules = {
|
||||||
lodash: _,
|
lodash: _,
|
||||||
|
uuidv1,
|
||||||
|
uuidv4,
|
||||||
|
moment,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function runMacro(
|
export function runMacro(
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ export default function DataGridCore(props) {
|
|||||||
grider,
|
grider,
|
||||||
onSelectionChanged,
|
onSelectionChanged,
|
||||||
frameSelection,
|
frameSelection,
|
||||||
|
onKeyDown,
|
||||||
} = props;
|
} = props;
|
||||||
// console.log('RENDER GRID', display.baseTable.pureName);
|
// console.log('RENDER GRID', display.baseTable.pureName);
|
||||||
const columns = React.useMemo(() => display.allColumns, [display]);
|
const columns = React.useMemo(() => display.allColumns, [display]);
|
||||||
@@ -668,6 +669,10 @@ export default function DataGridCore(props) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function handleGridKeyDown(event) {
|
function handleGridKeyDown(event) {
|
||||||
|
if (onKeyDown) {
|
||||||
|
onKeyDown(event);
|
||||||
|
}
|
||||||
|
|
||||||
if (event.keyCode == keycodes.f5) {
|
if (event.keyCode == keycodes.f5) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
display.reload();
|
display.reload();
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ export default function FreeTableGrid(props) {
|
|||||||
macroPreview={selectedMacro}
|
macroPreview={selectedMacro}
|
||||||
macroValues={macroValues}
|
macroValues={macroValues}
|
||||||
onSelectionChanged={setSelectedCells}
|
onSelectionChanged={setSelectedCells}
|
||||||
|
setSelectedMacro={setSelectedMacro}
|
||||||
/>
|
/>
|
||||||
{!!selectedMacro && (
|
{!!selectedMacro && (
|
||||||
<MacroDetail
|
<MacroDetail
|
||||||
|
|||||||
@@ -1,11 +1,21 @@
|
|||||||
import { createGridCache, FreeTableGridDisplay } from '@dbgate/datalib';
|
import { createGridCache, FreeTableGridDisplay } from '@dbgate/datalib';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import DataGridCore from '../datagrid/DataGridCore';
|
import DataGridCore from '../datagrid/DataGridCore';
|
||||||
|
import keycodes from '../utility/keycodes';
|
||||||
import FreeTableGrider from './FreeTableGrider';
|
import FreeTableGrider from './FreeTableGrider';
|
||||||
import MacroPreviewGrider from './MacroPreviewGrider';
|
import MacroPreviewGrider from './MacroPreviewGrider';
|
||||||
|
|
||||||
export default function FreeTableGridCore(props) {
|
export default function FreeTableGridCore(props) {
|
||||||
const { modelState, dispatchModel, config, setConfig, macroPreview, macroValues, onSelectionChanged } = props;
|
const {
|
||||||
|
modelState,
|
||||||
|
dispatchModel,
|
||||||
|
config,
|
||||||
|
setConfig,
|
||||||
|
macroPreview,
|
||||||
|
macroValues,
|
||||||
|
onSelectionChanged,
|
||||||
|
setSelectedMacro,
|
||||||
|
} = props;
|
||||||
const [cache, setCache] = React.useState(createGridCache());
|
const [cache, setCache] = React.useState(createGridCache());
|
||||||
const [selectedCells, setSelectedCells] = React.useState([]);
|
const [selectedCells, setSelectedCells] = React.useState([]);
|
||||||
const grider = React.useMemo(
|
const grider = React.useMemo(
|
||||||
@@ -34,6 +44,12 @@ export default function FreeTableGridCore(props) {
|
|||||||
[setSelectedCells]
|
[setSelectedCells]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleKeyDown = React.useCallback((event) => {
|
||||||
|
if (event.keyCode == keycodes.escape) {
|
||||||
|
setSelectedMacro(null);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataGridCore
|
<DataGridCore
|
||||||
{...props}
|
{...props}
|
||||||
@@ -41,6 +57,7 @@ export default function FreeTableGridCore(props) {
|
|||||||
display={display}
|
display={display}
|
||||||
onSelectionChanged={macroPreview ? handleSelectionChanged : null}
|
onSelectionChanged={macroPreview ? handleSelectionChanged : null}
|
||||||
frameSelection={!!macroPreview}
|
frameSelection={!!macroPreview}
|
||||||
|
onKeyDown={handleKeyDown}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,40 @@ const macros = [
|
|||||||
type: 'transformValue',
|
type: 'transformValue',
|
||||||
code: `return rowIndex + 1`,
|
code: `return rowIndex + 1`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: 'Generate UUID',
|
||||||
|
name: 'uuidv1',
|
||||||
|
group: 'Tools',
|
||||||
|
description: 'Generate unique identifier',
|
||||||
|
type: 'transformValue',
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
type: 'select',
|
||||||
|
options: [
|
||||||
|
{ value: 'uuidv1', name: 'V1 - from timestamp' },
|
||||||
|
{ value: 'uuidv4', name: 'V4 - random generated' },
|
||||||
|
],
|
||||||
|
label: 'Version',
|
||||||
|
name: 'uuidVersion',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
code: `return modules[args.uuidVersion || 'uuidv1']()`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Current date',
|
||||||
|
name: 'currentDate',
|
||||||
|
group: 'Tools',
|
||||||
|
description: 'Gets current date',
|
||||||
|
type: 'transformValue',
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
label: 'Format',
|
||||||
|
name: 'dateFormat',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
code: `return modules.moment().format(args.dateFormat || 'YYYY-MM-DD HH:mm:ss')`,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export default macros;
|
export default macros;
|
||||||
|
|||||||
Reference in New Issue
Block a user