diff --git a/packages/bruno-app/src/components/RequestPane/GraphQLRequestPane/StyledWrapper.js b/packages/bruno-app/src/components/RequestPane/GraphQLRequestPane/StyledWrapper.js deleted file mode 100644 index c8e3c482a..000000000 --- a/packages/bruno-app/src/components/RequestPane/GraphQLRequestPane/StyledWrapper.js +++ /dev/null @@ -1,30 +0,0 @@ -import styled from 'styled-components'; - -const StyledWrapper = styled.div` - div.tabs { - div.tab { - padding: 6px 0px; - border: none; - border-bottom: solid 2px transparent; - margin-right: ${(props) => props.theme.tabs.marginRight}; - color: var(--color-tab-inactive); - cursor: pointer; - - &:focus, - &:active, - &:focus-within, - &:focus-visible, - &:target { - outline: none !important; - box-shadow: none !important; - } - - &.active { - color: ${(props) => props.theme.tabs.active.color} !important; - border-bottom: solid 2px ${(props) => props.theme.tabs.active.border} !important; - } - } - } -`; - -export default StyledWrapper; diff --git a/packages/bruno-app/src/components/RequestPane/GraphQLRequestPane/index.js b/packages/bruno-app/src/components/RequestPane/GraphQLRequestPane/index.js index da48bb34a..6fac333e5 100644 --- a/packages/bruno-app/src/components/RequestPane/GraphQLRequestPane/index.js +++ b/packages/bruno-app/src/components/RequestPane/GraphQLRequestPane/index.js @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useState, useCallback, useMemo, useRef } from 'react'; import find from 'lodash/find'; import get from 'lodash/get'; import classnames from 'classnames'; @@ -15,54 +15,86 @@ import Tests from 'components/RequestPane/Tests'; import { useTheme } from 'providers/Theme'; import { updateRequestGraphqlQuery } from 'providers/ReduxStore/slices/collections'; import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions'; -import StyledWrapper from './StyledWrapper'; import Documentation from 'components/Documentation/index'; import GraphQLSchemaActions from '../GraphQLSchemaActions/index'; import HeightBoundContainer from 'ui/HeightBoundContainer'; import Settings from 'components/RequestPane/Settings'; +import RequestPaneTabs from 'components/RequestPane/RequestPaneTabs'; + +const MULTIPLE_CONTENT_TABS = new Set(['script', 'vars', 'auth', 'docs']); + +const TAB_CONFIG = [ + { key: 'query', label: 'Query' }, + { key: 'variables', label: 'Variables' }, + { key: 'headers', label: 'Headers' }, + { key: 'auth', label: 'Auth' }, + { key: 'vars', label: 'Vars' }, + { key: 'script', label: 'Script' }, + { key: 'assert', label: 'Assert' }, + { key: 'tests', label: 'Tests' }, + { key: 'docs', label: 'Docs' }, + { key: 'settings', label: 'Settings' } +]; const GraphQLRequestPane = ({ item, collection, onSchemaLoad, toggleDocs, handleGqlClickReference }) => { const dispatch = useDispatch(); const tabs = useSelector((state) => state.tabs.tabs); const activeTabUid = useSelector((state) => state.tabs.activeTabUid); + const preferences = useSelector((state) => state.app.preferences); + const query = item.draft ? get(item, 'draft.request.body.graphql.query', '') : get(item, 'request.body.graphql.query', ''); const variables = item.draft ? get(item, 'draft.request.body.graphql.variables') : get(item, 'request.body.graphql.variables'); + const { displayedTheme } = useTheme(); const [schema, setSchema] = useState(null); - const preferences = useSelector((state) => state.app.preferences); + const schemaActionsRef = useRef(null); + + const focusedTab = find(tabs, (t) => t.uid === activeTabUid); + const requestPaneTab = focusedTab?.requestPaneTab; useEffect(() => { onSchemaLoad(schema); - }, [schema]); + }, [schema, onSchemaLoad]); - const onQueryChange = (value) => { - dispatch( - updateRequestGraphqlQuery({ - query: value, - itemUid: item.uid, - collectionUid: collection.uid - }) - ); - }; - const onRun = () => dispatch(sendRequest(item, collection.uid)); - const onSave = () => dispatch(saveRequest(item.uid, collection.uid)); + const onQueryChange = useCallback( + (value) => { + dispatch( + updateRequestGraphqlQuery({ + query: value, + itemUid: item.uid, + collectionUid: collection.uid + }) + ); + }, + [dispatch, item.uid, collection.uid] + ); - const selectTab = (tab) => { - dispatch( - updateRequestPaneTab({ - uid: item.uid, - requestPaneTab: tab - }) - ); - }; + const onRun = useCallback( + () => dispatch(sendRequest(item, collection.uid)), + [dispatch, item, collection.uid] + ); - const getTabPanel = (tab) => { - switch (tab) { - case 'query': { + const onSave = useCallback( + () => dispatch(saveRequest(item.uid, collection.uid)), + [dispatch, item.uid, collection.uid] + ); + + const selectTab = useCallback( + (tabKey) => { + dispatch(updateRequestPaneTab({ uid: item.uid, requestPaneTab: tabKey })); + }, + [dispatch, item.uid] + ); + + const allTabs = useMemo(() => TAB_CONFIG.map(({ key, label }) => ({ key, label })), []); + + const tabPanel = useMemo(() => { + switch (requestPaneTab) { + case 'query': return ( ); - } - case 'variables': { + case 'variables': return ; - } - case 'headers': { + case 'headers': return ; - } - case 'auth': { + case 'auth': return ; - } - case 'vars': { + case 'vars': return ; - } - case 'assert': { + case 'assert': return ; - } - case 'script': { + case 'script': return