diff --git a/packages/unleash-frontend-next/src/component/archive/archive-container.js b/packages/unleash-frontend-next/src/component/archive/archive-container.js new file mode 100644 index 0000000000..cfa005c5d7 --- /dev/null +++ b/packages/unleash-frontend-next/src/component/archive/archive-container.js @@ -0,0 +1,15 @@ +import { connect } from 'react-redux'; +import ListComponent from './archive-list-component'; +import { fetchArchive, revive } from '../../store/archive-actions'; + +const mapStateToProps = (state) => { + const archive = state.archive.get('list').toArray(); // eslint-disable-line no-shadow + + return { + archive, + }; +}; + +const ArchiveListContainer = connect(mapStateToProps, { fetchArchive, revive })(ListComponent); + +export default ArchiveListContainer; diff --git a/packages/unleash-frontend-next/src/component/archive/archive-list-component.jsx b/packages/unleash-frontend-next/src/component/archive/archive-list-component.jsx new file mode 100644 index 0000000000..989912f9f5 --- /dev/null +++ b/packages/unleash-frontend-next/src/component/archive/archive-list-component.jsx @@ -0,0 +1,48 @@ +import React, { Component } from 'react'; +import { List, ListItem, ListSubHeader } from 'react-toolbox/lib/list'; +import FontIcon from 'react-toolbox/lib/font_icon'; +import Chip from 'react-toolbox/lib/chip'; +import Switch from 'react-toolbox/lib/switch'; + +const ArchivedFeature = ({ feature, revive }) => { + const { name, description, enabled, strategies } = feature; // eslint-disable-line no-shadow + const actions = [ +
{strategies && strategies.map(s => {s.name})}
, + revive(feature)} />, + ]; + + const leftActions = [ + , + ]; + + return ( + + ); +}; + +class ArchiveList extends Component { + componentDidMount () { + this.props.fetchArchive(); + } + + render () { + const { archive, revive } = this.props; + return ( + + + {archive.length > 0 ? + archive.map((feature, i) => ) : + } + + ); + } +} + + +export default ArchiveList; diff --git a/packages/unleash-frontend-next/src/component/history/history-container.js b/packages/unleash-frontend-next/src/component/history/history-container.js index 6f7c067526..957dc063b3 100644 --- a/packages/unleash-frontend-next/src/component/history/history-container.js +++ b/packages/unleash-frontend-next/src/component/history/history-container.js @@ -10,6 +10,6 @@ const mapStateToProps = (state) => { }; }; -const StrategiesListContainer = connect(mapStateToProps, { fetchHistory })(ListComponent); +const HistoryListContainer = connect(mapStateToProps, { fetchHistory })(ListComponent); -export default StrategiesListContainer; +export default HistoryListContainer; diff --git a/packages/unleash-frontend-next/src/component/history/history-list-component.jsx b/packages/unleash-frontend-next/src/component/history/history-list-component.jsx index fbd0d30398..74148fd35b 100644 --- a/packages/unleash-frontend-next/src/component/history/history-list-component.jsx +++ b/packages/unleash-frontend-next/src/component/history/history-list-component.jsx @@ -1,13 +1,7 @@ import React, { Component } from 'react'; -import { List, ListItem, ListSubHeader, ListDivider } from 'react-toolbox/lib/list'; -import FontIcon from 'react-toolbox/lib/font_icon'; -import Chip from 'react-toolbox/lib/chip'; +import { List, ListItem, ListSubHeader } from 'react-toolbox/lib/list'; -class StrategiesListComponent extends Component { - - static contextTypes = { - router: React.PropTypes.object, - } +class HistoryList extends Component { componentDidMount () { this.props.fetchHistory(); @@ -33,7 +27,7 @@ class StrategiesListComponent extends Component { } render () { - const { history } = this.props; + const { history } = this.props; // eslint-disable-line no-shadow return ( @@ -61,4 +55,4 @@ class StrategiesListComponent extends Component { } -export default StrategiesListComponent; +export default HistoryList; diff --git a/packages/unleash-frontend-next/src/data/archive-api.js b/packages/unleash-frontend-next/src/data/archive-api.js new file mode 100644 index 0000000000..82ce715b8d --- /dev/null +++ b/packages/unleash-frontend-next/src/data/archive-api.js @@ -0,0 +1,36 @@ +const URI = '/archive'; + +const headers = { + 'Accept': 'application/json', + 'Content-Type': 'application/json', +}; + +function throwIfNotSuccess (response) { + if (!response.ok) { + let error = new Error('API call failed'); + error.status = response.status; + throw error; + } + return response; +} + +function fetchAll () { + return fetch(`${URI}/features`) + .then(throwIfNotSuccess) + .then(response => response.json()); +} + +function revive (feature) { + return fetch(`${URI}/revive`, { + method: 'POST', + headers, + body: JSON.stringify(feature), + }).then(throwIfNotSuccess); +} + + +module.exports = { + fetchAll, + revive, +}; + diff --git a/packages/unleash-frontend-next/src/page/archive/index.js b/packages/unleash-frontend-next/src/page/archive/index.js index 7abb59def9..c88ee8d0e1 100644 --- a/packages/unleash-frontend-next/src/page/archive/index.js +++ b/packages/unleash-frontend-next/src/page/archive/index.js @@ -1,28 +1,6 @@ -import React, { Component } from 'react'; -import { Card, CardTitle, CardText } from 'react-toolbox'; +import React from 'react'; +import Archive from '../../component/archive/archive-container'; +const render = () => ; -export default class Archive extends Component { - render () { - return ( - - Archived Feture Toggles - -

- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam pharetra finibus - ullamcorper. Proin laoreet faucibus venenatis. Aenean quis leo finibus, maximus - nisi finibus, fringilla ex. Nam mollis congue orci eu consectetur. Aliquam a - massa quis tortor vestibulum lacinia. Phasellus nisi velit, mattis vel nulla - a, rhoncus porta dui. Vestibulum viverra augue in pellentesque tincidunt. - Aliquam rhoncus nunc ipsum, sed vehicula leo dictum in. Phasellus accumsan - elis sem, in ullamcorper nisi accumsan vitae. Nullam vitae consectetur mi, - sed vulputate augue. In quis augue tellus. Duis convallis cursus elit, in - interdum nisl pulvinar viverra. Sed vel ornare sapien, eu consectetur metus. - Vivamus at porta nisl. Nullam in aliquam nisl. -

-
-
- - ); - } -}; +export default render; diff --git a/packages/unleash-frontend-next/src/store/archive-actions.js b/packages/unleash-frontend-next/src/store/archive-actions.js new file mode 100644 index 0000000000..07ea4cbc6d --- /dev/null +++ b/packages/unleash-frontend-next/src/store/archive-actions.js @@ -0,0 +1,33 @@ +import api from '../data/archive-api'; + +export const REVIVE_TOGGLE = 'REVIVE_TOGGLE'; +export const RECEIVE_ARCHIVE = 'RECEIVE_ARCHIVE'; +export const ERROR_RECEIVE_ARCHIVE = 'ERROR_RECEIVE_ARCHIVE'; + +const receiveArchive = (json) => ({ + type: RECEIVE_ARCHIVE, + value: json.features, +}); + +const reviveToggle = (archiveFeatureToggle) => ({ + type: REVIVE_TOGGLE, + value: archiveFeatureToggle, +}); + +const errorReceiveArchive = (statusCode) => ({ + type: ERROR_RECEIVE_ARCHIVE, + statusCode, +}); + +export function revive (featureToggle) { + return dispatch => api.revive(featureToggle) + .then(() => dispatch(reviveToggle(featureToggle))) + .catch(error => dispatch(errorReceiveArchive(error))); +} + + +export function fetchArchive () { + return dispatch => api.fetchAll() + .then(json => dispatch(receiveArchive(json))) + .catch(error => dispatch(errorReceiveArchive(error))); +} diff --git a/packages/unleash-frontend-next/src/store/archive-store.js b/packages/unleash-frontend-next/src/store/archive-store.js new file mode 100644 index 0000000000..845b79d748 --- /dev/null +++ b/packages/unleash-frontend-next/src/store/archive-store.js @@ -0,0 +1,19 @@ +import { List, Map as $Map } from 'immutable'; +import { RECEIVE_ARCHIVE, REVIVE_TOGGLE } from './archive-actions'; + +function getInitState () { + return new $Map({ list: new List() }); +} + +const archiveStore = (state = getInitState(), action) => { + switch (action.type) { + case REVIVE_TOGGLE: + return state.update('list', (list) => list.remove(list.indexOf(action.value))); + case RECEIVE_ARCHIVE: + return state.set('list', new List(action.value)); + default: + return state; + } +}; + +export default archiveStore; diff --git a/packages/unleash-frontend-next/src/store/index.js b/packages/unleash-frontend-next/src/store/index.js index 85be261c21..4565f8ff8e 100644 --- a/packages/unleash-frontend-next/src/store/index.js +++ b/packages/unleash-frontend-next/src/store/index.js @@ -3,12 +3,14 @@ import features from './feature-store'; import strategies from './strategy-store'; import input from './input-store'; import history from './history-store'; // eslint-disable-line +import archive from './archive-store'; const unleashStore = combineReducers({ features, strategies, input, history, + archive, }); export default unleashStore;