diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b2e0a9a1e4..e29cd81fb8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - server: fix inherited_roles issue when some of the underlying roles don't have permissions configured (fixes #6672) - server: fix action custom types failing to parse when mutually recursive +- console: allow editing rest endpoints queries and misc ui improvements - cli: match ordering of keys in project metadata files with server metadata ## v2.0.0-alpha.5 diff --git a/console/src/components/Services/ApiExplorer/Rest/Create/RequestViewer.tsx b/console/src/components/Services/ApiExplorer/Rest/Create/RequestViewer.tsx index 3ba3bbb0237..0cfc05471c9 100644 --- a/console/src/components/Services/ApiExplorer/Rest/Create/RequestViewer.tsx +++ b/console/src/components/Services/ApiExplorer/Rest/Create/RequestViewer.tsx @@ -7,15 +7,27 @@ import styles from '../RESTStyles.scss'; type RequestViewerProps = { request: string; + onChangeQueryText?: (value: string) => void; + isEditable?: boolean; }; -const RequestViewer: React.FC = ({ request }) => ( +const RequestViewer: React.FC = ({ + request, + isEditable = false, + onChangeQueryText, +}) => (
- +
); diff --git a/console/src/components/Services/ApiExplorer/Rest/Create/index.tsx b/console/src/components/Services/ApiExplorer/Rest/Create/index.tsx index 4664ef985f0..e953b4d2462 100644 --- a/console/src/components/Services/ApiExplorer/Rest/Create/index.tsx +++ b/console/src/components/Services/ApiExplorer/Rest/Create/index.tsx @@ -1,4 +1,4 @@ -import React, { useReducer, useEffect, useState } from 'react'; +import React, { useReducer, useEffect, useRef } from 'react'; import { RouteComponentProps } from 'react-router'; import { connect, ConnectedProps } from 'react-redux'; @@ -47,7 +47,21 @@ const cleanUpState = (state: CreateEndpointState) => { }; const isErroredState = (state: CreateEndpointState) => { - return !state.name || !state.url || !state.request || !state.methods.length; + const errorFields = []; + if (!state.name) { + errorFields.push('Name'); + } + if (!state.url) { + errorFields.push('Location'); + } + if (!state.request) { + errorFields.push('Request'); + } + if (!state.methods.length) { + errorFields.push('Method'); + } + + return errorFields; }; const createEndpointObject = ( @@ -87,7 +101,7 @@ const CreateEndpoint: React.FC = ({ createEndpointReducer, defaultState ); - const [oldState, updateOldState] = useState(null); + const oldState = useRef(null); const isPageCreate = location.pathname === '/api/rest/create'; // currentPageName will have a valid value, when it's on the edit page let currentPageName = ''; @@ -166,7 +180,7 @@ const CreateEndpoint: React.FC = ({ // Ideally, this also, should not be happening return; } - updateOldState(oldRestEndpointEntry); + oldState.current = oldRestEndpointEntry; updateEndpointName(oldRestEndpointEntry.name); updateEndpointComment(oldRestEndpointEntry?.comment ?? ''); updateEndpointURL(oldRestEndpointEntry.url); @@ -190,14 +204,19 @@ const CreateEndpoint: React.FC = ({ const onClickCreate = () => { const cleanedUpState = cleanUpState(inputState); - if (isErroredState(cleanedUpState)) { + const catchedError = isErroredState(cleanedUpState); + const errorLen = catchedError.length; + if (errorLen >= 1) { + const fieldText = `field${errorLen >= 2 ? 's' : ''}`; + const isAreText = `${errorLen >= 2 ? 'are' : 'is a'}`; showError( 'Some required fields are empty', - 'Name, Location, Request and Methods are required fields.' + `${catchedError.join(', ')} ${isAreText} required ${fieldText}.` ); return; } - // NOTE: this is a case of extreme safe coding. Maybe be unecessary here. + // NOTE: this check is necessary for the edit page + // where queries can be edited if (!isQueryValid(cleanedUpState.request)) { showError( 'Invalid Query being used to create endpoint', @@ -209,10 +228,10 @@ const CreateEndpoint: React.FC = ({ createEndpoint(restEndpointObj, request, resetPageState); return; } - if (!oldState) { + if (!oldState || !oldState.current) { return; } - editEndpoint(oldState, restEndpointObj, request, resetPageState); + editEndpoint(oldState.current, restEndpointObj, request, resetPageState); }; return ( @@ -254,7 +273,11 @@ const CreateEndpoint: React.FC = ({ currentState={inputState.methods} updateState={updateEndpointMethods} /> - +