mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-25 21:55:49 +00:00
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
import React from 'react';
|
|
import get from 'lodash/get';
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
import CodeEditor from 'components/CodeEditor';
|
|
import { updateRequestGraphqlVariables } from 'providers/ReduxStore/slices/collections';
|
|
import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions';
|
|
import { useTheme } from 'providers/Theme';
|
|
import StyledWrapper from './StyledWrapper';
|
|
|
|
const GraphQLVariables = ({ variables, item, collection }) => {
|
|
const dispatch = useDispatch();
|
|
|
|
const { storedTheme } = useTheme();
|
|
const preferences = useSelector((state) => state.app.preferences);
|
|
|
|
const onEdit = (value) => {
|
|
dispatch(
|
|
updateRequestGraphqlVariables({
|
|
variables: value,
|
|
itemUid: item.uid,
|
|
collectionUid: collection.uid
|
|
})
|
|
);
|
|
};
|
|
|
|
const onRun = () => dispatch(sendRequest(item, collection.uid));
|
|
const onSave = () => dispatch(saveRequest(item.uid, collection.uid));
|
|
|
|
return (
|
|
<StyledWrapper className="w-full">
|
|
<CodeEditor
|
|
collection={collection}
|
|
value={variables || ''}
|
|
theme={storedTheme}
|
|
font={get(preferences, 'font.codeFont', 'default')}
|
|
onEdit={onEdit}
|
|
mode="javascript"
|
|
onRun={onRun}
|
|
onSave={onSave}
|
|
/>
|
|
</StyledWrapper>
|
|
);
|
|
};
|
|
|
|
export default GraphQLVariables;
|