Skip to content

Fixes #495: Improving Audience conditions for Push #524

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

Merged
merged 1 commit into from
Sep 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion src/components/DateTimeEntry/DateTimeEntry.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class DateTimeEntry extends React.Component {
let date = new Date(this.state.value);
if (isNaN(date.getTime())) {
this.setState({ value: this.props.value.toISOString() });
} else {
} else if (!this.state.value.toLowerCase().endsWith('z')) {
let utc = new Date(Date.UTC(
date.getFullYear(),
date.getMonth(),
Expand All @@ -79,6 +79,8 @@ export default class DateTimeEntry extends React.Component {
date.getMilliseconds()
));
this.props.onChange(utc);
} else {
this.props.onChange(date);
}
}

Expand Down
27 changes: 22 additions & 5 deletions src/components/PushAudienceDialog/InstallationCondition.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Field from 'components/Field/Field.react';
import Label from 'components/Label/Label.react';
import { List } from 'immutable';
import Option from 'components/Dropdown/Option.react';
import Parse from 'parse';
import React from 'react';
import ReactDOM from 'react-dom';
import styles from 'components/PushAudienceDialog/InstallationCondition.scss';
Expand All @@ -30,18 +31,34 @@ let setFocus = (input) => {
}
}

function compareValue(type, value, onChangeCompareTo) {
function compareValue(info, value, onChangeCompareTo) {
let type = info.type;
switch (type) {
case null:
return <div className={styles.empty}>-</div>;
case 'String':
return <TextInput placeholder='value' value={value} onChange={(value) => onChangeCompareTo(value)} ref={setFocus}/>;
return <TextInput placeholder='value' value={value} onChange={(_value) => onChangeCompareTo(_value)} ref={setFocus}/>;
case 'Pointer':
return <TextInput
placeholder='value'
value={value.objectId || ''}
onChange={(_value) => {
let obj = new Parse.Object(info.targetClass);
obj.id = _value;
onChangeCompareTo(Parse._encode(obj));
}}
ref={setFocus} />
case 'Boolean':
return <Dropdown value={value ? 'True' : 'False'} options={['True', 'False']} onChange={(val) => onChangeCompareTo(val === 'True')} />;
return <Dropdown value={value ? 'True' : 'False'} options={['True', 'False']} onChange={(_value) => onChangeCompareTo(_value === 'True')} />;
case 'Number':
return <TextInput placeholder='value' className={styles.conditionValue} value={value} onChange={(_value) => onChangeCompareTo(validateNumeric(_value) ? Number(_value) : Number(value))} ref={setFocus}/>;
case 'Date':
return <DateTimeEntry fixed={true} className={styles.date} value={value} onChange={onChangeCompareTo} />;
return <DateTimeEntry
fixed={true}
className={styles.date}
value={Parse._decode('date', value)}
onChange={(_value) => onChangeCompareTo(Parse._encode(_value))}
ref={setFocus} />
}
}

Expand Down Expand Up @@ -91,7 +108,7 @@ export default class InstallationCondition extends React.Component {
</Dropdown>
</div>
<div className={[styles.conditionInput, styles.valueInput].join(' ')}>
{compareValue(this.props.compareInfo.type, this.props.compareTo, this.props.onChangeCompareTo)}
{compareValue(this.props.compareInfo, this.props.compareTo, this.props.onChangeCompareTo)}
</div>
</div>
);
Expand Down