Skip to content

Commit

Permalink
Refactoring more of the components with using pageviews
Browse files Browse the repository at this point in the history
  • Loading branch information
Eimi Okuno authored and Eimi Okuno committed Sep 27, 2019
1 parent 22b49a5 commit e32536c
Show file tree
Hide file tree
Showing 15 changed files with 680 additions and 261 deletions.
404 changes: 326 additions & 78 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"videocontext": "^0.53.0"
},
"devDependencies": {
"@babel/core": "^7.6.0",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
"@babel/preset-env": "^7.6.0",
Expand Down
16 changes: 10 additions & 6 deletions packages/components/Breadcrumb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ CustomBreadcrumb.propTypes = {
};

CustomBreadcrumb.defaultProps = {
items: [ {
name: 'Projects',
link: '/projects',
}, {
name: 'Sample Project Name'
} ] };
items: [
{
name: 'Projects',
link: '/projects',
},
{
name: 'Sample Project Name'
}
]
};

export default CustomBreadcrumb;
42 changes: 25 additions & 17 deletions packages/components/Breadcrumb/stories/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@ import StoryRouter from 'storybook-react-router';
import Breadcrumb from '../index.js';

export const breadcrumbItems = {
projects: [ {
name: 'Projects',
link: '/projects',
}, {
name: 'Example project name'
} ],
paperEdits: [ {
name: 'Projects',
link: '/projects'
}, {
name: 'Project: The Sample',
link: '/projects/the-sample'
}, {
name: 'PaperEdits',
}, {
name: 'Example programme title'
} ]
projects: [
{
name: 'Projects',
link: '/projects',
},
{
name: 'Example project name'
}
],
paperEdits: [
{
name: 'Projects',
link: '/projects'
},
{
name: 'Project: The Sample',
link: '/projects/the-sample'
},
{
name: 'PaperEdits',
},
{
name: 'Example programme title'
}
]
};

