Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: all resources (except CustomResource) use ResourceListV2 #99

Merged
merged 3 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/frontend/src/components/ResourceListV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ export const ResourceListV2 = ({
ResourceListV2.propTypes = {
resources: PropTypes.arrayOf(PropTypes.object).isRequired,
children: PropTypes.node.isRequired,
title: PropTypes.string
title: PropTypes.string,
loading: PropTypes.bool
};
20 changes: 12 additions & 8 deletions src/main/frontend/src/configmaps/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
import React from 'react';
import {name, namespace, sortByCreationTimeStamp, uid} from '../metadata';
import {useFilteredResources} from '../redux';
import {Icon, Link, ResourceListV2, Table} from '../components';
import {api} from './';
import {Icon, Link, Table} from '../components';
import ResourceList from '../components/ResourceList';

const headers = [
<span>
Expand Down Expand Up @@ -50,10 +50,14 @@ const Rows = ({configMaps}) => {
));
};

export const List = ResourceList.resourceListConnect('configMaps')(
({resources, loadedResources, crudDelete, ...properties}) => (
<ResourceList headers={headers} resources={resources} {...properties}>
export const List = ({...properties}) => {
const resources = useFilteredResources({
resource: 'configMaps',
filters: {...properties}
});
return (
<ResourceListV2 headers={headers} resources={resources} {...properties}>
<Rows configMaps={resources} />
</ResourceList>
)
);
</ResourceListV2>
);
};
22 changes: 13 additions & 9 deletions src/main/frontend/src/cronjobs/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
import React from 'react';
import {name, namespace, sortByCreationTimeStamp, uid} from '../metadata';
import {useFilteredResources} from '../redux';
import {Icon, Link, ResourceListV2, Table} from '../components';
import {api, selectors} from './';
import {Icon, Link, Table} from '../components';
import ResourceList from '../components/ResourceList';

const headers = [
'',
Expand Down Expand Up @@ -66,10 +66,14 @@ const Rows = ({cronJobs}) => {
));
};

export const List = ResourceList.resourceListConnect('cronJobs')(
({resources, crudDelete, loadedResources, ...properties}) => (
<ResourceList headers={headers} resources={resources} {...properties}>
<Rows cronJobs={resources} loadedResources={loadedResources} />
</ResourceList>
)
);
export const List = ({...properties}) => {
const resources = useFilteredResources({
resource: 'cronJobs',
filters: {...properties}
});
return (
<ResourceListV2 headers={headers} resources={resources} {...properties}>
<Rows cronJobs={resources} />
</ResourceListV2>
);
};
45 changes: 16 additions & 29 deletions src/main/frontend/src/customresourcedefinitions/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
*
*/
import React from 'react';
import {connect} from 'react-redux';
import {name, sortByCreationTimeStamp, uid} from '../metadata';
import {useFilteredResources} from '../redux';
import {Icon, Link, ResourceListV2, Table} from '../components';
import {api, selectors, GroupLink} from './';
import {Icon, Link, Table} from '../components';
import ResourceList from '../components/ResourceList';

const headers = [
<span>
Expand Down Expand Up @@ -68,29 +67,17 @@ const Rows = ({customResourceDefinitions}) => {
));
};

const mapStateToProps = ({customResourceDefinitions}) => ({
customResourceDefinitions
});

const mergeProps = (stateProps, dispatchProps, ownProps) => ({
...stateProps,
...dispatchProps,
...ownProps,
customResourceDefinitions: Object.values(
selectors.crdsBy(stateProps.customResourceDefinitions, ownProps)
)
});

export const List = connect(
mapStateToProps,
null,
mergeProps
)(({customResourceDefinitions, group, ...properties}) => (
<ResourceList
headers={headers}
resources={customResourceDefinitions}
{...properties}
>
<Rows customResourceDefinitions={customResourceDefinitions} />
</ResourceList>
));
export const List = ({...properties}) => {
const filteredResources = useFilteredResources({
resource: 'customResourceDefinitions',
filters: {...properties}
});
const resources = Object.values(
selectors.crdsBy(filteredResources, properties)
);
return (
<ResourceListV2 headers={headers} resources={resources} {...properties}>
<Rows customResourceDefinitions={resources} />
</ResourceListV2>
);
};
22 changes: 13 additions & 9 deletions src/main/frontend/src/daemonsets/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
import React from 'react';
import {name, namespace, sortByCreationTimeStamp, uid} from '../metadata';
import {useFilteredResources} from '../redux';
import {Icon, Link, ResourceListV2, Table} from '../components';
import {api, selectors} from './';
import {Icon, Link, Table} from '../components';
import ResourceList from '../components/ResourceList';

const headers = [
'',
Expand Down Expand Up @@ -76,10 +76,14 @@ const Rows = ({daemonSets}) => {
));
};

export const List = ResourceList.resourceListConnect('daemonSets')(
({resources, crudDelete, loadedResources, ...properties}) => (
<ResourceList headers={headers} resources={resources} {...properties}>
<Rows daemonSets={resources} loadedResources={loadedResources} />
</ResourceList>
)
);
export const List = ({...properties}) => {
const resources = useFilteredResources({
resource: 'daemonSets',
filters: {...properties}
});
return (
<ResourceListV2 headers={headers} resources={resources} {...properties}>
<Rows daemonSets={resources} />
</ResourceListV2>
);
};
39 changes: 13 additions & 26 deletions src/main/frontend/src/deploymentconfigs/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
*
*/
import React from 'react';
import {connect} from 'react-redux';
import {name, namespace, sortByCreationTimeStamp, uid} from '../metadata';
import {useFilteredResources} from '../redux';
import {Icon, Link, ResourceListV2, Table} from '../components';
import {api, selectors} from './';
import {resourcesBy} from '../redux';
import {Icon, Link, Table} from '../components';
import ResourceList from '../components/ResourceList';

