Skip to content

Commit

Permalink
disabled vexplain button till sql and keyspace are set
Browse files Browse the repository at this point in the history
Signed-off-by: c-r-dev <[email protected]>
  • Loading branch information
c-r-dev committed Jan 27, 2025
1 parent 918d02e commit 65d7721
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions web/vtadmin/src/components/routes/VExplain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import React, { useMemo } from 'react';
import { orderBy } from 'lodash-es';

import { vtadmin as pb } from '../../proto/vtadmin';
Expand Down Expand Up @@ -69,25 +69,22 @@ export const VExplain = () => {

const onSubmit: React.FormEventHandler<HTMLFormElement> = (e) => {
e.preventDefault();
let alertMessage = '';
if (keyspaceName === '' || keyspaceName === null) {
alertMessage += 'Please choose keyspace.\n\n';
}
if (sql === '' || sql === null) {
alertMessage += 'Please enter SQL statement.\n\n';
}
if (vexplainOption === '' || vexplainOption === null) {
alertMessage += 'Please choose vexplain option.\n\n';
}
if (alertMessage.trim() !== '') {
alert(alertMessage);
return;
}

refetch();
};

const VEXPLAIN_OPTIONS = ['ALL', 'PLAN', 'QUERIES', 'TRACE', 'KEYS'];

const isReadyForSubmit = useMemo(() => {
return (
typeof keyspaceName !== 'undefined' &&
keyspaceName !== null &&
keyspaceName !== '' &&
typeof sql !== 'undefined' &&
sql !== null &&
sql !== ''
);
}, [keyspaceName, sql]);

return (
<div>
<WorkspaceHeader>
Expand Down Expand Up @@ -129,7 +126,7 @@ export const VExplain = () => {
selectedItem={vexplainOption || null}
/>
<div className={style.buttons}>
<button className="btn align-bottom" type="submit">
<button className="btn align-bottom" disabled={!isReadyForSubmit} type="submit">
Run VExplain {vexplainOption}
</button>
</div>
Expand Down

0 comments on commit 65d7721

Please sign in to comment.