Skip to content

Avoid triggering click event on key down, and set focus on search input after submit #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN yarn run build

# ==== SET ENV NGINX =====
# Bundle static assets with nginx
FROM nginxinc/nginx-unprivileged:1.23.0-alpine as production
FROM nginxinc/nginx-unprivileged:1.23.3-alpine as production
ENV NODE_ENV production
# Copy built assets from `builder` image
COPY --from=builder /app/build /usr/share/nginx/html
Expand All @@ -43,7 +43,14 @@ CMD ["nginx", "-g", "daemon off;"]

# needed for chmod
USER root

# needed for write access for deployment.sh
RUN mkdir /tmp/proxy_temp && chmod 0757 /usr/share/nginx/html/

Copy link
Collaborator

@seirasto seirasto Mar 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this code below for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a mismatch between the feature branch's base and the PR base. These changes are from acl2023_demo.

# needed to mitigate CVE-2023-23914, CVE-2023-23915 and CVE-2023-23916
RUN apk update && \
apk upgrade && \
apk add libcurl>=7.87.0-r2 curl>=7.87.0-r2

# reinstate the user
USER nginx
82 changes: 31 additions & 51 deletions src/applications/qa/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
*/

import PropTypes from "prop-types";
import React, { useState } from "react";
import React, { useState, useRef } from "react";
import { useSelector, useDispatch } from "react-redux";
import _ from "lodash";

import { Search, Button } from "@carbon/react";
import { Search, Form, Button } from "@carbon/react";

