Skip to content

Commit 8f464e9

Browse files
authored
Merge pull request mac-s-g#56 from mac-s-g/support-dates
added support for dates
2 parents 9f0da4b + 2ae4e92 commit 8f464e9

File tree

9 files changed

+76
-4
lines changed

9 files changed

+76
-4
lines changed

example/example.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
integer: 42,
7676
float: -2.757,
7777
array: [1, 2, 3, 'test'],
78+
date: new Date(),
7879
object: {
7980
sibling1: true,
8081
sibling2: false,

example/example.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ function getExampleJson1() {
7575
sibling2: false,
7676
sibling3: null,
7777
},
78-
string_number: "1234"
78+
string_number: "1234",
79+
date: new Date()
7980
};
8081
}
8182

@@ -132,6 +133,7 @@ function getExampleJson3() {
132133
function getExampleArray() {
133134
return [
134135
'you can also display arrays!',
136+
new Date(),
135137
1,
136138
2,
137139
3,

src/html/test-dist.html.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
another_sibling: 42,
6262
how_will_array_do: [1, 2, 3, 'test'],
6363
how_will_floats_do: -2.757,
64+
date: new Date(),
6465
parent: {
6566
sibling1: true,
6667
sibling2: false,

src/js/components/DataTypes/DataTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export {default as JsonBoolean} from './Boolean';
2+
export {default as JsonDate} from './Date';
23
export {default as JsonFloat} from './Float';
34
export {default as JsonFunction} from './Function';
45
export {default as JsonNan} from './Nan';
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react';
2+
import DataTypeLabel from './DataTypeLabel';
3+
4+
//theme
5+
import Theme from './../../themes/getStyle';
6+
7+
export default class extends React.Component {
8+
9+
render() {
10+
const type_name = 'date';
11+
const {props} = this;
12+
const {value} = props.variable;
13+
const display_options = {
14+
weekday: "short",
15+
year: "numeric",
16+
month: "short",
17+
day: "numeric",
18+
hour: "2-digit",
19+
minute: "2-digit"
20+
};
21+
return (
22+
<div {...Theme(props.theme, 'date')}>
23+
<DataTypeLabel type_name={type_name} {...props} />
24+
<span class="date-value" {...Theme(props.theme, 'date-value')}>
25+
{value.toLocaleTimeString(
26+
'en-us', display_options
27+
)}
28+
</span>
29+
</div>
30+
);
31+
}
32+
33+
}

src/js/components/VariableEditor.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import dispatcher from './../helpers/dispatcher';
55

66
//data type components
77
import {
8-
JsonBoolean, JsonFloat, JsonFunction, JsonInteger,
8+
JsonBoolean, JsonDate, JsonFloat, JsonFunction, JsonInteger,
99
JsonNan, JsonNull, JsonObject, JsonString, JsonUndefined
1010
} from './DataTypes/DataTypes';
1111

@@ -133,8 +133,10 @@ class VariableEditor extends React.Component {
133133
return <JsonNan {...props} />;
134134
case 'undefined':
135135
return <JsonUndefined {...props} />;
136+
case 'date':
137+
return <JsonDate {...props} />;
136138
default:
137-
//catch-all for types that weren't anticipated
139+
// catch-all for types that weren't anticipated
138140
return <div class="object-value" {...props} >
139141
{variable.value}
140142
</div>;

src/js/themes/getStyle.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const colorMap = theme => ({
2222
},
2323
dataTypes: {
2424
boolean: theme.base0E,
25+
date: theme.base0D,
2526
float: theme.base0B,
2627
function: theme.base0D,
2728
integer: theme.base0F,
@@ -132,6 +133,13 @@ const getDefaultThemeStyling = theme => {
132133
display: 'inline-block',
133134
color: colors.dataTypes.boolean
134135
},
136+
'date': {
137+
display: 'inline-block',
138+
color: colors.dataTypes.date
139+
},
140+
'date-value': {
141+
marginLeft: styleConstants.dateValueMarginLeft
142+
},
135143
'float': {
136144
display: 'inline-block',
137145
color: colors.dataTypes.float

src/js/themes/styleConstants.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ export default {
8080

8181
iconCursor: 'pointer',
8282
iconFontSize: '15px',
83-
iconPaddingRight: '1px'
83+
iconPaddingRight: '1px',
84+
85+
dateValueMarginLeft: '2px'
8486
};
8587

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
import {expect} from 'chai';
4+
5+
import JsonDate from '/react/src/js/components/DataTypes/Date';
6+
import DataTypeLabel from '/react/src/js/components/DataTypes/DataTypeLabel';
7+
8+
describe('<JsonDate />', function () {
9+
const rjvId = 1;
10+
11+
it('integer component should have a data type label', function () {
12+
const wrapper = shallow(
13+
<JsonDate
14+
variable={{value: new Date()}}
15+
displayDataTypes={true}
16+
rjvId={rjvId}
17+
theme='rjv-default'/>
18+
);
19+
expect(wrapper.find(DataTypeLabel)).to.have.length(1);
20+
});
21+
22+
});

0 commit comments

Comments
 (0)