Skip to content

Commit

Permalink
Create a new selector for both types of instances
Browse files Browse the repository at this point in the history
  • Loading branch information
rtorrero committed Aug 21, 2023
1 parent 029883f commit 205711b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 33 deletions.
22 changes: 6 additions & 16 deletions assets/js/components/ClustersList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { post, del } from '@lib/network';
import { useSearchParams } from 'react-router-dom';
import HealthSummary from '@components/HealthSummary/HealthSummary';
import { getCounters } from '@components/HealthSummary/summarySelection';
import { getConcatenatedInstances } from '@state/selectors';

import { get } from 'lodash';

const getClusterTypeLabel = (type) => {
Expand All @@ -26,20 +28,8 @@ const getClusterTypeLabel = (type) => {
}
};

const getSapSystemLinkBySID = (
applicationInstances,
databaseInstances,
sid
) => {
const foundInstance = applicationInstances
.map((instance) => ({ ...instance, type: 'sap_systems' }))
.concat(
databaseInstances.map((instance) => ({
...instance,
type: 'databases',
}))
)
.find((instance) => instance.sid === sid);
const getSapSystemLinkBySID = (instances, sid) => {
const foundInstance = instances.find((instance) => instance.sid === sid);

return foundInstance;
};
Expand All @@ -59,6 +49,7 @@ function ClustersList() {
const { applicationInstances, databaseInstances } = useSelector(
(state) => state.sapSystemsList
);
const concatenatedInstances = useSelector(getConcatenatedInstances());
const dispatch = useDispatch();
const [searchParams, setSearchParams] = useSearchParams();

Expand Down Expand Up @@ -97,8 +88,7 @@ function ClustersList() {
render: (_, { sid, id }) =>
sid.map((singleSid, index) => {
const linkData = getSapSystemLinkBySID(
applicationInstances,
databaseInstances,
concatenatedInstances,
singleSid
);
return (
Expand Down
22 changes: 5 additions & 17 deletions assets/js/components/HostsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,13 @@ import Tooltip from '@components/Tooltip';
import CleanUpButton from '@components/CleanUpButton';

import { addTagToHost, removeTagFromHost, deregisterHost } from '@state/hosts';
import { getConcatenatedInstances } from '@state/selectors';

import { post, del } from '@lib/network';
import { agentVersionWarning } from '@lib/agent';

const getInstancesByHost = (applicationInstances, databaseInstances, hostId) =>
applicationInstances
.map((instance) => ({ ...instance, type: 'sap_systems' }))
.concat(
databaseInstances.map((instance) => ({
...instance,
type: 'databases',
}))
)
.filter((instance) => instance.host_id === hostId);
const getInstancesByHost = (instances, hostId) =>
instances.filter((instance) => instance.host_id === hostId);

const addTag = (tag, hostId) => {
post(`/hosts/${hostId}/tags`, {
Expand All @@ -48,8 +41,7 @@ const removeTag = (tag, hostId) => {
function HostsList() {
const hosts = useSelector((state) => state.hostsList.hosts);
const clusters = useSelector((state) => state.clustersList.clusters);
const { applicationInstances } = useSelector((state) => state.sapSystemsList);
const { databaseInstances } = useSelector((state) => state.databasesList);
const concatenatedInstances = useSelector(getConcatenatedInstances());

const [searchParams, setSearchParams] = useSearchParams();
const [cleanUpModalOpen, setCleanUpModalOpen] = useState(false);
Expand Down Expand Up @@ -212,11 +204,7 @@ function HostsList() {

const data = hosts.map((host) => {
const cluster = clusters.find((c) => c.id === host.cluster_id);
const sapSystemList = getInstancesByHost(
applicationInstances,
databaseInstances,
host.id
);
const sapSystemList = getInstancesByHost(concatenatedInstances, host.id);

return {
heartbeat: host.heartbeat,
Expand Down
13 changes: 13 additions & 0 deletions assets/js/state/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,16 @@ export const getInstancesOnHost = (hostId) => (state) => {

return [...foundApplicationInstances, ...foundDatabaseInstances];
};

export const getConcatenatedInstances = () => (state) => {
const { databaseInstances, applicationInstances } = state.sapSystemsList;

return applicationInstances
.map((instance) => ({ ...instance, type: 'sap_systems' }))
.concat(
databaseInstances.map((instance) => ({
...instance,
type: 'databases',
}))
);
};

0 comments on commit 205711b

Please sign in to comment.