From ef8e3dcbfaa0271c25a4d4bc6339829a70baee6d Mon Sep 17 00:00:00 2001 From: Youssef Date: Thu, 10 Feb 2022 10:36:53 +0100 Subject: [PATCH] refactor: use explicit export and delete unused files --- .../ApplicationEdit/ApplicationEdit.tsx | 12 ++-- .../ApplicationList/ApplicationList.tsx | 8 +-- .../ApplicationUpdate/ApplicationUpdate.tsx | 4 +- .../ApplicationView/ApplicationView.tsx | 43 +++++++------- frontend/src/component/menu/routes.js | 5 +- frontend/src/page/applications/index.js | 6 -- frontend/src/page/applications/view.js | 12 ---- frontend/src/store/application/actions.js | 58 ------------------- frontend/src/store/application/api.js | 52 ----------------- frontend/src/store/application/index.js | 30 ---------- 10 files changed, 33 insertions(+), 197 deletions(-) delete mode 100644 frontend/src/page/applications/index.js delete mode 100644 frontend/src/page/applications/view.js delete mode 100644 frontend/src/store/application/actions.js delete mode 100644 frontend/src/store/application/api.js delete mode 100644 frontend/src/store/application/index.js diff --git a/frontend/src/component/application/ApplicationEdit/ApplicationEdit.tsx b/frontend/src/component/application/ApplicationEdit/ApplicationEdit.tsx index f272533c19..4a8d6e0a04 100644 --- a/frontend/src/component/application/ApplicationEdit/ApplicationEdit.tsx +++ b/frontend/src/component/application/ApplicationEdit/ApplicationEdit.tsx @@ -12,8 +12,8 @@ import { Link as LinkIcon } from '@material-ui/icons'; import ConditionallyRender from '../../common/ConditionallyRender/ConditionallyRender'; import { formatDateWithLocale } from '../../common/util'; import { UPDATE_APPLICATION } from '../../providers/AccessProvider/permissions'; -import ApplicationView from '../ApplicationView/ApplicationView'; -import ApplicationUpdate from '../ApplicationUpdate/ApplicationUpdate'; +import { ApplicationView } from '../ApplicationView/ApplicationView'; +import { ApplicationUpdate } from '../ApplicationUpdate/ApplicationUpdate'; import TabNav from '../../common/TabNav/TabNav'; import Dialogue from '../../common/Dialogue'; import PageContent from '../../common/PageContent'; @@ -26,7 +26,7 @@ import { useLocationSettings } from '../../../hooks/useLocationSettings'; import useToast from '../../../hooks/useToast'; import PermissionButton from '../../common/PermissionButton/PermissionButton'; -const ApplicationEdit = () => { +export const ApplicationEdit = () => { const history = useHistory(); const { name } = useParams<{ name: string }>(); const { application, loading } = useApplication(name); @@ -42,7 +42,7 @@ const ApplicationEdit = () => { setShowDialog(!showDialog); }; - const formatDate = (v: Date) => + const formatDate = (v: string) => formatDateWithLocale(v, locationSettings.locale); const onDeleteApplication = async (evt: Event) => { @@ -109,7 +109,7 @@ const ApplicationEdit = () => { actions={ <> @@ -147,5 +147,3 @@ const ApplicationEdit = () => { ); }; - -export default ApplicationEdit; diff --git a/frontend/src/component/application/ApplicationList/ApplicationList.tsx b/frontend/src/component/application/ApplicationList/ApplicationList.tsx index ae13460aa4..a7eae9f593 100644 --- a/frontend/src/component/application/ApplicationList/ApplicationList.tsx +++ b/frontend/src/component/application/ApplicationList/ApplicationList.tsx @@ -9,7 +9,7 @@ import HeaderTitle from '../../common/HeaderTitle'; import useApplications from '../../../hooks/api/getters/useApplications/useApplications'; import ConditionallyRender from '../../common/ConditionallyRender'; -const ApplicationList = () => { +export const ApplicationList = () => { const { applications, loading } = useApplications(); const [filter, setFilter] = useState(''); @@ -20,7 +20,7 @@ const ApplicationList = () => { : applications; }, [applications, filter]); - const RenderNoApplications = () => ( + const renderNoApplications = () => ( <>

@@ -57,7 +57,7 @@ const ApplicationList = () => { ...loading} - elseShow={} + elseShow={renderNoApplications()} /> } /> @@ -66,5 +66,3 @@ const ApplicationList = () => { ); }; - -export default ApplicationList; diff --git a/frontend/src/component/application/ApplicationUpdate/ApplicationUpdate.tsx b/frontend/src/component/application/ApplicationUpdate/ApplicationUpdate.tsx index ac8dc84115..a899851400 100644 --- a/frontend/src/component/application/ApplicationUpdate/ApplicationUpdate.tsx +++ b/frontend/src/component/application/ApplicationUpdate/ApplicationUpdate.tsx @@ -12,7 +12,7 @@ interface IApplicationUpdateProps { application: IApplication; } -const ApplicationUpdate = ({ application }: IApplicationUpdateProps) => { +export const ApplicationUpdate = ({ application }: IApplicationUpdateProps) => { const { storeApplicationMetaData } = useApplicationsApi(); const { appName, icon, url, description } = application; const [localUrl, setLocalUrl] = useState(url || ''); @@ -83,5 +83,3 @@ const ApplicationUpdate = ({ application }: IApplicationUpdateProps) => { ); }; - -export default ApplicationUpdate; diff --git a/frontend/src/component/application/ApplicationView/ApplicationView.tsx b/frontend/src/component/application/ApplicationView/ApplicationView.tsx index 5ba8b86838..5dbeb736ae 100644 --- a/frontend/src/component/application/ApplicationView/ApplicationView.tsx +++ b/frontend/src/component/application/ApplicationView/ApplicationView.tsx @@ -25,7 +25,8 @@ import { getTogglePath } from '../../../utils/route-path-helpers'; import useApplication from '../../../hooks/api/getters/useApplication/useApplication'; import AccessContext from '../../../contexts/AccessContext'; import { formatFullDateTimeWithLocale } from '../../common/util'; -const ApplicationView = () => { + +export const ApplicationView = () => { const { hasAccess } = useContext(AccessContext); const { name } = useParams<{ name: string }>(); const { application } = useApplication(name); @@ -129,24 +130,26 @@ const ApplicationView = () => {
- {strategies.map(({ name, description, notFound }, i: number) => ( - - ))} + {strategies.map( + ({ name, description, notFound }, i: number) => ( + + ) + )} @@ -203,5 +206,3 @@ const ApplicationView = () => { ); }; - -export default ApplicationView; diff --git a/frontend/src/component/menu/routes.js b/frontend/src/component/menu/routes.js index daab1f5d7f..b0724648e5 100644 --- a/frontend/src/component/menu/routes.js +++ b/frontend/src/component/menu/routes.js @@ -41,12 +41,11 @@ import EditProject from '../project/Project/EditProject/EditProject'; import CreateProject from '../project/Project/CreateProject/CreateProject'; import CreateFeature from '../feature/CreateFeature/CreateFeature'; import EditFeature from '../feature/EditFeature/EditFeature'; -import ApplicationEdit from '../application/ApplicationEdit/ApplicationEdit'; -import ApplicationList from '../application/ApplicationList/ApplicationList'; +import { ApplicationEdit } from '../application/ApplicationEdit/ApplicationEdit'; +import { ApplicationList } from '../application/ApplicationList/ApplicationList'; import ContextList from '../context/ContextList/ContextList'; import RedirectFeatureView from '../feature/RedirectFeatureView/RedirectFeatureView'; - export const routes = [ // Project diff --git a/frontend/src/page/applications/index.js b/frontend/src/page/applications/index.js deleted file mode 100644 index 2d5b6874a7..0000000000 --- a/frontend/src/page/applications/index.js +++ /dev/null @@ -1,6 +0,0 @@ -import React from 'react'; -import ApplicationListConmponent from '../../component/application/application-list-container'; - -const render = () => ; - -export default render; diff --git a/frontend/src/page/applications/view.js b/frontend/src/page/applications/view.js deleted file mode 100644 index 95d163ca64..0000000000 --- a/frontend/src/page/applications/view.js +++ /dev/null @@ -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 }) => ; - -render.propTypes = { - match: PropTypes.object.isRequired, - history: PropTypes.object.isRequired, -}; - -export default render; diff --git a/frontend/src/store/application/actions.js b/frontend/src/store/application/actions.js deleted file mode 100644 index 0a2b62423b..0000000000 --- a/frontend/src/store/application/actions.js +++ /dev/null @@ -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)); -} diff --git a/frontend/src/store/application/api.js b/frontend/src/store/application/api.js deleted file mode 100644 index 5a941d27f4..0000000000 --- a/frontend/src/store/application/api.js +++ /dev/null @@ -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, -}; diff --git a/frontend/src/store/application/index.js b/frontend/src/store/application/index.js deleted file mode 100644 index 06da890586..0000000000 --- a/frontend/src/store/application/index.js +++ /dev/null @@ -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;