mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01: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(' ')}> | ||||||
|  |                 {toggleFeature ? ( // display feature list, toggleFeature is available | ||||||
|                     <Link |                     <Link | ||||||
|                         to={`/features/strategies/${name}`} |                         to={`/features/strategies/${name}`} | ||||||
|                         className={[commonStyles.listLink, commonStyles.truncate].join(' ')} |                         className={[commonStyles.listLink, commonStyles.truncate].join(' ')} | ||||||
|                     > |                     > | ||||||
|                         {name} |                         {name} | ||||||
|                     <span className={['mdl-list__item-sub-title', commonStyles.truncate].join(' ')}>{description}</span> |                         <span className={['mdl-list__item-sub-title', commonStyles.truncate].join(' ')}> | ||||||
|  |                             {description} | ||||||
|  |                         </span> | ||||||
|                     </Link> |                     </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) { | ||||||
|  |             if (this.isFeatureView) { | ||||||
|                 this.props.fetchFeatureToggles(); |                 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,6 +122,7 @@ 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> | ||||||
|  |                     {this.isFeatureView ? ( | ||||||
|                         <Textfield |                         <Textfield | ||||||
|                             floatingLabel |                             floatingLabel | ||||||
|                             style={{ width: '100%' }} |                             style={{ width: '100%' }} | ||||||
| @ -123,6 +133,17 @@ export default class ViewFeatureToggleComponent extends React.Component { | |||||||
|                             onChange={v => setValue('description', v)} |                             onChange={v => setValue('description', v)} | ||||||
|                             onBlur={updateFeatureToggle} |                             onBlur={updateFeatureToggle} | ||||||
|                         /> |                         /> | ||||||
|  |                     ) : ( | ||||||
|  |                         <Textfield | ||||||
|  |                             disabled | ||||||
|  |                             floatingLabel | ||||||
|  |                             style={{ width: '100%' }} | ||||||
|  |                             rows={1} | ||||||
|  |                             label="Description" | ||||||
|  |                             required | ||||||
|  |                             value={featureToggle.description} | ||||||
|  |                         /> | ||||||
|  |                     )} | ||||||
|                 </CardText> |                 </CardText> | ||||||
| 
 | 
 | ||||||
|                 <CardActions |                 <CardActions | ||||||
| @ -134,6 +155,7 @@ export default class ViewFeatureToggleComponent extends React.Component { | |||||||
|                     }} |                     }} | ||||||
|                 > |                 > | ||||||
|                     <span style={{ paddingRight: '24px' }}> |                     <span style={{ paddingRight: '24px' }}> | ||||||
|  |                         {this.isFeatureView ? ( | ||||||
|                             <Switch |                             <Switch | ||||||
|                                 ripple |                                 ripple | ||||||
|                                 checked={featureToggle.enabled} |                                 checked={featureToggle.enabled} | ||||||
| @ -141,10 +163,25 @@ export default class ViewFeatureToggleComponent extends React.Component { | |||||||
|                             > |                             > | ||||||
|                                 {featureToggle.enabled ? 'Enabled' : 'Disabled'} |                                 {featureToggle.enabled ? 'Enabled' : 'Disabled'} | ||||||
|                             </Switch> |                             </Switch> | ||||||
|  |                         ) : ( | ||||||
|  |                             <Switch | ||||||
|  |                                 disabled | ||||||
|  |                                 ripple | ||||||
|  |                                 checked={featureToggle.enabled} | ||||||
|  |                                 onChange={() => toggleFeature(featureToggle.name)} | ||||||
|  |                             > | ||||||
|  |                                 {featureToggle.enabled ? 'Enabled' : 'Disabled'} | ||||||
|  |                             </Switch> | ||||||
|  |                         )} | ||||||
|                     </span> |                     </span> | ||||||
|  | 
 | ||||||
|  |                     {this.isFeatureView ? ( | ||||||
|                         <Button onClick={removeToggle} style={{ flexShrink: 0 }}> |                         <Button onClick={removeToggle} style={{ flexShrink: 0 }}> | ||||||
|                             Archive |                             Archive | ||||||
|                         </Button> |                         </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