Commit ae5c5d62 authored by Oleksii Savran's avatar Oleksii Savran Committed by Matija Obreza
Browse files

Simple search form

- Updated institute filter
parent fc53b12b
import React, { useState } from 'react'; import React, { useState } from 'react';
import AccessionFilter from '@genesys/client/model/accession/AccessionFilter'; import AccessionFilter from '@genesys/client/model/accession/AccessionFilter';
import { useTranslation } from 'react-i18next';
interface IAccessionFilters extends React.ClassAttributes<any> { interface IAccessionFilters extends React.ClassAttributes<any> {
filter: AccessionFilter; filter: AccessionFilter;
...@@ -8,24 +9,70 @@ interface IAccessionFilters extends React.ClassAttributes<any> { ...@@ -8,24 +9,70 @@ interface IAccessionFilters extends React.ClassAttributes<any> {
export function AccessionFilters(props: IAccessionFilters) { export function AccessionFilters(props: IAccessionFilters) {
const { filter, applyFilter } = props; const { filter, applyFilter } = props;
const { t } = useTranslation();
const [text, setText] = useState(filter._text || ''); const [text, setText] = useState(filter._text || '');
const [historic, setHistoric] = useState(filter.historic === null);
const [available, setAvailable] = useState(!!filter.available && filter.institute && !!filter.institute.allowMaterialRequests);
const handleSubmit = (e) => { const handleSubmit = (e) => {
e.preventDefault(); e.preventDefault();
applyFilter({ _text: text });
applyFilter({
_text: text,
historic: historic ? null : false,
available: available || null,
institute: { ...(filter.institute || {}), allowMaterialRequests: !!available || null },
});
}; };
const onInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { const onInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setText(e.target.value); setText(e.target.value);
}; };
const onHistoricChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { checked } = e.currentTarget as HTMLInputElement;
setHistoric(checked);
};
const onAvailableChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { checked } = e.currentTarget as HTMLInputElement;
setAvailable(checked);
};
return ( return (
<form className="form-inline mb-4" onSubmit={ handleSubmit }> <form className="form-inline mb-4" onSubmit={ handleSubmit }>
<div className="form-group mx-sm-2"> <div className="form-group mx-sm-2">
<label className="mr-2">Full text search</label> <label className="mr-2">{ t('accession.filters.fullText') }</label>
<input name="full-text-search" type="text" className="form-control" value={ text } onChange={ onInputChange }/> <input name="full-text-search" type="text" className="form-control" value={ text } onChange={ onInputChange }/>
</div> </div>
<button className="btn btn-primary" type="submit">Submit</button> <div className="form-check pr-2">
<input
id="historical"
className="form-check-input"
name="historic"
type="checkbox"
onChange={ onHistoricChange }
checked={ historic }
/>
<label htmlFor="historical" className="form-check-label">
{ t('accession.filters.historical') }
</label>
</div>
<div className="form-check pr-2">
<input
id="available"
className="form-check-input"
name="internalRequest"
type="checkbox"
onChange={ onAvailableChange }
checked={ available }
/>
<label htmlFor="available" className="form-check-label">
{ t('accession.filters.available') }
</label>
</div>
<button className="btn btn-primary" type="submit">{ t('action.submit') }</button>
</form> </form>
); );
} }
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
"label": { "label": {
"andMore": "And {{otherMore, number}} more" "andMore": "And {{otherMore, number}} more"
}, },
"action": {
"submit": "Submit"
},
"pag": { "pag": {
"first": "First", "first": "First",
"prev": "Prev", "prev": "Prev",
...@@ -74,6 +77,11 @@ ...@@ -74,6 +77,11 @@
"accessionNames": "Accession names", "accessionNames": "Accession names",
"remarks": "Remarks" "remarks": "Remarks"
}, },
"filters": {
"fullText": "Full text search",
"historical": "Include historical material",
"available": "Only material I can request"
},
"overview": { "overview": {
"title": "Collection overview", "title": "Collection overview",
"about": "About {{count, number}} {{what, lowercase}}", "about": "About {{count, number}} {{what, lowercase}}",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment