Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1507 from metasfresh/dev-1387
Browse files Browse the repository at this point in the history
  • Loading branch information
metas-mk committed Jan 18, 2018
2 parents b0b00de + 750c141 commit 7d7e4fb
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 27 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"react-router": "^3.2.0",
"react-router-redux": "^4.0.8",
"react-tagsinput": "~3.18.0",
"react-tether": "^0.6.0",
"react-translate-component": "~0.14.0",
"redux": "~3.7.2",
"redux-thunk": "~2.2.0",
Expand Down
9 changes: 8 additions & 1 deletion src/actions/ViewActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from "axios";

import Moment from "moment";
import { getQueryString } from "./GenericActions";

export function getViewLayout(windowId, viewType, viewProfileId = null) {
Expand Down Expand Up @@ -86,6 +86,13 @@ export function createViewRequest({
}

export function filterViewRequest(windowId, viewId, filters) {
filters.map(filter => {
filter.parameters.map((param, index) => {
if (param.caption === "Date") {
filter.parameters[index].value = Moment(param.value).format();
}
});
});
return axios.post(
config.API_URL + "/documentView/" + windowId + "/" + viewId + "/filter",
{
Expand Down
12 changes: 10 additions & 2 deletions src/assets/css/datetime.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
}

.rdtPicker {
display: none;
position: absolute;
display: block;
position: static;
width: 260px;
padding: 0;
margin-top: 3px;
Expand Down Expand Up @@ -230,3 +230,11 @@ td.rdtYear:hover {
.rdtDayPart {
margin-top: 43px;
}

.tether-element {
z-index: 9;
}

.tether-out-of-bounds-top .rdtPicker {
visibility: hidden;
}
19 changes: 17 additions & 2 deletions src/components/filters/FiltersFrequent.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ const classes = "btn btn-filter btn-meta-outline-secondary btn-sm";
class FiltersFrequent extends Component {
state = { openFilterId: null };

constructor(props) {
super(props);
this.state = {
allowOutsideClickListener: true
};
}

toggleFilter = index => {
this.setState({
openFilterId: index
Expand All @@ -24,8 +31,15 @@ class FiltersFrequent extends Component {

outsideClick = () => {
const { widgetShown, dropdownToggled } = this.props;
!widgetShown && this.toggleFilter(null, null);
dropdownToggled();
const { allowOutsideClickListener } = this.state;
if (allowOutsideClickListener) {
!widgetShown && this.toggleFilter(null);
dropdownToggled();
}
};

allowOutsideClickListener = value => {
this.setState({ allowOutsideClickListener: value });
};

render() {
Expand Down Expand Up @@ -115,6 +129,7 @@ class FiltersFrequent extends Component {
onHide={() => handleShow(false)}
viewId={viewId}
outsideClick={this.outsideClick}
allowOutsideClickListener={this.allowOutsideClickListener}
/>
)}
</div>
Expand Down
40 changes: 26 additions & 14 deletions src/components/filters/FiltersItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,28 @@ class FiltersItem extends Component {
}
};

parseDateToReadable = value => {
if (value) {
return new Date(value);
}
};

mergeData = (property, value, valueTo) => {
const DATE_FIELD = "DateDoc";
this.setState(prevState => ({
filter: Object.assign({}, prevState.filter, {
parameters: prevState.filter.parameters.map(param => {
if (param.parameterName === property) {
return Object.assign(
{},
param,
valueTo
? {
value,
valueTo
}
: {
value
}
);
return Object.assign({}, param, {
value:
DATE_FIELD === property
? this.parseDateToReadable(value)
: value,
valueTo:
DATE_FIELD === property
? this.parseDateToReadable(valueTo)
: valueTo
});
} else {
return param;
}
Expand Down Expand Up @@ -139,7 +144,8 @@ class FiltersItem extends Component {
onHide,
viewId,
outsideClick,
captionValue
captionValue,
allowOutsideClickListener
} = this.props;

const { filter, isTooltipShow } = this.state;
Expand Down Expand Up @@ -193,7 +199,13 @@ class FiltersItem extends Component {
caption={item.caption}
noLabel={false}
filterWidget={true}
{...{ viewId, windowType, onShow, onHide }}
{...{
viewId,
windowType,
onShow,
onHide,
allowOutsideClickListener
}}
/>
))}
</div>
Expand Down
11 changes: 9 additions & 2 deletions src/components/filters/FiltersNotFrequent.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class FiltersNotFrequent extends Component {

this.state = {
isOpenDropdown: false,
openFilterId: null
openFilterId: null,
allowOutsideClickListener: true
};
}

Expand All @@ -22,13 +23,18 @@ class FiltersNotFrequent extends Component {

outsideClick = () => {
const { widgetShown, dropdownToggled } = this.props;
if (!widgetShown) {
const { allowOutsideClickListener } = this.state;
if (allowOutsideClickListener && !widgetShown) {
dropdownToggled();
this.toggleDropdown(false);
this.toggleFilter(null);
}
};

allowOutsideClickListener = value => {
this.setState({ allowOutsideClickListener: value });
};

toggleDropdown = value => {
this.setState({
isOpenDropdown: value
Expand Down Expand Up @@ -119,6 +125,7 @@ class FiltersNotFrequent extends Component {
onHide={() => handleShow(false)}
viewId={viewId}
outsideClick={this.outsideClick}
allowOutsideClickListener={this.allowOutsideClickListener}
/>
)}
</div>
Expand Down
13 changes: 8 additions & 5 deletions src/components/widget/DatePicker.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import PropTypes from "prop-types";
import React, { Component } from "react";
import Datetime from "react-datetime";
import { connect } from "react-redux";

import TetheredDateTime from "./TetheredDateTime";
import { addNotification } from "../../actions/AppActions";

const propTypes = {
Expand All @@ -11,7 +10,8 @@ const propTypes = {
patch: PropTypes.func,
field: PropTypes.string,
value: PropTypes.any,
isOpenDatePicker: PropTypes.bool
isOpenDatePicker: PropTypes.bool,
allowOutsideClickListener: PropTypes.func // function to manage outside Click Listener from FilterFrequency component
};

class DatePicker extends Component {
Expand Down Expand Up @@ -56,17 +56,20 @@ class DatePicker extends Component {
};

handleFocus = () => {
const { value } = this.props;
const { value, allowOutsideClickListener } = this.props;
this.setState({
cache: value,
open: true
});
allowOutsideClickListener && allowOutsideClickListener(false);
};

handleClose = () => {
const { allowOutsideClickListener } = this.props;
this.setState({
open: false
});
allowOutsideClickListener && allowOutsideClickListener(true);
};

handleClickOutside = () => {
Expand Down Expand Up @@ -94,7 +97,7 @@ class DatePicker extends Component {
render() {
return (
<div tabIndex="-1" onKeyDown={this.handleKeydown} className="datepicker">
<Datetime
<TetheredDateTime
ref={c => (this.picker = c)}
closeOnTab={true}
renderDay={this.renderDay}
Expand Down
6 changes: 5 additions & 1 deletion src/components/widget/RawWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class RawWidget extends Component {
allowShowPassword,
onBlurWidget,
defaultValue,
allowOutsideClickListener,
isOpenDatePicker
} = this.props;
const widgetValue = data || widgetData[0].value;
Expand Down Expand Up @@ -297,7 +298,10 @@ class RawWidget extends Component {
date ? Moment(date).format(DATE_FORMAT) : null
)
}
handleBackdropLock={handleBackdropLock}
{...{
allowOutsideClickListener,
handleBackdropLock
}}
/>
</div>
);
Expand Down
69 changes: 69 additions & 0 deletions src/components/widget/TetheredDateTime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React from "react";
import DateTime from "react-datetime";
import CalendarContainer from "react-datetime/src/CalendarContainer";
import TetherComponent from "react-tether";

export default class TetheredDateTime extends DateTime {
render() {
const { open } = this.state;
let className =
"rdt" +
(this.props.className
? Array.isArray(this.props.className)
? " " + this.props.className.join(" ")
: " " + this.props.className
: "");
let children = [];

if (this.props.input) {
const props = {
type: "text",
className: "form-control",
onFocus: this.openCalendar,
onChange: this.onInputChange,
onKeyDown: this.onInputKey,
value: this.state.inputValue,
...this.props.inputProps
};

if (this.props.renderInput) {
children = [
<div key="i">{this.props.renderInput(props, this.openCalendar)}</div>
];
} else {
children = [<input key="i" {...props} />];
}
} else {
className += " rdtStatic";
}

return (
<div className={className}>
<TetherComponent
attachment="top left"
targetAttachment="bottom left"
constraints={[
{
to: "scrollParent"
},
{
to: "window",
pin: ["bottom"]
}
]}
>
{children}
{open && (
<div className="rdtPicker">
<CalendarContainer
view={this.state.currentView}
viewProps={this.getComponentProps()}
onClickOutside={this.handleClickOutside}
/>
</div>
)}
</TetherComponent>
</div>
);
}
}
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7157,6 +7157,13 @@ react-tagsinput@~3.18.0:
version "3.18.0"
resolved "https://registry.yarnpkg.com/react-tagsinput/-/react-tagsinput-3.18.0.tgz#40e036fc0f4c3d6b4689858189ab02926717a818"

react-tether@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/react-tether/-/react-tether-0.6.0.tgz#428fb676467aa033336790997477ffcebe0aeca8"
dependencies:
prop-types "^15.5.8"
tether "^1.3.7"

react-themeable@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/react-themeable/-/react-themeable-1.1.0.tgz#7d4466dd9b2b5fa75058727825e9f152ba379a0e"
Expand Down

0 comments on commit 7d7e4fb

Please sign in to comment.