// SPDX-License-Identifier: AGPL-3.0
import * as React from "react";
-import { Field, WrappedFieldProps, FieldArray } from 'redux-form';
+import { Field, WrappedFieldProps, FieldArray, formValues } from 'redux-form';
import { TextField, DateTextField } from "~/components/text-field/text-field";
import { CheckboxField } from '~/components/checkbox-field/checkbox-field';
import { NativeSelectField } from '~/components/select-field/select-field';
import { SearchBarAdvancedPropertiesView } from '~/views-components/search-bar/search-bar-advanced-properties-view';
import { TreeItem } from "~/components/tree/tree";
import { ProjectsTreePickerItem } from "~/views-components/projects-tree-picker/generic-projects-tree-picker";
+import { PropertyKeyInput } from '~/views-components/resource-properties-form/property-key-field';
+import { PropertyValueInput, PropertyValueFieldProps } from '~/views-components/resource-properties-form/property-value-field';
+import { VocabularyProp, connectVocabulary } from '~/views-components/resource-properties-form/property-field-common';
+import { compose } from 'redux';
export const SearchBarTypeField = () =>
<Field
(_: any, { id }: TreeItem<ProjectsTreePickerItem>) => {
props.input.onChange(id);
}
- }/>
+ } />
</div>;
export const SearchBarTrashField = () =>
name="properties"
component={SearchBarAdvancedPropertiesView} />;
-export const SearchBarKeyField = () =>
- <Field
- name='key'
- component={TextField}
- label="Key" />;
+export const SearchBarKeyField = connectVocabulary(
+ ({ vocabulary }: VocabularyProp) =>
+ <Field
+ name='key'
+ component={PropertyKeyInput}
+ vocabulary={vocabulary} />);
-export const SearchBarValueField = () =>
- <Field
- name='value'
- component={TextField}
- label="Value" />;
+export const SearchBarValueField = compose(
+ connectVocabulary,
+ formValues({ propertyKey: 'key' })
+)(
+ (props: PropertyValueFieldProps) =>
+ <Field
+ name='value'
+ component={PropertyValueInput}
+ {...props} />);
export const SearchBarSaveSearchField = () =>
<Field
WithStyles,
Tooltip,
InputAdornment, Input,
- ClickAwayListener
+ Popover,
} from '@material-ui/core';
import SearchIcon from '@material-ui/icons/Search';
import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown';
};
export const SearchBarView = withStyles(styles)(
- (props : SearchBarViewProps) => {
- const { classes, isPopoverOpen } = props;
- return (
- <ClickAwayListener onClickAway={props.closeView}>
- <Paper className={isPopoverOpen ? classes.containerSearchViewOpened : classes.container} >
- <form onSubmit={props.onSubmit}>
- <Input
- className={classes.input}
- onChange={props.onChange}
- placeholder="Search"
- value={props.searchValue}
- fullWidth={true}
- disableUnderline={true}
- onClick={e => handleInputClick(e, props)}
- onKeyDown={e => handleKeyDown(e, props)}
- startAdornment={
- <InputAdornment position="start">
- <Tooltip title='Search'>
- <IconButton type="submit">
- <SearchIcon />
- </IconButton>
- </Tooltip>
- </InputAdornment>
- }
- endAdornment={
- <InputAdornment position="end">
- <Tooltip title='Advanced search'>
- <IconButton onClick={e => handleDropdownClick(e, props)}>
- <ArrowDropDownIcon />
- </IconButton>
- </Tooltip>
- </InputAdornment>
- } />
- </form>
- <div className={classes.view}>
- {isPopoverOpen && getView({...props})}
+ class SearchBarView extends React.Component<SearchBarViewProps> {
+
+ viewAnchorRef = React.createRef<HTMLDivElement>();
+
+ render() {
+ const { children, ...props } = this.props;
+ const { classes, isPopoverOpen } = props;
+ return (
+ <Paper
+ className={isPopoverOpen ? classes.containerSearchViewOpened : classes.container}>
+ <div ref={this.viewAnchorRef}>
+ <form onSubmit={props.onSubmit}>
+ <SearchInput {...props} />
+ </form>
</div>
+ <SearchViewContainer
+ {...props}
+ width={this.getViewWidth()}
+ anchorEl={this.viewAnchorRef.current}>
+ {
+ getView({ ...props })
+ }
+ </SearchViewContainer>
</Paper >
- </ClickAwayListener>
- );
+ );
+ }
+
+ getViewWidth() {
+ const { current } = this.viewAnchorRef;
+ return current ? current.offsetWidth : 0;
+ }
}
+
);
+const SearchInput = (props: SearchBarViewProps) => {
+ const { classes } = props;
+ return <Input
+ className={classes.input}
+ onChange={props.onChange}
+ placeholder="Search"
+ value={props.searchValue}
+ fullWidth={true}
+ disableUnderline={true}
+ onClick={e => handleInputClick(e, props)}
+ onKeyDown={e => handleKeyDown(e, props)}
+ startAdornment={
+ <InputAdornment position="start">
+ <Tooltip title='Search'>
+ <IconButton type="submit">
+ <SearchIcon />
+ </IconButton>
+ </Tooltip>
+ </InputAdornment>
+ }
+ endAdornment={
+ <InputAdornment position="end">
+ <Tooltip title='Advanced search'>
+ <IconButton onClick={e => handleDropdownClick(e, props)}>
+ <ArrowDropDownIcon />
+ </IconButton>
+ </Tooltip>
+ </InputAdornment>
+ } />;
+};
+
+const SearchViewContainer = (props: SearchBarViewProps & { width: number, anchorEl: HTMLElement | null, children: React.ReactNode }) =>
+ <Popover
+ PaperProps={{
+ style: {
+ width: props.width,
+ borderRadius: '0 0 4px 4px',
+ }
+ }}
+ anchorEl={props.anchorEl}
+ anchorOrigin={{
+ vertical: 'bottom',
+ horizontal: 'center',
+ }}
+ transformOrigin={{
+ vertical: 'top',
+ horizontal: 'center',
+ }}
+ disableAutoFocus
+ open={props.isPopoverOpen}
+ onClose={props.closeView}>
+ {
+ props.children
+ }
+ </Popover>;
+
+
const getView = (props: SearchBarViewProps) => {
switch (props.currentView) {
case SearchView.AUTOCOMPLETE: