From 471f5b51f5eb9010f88241211d213fe31054116b Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Mon, 6 May 2024 13:06:02 +0200 Subject: [PATCH] refactor: routes use named exports (#86) --- src/main/frontend/src/App.js | 16 ++----- src/main/frontend/src/router.js | 5 +++ src/main/frontend/src/routes/Host.js | 12 +++-- src/main/frontend/src/routes/List.js | 20 ++++----- .../frontend/src/routes/RoutesDetailPage.js | 44 ++++++++++--------- .../frontend/src/routes/RoutesEditPage.js | 10 ++--- src/main/frontend/src/routes/RoutesPage.js | 10 ++--- src/main/frontend/src/routes/api.js | 8 +--- src/main/frontend/src/routes/index.js | 26 +++-------- src/main/frontend/src/routes/selectors.js | 10 ++--- src/main/frontend/src/search/SearchPage.js | 4 +- 11 files changed, 69 insertions(+), 96 deletions(-) diff --git a/src/main/frontend/src/App.js b/src/main/frontend/src/App.js index 7b6ead8..4dfff9d 100644 --- a/src/main/frontend/src/App.js +++ b/src/main/frontend/src/App.js @@ -82,7 +82,7 @@ import pods from './pods'; import rc from './replicationcontrollers'; import {apiGroupsSet, setError, setOffline} from './redux'; import roles from './roles'; -import routes from './routes'; +import {RoutesPage, RoutesDetailPage, RoutesEditPage} from './routes'; import {SearchPage} from './search'; import secrets from './secrets'; import services from './services'; @@ -331,17 +331,9 @@ export const App = () => { path='/roles/:uid/edit' element={} /> - } /> - } - /> - } - /> + } /> + } /> + } /> } /> } /> props => { const params = useParams(); return ; diff --git a/src/main/frontend/src/routes/Host.js b/src/main/frontend/src/routes/Host.js index ab23c95..e18bd8b 100644 --- a/src/main/frontend/src/routes/Host.js +++ b/src/main/frontend/src/routes/Host.js @@ -15,16 +15,16 @@ * */ import React from 'react'; -import r from './'; +import {selectors} from './'; import {Icon, Link} from '../components'; -const Host = ({route}) => { +export const Host = ({route}) => { const url = `http${ - r.selectors.specTls(route) ? 's' : '' - }://${r.selectors.specHost(route)}${r.selectors.specPath(route)}`; + selectors.specTls(route) ? 's' : '' + }://${selectors.specHost(route)}${selectors.specPath(route)}`; return ( - {r.selectors.specHost(route)} + {selectors.specHost(route)} { ); }; - -export default Host; diff --git a/src/main/frontend/src/routes/List.js b/src/main/frontend/src/routes/List.js index e8f7a69..34cf701 100644 --- a/src/main/frontend/src/routes/List.js +++ b/src/main/frontend/src/routes/List.js @@ -16,7 +16,7 @@ */ import React from 'react'; import {name, namespace, sortByCreationTimeStamp, uid} from '../metadata'; -import r from './'; +import {Host, api, selectors} from './'; import {Icon, Link, Table} from '../components'; import ResourceList from '../components/ResourceList'; @@ -31,7 +31,7 @@ const headers = [ ]; const Rows = ({routes}) => { - const deleteRoute = route => () => r.api.delete(route); + const deleteRoute = route => () => api.deleteRoute(route); return routes.sort(sortByCreationTimeStamp).map(route => ( @@ -43,9 +43,9 @@ const Rows = ({routes}) => { - + - {r.selectors.specPath(route)} + {selectors.specPath(route)} @@ -53,10 +53,10 @@ const Rows = ({routes}) => { )); }; -const List = ({resources, crudDelete, loadedResources, ...properties}) => ( - - - +export const List = ResourceList.resourceListConnect('routes')( + ({resources, crudDelete, loadedResources, ...properties}) => ( + + + + ) ); - -export default ResourceList.resourceListConnect('routes')(List); diff --git a/src/main/frontend/src/routes/RoutesDetailPage.js b/src/main/frontend/src/routes/RoutesDetailPage.js index fb32713..f483ec2 100644 --- a/src/main/frontend/src/routes/RoutesDetailPage.js +++ b/src/main/frontend/src/routes/RoutesDetailPage.js @@ -18,27 +18,9 @@ import React from 'react'; import {connect} from 'react-redux'; import {withParams} from '../router'; import {Details} from '../metadata'; -import r from './'; +import {Host, api, selectors} from './'; import {Form, ResourceDetailPage} from '../components'; -const RoutesDetailPage = ({route}) => ( - -
- - - - {r.selectors.specPath(route)} - - } - /> -); - const mapStateToProps = ({routes}) => ({ routes }); @@ -50,6 +32,26 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => ({ route: stateProps.routes[ownProps.params.uid] }); -export default withParams( - connect(mapStateToProps, null, mergeProps)(RoutesDetailPage) +export const RoutesDetailPage = withParams( + connect( + mapStateToProps, + null, + mergeProps + )(({route}) => ( + +
+ + + + {selectors.specPath(route)} + + } + /> + )) ); diff --git a/src/main/frontend/src/routes/RoutesEditPage.js b/src/main/frontend/src/routes/RoutesEditPage.js index 1b89f7b..e0e5ea2 100644 --- a/src/main/frontend/src/routes/RoutesEditPage.js +++ b/src/main/frontend/src/routes/RoutesEditPage.js @@ -17,19 +17,17 @@ import React from 'react'; import {withParams} from '../router'; import {name} from '../metadata'; -import r from './'; +import {api} from './'; import {Link, ResourceEditPage} from '../components'; -const RoutesEditPage = ({params: {uid}}) => ( +export const RoutesEditPage = withParams(({params: {uid}}) => ( ( {name(resource)} )} - save={async resource => await r.api.update(resource)} + save={async resource => await api.update(resource)} resourceFromState={state => state.routes[uid]} /> -); - -export default withParams(RoutesEditPage); +)); diff --git a/src/main/frontend/src/routes/RoutesPage.js b/src/main/frontend/src/routes/RoutesPage.js index 670fe59..9283bc6 100644 --- a/src/main/frontend/src/routes/RoutesPage.js +++ b/src/main/frontend/src/routes/RoutesPage.js @@ -15,18 +15,16 @@ * */ import React from 'react'; -import r from './'; -import {DashboardPage, FilterBar} from '../components'; import {useUiNamespace} from '../redux'; +import {DashboardPage, FilterBar} from '../components'; +import {RoutesList} from './'; -const RoutesPage = () => { +export const RoutesPage = () => { const {selectedNamespace} = useUiNamespace(); return ( - + ); }; - -export default RoutesPage; diff --git a/src/main/frontend/src/routes/api.js b/src/main/frontend/src/routes/api.js index d5fbcd0..7ab2205 100644 --- a/src/main/frontend/src/routes/api.js +++ b/src/main/frontend/src/routes/api.js @@ -16,9 +16,5 @@ */ import {deleteNamespacedResource, updateNamespacedResource} from '../fetch'; -const api = { - delete: deleteNamespacedResource('routes'), - update: updateNamespacedResource('routes') -}; - -export default api; +export const deleteRoute = deleteNamespacedResource('routes'); +export const update = updateNamespacedResource('routes'); diff --git a/src/main/frontend/src/routes/index.js b/src/main/frontend/src/routes/index.js index c0536bf..09ec20a 100644 --- a/src/main/frontend/src/routes/index.js +++ b/src/main/frontend/src/routes/index.js @@ -14,22 +14,10 @@ * limitations under the License. * */ -import api from './api'; -import selectors from './selectors'; -import Host from './Host'; -import List from './List'; -import RoutesDetailPage from './RoutesDetailPage'; -import RoutesEditPage from './RoutesEditPage'; -import RoutesPage from './RoutesPage'; - -const index = { - api, - selectors, - Host, - List, - RoutesDetailPage, - RoutesEditPage, - RoutesPage -}; - -export default index; +export * as api from './api'; +export * as selectors from './selectors'; +export {Host} from './Host'; +export {List as RoutesList} from './List'; +export {RoutesDetailPage} from './RoutesDetailPage'; +export {RoutesEditPage} from './RoutesEditPage'; +export {RoutesPage} from './RoutesPage'; diff --git a/src/main/frontend/src/routes/selectors.js b/src/main/frontend/src/routes/selectors.js index 532cbcd..f7f896e 100644 --- a/src/main/frontend/src/routes/selectors.js +++ b/src/main/frontend/src/routes/selectors.js @@ -14,12 +14,8 @@ * limitations under the License. * */ -const selectors = {}; +export const specHost = route => route?.spec?.host ?? ''; -selectors.specHost = route => route?.spec?.host ?? ''; +export const specPath = route => route?.spec?.path ?? ''; -selectors.specPath = route => route?.spec?.path ?? ''; - -selectors.specTls = route => route?.spec?.tls; - -export default selectors; +export const specTls = route => route?.spec?.tls; diff --git a/src/main/frontend/src/search/SearchPage.js b/src/main/frontend/src/search/SearchPage.js index 8c81596..66b97f1 100644 --- a/src/main/frontend/src/search/SearchPage.js +++ b/src/main/frontend/src/search/SearchPage.js @@ -41,7 +41,7 @@ import {setQuery} from '../redux'; import rs from '../replicasets'; import rc from '../replicationcontrollers'; import roles from '../roles'; -import routes from '../routes'; +import {RoutesList} from '../routes'; import {Card, DashboardPage, FilterBar, Textfield} from '../components'; const Instructions = () => ( @@ -138,7 +138,7 @@ const Results = ({query, selectedNamespace}) => { nameLike={query} namespace={selectedNamespace} /> -