Skip to content

Commit

Permalink
Merge pull request #539 from NBISweden/dev/autoselect
Browse files Browse the repository at this point in the history
Autoselect valid issue ids
  • Loading branch information
jonandernovella authored Aug 3, 2022
2 parents f33c74f + 5147032 commit 5e4d535
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions frontend/src/components/QuickAdd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export const QuickAdd = ({
const debouncedSearch = useDebounce(search, 500);
const context = React.useContext(AuthContext);

const isNumber = (s: string) => {
return Number.isInteger(Number(s));
};

React.useEffect(() => {
let endpoint = "/api/activities";
if (issue) endpoint += "?issue_id=" + issue.id;
Expand Down Expand Up @@ -58,7 +62,7 @@ export const QuickAdd = ({
let res: { issues: Issue[] };
let candidateIssues: Issue[];

if (Number.isInteger(Number(search.text))) {
if (isNumber(search.text)) {
const endpoint = `/api/issues?status_id=*&issue_id=${search.text}`;
res = await getApiEndpoint(endpoint, context);
} else {
Expand All @@ -67,7 +71,12 @@ export const QuickAdd = ({
if (!didCancel && res.issues) {
if (res.issues.length > 0) {
if (res.issues.length === 1) {
candidateIssues = [res.issues[0]];
let foundIssue = res.issues[0];
candidateIssues = [foundIssue];
//allow for valid issue id autoselection
if (isNumber(search.text)) {
setIssue(foundIssue);
}
} else {
candidateIssues = res.issues;
}
Expand Down

0 comments on commit 5e4d535

Please sign in to comment.