mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	refactor: use explicit export and delete unused files
This commit is contained in:
		
							parent
							
								
									3fb8a4f5f3
								
							
						
					
					
						commit
						ef8e3dcbfa
					
				| @ -12,8 +12,8 @@ import { Link as LinkIcon } from '@material-ui/icons'; | |||||||
| import ConditionallyRender from '../../common/ConditionallyRender/ConditionallyRender'; | import ConditionallyRender from '../../common/ConditionallyRender/ConditionallyRender'; | ||||||
| import { formatDateWithLocale } from '../../common/util'; | import { formatDateWithLocale } from '../../common/util'; | ||||||
| import { UPDATE_APPLICATION } from '../../providers/AccessProvider/permissions'; | import { UPDATE_APPLICATION } from '../../providers/AccessProvider/permissions'; | ||||||
| import ApplicationView from '../ApplicationView/ApplicationView'; | import { ApplicationView } from '../ApplicationView/ApplicationView'; | ||||||
| import ApplicationUpdate from '../ApplicationUpdate/ApplicationUpdate'; | import { ApplicationUpdate } from '../ApplicationUpdate/ApplicationUpdate'; | ||||||
| import TabNav from '../../common/TabNav/TabNav'; | import TabNav from '../../common/TabNav/TabNav'; | ||||||
| import Dialogue from '../../common/Dialogue'; | import Dialogue from '../../common/Dialogue'; | ||||||
| import PageContent from '../../common/PageContent'; | import PageContent from '../../common/PageContent'; | ||||||
| @ -26,7 +26,7 @@ import { useLocationSettings } from '../../../hooks/useLocationSettings'; | |||||||
| import useToast from '../../../hooks/useToast'; | import useToast from '../../../hooks/useToast'; | ||||||
| import PermissionButton from '../../common/PermissionButton/PermissionButton'; | import PermissionButton from '../../common/PermissionButton/PermissionButton'; | ||||||
| 
 | 
 | ||||||
