diff --git a/app/assets/javascripts/components/story/ExpandedStory/ExpandedStoryNotes.jsx b/app/assets/javascripts/components/story/ExpandedStory/ExpandedStoryNotes.jsx
index 74fd79592..ded8d273f 100644
--- a/app/assets/javascripts/components/story/ExpandedStory/ExpandedStoryNotes.jsx
+++ b/app/assets/javascripts/components/story/ExpandedStory/ExpandedStoryNotes.jsx
@@ -1,77 +1,60 @@
-import React, { Fragment } from 'react';
+import React, { useState } from 'react';
import PropTypes from 'prop-types';
import NotesList from '../note/NotesList';
import { editingStoryPropTypesShape } from '../../../models/beta/story';
import ExpandedStorySection from './ExpandedStorySection';
-class ExpandedStoryNotes extends React.Component {
- constructor(props) {
- super(props);
+const ExpandedStoryNotes = ({ story, onCreate, onDelete, disabled }) => {
+ const [value, setValue] = useState('');
- this.state = {
- value: ''
- };
-
- this.handleChange = this.handleChange.bind(this);
- this.handleSave = this.handleSave.bind(this);
+ const handleChange = (event) => {
+ setValue(event.target.value);
};
- handleChange(event) {
- this.setState({ value: event.target.value })
- }
-
- handleSave() {
- const { onCreate } = this.props;
+ const handleSave = () => {
+ onCreate(value);
+ setValue('');
+ };
- onCreate(this.state.value);
- this.setState({ value: '' });
- }
+ const hasAnEmptyValue = () => {
+ return !value.trim();
+ };
- hasAnEmptyValue() {
- return !this.state.value.trim()
- }
+ const notesForm = () => (
+ <>
+
- notesForm() {
- return (
-
-
- );
- }
+ if(disabled && !story.notes.length) return null;
- render() {
- const { story, onDelete, disabled } = this.props;
-
- if(disabled && !story.notes.length) return null
-
- return (
-
-
+ return (
+
+
- {!disabled && this.notesForm()}
-
- );
- }
+ {!disabled && notesForm()}
+
+ );
};
ExpandedStoryNotes.propTypes = {
diff --git a/spec/javascripts/components/story/expanded_story/expanded_story_notes_spec.js b/spec/javascripts/components/story/expanded_story/expanded_story_notes_spec.js
index 3d61615d9..690f564ed 100644
--- a/spec/javascripts/components/story/expanded_story/expanded_story_notes_spec.js
+++ b/spec/javascripts/components/story/expanded_story/expanded_story_notes_spec.js
@@ -7,17 +7,17 @@ describe('', () => {
let onCreate;
let onDelete;
- const newStory = notes => ({
+ const newStory = (notes) => ({
...storyFactory({ notes: notes || [] }),
_editing: {
- ...storyFactory({ notes: notes || [] })
- }
- })
+ ...storyFactory({ notes: notes || [] }),
+ },
+ });
beforeEach(() => {
onCreate = sinon.stub();
onDelete = sinon.stub();
- })
+ });
it('renders component title', () => {
const story = newStory();
@@ -62,7 +62,7 @@ describe('', () => {
const onCreateSpy = sinon.spy();
- const wrapper = shallow(
+ const wrapper = mount(
', () => {
it('disables the add note button if text area is empty', () => {
const story = newStory();
-
+
const wrapper = shallow(
', () => {
disabled={false}
/>
);
-
+
const textArea = wrapper.find('.create-note-text');
const button = wrapper.find('.create-note-button input');
-
+
textArea.simulate('change', { target: { value: '' } });
expect(button.prop('disabled')).toBe(true);
});
@@ -103,9 +103,9 @@ describe('', () => {
describe('when component is disabled', () => {
it('does not render a create note button', () => {
- const notes = [{id: 0, note: 'foo'}]
+ const notes = [{ id: 0, note: 'foo' }];
const story = newStory(notes);
-
+
const wrapper = shallow(
', () => {
disabled={true}
/>
);
-
+
expect(wrapper.exists('.create-note-button')).toBe(false);
});
it('does not render a create note text area', () => {
- const notes = [{id: 0, note: 'foo'}]
+ const notes = [{ id: 0, note: 'foo' }];
const story = newStory(notes);
-
+
const wrapper = shallow(
', () => {
disabled={true}
/>
);
-
+
expect(wrapper.exists('.create-note-text')).toBe(false);
});
describe('when there are no notes', () => {
it('renders nothing', () => {
const story = newStory();
-
+
const wrapper = shallow(
', () => {
});
});
});
-