import Collections from "../../components/collections";
import Retrievers from "../../components/retrievers";
Expand Down Expand Up @@ -125,6 +125,9 @@ function QuestionAnswering({ application, showSettings }) {
const readers = useSelector((state) => state.readers);
const dispatch = useDispatch();

// Reference for search input
const searchRef = useRef(null);

return (
<div className="application">
<div className="application__body">
Expand All @@ -133,10 +136,33 @@ function QuestionAnswering({ application, showSettings }) {
</div>
<div className="application__content">
<h4>What would you like to know?</h4>
<div className="qa__input">
<Form className="qa__input"
onSubmit={evt => {
evt.preventDefault();

// Step 1: Set processing to true
setProcessing(true);

// Step 2: Trigger ask function
ask(
questionText,
retrievers.selectedRetriever,
selectedCollection,
readers.selectedReader,
setAnswers,
setProcessing,
setProcessed,
dispatch
);

// Sets the focus on search input, accessing it through its reference
searchRef.current.focus();
Copy link
Collaborator

@seirasto seirasto Mar 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment here (and in the similar locations in the other files) regarding functionality e.g. "Switch focus to question text field"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Comments added.

}}
>
<div className="qa__input--box">
<Search
id="qa__question"
ref={searchRef}
labelText={questionText}
placeholder={strings.PLACEHOLDER_QUESTION}
disabled={
Expand All @@ -155,20 +181,6 @@ function QuestionAnswering({ application, showSettings }) {
setProcessed(false);
setQuestionText(event.target.value);
}}
onKeyDown={(event) => {
if (event.key === "Enter") {
ask(
questionText,
retrievers.selectedRetriever,
selectedCollection,
readers.selectedReader,
setAnswers,
setProcessing,
setProcessed,
dispatch
);
}
}}
onClick={() => {
setShowSuggestedQuestions(true);
}}
Expand Down Expand Up @@ -205,40 +217,8 @@ function QuestionAnswering({ application, showSettings }) {
) : null}
</div>
<Button
className="qa__question--submit-btn"
kind="primary"
onClick={() => {
// Step 1: Set processing to true
setProcessing(true);

// Step 2: Trigger ask function
ask(
questionText,
retrievers.selectedRetriever,
selectedCollection,
readers.selectedReader,
setAnswers,
setProcessing,
setProcessed,
dispatch
);
}}
onKeyDown={() => {
// Step 1: Set processing to true
setProcessing(true);

// Step 2: Trigger ask function
ask(
questionText,
retrievers.selectedRetriever,
selectedCollection,
readers.selectedReader,
setAnswers,
setProcessing,
setProcessed,
dispatch
);
}}
type="submit"
disabled={
disabled ||
!retrievers.selectedRetriever ||
Expand All @@ -249,7 +229,7 @@ function QuestionAnswering({ application, showSettings }) {
>
Ask
</Button>
</div>
</Form>
{questionText !== strings.PLACEHOLDER_QUESTION ? (
<div className="answers">
{(processing || processed) && questionText ? (
Expand Down
78 changes: 30 additions & 48 deletions src/applications/reading/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
*/

import PropTypes from "prop-types";
import React, { useState } from "react";
import React, { useState, useRef } from "react";
import { useSelector, useDispatch } from "react-redux";
import _ from "lodash";

import { TextArea, TextInput, Button } from "@carbon/react";
import { TextArea, TextInput, Form, Button } from "@carbon/react";

import Readers from "../../components/readers";
import Answers from "../../components/answers";
Expand Down Expand Up @@ -117,6 +117,9 @@ function Reading({ application, showSettings }) {
const readers = useSelector((state) => state.readers);
const dispatch = useDispatch();

// Reference for question input
const questionRef = useRef(null);

return (
<div className="application">
<div className="application__body">
Expand All @@ -137,9 +140,31 @@ function Reading({ application, showSettings }) {
setContext(event.target.value);
}}
></TextArea>
<div className="reading__input--box">
<Form className="reading__input--box"
onSubmit={evt => {
evt.preventDefault();

// Step 1: Set processing to true
setProcessing(true);

// Step 2: Trigger read function
read(
questionText,
context,
readers.selectedReader,
setAnswers,
setProcessing,
setProcessed,
dispatch
);

// Sets the focus on question input, accessing it through its reference
questionRef.current.focus();
}}
>
<TextInput
id="reading__question"
ref={questionRef}
labelText={"Question"}
placeholder={strings.PLACEHOLDER_QUESTION}
disabled={disabled || !context || !readers.selectedReader}
Expand All @@ -152,53 +177,10 @@ function Reading({ application, showSettings }) {
setProcessed(false);
setQuestionText(event.target.value);
}}
onKeyDown={(event) => {
if (event.key === "Enter") {
read(
questionText,
context,
readers.selectedReader,
setAnswers,
setProcessing,
setProcessed,
dispatch
);
}
}}
></TextInput>
<Button
className="reading__question--submit-btn"
kind="primary"
onClick={() => {
// Step 1: Set processing to true
setProcessing(true);

// Step 2: Trigger ask function
read(
questionText,
context,
readers.selectedReader,
setAnswers,
setProcessing,
setProcessed,
dispatch
);
}}
onKeyDown={() => {
// Step 1: Set processing to true
setProcessing(true);

// Step 2: Trigger ask function
read(
questionText,
context,
readers.selectedReader,
setAnswers,
setProcessing,
setProcessed,
dispatch
);
}}
type="submit"
disabled={
disabled ||
!context ||
Expand All @@ -208,7 +190,7 @@ function Reading({ application, showSettings }) {
>
Ask
</Button>
</div>
</Form>
</div>
{questionText !== strings.PLACEHOLDER_QUESTION ? (
<div className="answers">
Expand Down
65 changes: 30 additions & 35 deletions src/applications/retrieval/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*/

import PropTypes from "prop-types";
import React, { useState } from "react";
import React, { useState, useRef } from "react";
import { useSelector, useDispatch } from "react-redux";

import { Search, Button } from "@carbon/react";
import { Search, Form, Button } from "@carbon/react";

import Collections from "../../components/collections";
import Retrievers from "../../components/retrievers";
Expand Down Expand Up @@ -103,6 +103,9 @@ function Retrieval({ application, showSettings }) {
const retrievers = useSelector((state) => state.retrievers);
const dispatch = useDispatch();

// Reference for search input
const searchRef = useRef(null);

return (
<div className="application">
<div className="application__body">
Expand All @@ -111,10 +114,32 @@ function Retrieval({ application, showSettings }) {
</div>
<div className="application__content">
<h4>What would you like to know?</h4>
<div className="qa__input">
<Form className="qa__input"
onSubmit={evt => {
evt.preventDefault();

// Step 1: Set processing to true
setProcessing(true);

// Step 2: Trigger ask function
ask(
questionText,
retrievers.selectedRetriever,
selectedCollection,
setDocuments,
setProcessing,
setProcessed,
dispatch
);

// Sets the focus on search input, accessing it through its reference
searchRef.current.focus();
}}
>
<div className="qa__input--box">
<Search
id="qa__question"
ref={searchRef}
labelText={questionText}
placeholder={strings.PLACEHOLDER_QUESTION}
disabled={
Expand Down Expand Up @@ -181,38 +206,8 @@ function Retrieval({ application, showSettings }) {
) : null}
</div>
<Button
className="qa__question--submit-btn"
kind="primary"
onClick={() => {
// Step 1: Set processing to true
setProcessing(true);

// Step 2: Trigger ask function
ask(
questionText,
retrievers.selectedRetriever,
selectedCollection,
setDocuments,
setProcessing,
setProcessed,
dispatch
);
}}
onKeyDown={() => {
// Step 1: Set processing to true
setProcessing(true);

// Step 2: Trigger ask function
ask(
questionText,
retrievers.selectedRetriever,
selectedCollection,
setDocuments,
setProcessing,
setProcessed,
dispatch
);
}}
type="submit"
disabled={
disabled ||
!retrievers.selectedRetriever ||
Expand All @@ -222,7 +217,7 @@ function Retrieval({ application, showSettings }) {
>
Ask
</Button>
</div>
</Form>
{questionText !== strings.PLACEHOLDER_QUESTION ? (
<div className="documents">
{(processing || processed) && questionText ? (
Expand Down
Loading