| const ApplicationEdit = () => { | export const ApplicationEdit = () => { | ||||||
|     const history = useHistory(); |     const history = useHistory(); | ||||||
|     const { name } = useParams<{ name: string }>(); |     const { name } = useParams<{ name: string }>(); | ||||||
|     const { application, loading } = useApplication(name); |     const { application, loading } = useApplication(name); | ||||||
| @ -42,7 +42,7 @@ const ApplicationEdit = () => { | |||||||
|         setShowDialog(!showDialog); |         setShowDialog(!showDialog); | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     const formatDate = (v: Date) => |     const formatDate = (v: string) => | ||||||
|         formatDateWithLocale(v, locationSettings.locale); |         formatDateWithLocale(v, locationSettings.locale); | ||||||
| 
 | 
 | ||||||
|     const onDeleteApplication = async (evt: Event) => { |     const onDeleteApplication = async (evt: Event) => { | ||||||
| @ -109,7 +109,7 @@ const ApplicationEdit = () => { | |||||||
|                     actions={ |                     actions={ | ||||||
|                         <> |                         <> | ||||||
|                             <ConditionallyRender |                             <ConditionallyRender | ||||||
|                                 condition={url} |                                 condition={Boolean(url)} | ||||||
|                                 show={ |                                 show={ | ||||||
|                                     <IconButton component={Link} href={url}> |                                     <IconButton component={Link} href={url}> | ||||||
|                                         <LinkIcon /> |                                         <LinkIcon /> | ||||||
| @ -147,5 +147,3 @@ const ApplicationEdit = () => { | |||||||
|         </PageContent> |         </PageContent> | ||||||
|     ); |     ); | ||||||
| }; | }; | ||||||
| 
 |  | ||||||
| export default ApplicationEdit; |  | ||||||
|  | |||||||
| @ -9,7 +9,7 @@ import HeaderTitle from '../../common/HeaderTitle'; | |||||||
| import useApplications from '../../../hooks/api/getters/useApplications/useApplications'; | import useApplications from '../../../hooks/api/getters/useApplications/useApplications'; | ||||||
| import ConditionallyRender from '../../common/ConditionallyRender'; | import ConditionallyRender from '../../common/ConditionallyRender'; | ||||||
| 
 | 
 | ||||||
| const ApplicationList = () => { | export const ApplicationList = () => { | ||||||
|     const { applications, loading } = useApplications(); |     const { applications, loading } = useApplications(); | ||||||
|     const [filter, setFilter] = useState(''); |     const [filter, setFilter] = useState(''); | ||||||
| 
 | 
 | ||||||
| @ -20,7 +20,7 @@ const ApplicationList = () => { | |||||||
|             : applications; |             : applications; | ||||||
|     }, [applications, filter]); |     }, [applications, filter]); | ||||||
| 
 | 
 | ||||||
|     const RenderNoApplications = () => ( |     const renderNoApplications = () => ( | ||||||
|         <> |         <> | ||||||
|             <section style={{ textAlign: 'center' }}> |             <section style={{ textAlign: 'center' }}> | ||||||
|                 <Warning /> <br /> |                 <Warning /> <br /> | ||||||
| @ -57,7 +57,7 @@ const ApplicationList = () => { | |||||||
|                             <ConditionallyRender |                             <ConditionallyRender | ||||||
|                                 condition={loading} |                                 condition={loading} | ||||||
|                                 show={<div>...loading</div>} |                                 show={<div>...loading</div>} | ||||||
|                                 elseShow={<RenderNoApplications />} |                                 elseShow={renderNoApplications()} | ||||||
|                             /> |                             /> | ||||||
|                         } |                         } | ||||||
|                     /> |                     /> | ||||||
| @ -66,5 +66,3 @@ const ApplicationList = () => { | |||||||
|         </> |         </> | ||||||
|     ); |     ); | ||||||
| }; | }; | ||||||
| 
 |  | ||||||
| export default ApplicationList; |  | ||||||
|  | |||||||
| @ -12,7 +12,7 @@ interface IApplicationUpdateProps { | |||||||
|     application: IApplication; |     application: IApplication; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const ApplicationUpdate = ({ application }: IApplicationUpdateProps) => { | export const ApplicationUpdate = ({ application }: IApplicationUpdateProps) => { | ||||||
|     const { storeApplicationMetaData } = useApplicationsApi(); |     const { storeApplicationMetaData } = useApplicationsApi(); | ||||||
|     const { appName, icon, url, description } = application; |     const { appName, icon, url, description } = application; | ||||||
|     const [localUrl, setLocalUrl] = useState(url || ''); |     const [localUrl, setLocalUrl] = useState(url || ''); | ||||||
| @ -83,5 +83,3 @@ const ApplicationUpdate = ({ application }: IApplicationUpdateProps) => { | |||||||
|         </Grid> |         </Grid> | ||||||
|     ); |     ); | ||||||
| }; | }; | ||||||
| 
 |  | ||||||
| export default ApplicationUpdate; |  | ||||||
|  | |||||||
| @ -25,7 +25,8 @@ import { getTogglePath } from '../../../utils/route-path-helpers'; | |||||||
| import useApplication from '../../../hooks/api/getters/useApplication/useApplication'; | import useApplication from '../../../hooks/api/getters/useApplication/useApplication'; | ||||||
| import AccessContext from '../../../contexts/AccessContext'; | import AccessContext from '../../../contexts/AccessContext'; | ||||||
| import { formatFullDateTimeWithLocale } from '../../common/util'; | import { formatFullDateTimeWithLocale } from '../../common/util'; | ||||||
| const ApplicationView = () => { | 
 | ||||||
|  | export const ApplicationView = () => { | ||||||
|     const { hasAccess } = useContext(AccessContext); |     const { hasAccess } = useContext(AccessContext); | ||||||
|     const { name } = useParams<{ name: string }>(); |     const { name } = useParams<{ name: string }>(); | ||||||
|     const { application } = useApplication(name); |     const { application } = useApplication(name); | ||||||
| @ -129,24 +130,26 @@ const ApplicationView = () => { | |||||||
|                 </Typography> |                 </Typography> | ||||||
|                 <hr /> |                 <hr /> | ||||||
|                 <List> |                 <List> | ||||||
|                     {strategies.map(({ name, description, notFound }, i: number) => ( |                     {strategies.map( | ||||||
|                         <ConditionallyRender |                         ({ name, description, notFound }, i: number) => ( | ||||||
|                             key={`strategies_conditional_${name}`} |                             <ConditionallyRender | ||||||
|                             condition={notFound} |                                 key={`strategies_conditional_${name}`} | ||||||
|                             show={notFoundListItem({ |                                 condition={notFound} | ||||||
|                                 createUrl: '/strategies/create', |                                 show={notFoundListItem({ | ||||||
|                                 name, |                                     createUrl: '/strategies/create', | ||||||
|                                 permission: CREATE_STRATEGY, |                                     name, | ||||||
|                             })} |                                     permission: CREATE_STRATEGY, | ||||||
|                             elseShow={foundListItem({ |                                 })} | ||||||
|                                 viewUrl: '/strategies/view', |                                 elseShow={foundListItem({ | ||||||
|                                 name, |                                     viewUrl: '/strategies/view', | ||||||
|                                 Icon: Extension, |                                     name, | ||||||
|                                 description, |                                     Icon: Extension, | ||||||
|                                 i, |                                     description, | ||||||
|                             })} |                                     i, | ||||||
|                         /> |                                 })} | ||||||
|                     ))} |                             /> | ||||||
|  |                         ) | ||||||
|  |                     )} | ||||||
|                 </List> |                 </List> | ||||||
|             </Grid> |             </Grid> | ||||||
|             <Grid item xl={12} md={12}> |             <Grid item xl={12} md={12}> | ||||||
| @ -203,5 +206,3 @@ const ApplicationView = () => { | |||||||
|         </Grid> |         </Grid> | ||||||
|     ); |     ); | ||||||
| }; | }; | ||||||
| 
 |  | ||||||
| export default ApplicationView; |  | ||||||
|  | |||||||
| @ -41,12 +41,11 @@ import EditProject from '../project/Project/EditProject/EditProject'; | |||||||
| import CreateProject from '../project/Project/CreateProject/CreateProject'; | import CreateProject from '../project/Project/CreateProject/CreateProject'; | ||||||
| import CreateFeature from '../feature/CreateFeature/CreateFeature'; | import CreateFeature from '../feature/CreateFeature/CreateFeature'; | ||||||
| import EditFeature from '../feature/EditFeature/EditFeature'; | import EditFeature from '../feature/EditFeature/EditFeature'; | ||||||
| import ApplicationEdit from '../application/ApplicationEdit/ApplicationEdit'; | import { ApplicationEdit } from '../application/ApplicationEdit/ApplicationEdit'; | ||||||
| import ApplicationList from '../application/ApplicationList/ApplicationList'; | import { ApplicationList } from '../application/ApplicationList/ApplicationList'; | ||||||
| import ContextList from '../context/ContextList/ContextList'; | import ContextList from '../context/ContextList/ContextList'; | ||||||
| import RedirectFeatureView from '../feature/RedirectFeatureView/RedirectFeatureView'; | import RedirectFeatureView from '../feature/RedirectFeatureView/RedirectFeatureView'; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| export const routes = [ | export const routes = [ | ||||||
|     // Project
 |     // Project
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,6 +0,0 @@ | |||||||
| import React from 'react'; |  | ||||||
| import ApplicationListConmponent from '../../component/application/application-list-container'; |  | ||||||
| 
 |  | ||||||
| const render = () => <ApplicationListConmponent />; |  | ||||||
| 
 |  | ||||||
| export default render; |  | ||||||
| @ -1,12 +0,0 @@ | |||||||
| import React from 'react'; |  | ||||||
| import PropTypes from 'prop-types'; |  | ||||||
| import ApplicationEditComponent from '../../component/application/application-edit-container'; |  | ||||||
| 
 |  | ||||||
| const render = ({ match: { params }, history }) => <ApplicationEditComponent appName={params.name} history={history} />; |  | ||||||
| 
 |  | ||||||
| render.propTypes = { |  | ||||||
|     match: PropTypes.object.isRequired, |  | ||||||
|     history: PropTypes.object.isRequired, |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| export default render; |  | ||||||
| @ -1,58 +0,0 @@ | |||||||
| import api from './api'; |  | ||||||
| import { dispatchError } from '../util'; |  | ||||||
| import { MUTE_ERROR } from '../error/actions'; |  | ||||||
| 
 |  | ||||||
| export const RECEIVE_ALL_APPLICATIONS = 'RECEIVE_ALL_APPLICATIONS'; |  | ||||||
| export const ERROR_RECEIVE_ALL_APPLICATIONS = 'ERROR_RECEIVE_ALL_APPLICATIONS'; |  | ||||||
| export const ERROR_UPDATING_APPLICATION_DATA = 'ERROR_UPDATING_APPLICATION_DATA'; |  | ||||||
| 
 |  | ||||||
| export const RECEIVE_APPLICATION = 'RECEIVE_APPLICATION'; |  | ||||||
| export const UPDATE_APPLICATION_FIELD = 'UPDATE_APPLICATION_FIELD'; |  | ||||||
| export const DELETE_APPLICATION = 'DELETE_APPLICATION'; |  | ||||||
| export const ERROR_DELETE_APPLICATION = 'ERROR_DELETE_APPLICATION'; |  | ||||||
| 
 |  | ||||||
| const recieveAllApplications = json => ({ |  | ||||||
|     type: RECEIVE_ALL_APPLICATIONS, |  | ||||||
|     value: json, |  | ||||||
| }); |  | ||||||
| 
 |  | ||||||
| const recieveApplication = json => ({ |  | ||||||
|     type: RECEIVE_APPLICATION, |  | ||||||
|     value: json, |  | ||||||
| }); |  | ||||||
| 
 |  | ||||||
| export function fetchAll() { |  | ||||||
|     return dispatch => |  | ||||||
|         api |  | ||||||
|             .fetchAll() |  | ||||||
|             .then(json => dispatch(recieveAllApplications(json))) |  | ||||||
|             .catch(dispatchError(dispatch, ERROR_RECEIVE_ALL_APPLICATIONS)); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export function storeApplicationMetaData(appName, key, value) { |  | ||||||
|     return dispatch => |  | ||||||
|         api |  | ||||||
|             .storeApplicationMetaData(appName, key, value) |  | ||||||
|             .then(() => { |  | ||||||
|                 const info = `${appName} successfully updated!`; |  | ||||||
|                 setTimeout(() => dispatch({ type: MUTE_ERROR, error: info }), 1000); |  | ||||||
|                 dispatch({ type: UPDATE_APPLICATION_FIELD, appName, key, value, info }); |  | ||||||
|             }) |  | ||||||
|             .catch(dispatchError(dispatch, ERROR_UPDATING_APPLICATION_DATA)); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export function fetchApplication(appName) { |  | ||||||
|     return dispatch => |  | ||||||
|         api |  | ||||||
|             .fetchApplication(appName) |  | ||||||
|             .then(json => dispatch(recieveApplication(json))) |  | ||||||
|             .catch(dispatchError(dispatch, ERROR_RECEIVE_ALL_APPLICATIONS)); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export function deleteApplication(appName) { |  | ||||||
|     return dispatch => |  | ||||||
|         api |  | ||||||
|             .deleteApplication(appName) |  | ||||||
|             .then(() => dispatch({ type: DELETE_APPLICATION, appName })) |  | ||||||
|             .catch(dispatchError(dispatch, ERROR_DELETE_APPLICATION)); |  | ||||||
| } |  | ||||||
| @ -1,52 +0,0 @@ | |||||||
| import { formatApiPath } from '../../utils/format-path'; |  | ||||||
| import { throwIfNotSuccess, headers } from '../api-helper'; |  | ||||||
| 
 |  | ||||||
| const URI = formatApiPath('api/admin/metrics/applications'); |  | ||||||
| 
 |  | ||||||
| function fetchAll() { |  | ||||||
|     return fetch(URI, { headers, credentials: 'include' }) |  | ||||||
|         .then(throwIfNotSuccess) |  | ||||||
|         .then(response => response.json()); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| function fetchApplication(appName) { |  | ||||||
|     return fetch(`${URI}/${appName}`, { headers, credentials: 'include' }) |  | ||||||
|         .then(throwIfNotSuccess) |  | ||||||
|         .then(response => response.json()); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| function fetchApplicationsWithStrategyName(strategyName) { |  | ||||||
|     return fetch(`${URI}?strategyName=${strategyName}`, { |  | ||||||
|         headers, |  | ||||||
|         credentials: 'include', |  | ||||||
|     }) |  | ||||||
|         .then(throwIfNotSuccess) |  | ||||||
|         .then(response => response.json()); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| function storeApplicationMetaData(appName, key, value) { |  | ||||||
|     const data = {}; |  | ||||||
|     data[key] = value; |  | ||||||
|     return fetch(`${URI}/${appName}`, { |  | ||||||
|         method: 'POST', |  | ||||||
|         headers, |  | ||||||
|         body: JSON.stringify(data), |  | ||||||
|         credentials: 'include', |  | ||||||
|     }).then(throwIfNotSuccess); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| function deleteApplication(appName) { |  | ||||||
|     return fetch(`${URI}/${appName}`, { |  | ||||||
|         method: 'DELETE', |  | ||||||
|         headers, |  | ||||||
|         credentials: 'include', |  | ||||||
|     }).then(throwIfNotSuccess); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export default { |  | ||||||
|     fetchApplication, |  | ||||||
|     fetchAll, |  | ||||||
|     fetchApplicationsWithStrategyName, |  | ||||||
|     storeApplicationMetaData, |  | ||||||
|     deleteApplication, |  | ||||||
| }; |  | ||||||
| @ -1,30 +0,0 @@ | |||||||
| import { fromJS, List, Map } from 'immutable'; |  | ||||||
| import { RECEIVE_ALL_APPLICATIONS, RECEIVE_APPLICATION, UPDATE_APPLICATION_FIELD, DELETE_APPLICATION } from './actions'; |  | ||||||
| import { USER_LOGOUT, USER_LOGIN } from '../user/actions'; |  | ||||||
| 
 |  | ||||||
| function getInitState() { |  | ||||||
|     return fromJS({ list: [], apps: {} }); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| const store = (state = getInitState(), action) => { |  | ||||||
|     switch (action.type) { |  | ||||||
|         case RECEIVE_APPLICATION: |  | ||||||
|             return state.setIn(['apps', action.value.appName], new Map(action.value)); |  | ||||||
|         case RECEIVE_ALL_APPLICATIONS: |  | ||||||
|             return state.set('list', new List(action.value.applications)); |  | ||||||
|         case UPDATE_APPLICATION_FIELD: |  | ||||||
|             return state.setIn(['apps', action.appName, action.key], action.value); |  | ||||||
|         case DELETE_APPLICATION: { |  | ||||||
|             const index = state.get('list').findIndex(item => item.appName === action.appName); |  | ||||||
|             const result = state.removeIn(['list', index]); |  | ||||||
|             return result.removeIn(['apps', action.appName]); |  | ||||||
|         } |  | ||||||
|         case USER_LOGOUT: |  | ||||||
|         case USER_LOGIN: |  | ||||||
|             return getInitState(); |  | ||||||
|         default: |  | ||||||
|             return state; |  | ||||||
|     } |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| export default store; |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user