const headers = [
'',
Expand Down Expand Up @@ -92,25 +90,14 @@ const Rows = ({deploymentConfigs}) => {
));
};

const mapStateToProps = ({deploymentConfigs}) => ({
deploymentConfigs
});

const mergeProps = (stateProps, dispatchProps, ownProps) => ({
...stateProps,
...dispatchProps,
...ownProps,
deploymentConfigs: Object.values(
resourcesBy(stateProps.deploymentConfigs, ownProps)
)
});

export const List = connect(
mapStateToProps,
null,
mergeProps
)(({deploymentConfigs, ...properties}) => (
<ResourceList headers={headers} resources={deploymentConfigs} {...properties}>
<Rows deploymentConfigs={deploymentConfigs} />
</ResourceList>
));
export const List = ({...properties}) => {
const resources = useFilteredResources({
resource: 'deploymentConfigs',
filters: {...properties}
});
return (
<ResourceListV2 headers={headers} resources={resources} {...properties}>
<Rows deploymentConfigs={resources} />
</ResourceListV2>
);
};
37 changes: 13 additions & 24 deletions src/main/frontend/src/deployments/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
*
*/
import React from 'react';
import {connect} from 'react-redux';
import {name, namespace, sortByCreationTimeStamp, uid} from '../metadata';
import {useFilteredResources} from '../redux';
import {Icon, Link, ResourceListV2, Table} from '../components';
import {api, selectors} from './';
import {resourcesBy} from '../redux';
import {Icon, Link, Table} from '../components';
import ResourceList from '../components/ResourceList';

const headers = [
'',
Expand Down Expand Up @@ -83,23 +81,14 @@ const Rows = ({deployments}) => {
));
};

const mapStateToProps = ({deployments}) => ({
deployments
});

const mergeProps = (stateProps, dispatchProps, ownProps) => ({
...stateProps,
...dispatchProps,
...ownProps,
deployments: Object.values(resourcesBy(stateProps.deployments, ownProps))
});

export const List = connect(
mapStateToProps,
null,
mergeProps
)(({deployments, ...properties}) => (
<ResourceList headers={headers} resources={deployments} {...properties}>
<Rows deployments={deployments} />
</ResourceList>
));
export const List = ({...properties}) => {
const resources = useFilteredResources({
resource: 'deployments',
filters: {...properties}
});
return (
<ResourceListV2 headers={headers} resources={resources} {...properties}>
<Rows deployments={resources} />
</ResourceListV2>
);
};
22 changes: 13 additions & 9 deletions src/main/frontend/src/endpoints/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
*
*/
import React from 'react';
import {api, selectors} from './';
import {
creationTimestamp,
name,
namespace,
sortByCreationTimeStamp,
uid
} from '../metadata';
import {Age, Icon, Link, Table} from '../components';
import ResourceList from '../components/ResourceList';
import {useFilteredResources} from '../redux';
import {Age, Icon, Link, ResourceListV2, Table} from '../components';
import {api, selectors} from './';

const headers = [
<span>
Expand Down Expand Up @@ -62,10 +62,14 @@ const Rows = ({endpoints}) => {
));
};

export const List = ResourceList.resourceListConnect('endpoints')(
({resources, loadedResources, crudDelete, ...properties}) => (
<ResourceList headers={headers} resources={resources} {...properties}>
export const List = ({...properties}) => {
const resources = useFilteredResources({
resource: 'endpoints',
filters: {...properties}
});
return (
<ResourceListV2 headers={headers} resources={resources} {...properties}>
<Rows endpoints={resources} />
</ResourceList>
)
);
</ResourceListV2>
);
};
47 changes: 19 additions & 28 deletions src/main/frontend/src/events/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
*
*/
import React from 'react';
import {connect} from 'react-redux';
import {uid} from '../metadata';
import {useFilteredResources} from '../redux';
import {Age, Icon, Link, ResourceListV2, Table} from '../components';
import {selectors} from './';
import {Age, Icon, Link, Table} from '../components';
import ResourceList from '../components/ResourceList';

const headers = [
'',
Expand Down Expand Up @@ -147,28 +146,20 @@ const filterEvents = (events = [], {namespace} = undefined) =>
return acc;
}, {});

const mapStateToProps = ({events}) => ({
events
});

const mergeProps = (stateProps, dispatchProps, ownProps) => ({
...stateProps,
...dispatchProps,
...ownProps,
events: Object.values(filterEvents(stateProps.events, ownProps))
});

export const List = connect(
mapStateToProps,
null,
mergeProps
)(({events, ...properties}) => (
<ResourceList
title='Latest Events'
headers={headers}
resources={events}
{...properties}
>
<Rows events={events} />
</ResourceList>
));
export const List = ({...properties}) => {
const filteredResources = useFilteredResources({
resource: 'events',
filters: {...properties}
});
const resources = Object.values(filterEvents(filteredResources, properties));
return (
<ResourceListV2
title='Latest Events'
headers={headers}
resources={resources}
{...properties}
>
<Rows events={resources} />
</ResourceListV2>
);
};
Loading