1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

refactor: use explicit export and delete unused files

This commit is contained in:
Youssef 2022-02-10 10:36:53 +01:00
parent 3fb8a4f5f3
commit ef8e3dcbfa
10 changed files with 33 additions and 197 deletions

View File

@ -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={
<>
<ConditionallyRender
condition={url}
condition={Boolean(url)}
show={
<IconButton component={Link} href={url}>
<LinkIcon />
@ -147,5 +147,3 @@ const ApplicationEdit = () => {
</PageContent>
);
};
export default ApplicationEdit;

View File

@ -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 = () => (
<>
<section style={{ textAlign: 'center' }}>
<Warning /> <br />
@ -57,7 +57,7 @@ const ApplicationList = () => {
<ConditionallyRender
condition={loading}
show={<div>...loading</div>}
elseShow={<RenderNoApplications />}
elseShow={renderNoApplications()}
/>
}
/>
@ -66,5 +66,3 @@ const ApplicationList = () => {
</>
);
};
export default ApplicationList;

View File

@ -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) => {
</Grid>
);
};
export default ApplicationUpdate;

View File

@ -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 = () => {
</Typography>
<hr />
<List>
{strategies.map(({ name, description, notFound }, i: number) => (
<ConditionallyRender
key={`strategies_conditional_${name}`}
condition={notFound}
show={notFoundListItem({
createUrl: '/strategies/create',
name,
permission: CREATE_STRATEGY,
})}
elseShow={foundListItem({
viewUrl: '/strategies/view',
name,
Icon: Extension,
description,
i,
})}
/>
))}
{strategies.map(
({ name, description, notFound }, i: number) => (
<ConditionallyRender
key={`strategies_conditional_${name}`}
condition={notFound}
show={notFoundListItem({
createUrl: '/strategies/create',
name,
permission: CREATE_STRATEGY,
})}
elseShow={foundListItem({
viewUrl: '/strategies/view',
name,
Icon: Extension,
description,
i,
})}
/>
)
)}
</List>
</Grid>
<Grid item xl={12} md={12}>
@ -203,5 +206,3 @@ const ApplicationView = () => {
</Grid>
);
};
export default ApplicationView;

View File

@ -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

View File

@ -1,6 +0,0 @@
import React from 'react';
import ApplicationListConmponent from '../../component/application/application-list-container';
const render = () => <ApplicationListConmponent />;
export default render;

View File

@ -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;

View File

@ -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));
}

View File

@ -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,
};

View File

@ -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;