storiesOf('Breadcrumb', module)
Expand Down
20 changes: 10 additions & 10 deletions packages/components/FormModal/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useState } from 'react';
import { withKnobs, text, boolean, number } from '@storybook/addon-knobs';
import PropTypes from 'prop-types';
import Modal from 'react-bootstrap/Modal';
import ItemForm from '../ItemForm/index.js';
Expand All @@ -8,8 +7,9 @@ import TranscriptForm from '../TranscriptForm/index.js';
const ItemFormModal = (props) => {

const [ showModal, toggleShowModal ] = useState(props.showModal);
const type = props.type.toLowerCase();

const form = (props.type === 'transcript') ? <TranscriptForm { ...props }/> : <ItemForm { ...props }/>;
const form = (type === 'transcript') ? <TranscriptForm { ...props }/> : <ItemForm { ...props }/>;

return (
<Modal show={ showModal } onHide={ () => toggleShowModal(!showModal) }>
Expand All @@ -24,21 +24,21 @@ const ItemFormModal = (props) => {
};

ItemFormModal.propTypes = {
id: PropTypes.number.isRequired,
title: PropTypes.string,
description: PropTypes.string,
showModal: PropTypes.bool.isRequired,
modalTitle: PropTypes.string.isRequired,
handleSaveForm: PropTypes.func.isRequired,
id: PropTypes.number.isRequired,
showModal: PropTypes.bool,
modalTitle: PropTypes.string.isRequired,
showModal: PropTypes.bool.isRequired,
title: PropTypes.string,
type: PropTypes.any
};

ItemFormModal.defaultProps = {
handleSaveForm: () => {
console.log('Handling a project save');
},
id: 1,
isNewItemModalShow: false,
showModal: false,
modalTitle: 'New Project',
type: 'Project'
};

export default ItemFormModal;
49 changes: 27 additions & 22 deletions packages/components/FormModal/stories/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,33 @@ import { actions } from '@storybook/addon-actions';
import StoryRouter from 'storybook-react-router';
import FormModal from '../index.js';

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 modalItems = [
{
id: 1,
type: '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,
type: 'Project'
},
{
projectId: 123,
title: '',
description: '',
uploadCompleted: true,
showModal: true,
modalTitle: 'New Transcript',
id: 3,
type: 'Transcript'
}
];

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

Expand Down
2 changes: 1 addition & 1 deletion packages/components/ItemForm/stories/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { actions } from '@storybook/addon-actions';

const modalItems = [ {
id: 1,
itemType: 'project',
type: 'project',
showModal: true,
title: 'Example Project Title',
description: 'This is a sample card description. This is fun!',
Expand Down
71 changes: 15 additions & 56 deletions packages/components/List/index.js
Original file line number Diff line number Diff line change
@@ -1,98 +1,57 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import SimpleCard from '../SimpleCard';
import SearchBar from './SearchBar';
import TranscriptCard from '../TranscriptCard';

const List = (props) => {

const [ items, setItems ] = useState(props.items);

const includesText = (text, subsetText) => {
return text.toLowerCase().includes(subsetText.toLowerCase().trim());
};

const handleDeleteItem = (itemId) => {
const updatedList = items.filter((item) => {
return item.id !== itemId;
});
props.handleDelete(itemId);
setItems(updatedList);
};

const handleDisplay = (item, searchText) => {
if (
includesText(item.title, searchText) ||
includesText(item.description, searchText)
) {
item.display = true;
} else {
item.display = false;
useEffect(() => {
if (items.length === 0) {
setItems(props.items);
}

return item;
};
return () => {

const handleSearchItem = searchText => {
const results = items.filter(item => handleDisplay(item, searchText));
setItems(results);
};
};
}, [ props.items ]);

const listItems = items.map((item) => {
if (item.display && item.status) {
return (
<TranscriptCard
{ ...item }
handleEdit={ props.handleEdit(item.id) }
handleDelete={ handleDeleteItem }
key={ item.key }
handleEditItem={ props.handleEditItem }
handleDeleteItem={ props.handleDeleteItem }
/>
);
}
else if (item.display) {
return (
<SimpleCard
{ ...item }
handleEdit={ props.handleEdit(item.id) }
handleDelete={ handleDeleteItem }
key={ item.key }
handleEditItem={ props.handleEditItem }
handleDeleteItem={ props.handleDeleteItem }
/>
);}

return null;
}).filter(item => {
return item !== null;
});

return (
<section style={ { height: '75vh', overflow: 'scroll' } }>
{items !== null && items.length !== 0 ? <SearchBar handleSearch={ handleSearchItem }/> : null}
{listItems}
</section>
);
};

List.propTypes = {
items: PropTypes.array.isRequired,
handleEdit: PropTypes.func.isRequired,
handleDelete: PropTypes.func.isRequired,
};

List.defaultProps = {
items: [
{
id: '1234',
key: 'abc123',
title: 'Sample Simple Card Title One',
description: 'This is a sample card description. This is fun!',
display: true,
url: '/projects/1/transcripts/5678'
}
],
handleEdit: () => {
console.log('Edit button clicked');
},
handleDelete: () => {
console.log('Delete button clicked');
},
handleEditItem: PropTypes.func.isRequired,
handleDeleteItem: PropTypes.func.isRequired,
};

export default List;
31 changes: 7 additions & 24 deletions packages/components/List/stories/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ import { storiesOf } from '@storybook/react';
import { actions } from '@storybook/addon-actions';
import StoryRouter from 'storybook-react-router';
import List from '../index.js';
import SearchBar from '../SearchBar';

const cardActions = actions({
handleEdit: 'Edit button clicked',
handleDelete: 'Delete button clicked'
handleEditItem: 'Edit button clicked',
handleDeleteItem: 'Delete button clicked'
});

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

const items = [ {
id: '1234',
key: 'abc123',
Expand Down Expand Up @@ -67,9 +64,8 @@ storiesOf('List', module)
<section style={ { height: '90vh', overflow: 'scroll' } }>
<List
items={ items }
handleEdit={ cardActions.handleEdit }
handleDelete={ cardActions.handleDelete }
handleSearch={ searchActions.handleSearch }
handleEditItem={ cardActions.handleEditItem }
handleDeleteItem={ cardActions.handleDeleteItem }
/>
</section>
);
Expand All @@ -78,21 +74,8 @@ storiesOf('List', module)
<section style={ { height: '100%', overflow: 'scroll' } }>
<List
items={ transItems }
handleEdit={ cardActions.handleEdit }
handleDelete={ cardActions.handleDelete }
handleSearch={ searchActions.handleSearch }
handleEditItem={ cardActions.handleEditItem }
handleDeleteItem={ cardActions.handleDeleteItem }
/>
</section>
);

storiesOf('List/Search Bar', module)
.addDecorator(StoryRouter())
.add('Default', () => {
return (
<section style={ { height: '90vh', overflow: 'scroll' } }>
<SearchBar
handleSearch={ searchActions.handleSearch }
/>
</section>
);
});
);
Loading

0 comments on commit e32536c

Please sign in to comment.