Bug/UI/tra 4169 apply qury by enter (#660)

* add shortcuts listeners and config

* key added

* listen for shortcut on input

* refactoring listensing to Enter Press

* comment for support

Co-authored-by: Leon <>
This commit is contained in:
leon-up9
2022-01-18 12:08:53 +02:00
committed by GitHub
parent c8a3033f87
commit 6235217ead
5 changed files with 62 additions and 14 deletions

View File

@@ -9,6 +9,8 @@ import filterUIExample2 from "./assets/filter-ui-example-2.png"
import variables from '../variables.module.scss';
import {useRecoilState} from "recoil";
import queryAtom from "../recoil/query";
import useKeyPress from "../hooks/useKeyPress"
import shortcutsKeyboard from "../configs/shortcutsKeyboard"
interface FiltersProps {
backgroundColor: string
@@ -60,6 +62,8 @@ export const QueryForm: React.FC<QueryFormProps> = ({backgroundColor, ws, openWe
setQuery(e.target.value);
}
const handleSubmit = (e) => {
ws.close();
if (query) {
@@ -70,6 +74,8 @@ export const QueryForm: React.FC<QueryFormProps> = ({backgroundColor, ws, openWe
e.preventDefault();
}
useKeyPress(shortcutsKeyboard.ctrlEnter, handleSubmit, formRef.current);
return <>
<form
ref={formRef}

View File

@@ -1,5 +1,5 @@
import { Button } from "@material-ui/core";
import React, { useState } from "react";
import React, { useState,useRef } from "react";
import { adminUsername } from "../consts";
import Api, { FormValidationErrorType } from "../helpers/api";
import { toast } from 'react-toastify';
@@ -7,6 +7,9 @@ import LoadingOverlay from "./LoadingOverlay";
import { useCommonStyles } from "../helpers/commonStyle";
import {useSetRecoilState} from "recoil";
import entPageAtom, {Page} from "../recoil/entPage";
import useKeyPress from "../hooks/useKeyPress"
import shortcutsKeyboard from "../configs/shortcutsKeyboard"
const api = Api.getInstance();
@@ -16,6 +19,7 @@ interface InstallPageProps {
export const InstallPage: React.FC<InstallPageProps> = ({onFirstLogin}) => {
const formRef = useRef(null);
const classes = useCommonStyles();
const [isLoading, setIsLoading] = useState(false);
const [password, setPassword] = useState("");
@@ -54,13 +58,9 @@ export const InstallPage: React.FC<InstallPageProps> = ({onFirstLogin}) => {
}
const handleFormOnKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === "Enter") {
onFormSubmit();
}
};
useKeyPress(shortcutsKeyboard.enter, onFormSubmit, formRef.current);
return <div className="centeredForm" onKeyPress={handleFormOnKeyPress}>
return <div className="centeredForm" ref={formRef}>
{isLoading && <LoadingOverlay/>}
<div className="form-title left-text">Setup</div>
<span className="form-subtitle">Welcome to Mizu, please set up the admin user to continue</span>

View File

@@ -1,11 +1,14 @@
import { Button } from "@material-ui/core";
import React, { useState } from "react";
import React, { useState,useRef } from "react";
import { toast } from "react-toastify";
import Api from "../helpers/api";
import { useCommonStyles } from "../helpers/commonStyle";
import LoadingOverlay from "./LoadingOverlay";
import entPageAtom, {Page} from "../recoil/entPage";
import {useSetRecoilState} from "recoil";
import useKeyPress from "../hooks/useKeyPress"
import shortcutsKeyboard from "../configs/shortcutsKeyboard"
const api = Api.getInstance();
@@ -15,6 +18,7 @@ const LoginPage: React.FC = () => {
const [isLoading, setIsLoading] = useState(false);
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const formRef = useRef(null);
const setEntPage = useSetRecoilState(entPageAtom);
@@ -36,13 +40,9 @@ const LoginPage: React.FC = () => {
}
}
const handleFormOnKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === "Enter") {
onFormSubmit();
}
};
useKeyPress(shortcutsKeyboard.enter, onFormSubmit, formRef.current);
return <div className="centeredForm" onKeyPress={handleFormOnKeyPress}>
return <div className="centeredForm" ref={formRef}>
{isLoading && <LoadingOverlay/>}
<div className="form-title left-text">Login</div>
<div className="form-input">