Skip to content

Commit eee5f4c

Browse files
committed
render error msg if metadata["tags"] is a String
1 parent fb29a68 commit eee5f4c

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

src/components/metadata/MetaTags.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,22 @@ export class MetaTags extends Component {
6363
}
6464

6565
render() {
66-
const { fieldValue } = this.props;
67-
const pageTags = this.state.pageTags.filter(
66+
const { pageTags } = this.state;
67+
68+
if (pageTags.length > 0 && !(pageTags instanceof(Array))) {
69+
return (
70+
<span className="meta-error">
71+
Invalid array of tags! Found string: <b>"{pageTags}"</b>
72+
</span>
73+
);
74+
}
75+
76+
const tagPool = pageTags.filter(
6877
function(tag, index, self) {
6978
return index == self.indexOf(tag);
7079
}
7180
);
7281

73-
const tagPool = pageTags || fieldValue;
74-
7582
const tags = _.map(tagPool, (tag, i) => {
7683
return (
7784
<span key={i} className="tag">

src/components/metadata/tests/metatags.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ describe('Components::MetaTags', () => {
3838
expect(editable.node).toBeTruthy();
3939
});
4040

41+
it('should render an error if fieldValue prop is a String', () => {
42+
const { component, editable } = setup(Object.assign({}, defaultProps, {
43+
fieldValue: 'foo'
44+
}));
45+
expect(component.find('.meta-error').text()).toEqual('Invalid array of tags! Found string: "foo"');
46+
expect(editable.node).toBeFalsy();
47+
});
48+
4149
it('should create tags on certain keypresses', () => {
4250
const { component, editable } = setup();
4351
editable.node.value = 'foo';

src/styles/datagui.scss

+6
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,10 @@
365365
color: white;
366366
background: #2b2b2b;
367367
}
368+
.meta-error {
369+
display: inline-block;
370+
height: 48px;
371+
margin-left: 15px;
372+
padding: 14px 0;
373+
}
368374
}

src/styles/metafields.scss

+14
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,20 @@
316316
}
317317
}
318318
}
319+
320+
.meta-error {
321+
display: flex;
322+
padding: 5px;
323+
background-color: lighten($dark-red, 37%);
324+
}
325+
}
326+
327+
.meta-error {
328+
color: $dark-red;
329+
b {
330+
margin-left: 5px;
331+
color: $dark-red;
332+
}
319333
}
320334

321335
.tags-wrap {

0 commit comments

Comments
 (0)