Skip to content

Commit

Permalink
Adding PageView to test the changes in client
Browse files Browse the repository at this point in the history
  • Loading branch information
Eimi Okuno authored and Eimi Okuno committed Sep 26, 2019
1 parent 95672ac commit 22b49a5
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 25 deletions.
4 changes: 2 additions & 2 deletions packages/components/FormModal/stories/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { actions } from '@storybook/addon-actions';
import StoryRouter from 'storybook-react-router';
import FormModal from '../index.js';

export const modalItems = [ {
const modalItems = [ {
id: 1,
itemType: 'project',
showModal: true,
Expand All @@ -27,7 +27,7 @@ export const modalItems = [ {
type: 'transcript'
} ];

export const modalActions = actions({ handleSaveForm: 'Form saved' });
const modalActions = actions({ handleSaveForm: 'Form saved' });

storiesOf('Form Modal', module)
.addDecorator(StoryRouter())
Expand Down
29 changes: 27 additions & 2 deletions packages/components/ItemForm/stories/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,40 @@ import React from 'react';
import { storiesOf } from '@storybook/react';
import StoryRouter from 'storybook-react-router';
import ItemForm from '../index.js';
import { modalActions, modalItems } from '../../FormModal/stories/index.stories.js';
import { actions } from '@storybook/addon-actions';

const modalItems = [ {
id: 1,
itemType: 'project',
showModal: true,
title: 'Example Project Title',
description: 'This is a sample card description. This is fun!',
url: '/projects/1/transcripts/1234',
modalTitle: 'Edit Project',
}, {
showModal: true,
modalTitle: 'New Project',
id: 2
}, {
projectId: 123,
title: '',
description: '',
uploadCompleted: true,
showModal: true,
modalTitle: 'New Transcript',
id: 3,
type: 'transcript'
} ];

const modalActions = actions({ handleSaveForm: 'Form saved' });

storiesOf('Item Form', module)
.addDecorator(StoryRouter())
.add('Edit Project', () => {
return (
<section style={ { height: '90vh', overflow: 'scroll' } }>
<ItemForm
{ ...modalActions }
handleSaveForm={ modalActions.handleSaveForm }
{ ...modalItems[0] }
/>
</section>
Expand Down
57 changes: 45 additions & 12 deletions packages/components/List/stories/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import StoryRouter from 'storybook-react-router';
import List from '../index.js';
import SearchBar from '../SearchBar';

import { item, cardActions } from '../../SimpleCard/stories/index.stories.js';
import { transcriptItems } from '../../TranscriptCard/stories/index.stories.js';
const cardActions = actions({
handleEdit: 'Edit button clicked',
handleDelete: 'Delete button clicked'
});

export const searchActions = actions({ handleSearch: 'Handle search' });
const searchActions = actions({ handleSearch: 'Handle search' });

export const items = [ {
...item,
const items = [ {
id: '1234',
key: 'abc123',
title: 'Sample Simple Card Title One',
description: 'This is a sample card description. This is fun!',
display: true,
}, { ...item,
}, {
id: '5678',
key: 'def456',
title: 'Sample Simple Card Title Two',
Expand All @@ -27,7 +28,37 @@ export const items = [ {
url: '/projects/1/transcripts/5678'
} ];

export const transItems = transcriptItems;
const transcriptItems = [ {
id: 1,
key: 'transcript_key_1',
title: 'Title - Done Transcript',
description: 'This transcript has finished processing.',
subtitle: 'This transcript has finished processing.',
url: '/projects/1/transcripts/',
status: 'done',
display: true
}, {
id: 2,
key: 'transcript_key_2',
title: 'Title - In Progress Transcript',
description: 'This transcript is still being generated.',
subtitle: 'This transcript is still being generated.',
url: '/projects/1/transcripts/',
status: 'in-progress',
display: true
}, {
id: 3,
key: 'transcript_key_3',
title: 'Title - Error Transcript',
description: 'Transcript generation failed for this card.',
subtitle: 'Transcript generation failed for this card.',
url: '/projects/1/transcripts/',
status: 'error',
errorMessage: 'Something has gone wrong with your transcription',
display: true
} ];

const transItems = transcriptItems;

storiesOf('List', module)
.addDecorator(StoryRouter())
Expand All @@ -36,8 +67,9 @@ storiesOf('List', module)
<section style={ { height: '90vh', overflow: 'scroll' } }>
<List
items={ items }
{ ...cardActions }
{ ...searchActions }
handleEdit={ cardActions.handleEdit }
handleDelete={ cardActions.handleDelete }
handleSearch={ searchActions.handleSearch }
/>
</section>
);
Expand All @@ -46,8 +78,9 @@ storiesOf('List', module)
<section style={ { height: '100%', overflow: 'scroll' } }>
<List
items={ transItems }
{ ...cardActions }
{ ...searchActions }
handleEdit={ cardActions.handleEdit }
handleDelete={ cardActions.handleDelete }
handleSearch={ searchActions.handleSearch }
/>
</section>
);
Expand All @@ -58,7 +91,7 @@ storiesOf('List/Search Bar', module)
return (
<section style={ { height: '90vh', overflow: 'scroll' } }>
<SearchBar
{ ...searchActions }
handleSearch={ searchActions.handleSearch }
/>
</section>
);
Expand Down
89 changes: 89 additions & 0 deletions packages/components/PageView/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React, { useState, useEffect } from 'react';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';
import Button from 'react-bootstrap/Button';
import PropTypes from 'prop-types';

import { includesText } from '../../utils';
import List from '../List';

const PageView = (props) => {
const [ items, setItems ] = useState();
console.log('page', items);

useEffect(() => {
if (!items) {
setItems(props.items);
console.log('effect', items);
}

return () => {

};
}, [ items, props.items ]);

const handleSearch = searchText => {
const results = items.filter(project => {
if (
includesText(project.title, searchText) ||
includesText(project.description, searchText)
) {
project.display = true;

return project;
} else {
project.display = false;

return project;
}
});
props.handleUpdateList(results);
};

let searchEl;
let showItems;

if (items && items.length !== 0) {

showItems = (
<List
items={ items }
handleEdit={ () => props.handleEdit }
handleDelete={ () => props.handleDelete }
handleSearch={ handleSearch }
/>
);
} else {
showItems = (<i>There are no {props.model}s, create a new one to get started.</i>);
}

return (
<>
<Row>
<Col sm={ 9 } >
{searchEl}
</Col>

<Col xs={ 12 } sm={ 3 } >
<Button onClick={ props.handleShowModal }
variant="outline-secondary"
size="sm" block>
New {props.model}
</Button>
</Col>
</Row>
{showItems}
</>
);
};

PageView.propTypes = {
handleDelete: PropTypes.any,
handleEdit: PropTypes.any,
handleShowModal: PropTypes.any,
handleUpdateList: PropTypes.any,
items: PropTypes.any,
model: PropTypes.any,
};

export default PageView;
80 changes: 80 additions & 0 deletions packages/components/PageView/stories/index.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { actions } from '@storybook/addon-actions';
import StoryRouter from 'storybook-react-router';
import PageView from '..';

const projectItems = [ {
id: '1234',
key: 'abc123',
title: 'Sample Simple Card Title One',
description: 'This is a sample card description. This is fun!',
display: true,
}, {
id: '5678',
key: 'def456',
title: 'Sample Simple Card Title Two',
description: 'This is a sample card description. This is fun!',
display: true,
url: '/projects/1/transcripts/5678'
} ];

const transcriptItems = [ {
id: 1,
key: 'transcript_key_1',
title: 'Title - Done Transcript',
description: 'This transcript has finished processing.',
subtitle: 'This transcript has finished processing.',
url: '/projects/1/transcripts/',
status: 'done',
display: true
}, {
id: 2,
key: 'transcript_key_2',
title: 'Title - In Progress Transcript',
description: 'This transcript is still being generated.',
subtitle: 'This transcript is still being generated.',
url: '/projects/1/transcripts/',
status: 'in-progress',
display: true
}, {
id: 3,
key: 'transcript_key_3',
title: 'Title - Error Transcript',
description: 'Transcript generation failed for this card.',
subtitle: 'Transcript generation failed for this card.',
url: '/projects/1/transcripts/',
status: 'error',
errorMessage: 'Something has gone wrong with your transcription',
display: true
} ];
const modalActions = actions({ handleSaveForm: 'Form saved' });

storiesOf('PageView', module)
.addDecorator(StoryRouter())
.add('Project View', () => {
return (
<PageView
handleDelete={ actions('handleDelete') }
handleEdit={ actions('handleEdit') }
handleShowModal={ actions('handleShowModal') }
handleUpdateList={ actions('handleUpdateList') }
items={ projectItems }
model="Project"
handleSaveForm={ modalActions.handleSaveForm }
/>
);
})
.add('Transcripts View', () => {
return (
<PageView
handleDelete={ actions('handleDelete') }
handleEdit={ actions('handleEdit') }
handleShowModal={ actions('handleShowModal') }
handleUpdateList={ actions('handleUpdateList') }
items={ transcriptItems }
model="Transcripts"
handleSaveForm={ modalActions.handleSaveForm }
/>
);
});
22 changes: 15 additions & 7 deletions packages/components/TranscriptCard/stories/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { actions } from '@storybook/addon-actions';
import StoryRouter from 'storybook-react-router';
import TranscriptCard from '../index.js';

export const transcriptItems = [ {
const transcriptItems = [ {
id: 1,
key: 'transcript_key_1',
title: 'Title - Done Transcript',
Expand Down Expand Up @@ -35,26 +35,33 @@ export const transcriptItems = [ {
display: true
} ];

export const transcriptCardActions = actions({ handleEdit: 'Edit button clicked', handleDelete: 'Delete button clicked' });
const transcriptCardActions = actions({
handleEdit: 'Edit button clicked',
handleDelete: 'Delete button clicked'
});

const style = { height: '90vh', overflow: 'scroll' };

storiesOf('Transcript Card', module)
.addDecorator(StoryRouter())
.add('Success', () => {
return (
<section style={ { height: '90vh', overflow: 'scroll' } }>
<section style={ style }>
<TranscriptCard
{ ...transcriptItems[0] }
{ ...transcriptCardActions }
handleEdit={ transcriptCardActions.handleEdit }
handleDelete={ transcriptCardActions.handleDelete }
/>
</section>
);
})
.add('In Progress', () => {
return (
<section style={ { height: '90vh', overflow: 'scroll' } }>
<section style={ style }>
<TranscriptCard
{ ...transcriptItems[1] }
{ ...transcriptCardActions }
handleEdit={ transcriptCardActions.handleEdit }
handleDelete={ transcriptCardActions.handleDelete }
/>
</section>
);
Expand All @@ -64,7 +71,8 @@ storiesOf('Transcript Card', module)
<section style={ { height: '90vh', overflow: 'scroll' } }>
<TranscriptCard
{ ...transcriptItems[2] }
{ ...transcriptCardActions }
handleEdit={ transcriptCardActions.handleEdit }
handleDelete={ transcriptCardActions.handleDelete }
/>
</section>
);
Expand Down
Loading

0 comments on commit 22b49a5

Please sign in to comment.