Skip to content

Commit

Permalink
Format function source on save (#942)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored Sep 8, 2022
1 parent ec1b10d commit 8fb2a08
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/toolpad-app/src/toolpadDataSources/function/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { createHarLog, mergeHar } from '../../utils/har';
import useQueryPreview from '../useQueryPreview';
import QueryInputPanel from '../QueryInputPanel';
import { useEvaluateLiveBindingEntries } from '../../toolpad/AppEditor/useEvaluateLiveBinding';
import { tryFormat } from '../../utils/prettier';
import useShortcut from '../../utils/useShortcut';

const EVENT_INTERFACE_IDENTIFIER = 'ToolpadFunctionEvent';

Expand Down Expand Up @@ -154,7 +156,19 @@ function QueryEditor({
const handleLogClear = React.useCallback(() => setPreviewLogs([]), []);
const handleHarClear = React.useCallback(() => setPreviewHar(createHarLog()), []);

const handleCommit = React.useCallback(() => onChange(input), [onChange, input]);
const handleCommit = React.useCallback(
() =>
onChange({
...input,
query: {
...input.query,
module: tryFormat(input.query.module),
},
}),
[onChange, input],
);

useShortcut({ code: 'KeyS', metaKey: true }, handleCommit);

const isDirty = input !== value;

Expand Down

0 comments on commit 8fb2a08

Please sign in to comment.