mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-23 01:16:27 +02:00
feat(archive): reuse feature/view-component.jsx to display archive details
This commit is contained in:
parent
d31d5340c2
commit
a88f0da822
@ -11,10 +11,10 @@ class ArchiveList extends React.PureComponent {
|
|||||||
name: PropTypes.string,
|
name: PropTypes.string,
|
||||||
archive: PropTypes.array.isRequired,
|
archive: PropTypes.array.isRequired,
|
||||||
fetchArchive: PropTypes.func,
|
fetchArchive: PropTypes.func,
|
||||||
featureMetrics: PropTypes.object.isRequired,
|
featureMetrics: PropTypes.object,
|
||||||
updateSetting: PropTypes.func.isRequired,
|
updateSetting: PropTypes.func,
|
||||||
settings: PropTypes.object,
|
settings: PropTypes.object,
|
||||||
revive: PropTypes.func.optional,
|
revive: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
18
frontend/src/component/archive/view-container.js
Normal file
18
frontend/src/component/archive/view-container.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { fetchArchive } from './../../store/archive-actions';
|
||||||
|
|
||||||
|
import ViewToggleComponent from './../feature/view-component';
|
||||||
|
|
||||||
|
export default connect(
|
||||||
|
(state, props) => ({
|
||||||
|
features: state.archive.get('list').toArray(),
|
||||||
|
featureToggle: state.archive
|
||||||
|
.get('list')
|
||||||
|
.toArray()
|
||||||
|
.find(toggle => toggle.name === props.featureToggleName),
|
||||||
|
activeTab: props.activeTab,
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
fetchArchive,
|
||||||
|
}
|
||||||
|
)(ViewToggleComponent);
|
@ -43,7 +43,7 @@ const Feature = ({
|
|||||||
<span className={styles.listItemMetric}>
|
<span className={styles.listItemMetric}>
|
||||||
<Progress strokeWidth={15} percentage={percent} isFallback={isStale} />
|
<Progress strokeWidth={15} percentage={percent} isFallback={isStale} />
|
||||||
</span>
|
</span>
|
||||||
{toggleFeature ? ( // display feature list
|
{toggleFeature ? ( // display feature list, toggleFeature is available
|
||||||
<span className={styles.listItemToggle}>
|
<span className={styles.listItemToggle}>
|
||||||
<Switch
|
<Switch
|
||||||
title={`Toggle ${name}`}
|
title={`Toggle ${name}`}
|
||||||
@ -53,17 +53,31 @@ const Feature = ({
|
|||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
// display archive
|
// display archive, toggleFeature is undefined
|
||||||
<span />
|
<span />
|
||||||
)}
|
)}
|
||||||
<span className={['mdl-list__item-primary-content', styles.listItemLink].join(' ')}>
|
<span className={['mdl-list__item-primary-content', styles.listItemLink].join(' ')}>
|
||||||
<Link
|
{toggleFeature ? ( // display feature list, toggleFeature is available
|
||||||
to={`/features/strategies/${name}`}
|
<Link
|
||||||
className={[commonStyles.listLink, commonStyles.truncate].join(' ')}
|
to={`/features/strategies/${name}`}
|
||||||
>
|
className={[commonStyles.listLink, commonStyles.truncate].join(' ')}
|
||||||
{name}
|
>
|
||||||
<span className={['mdl-list__item-sub-title', commonStyles.truncate].join(' ')}>{description}</span>
|
{name}
|
||||||
</Link>
|
<span className={['mdl-list__item-sub-title', commonStyles.truncate].join(' ')}>
|
||||||
|
{description}
|
||||||
|
</span>
|
||||||
|
</Link>
|
||||||
|
) : (
|
||||||
|
<Link
|
||||||
|
to={`/archive/strategies/${name}`}
|
||||||
|
className={[commonStyles.listLink, commonStyles.truncate].join(' ')}
|
||||||
|
>
|
||||||
|
{name}
|
||||||
|
<span className={['mdl-list__item-sub-title', commonStyles.truncate].join(' ')}>
|
||||||
|
{description}
|
||||||
|
</span>
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
<span className={[styles.listItemStrategies, commonStyles.hideLt920].join(' ')}>
|
<span className={[styles.listItemStrategies, commonStyles.hideLt920].join(' ')}>
|
||||||
{strategyChips}
|
{strategyChips}
|
||||||
|
@ -15,24 +15,31 @@ const TABS = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default class ViewFeatureToggleComponent extends React.Component {
|
export default class ViewFeatureToggleComponent extends React.Component {
|
||||||
|
isFeatureView;
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
this.isFeatureView = !!props.fetchFeatureToggles;
|
||||||
}
|
}
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
activeTab: PropTypes.string.isRequired,
|
activeTab: PropTypes.string.isRequired,
|
||||||
featureToggleName: PropTypes.string.isRequired,
|
featureToggleName: PropTypes.string.isRequired,
|
||||||
features: PropTypes.array.isRequired,
|
features: PropTypes.array.isRequired,
|
||||||
toggleFeature: PropTypes.func.isRequired,
|
toggleFeature: PropTypes.func,
|
||||||
removeFeatureToggle: PropTypes.func.isRequired,
|
removeFeatureToggle: PropTypes.func,
|
||||||
fetchFeatureToggles: PropTypes.func.isRequired,
|
fetchArchive: PropTypes.func,
|
||||||
editFeatureToggle: PropTypes.func.isRequired,
|
fetchFeatureToggles: PropTypes.func,
|
||||||
|
editFeatureToggle: PropTypes.func,
|
||||||
featureToggle: PropTypes.object,
|
featureToggle: PropTypes.object,
|
||||||
};
|
};
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
if (this.props.features.length === 0) {
|
if (this.props.features.length === 0) {
|
||||||
this.props.fetchFeatureToggles();
|
if (this.isFeatureView) {
|
||||||
|
this.props.fetchFeatureToggles();
|
||||||
|
} else {
|
||||||
|
this.props.fetchArchive();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,14 +49,16 @@ export default class ViewFeatureToggleComponent extends React.Component {
|
|||||||
if (TABS[activeTab] === TABS.history) {
|
if (TABS[activeTab] === TABS.history) {
|
||||||
return <HistoryComponent toggleName={featureToggleName} />;
|
return <HistoryComponent toggleName={featureToggleName} />;
|
||||||
} else if (TABS[activeTab] === TABS.strategies) {
|
} else if (TABS[activeTab] === TABS.strategies) {
|
||||||
return <EditFeatureToggle featureToggle={featureToggle} />;
|
return <EditFeatureToggle featureToggle={featureToggle} />
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return <MetricComponent featureToggle={featureToggle} />;
|
return <MetricComponent featureToggle={featureToggle} />;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
goToTab(tabName, featureToggleName) {
|
goToTab(tabName, featureToggleName) {
|
||||||
hashHistory.push(`/features/${tabName}/${featureToggleName}`);
|
let view = this.props.fetchFeatureToggles ? 'features' : 'archive';
|
||||||
|
hashHistory.push(`/${view}/${tabName}/${featureToggleName}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -113,16 +122,28 @@ export default class ViewFeatureToggleComponent extends React.Component {
|
|||||||
<Card shadow={0} className={commonStyles.fullwidth} style={{ overflow: 'visible' }}>
|
<Card shadow={0} className={commonStyles.fullwidth} style={{ overflow: 'visible' }}>
|
||||||
<CardTitle style={{ paddingTop: '24px', wordBreak: 'break-all' }}>{featureToggle.name}</CardTitle>
|
<CardTitle style={{ paddingTop: '24px', wordBreak: 'break-all' }}>{featureToggle.name}</CardTitle>
|
||||||
<CardText>
|
<CardText>
|
||||||
<Textfield
|
{this.isFeatureView ? (
|
||||||
floatingLabel
|
<Textfield
|
||||||
style={{ width: '100%' }}
|
floatingLabel
|
||||||
rows={1}
|
style={{ width: '100%' }}
|
||||||
label="Description"
|
rows={1}
|
||||||
required
|
label="Description"
|
||||||
value={featureToggle.description}
|
required
|
||||||
onChange={v => setValue('description', v)}
|
value={featureToggle.description}
|
||||||
onBlur={updateFeatureToggle}
|
onChange={v => setValue('description', v)}
|
||||||
/>
|
onBlur={updateFeatureToggle}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Textfield
|
||||||
|
disabled
|
||||||
|
floatingLabel
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
rows={1}
|
||||||
|
label="Description"
|
||||||
|
required
|
||||||
|
value={featureToggle.description}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</CardText>
|
</CardText>
|
||||||
|
|
||||||
<CardActions
|
<CardActions
|
||||||
@ -134,17 +155,33 @@ export default class ViewFeatureToggleComponent extends React.Component {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span style={{ paddingRight: '24px' }}>
|
<span style={{ paddingRight: '24px' }}>
|
||||||
<Switch
|
{this.isFeatureView ? (
|
||||||
ripple
|
<Switch
|
||||||
checked={featureToggle.enabled}
|
ripple
|
||||||
onChange={() => toggleFeature(featureToggle.name)}
|
checked={featureToggle.enabled}
|
||||||
>
|
onChange={() => toggleFeature(featureToggle.name)}
|
||||||
{featureToggle.enabled ? 'Enabled' : 'Disabled'}
|
>
|
||||||
</Switch>
|
{featureToggle.enabled ? 'Enabled' : 'Disabled'}
|
||||||
|
</Switch>
|
||||||
|
) : (
|
||||||
|
<Switch
|
||||||
|
disabled
|
||||||
|
ripple
|
||||||
|
checked={featureToggle.enabled}
|
||||||
|
onChange={() => toggleFeature(featureToggle.name)}
|
||||||
|
>
|
||||||
|
{featureToggle.enabled ? 'Enabled' : 'Disabled'}
|
||||||
|
</Switch>
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
<Button onClick={removeToggle} style={{ flexShrink: 0 }}>
|
|
||||||
Archive
|
{this.isFeatureView ? (
|
||||||
</Button>
|
<Button onClick={removeToggle} style={{ flexShrink: 0 }}>
|
||||||
|
Archive
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<span />
|
||||||
|
)}
|
||||||
</CardActions>
|
</CardActions>
|
||||||
<hr />
|
<hr />
|
||||||
<Tabs
|
<Tabs
|
||||||
|
@ -23,6 +23,7 @@ import CreateStrategies from './page/strategies/create';
|
|||||||
import HistoryPage from './page/history';
|
import HistoryPage from './page/history';
|
||||||
import HistoryTogglePage from './page/history/toggle';
|
import HistoryTogglePage from './page/history/toggle';
|
||||||
import Archive from './page/archive';
|
import Archive from './page/archive';
|
||||||
|
import ShowArchive from './page/archive/show';
|
||||||
import Applications from './page/applications';
|
import Applications from './page/applications';
|
||||||
import ApplicationView from './page/applications/view';
|
import ApplicationView from './page/applications/view';
|
||||||
|
|
||||||
@ -68,7 +69,7 @@ ReactDOM.render(
|
|||||||
</Route>
|
</Route>
|
||||||
<Route pageTitle="Archived Toggles" link="/archive">
|
<Route pageTitle="Archived Toggles" link="/archive">
|
||||||
<Route pageTitle="Archived Toggles" path="/archive" component={Archive} />
|
<Route pageTitle="Archived Toggles" path="/archive" component={Archive} />
|
||||||
<Route pageTitle=":name" path="/archive/:name" component={Archive} />
|
<Route pageTitle=":name" path="/archive/:activeTab/:name" component={ShowArchive} />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
<Route pageTitle="Applications" link="/applications">
|
<Route pageTitle="Applications" link="/applications">
|
||||||
|
14
frontend/src/page/archive/show.js
Normal file
14
frontend/src/page/archive/show.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import React, { PureComponent } from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import ViewFeatureToggle from './../../component/archive/view-container';
|
||||||
|
|
||||||
|
export default class Features extends PureComponent {
|
||||||
|
static propTypes = {
|
||||||
|
params: PropTypes.object.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { params } = this.props;
|
||||||
|
return <ViewFeatureToggle featureToggleName={params.name} activeTab={params.activeTab} />;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user