Skip to content
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

feat: Search functionality - Frontend #92

Merged
merged 73 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
d0a626a
Initial commit: Front page + list of entries
aadarsh-ram Jul 29, 2022
5cdf10d
Removed duplicate file
aadarsh-ram Jul 29, 2022
058877f
Change import
aadarsh-ram Jul 29, 2022
69386ec
Changed buttons and image types
aadarsh-ram Jul 30, 2022
fa5f076
View parents and children in frontend
aadarsh-ram Jul 30, 2022
40bcc0a
Added navbar + parents/children + Main language synonyms
aadarsh-ram Jul 31, 2022
1f181f2
Added all translations and properties
aadarsh-ram Aug 1, 2022
21babe6
Fix stopwords/synonyms page + add preceding_lines
aadarsh-ram Aug 2, 2022
865d98b
Change favicons and manifest
aadarsh-ram Aug 2, 2022
26d4ba6
Add requested changes
aadarsh-ram Aug 3, 2022
87a7f4f
Add requested changes (part 2)
aadarsh-ram Aug 3, 2022
082f90f
Added submit button + update functionality
aadarsh-ram Aug 4, 2022
6b93681
Add requested changes (part 3)
aadarsh-ram Aug 5, 2022
55b4b4e
Change variable obj to value
aadarsh-ram Aug 5, 2022
bcc52a1
Remove console.log
aadarsh-ram Aug 5, 2022
4acd997
Changed div to Mui Box
aadarsh-ram Aug 5, 2022
d07ea89
Changes regarding variable nodeObject
aadarsh-ram Aug 5, 2022
2355c4a
Restructure AccumulateAllComponents.jsx and index.jsx
aadarsh-ram Aug 5, 2022
48c57a4
Change text css
aadarsh-ram Aug 5, 2022
352aaa7
Add/Delete Properties WIP
aadarsh-ram Aug 6, 2022
b6aac40
Properties CRUD WIP2
aadarsh-ram Aug 7, 2022
81ce0a7
Properties Table Edit WIP
aadarsh-ram Aug 8, 2022
bd9062e
Remove WIP Properties table implementation
aadarsh-ram Aug 8, 2022
caff9d8
Add comment
aadarsh-ram Aug 8, 2022
971997c
Add helper comments
aadarsh-ram Aug 8, 2022
f8807d3
Added CRUD for properties of an entry
aadarsh-ram Aug 9, 2022
e4f6c14
Add useEffect
aadarsh-ram Aug 12, 2022
bcc0385
Implement CRUD for translations + Refactor previous code
aadarsh-ram Aug 12, 2022
85c92b6
Added CRUD for synonyms, stopwords
aadarsh-ram Aug 13, 2022
a0bfe11
Previous PR changes WIP
aadarsh-ram Aug 17, 2022
61b209e
Add a translation button
aadarsh-ram Aug 17, 2022
2594806
Added functionality to add translation language
aadarsh-ram Aug 19, 2022
03efc9a
Added deletion of a translation language
aadarsh-ram Aug 19, 2022
6981ff9
Add paths for updating children and add in frontend
aadarsh-ram Aug 30, 2022
e411183
Update children query changed
aadarsh-ram Sep 2, 2022
aeca594
Added update in backend
aadarsh-ram Sep 8, 2022
4150a8c
Add node functionality completed
aadarsh-ram Sep 9, 2022
57dc9dc
Completed delete root node functionality
aadarsh-ram Sep 11, 2022
969559b
Rename files and add previous PR changes
aadarsh-ram Sep 12, 2022
3224c95
Merge branch 'main' into propertiesTable
aadarsh-ram Sep 12, 2022
331278c
Change variable names + Remove backend changes
aadarsh-ram Sep 12, 2022
6cf8533
Merge with main
aadarsh-ram Sep 12, 2022
9f680c5
Add requested changes + fixes
aadarsh-ram Sep 21, 2022
b0f2683
Remove state from originalNodeObject
aadarsh-ram Sep 21, 2022
b935ac9
Change then/catch position
aadarsh-ram Sep 21, 2022
e94196e
Change dialog to snackbar
aadarsh-ram Sep 21, 2022
7a49723
Add requested changes
aadarsh-ram Sep 22, 2022
eb492c2
Merge branch 'main' into propertiesTable
aadarsh-ram Sep 22, 2022
6d764db
Added search functionality
aadarsh-ram Sep 23, 2022
4bfd008
Added indexes for tags
aadarsh-ram Sep 24, 2022
e1231cf
Remove backend commits
aadarsh-ram Sep 24, 2022
62ad543
Remove test.txt
aadarsh-ram Sep 24, 2022
b9ae4dd
Remove whitespaces
aadarsh-ram Sep 24, 2022
30a921c
Add newline
aadarsh-ram Sep 24, 2022
45ffdb3
Add newline
aadarsh-ram Sep 24, 2022
5cc96de
Add requested changes WIP
aadarsh-ram Sep 26, 2022
4429926
Change variable type
aadarsh-ram Sep 26, 2022
382ac5f
Add keyCode
aadarsh-ram Sep 27, 2022
16a4f68
Change to e.KeyCode
aadarsh-ram Sep 27, 2022
93ee59c
Change typo
aadarsh-ram Sep 27, 2022
413531e
Remove original nodeObject
aadarsh-ram Oct 3, 2022
0bd9fd5
Add early return and comments
aadarsh-ram Oct 5, 2022
dd41e31
Merge branch 'main' into propertiesTable
aadarsh-ram Oct 5, 2022
0cb09b3
Merge branch 'propertiesTable' into search
aadarsh-ram Oct 5, 2022
230712d
Merge branch 'main' into search
aadarsh-ram Oct 5, 2022
b4bd13b
Remove separate results page
aadarsh-ram Oct 7, 2022
ad006be
Merge branch 'search' of https://github.com/openfoodfacts/taxonomy-ed…
aadarsh-ram Oct 7, 2022
0a3a273
Remove query params
aadarsh-ram Oct 8, 2022
8963b4d
Merge branch 'main' into search
aadarsh-ram Oct 8, 2022
260e266
Add requested changes (part 2)
aadarsh-ram Oct 8, 2022
7a8cded
Add enter keycode to constants
aadarsh-ram Oct 8, 2022
9933095
Change trim location
aadarsh-ram Oct 9, 2022
ec38a09
Add issue as comment
aadarsh-ram Oct 10, 2022
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
33 changes: 12 additions & 21 deletions taxonomy-editor-frontend/src/pages/search/index.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { Typography, Box, TextField, Grid, IconButton, InputAdornment } from "@mui/material";
import SearchIcon from '@mui/icons-material/Search';
import Container from '@mui/material/Container';
import { useState } from "react";
import { Link, useNavigate, useSearchParams } from "react-router-dom";
import SearchResults from "./results";

