Skip to content

Commit

Permalink
refactor: horizontal pod autoscalers use named exports (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
manusa authored May 1, 2024
1 parent a6c816f commit 5d26da2
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 102 deletions.
12 changes: 8 additions & 4 deletions src/main/frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ import {
DeploymentsDetailPage
} from './deployments';
import * as ep from './endpoints';
import hpa from './horizontalpodautoscalers';
import {
HorizontalPodAutoscalersPage,
HorizontalPodAutoscalersDetailPage,
HorizontalPodAutoscalersEditPage
} from './horizontalpodautoscalers';
import * as ingresses from './ingresses';
import {JobsPage, JobsEditPage, JobsDetailPage} from './jobs';
import nodes from './nodes';
Expand Down Expand Up @@ -208,17 +212,17 @@ const App = ({dispatch}) => {
<Route
exact
path='/horizontalpodautoscalers'
element={<hpa.HorizontalPodAutoscalersPage />}
element={<HorizontalPodAutoscalersPage />}
/>
<Route
exact
path='/horizontalpodautoscalers/:uid'
element={<hpa.HorizontalPodAutoscalersDetailPage />}
element={<HorizontalPodAutoscalersDetailPage />}
/>
<Route
exact
path='/horizontalpodautoscalers/:uid/edit'
element={<hpa.HorizontalPodAutoscalersEditPage />}
element={<HorizontalPodAutoscalersEditPage />}
/>
<Route exact path='/ingresses' element={<ingresses.IngressesPage />} />
<Route
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,10 @@ import React from 'react';
import {connect} from 'react-redux';
import {withParams} from '../router';
import metadata from '../metadata';
import hpa from './';
import {api, selectors} from './';
import {Form} from '../components';
import ResourceDetailPage from '../components/ResourceDetailPage';

const HorizontalPodAutoscalersDetailPage = ({horizontalPodAutoscaler}) => (
<ResourceDetailPage
kind='HorizontalPodAutoscalers'
path='horizontalpodautoscalers'
resource={horizontalPodAutoscaler}
isReadyFunction={hpa.selectors.isReady}
deleteFunction={hpa.api.delete}
body={
<Form>
<metadata.Details resource={horizontalPodAutoscaler} />
<Form.Field label='Scale Target'>
{hpa.selectors.scaleTargetRefName(horizontalPodAutoscaler)}
</Form.Field>
</Form>
}
/>
);

const mapStateToProps = ({horizontalPodAutoscalers}) => ({
horizontalPodAutoscalers
});
Expand All @@ -52,6 +34,26 @@ const mergeProps = (
horizontalPodAutoscaler: horizontalPodAutoscalers[uid]
});

export default withParams(
connect(mapStateToProps, null, mergeProps)(HorizontalPodAutoscalersDetailPage)
export const HorizontalPodAutoscalersDetailPage = withParams(
connect(
mapStateToProps,
null,
mergeProps
)(({horizontalPodAutoscaler}) => (
<ResourceDetailPage
kind='HorizontalPodAutoscalers'
path='horizontalpodautoscalers'
resource={horizontalPodAutoscaler}
isReadyFunction={selectors.isReady}
deleteFunction={api.deleteHpa}
body={
<Form>
<metadata.Details resource={horizontalPodAutoscaler} />
<Form.Field label='Scale Target'>
{selectors.scaleTargetRefName(horizontalPodAutoscaler)}
</Form.Field>
</Form>
}
/>
))
);
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
import React from 'react';
import {withParams} from '../router';
import md from '../metadata';
import hpa from './';
import {api} from './';
import ResourceEditPage from '../components/ResourceEditPage';
import Link from '../components/Link';

const HorizontalPodAutoscalersEditPage = ({params: {uid}}) => (
<ResourceEditPage
kind='HorizontalPodAutoscalers'
h
path='horizontalpodautoscalers'
cardTitle={resource => (
<Link.RouterLink to={`/horizontalpodautoscalers/${uid}`}>
{md.selectors.name(resource)}
</Link.RouterLink>
)}
save={async resource => await hpa.api.update(resource)}
resourceFromState={state => state.horizontalPodAutoscalers[uid]}
/>
export const HorizontalPodAutoscalersEditPage = withParams(
({params: {uid}}) => (
<ResourceEditPage
kind='HorizontalPodAutoscalers'
h
path='horizontalpodautoscalers'
cardTitle={resource => (
<Link.RouterLink to={`/horizontalpodautoscalers/${uid}`}>
{md.selectors.name(resource)}
</Link.RouterLink>
)}
save={async resource => await api.update(resource)}
resourceFromState={state => state.horizontalPodAutoscalers[uid]}
/>
)
);

export default withParams(HorizontalPodAutoscalersEditPage);
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@
*/
import React from 'react';
import {connect} from 'react-redux';
import hpa from './';
import {HorizontalPodAutoscalersList} from './';
import {FilterBar} from '../components';
import DashboardPage from '../components/DashboardPage';

const HorizontalPodAutoscalersPage = ({selectedNamespace}) => (
<DashboardPage title='HorizontalPodAutoscalers'>
<FilterBar />
<hpa.List className='mt-4' namespace={selectedNamespace} />
</DashboardPage>
);

const mapStateToProps = ({ui: {selectedNamespace}}) => ({
selectedNamespace
});

export default connect(mapStateToProps)(HorizontalPodAutoscalersPage);
export const HorizontalPodAutoscalersPage = connect(mapStateToProps)(
({selectedNamespace}) => (
<DashboardPage title='HorizontalPodAutoscalers'>
<FilterBar />
<HorizontalPodAutoscalersList
className='mt-4'
namespace={selectedNamespace}
/>
</DashboardPage>
)
);
20 changes: 9 additions & 11 deletions src/main/frontend/src/horizontalpodautoscalers/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
*/
import React from 'react';
import metadata from '../metadata';
import hpa from './';
import Icon from '../components/Icon';
import Link from '../components/Link';
import ResourceList from '../components/ResourceList';
import Table from '../components/Table';
import {api, selectors} from './';

const headers = [
'',
Expand All @@ -34,7 +34,7 @@ const headers = [

const Rows = ({horizontalPodAutoscalers}) => {
const deleteAction = horizontalPodAutoscaler => () =>
hpa.api.delete(horizontalPodAutoscaler);
api.deleteHpa(horizontalPodAutoscaler);
return horizontalPodAutoscalers
.sort(metadata.selectors.sortByCreationTimeStamp)
.map(horizontalPodAutoscaler => (
Expand All @@ -45,12 +45,12 @@ const Rows = ({horizontalPodAutoscalers}) => {
<Table.Cell className='whitespace-nowrap w-3 text-center'>
<Icon
className={
hpa.selectors.isReady(horizontalPodAutoscaler)
selectors.isReady(horizontalPodAutoscaler)
? 'text-green-500'
: 'text-red-500'
}
icon={
hpa.selectors.isReady(horizontalPodAutoscaler)
selectors.isReady(horizontalPodAutoscaler)
? 'fa-check'
: 'fa-exclamation-circle'
}
Expand All @@ -75,7 +75,7 @@ const Rows = ({horizontalPodAutoscalers}) => {
</Link.Namespace>
</Table.Cell>
<Table.Cell>
{hpa.selectors.scaleTargetRefName(horizontalPodAutoscaler)}
{selectors.scaleTargetRefName(horizontalPodAutoscaler)}
</Table.Cell>
<Table.Cell className='whitespace-nowrap text-center'>
<Table.DeleteButton onClick={deleteAction(horizontalPodAutoscaler)} />
Expand All @@ -84,15 +84,13 @@ const Rows = ({horizontalPodAutoscalers}) => {
));
};

const List = ({resources, crudDelete, loadedResources, ...properties}) => (
export const List = ResourceList.resourceListConnect(
'horizontalPodAutoscalers'
)(({resources, crudDelete, loadedResources, ...properties}) => (
<ResourceList headers={headers} resources={resources} {...properties}>
<Rows
horizontalPodAutoscalers={resources}
loadedResources={loadedResources}
/>
</ResourceList>
);

export default ResourceList.resourceListConnect('horizontalPodAutoscalers')(
List
);
));
8 changes: 2 additions & 6 deletions src/main/frontend/src/horizontalpodautoscalers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,5 @@
*/
import {deleteNamespacedResource, updateNamespacedResource} from '../fetch';

const api = {
delete: deleteNamespacedResource('horizontalpodautoscalers'),
update: updateNamespacedResource('horizontalpodautoscalers')
};

export default api;
export const deleteHpa = deleteNamespacedResource('horizontalpodautoscalers');
export const update = updateNamespacedResource('horizontalpodautoscalers');
26 changes: 7 additions & 19 deletions src/main/frontend/src/horizontalpodautoscalers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,10 @@
* limitations under the License.
*
*/
import api from './api';
import reducer from './reducer';
import selectors from './selectors';
import List from './List';
import HorizontalPodAutoscalersDetailPage from './HorizontalPodAutoscalersDetailPage';
import HorizontalPodAutoscalersEditPage from './HorizontalPodAutoscalersEditPage';
import HorizontalPodAutoscalersPage from './HorizontalPodAutoscalersPage';

const index = {
api,
reducer,
selectors,
HorizontalPodAutoscalersDetailPage,
HorizontalPodAutoscalersEditPage,
HorizontalPodAutoscalersPage,
List
};

export default index;
export * as api from './api';
export {reducer} from './reducer';
export * as selectors from './selectors';
export {List as HorizontalPodAutoscalersList} from './List';
export {HorizontalPodAutoscalersDetailPage} from './HorizontalPodAutoscalersDetailPage';
export {HorizontalPodAutoscalersEditPage} from './HorizontalPodAutoscalersEditPage';
export {HorizontalPodAutoscalersPage} from './HorizontalPodAutoscalersPage';
4 changes: 1 addition & 3 deletions src/main/frontend/src/horizontalpodautoscalers/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@
*/
import redux from '../redux';

const reducer = redux.reducer('HorizontalPodAutoscaler');

export default reducer;
export const reducer = redux.reducer('HorizontalPodAutoscaler');
16 changes: 6 additions & 10 deletions src/main/frontend/src/horizontalpodautoscalers/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@
* limitations under the License.
*
*/
const selectors = {};
export const statusDesiredReplicas = hpa => hpa?.status?.desiredReplicas ?? 0;
export const statusCurrentReplicas = hpa => hpa?.status?.currentReplicas ?? 0;

selectors.statusDesiredReplicas = hpa => hpa?.status?.desiredReplicas ?? 0;
selectors.statusCurrentReplicas = hpa => hpa?.status?.currentReplicas ?? 0;
export const isReady = hpa =>
statusDesiredReplicas(hpa) === statusCurrentReplicas(hpa);

selectors.isReady = hpa =>
selectors.statusDesiredReplicas(hpa) === selectors.statusCurrentReplicas(hpa);

selectors.scaleTargetRef = hpa => hpa?.spec?.scaleTargetRef ?? {};
selectors.scaleTargetRefName = hpa => selectors.scaleTargetRef(hpa)?.name ?? '';

export default selectors;
export const scaleTargetRef = hpa => hpa?.spec?.scaleTargetRef ?? {};
export const scaleTargetRefName = hpa => scaleTargetRef(hpa)?.name ?? '';
2 changes: 1 addition & 1 deletion src/main/frontend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import dc from './deploymentconfigs';
import * as deployments from './deployments';
import * as ep from './endpoints';
import * as events from './events';
import hpa from './horizontalpodautoscalers';
import * as hpa from './horizontalpodautoscalers';
import * as ing from './ingresses';
import * as job from './jobs';
import ns from './namespaces';
Expand Down
4 changes: 2 additions & 2 deletions src/main/frontend/src/search/SearchPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {DeploymentsList} from '../deployments';
import dc from '../deploymentconfigs';
import * as ds from '../daemonsets';
import * as ep from '../endpoints';
import hpa from '../horizontalpodautoscalers';
import {HorizontalPodAutoscalersList} from '../horizontalpodautoscalers';
import {IngressesList} from '../ingresses';
import {JobsList} from '../jobs';
import ns from '../namespaces';
Expand Down Expand Up @@ -116,7 +116,7 @@ const Results = ({query, selectedNamespace}) => {
nameLike={query}
namespace={selectedNamespace}
/>
<hpa.List
<HorizontalPodAutoscalersList
{...commonProps}
title='HorizontalPodAutoscalers'
nameLike={query}
Expand Down

0 comments on commit 5d26da2

Please sign in to comment.