const SearchNode = () => {
const [searchParams] = useSearchParams();
let queryString = searchParams.get('query');
if (queryString === "") queryString = "\"\""

const [query, setQuery] = useState("");
const navigate = useNavigate();
const [queryToBeSent, setQueryToBeSent] = useState(null);
return (
<Box>
<Container component="main" maxWidth="xs">
{/* <Container component="main" maxWidth="xs"> */}
<Grid
container
direction="column"
Expand All @@ -32,37 +26,34 @@ const SearchNode = () => {
src={require('../../assets/classification.png')}
alt="Classification Logo"
/>
<TextField
sx={{mt: 3}}
<form onSubmit={(event) => {event.preventDefault(); setQueryToBeSent(query)}}>
<TextField
sx={{mt: 3, width: 350}}
InputProps={{
endAdornment: (
<InputAdornment position="end">
<IconButton
disabled={query.trim().length === 0}
component={Link}
to={{
pathname: '/search',
search: `?query=${query}`
}}
disabled={query.length === 0}
type="submit"
>
<SearchIcon />
</IconButton>
</InputAdornment>
)
}}
fullWidth
onKeyDown={(e) => {
if (e.key === "Enter" && query.trim().length !== 0) {
navigate(`/search?query=${query}`)
if (e.keyCode === 13 && query.length !== 0) {
setQueryToBeSent(query)
}
}}
onChange = {event => {
setQuery(event.target.value.trim())
}}
value={query} />
</form>
</Grid>
</Container>
{queryString !== null && <SearchResults query={queryString}/>}
{/* </Container> */}
{queryToBeSent !== null && <SearchResults query={queryToBeSent}/>}
</Box>
);
}
Expand Down
82 changes: 43 additions & 39 deletions taxonomy-editor-frontend/src/pages/search/results.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Typography, Box, TextField, Grid, Stack, Button, IconButton, Paper, FormControl, InputLabel } from "@mui/material";
import { Typography, Snackbar, Alert, Box, TextField, Grid, Stack, Button, IconButton, Paper, FormControl, InputLabel } from "@mui/material";
import useFetch from "../../components/useFetch";
import { useNavigate } from "react-router-dom";
import { useState } from "react";
Expand All @@ -15,21 +15,20 @@ import AddBoxIcon from '@mui/icons-material/AddBox';
import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
import DialogTitle from '@mui/material/DialogTitle';
import Select from '@mui/material/Select';
import ISO6391 from 'iso-639-1';

const SearchResults = ({query}) => {
const url = API_URL+`search?query=${query}`
const { data: nodes, isPending, isError, isSuccess, errorMessage } = useFetch(url);

const [nodeType, setNodeType] = useState('entry'); // Used for storing node type
const [newLanguageCode, setNewLanguageCode] = useState(null); // Used for storing new Language Code
const [newNode, setnewNode] = useState(null); // Used for storing canonical tag
const [isValidLC, setisValidLC] = useState(false); // Used for validating a new LC
const [isValidLanguageCode, setIsValidLanguageCode] = useState(false); // Used for validating a new LC
const [openAddDialog, setOpenAddDialog] = useState(false);
const [openSuccessDialog, setOpenSuccessDialog] = useState(false);
const [btnDisabled, setBtnDisabled] = useState(true);
const [openSuccessSnackbar, setOpenSuccessSnackbar] = useState(false);
const navigate = useNavigate();

// Handler function for button clicks
Expand All @@ -40,27 +39,38 @@ const SearchResults = ({query}) => {
// Helper functions for Dialog component
function handleCloseAddDialog() { setOpenAddDialog(false); }
function handleOpenAddDialog() { setOpenAddDialog(true); }
function handleCloseSuccessDialog() { setOpenSuccessDialog(false); }
function handleOpenSuccessDialog() { setOpenSuccessDialog(true); }
function handleOpenSuccessSnackbar() { setOpenSuccessSnackbar(true); }
function handleCloseSuccessSnackbar() { setOpenSuccessSnackbar(false); }

function handleAddNode() {
const newNodeID = newLanguageCode + ':' + newNode // Reconstructing node ID
const data = {"id": newNodeID, "main_language": newLanguageCode};
fetch(url, {
fetch(API_URL+'nodes', {
method : 'POST',
headers: {"Content-Type" : "application/json"},
body: JSON.stringify(data)
}).then(() => {
handleCloseAddDialog();
handleOpenSuccessDialog();
handleOpenSuccessSnackbar();
}).catch((errorMessage) => {
// Do nothing
})
}

// Displaying errorMessages if any
if (isError) {
return (<Typography variant='h5'>{errorMessage}</Typography>)
return (
<Container component="main" maxWidth="xs">
<Grid
container
direction="column"
alignItems="center"
justifyContent="center"
>
<Typography sx={{mt: 2}} variant='h5'>{errorMessage}</Typography>
</Grid>
</Container>
)
}

// Loading...
Expand All @@ -73,7 +83,7 @@ const SearchResults = ({query}) => {
alignItems="center"
justifyContent="center"
>
<Typography variant='h5'>Loading..</Typography>
<Typography sx={{mt: 2}} variant='h5'>Loading..</Typography>
</Grid>
</Container>
)
Expand All @@ -95,7 +105,7 @@ const SearchResults = ({query}) => {
Number of nodes found: {nodes.length}
</Typography>
{/* Table for listing all nodes in taxonomy */}
<TableContainer sx={{ml: 2, width: 400}} component={Paper}>
<TableContainer sx={{width: 375}} component={Paper}>
<Table>
<TableHead>
<TableRow>
Expand All @@ -117,17 +127,17 @@ const SearchResults = ({query}) => {
</TableRow>
</TableHead>
<TableBody>
{nodes.map((node) => (
{nodes.map((nodeID) => (
<TableRow
key={node}
key={nodeID}
>
<TableCell align="left" component="td" scope="row">
<Typography variant="subtitle1">
{node}
{nodeID}
</Typography>
</TableCell>
<TableCell align="left" component="td" scope="row">
<IconButton onClick={event => handleClick(event, node) } aria-label="edit">
<IconButton onClick={event => handleClick(event, nodeID) } aria-label="edit">
<EditIcon color="primary"/>
</IconButton>
</TableCell>
Expand Down Expand Up @@ -163,11 +173,14 @@ const SearchResults = ({query}) => {
onChange={(e) => {
setNewLanguageCode(e.target.value);
const validateBool = ISO6391.validate(e.target.value);
validateBool ? setisValidLC(true) : setisValidLC(false);
validateBool ? setBtnDisabled(false) : setBtnDisabled(true);
if (validateBool) {
setIsValidLanguageCode(true);
} else {
setIsValidLanguageCode(false);
}
}}
label="Language Code"
error={!isValidLC}
error={!isValidLanguageCode}
sx={{width : 150, ml: 4.5}}
size="small"
variant="outlined"
Expand All @@ -192,32 +205,23 @@ const SearchResults = ({query}) => {
<DialogActions>
<Button onClick={handleCloseAddDialog}>Cancel</Button>
<Button
disabled={btnDisabled}
disabled={!isValidLanguageCode}
onClick={(e) => {handleAddNode(e)}}>
Add
</Button>
</DialogActions>
</Dialog>
{/* Dialog box for acknowledgement of addition of node */}
<Dialog
open={openSuccessDialog}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
{/* Snackbar for acknowledgment of addition of node */}
<Snackbar
anchorOrigin={{vertical: 'top', horizontal: 'right'}}
open={openSuccessSnackbar}
autoHideDuration={3000}
onClose={handleCloseSuccessSnackbar}
>
<DialogTitle id="alert-dialog-title">
{"Your edits have been saved!"}
</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description">
The node {newNode} has been successfully added.
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={handleCloseSuccessDialog} autoFocus>
Continue
</Button>
</DialogActions>
</Dialog>
<Alert elevation={6} variant="filled" onClose={handleCloseSuccessSnackbar} severity="success">
The node has been successfully added!
</Alert>
</Snackbar>
</Grid>
</Container>
</Box>
Expand Down