-
Notifications
You must be signed in to change notification settings - Fork 15
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
Deregister hosts list frontend #1601
Changes from all commits
85ceda6
92c45dc
7be678b
3c1dd36
3614c2e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import React from 'react'; | ||
import React, { useState } from 'react'; | ||
|
||
import { useSearchParams } from 'react-router-dom'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
import { EOS_WARNING_OUTLINED } from 'eos-icons-react'; | ||
|
||
import Table from '@components/Table'; | ||
import DeregistrationModal from '@components/DeregistrationModal'; | ||
import HealthIcon from '@components/Health/HealthIcon'; | ||
import Tags from '@components/Tags'; | ||
import HostLink from '@components/HostLink'; | ||
|
@@ -16,8 +17,10 @@ import HealthSummary from '@components/HealthSummary/HealthSummary'; | |
import { getCounters } from '@components/HealthSummary/summarySelection'; | ||
import ProviderLabel from '@components/ProviderLabel'; | ||
import Tooltip from '@components/Tooltip'; | ||
import CleanUpButton from '@components/CleanUpButton'; | ||
|
||
import { addTagToHost, removeTagFromHost, deregisterHost } from '@state/hosts'; | ||
|
||
import { addTagToHost, removeTagFromHost } from '@state/hosts'; | ||
import { post, del } from '@lib/network'; | ||
import { agentVersionWarning } from '@lib/agent'; | ||
|
||
|
@@ -50,9 +53,21 @@ function HostsList() { | |
); | ||
|
||
const [searchParams, setSearchParams] = useSearchParams(); | ||
const [cleanUpModalOpen, setCleanUpModalOpen] = useState(false); | ||
const [hostToDeregister, setHostToDeregister] = useState(undefined); | ||
|
||
const dispatch = useDispatch(); | ||
|
||
const openDeregistrationModal = (host) => { | ||
setHostToDeregister(host); | ||
setCleanUpModalOpen(true); | ||
}; | ||
|
||
const cleanUpHost = (host) => { | ||
setCleanUpModalOpen(false); | ||
dispatch(deregisterHost(host)); | ||
}; | ||
|
||
const config = { | ||
pagination: true, | ||
usePadding: false, | ||
|
@@ -177,6 +192,20 @@ function HostsList() { | |
/> | ||
), | ||
}, | ||
{ | ||
title: '', | ||
key: 'deregisterable', | ||
className: 'w-48', | ||
render: (content, item) => | ||
content && ( | ||
<CleanUpButton | ||
cleaning={item.deregistering} | ||
onClick={() => { | ||
openDeregistrationModal(item); | ||
}} | ||
/> | ||
), | ||
}, | ||
], | ||
}; | ||
|
||
|
@@ -199,13 +228,25 @@ function HostsList() { | |
id: host.id, | ||
tags: (host.tags && host.tags.map((tag) => tag.value)) || [], | ||
sap_systems: sapSystemList, | ||
deregisterable: host.deregisterable, | ||
deregistering: host.deregistering, | ||
}; | ||
}); | ||
|
||
const counters = getCounters(data || []); | ||
return ( | ||
<> | ||
<PageHeader className="font-bold">Hosts</PageHeader> | ||
<DeregistrationModal | ||
hostname={hostToDeregister?.hostname} | ||
isOpen={!!cleanUpModalOpen} | ||
onCleanUp={() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we extract this to a named function in the component? |
||
cleanUpHost(hostToDeregister); | ||
}} | ||
onCancel={() => { | ||
setCleanUpModalOpen(false); | ||
}} | ||
/> | ||
<div className="bg-white rounded-lg shadow"> | ||
<HealthSummary {...counters} className="px-4 py-2" /> | ||
<Table | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,22 @@ export const hostsListSlice = createSlice({ | |
return host; | ||
}); | ||
}, | ||
setHostDeregistering: (state, action) => { | ||
state.hosts = state.hosts.map((host) => { | ||
if (host.id === action.payload.id) { | ||
return { ...host, deregistering: true }; | ||
} | ||
return host; | ||
}); | ||
}, | ||
setHostNotDeregistering: (state, action) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a doubt about naming. I would have thought of something that talks about starting a deregistration and completing a deregistration. |
||
state.hosts = state.hosts.map((host) => { | ||
if (host.id === action.payload.id) { | ||
return { ...host, deregistering: false }; | ||
} | ||
return host; | ||
}); | ||
}, | ||
startHostsLoading: (state) => { | ||
state.loading = true; | ||
}, | ||
|
@@ -95,13 +111,15 @@ export const CHECK_HOST_IS_DEREGISTERABLE = 'CHECK_HOST_IS_DEREGISTERABLE'; | |
export const CANCEL_CHECK_HOST_IS_DEREGISTERABLE = | ||
'CANCEL_CHECK_HOST_IS_DEREGISTERABLE'; | ||
export const HOST_DEREGISTERED = 'HOST_DEREGISTERED'; | ||
export const DEREGISTER_HOST = 'DEREGISTER_HOST'; | ||
|
||
export const checkHostIsDeregisterable = createAction( | ||
CHECK_HOST_IS_DEREGISTERABLE | ||
); | ||
export const cancelCheckHostIsDeregisterable = createAction( | ||
CANCEL_CHECK_HOST_IS_DEREGISTERABLE | ||
); | ||
export const deregisterHost = createAction(DEREGISTER_HOST); | ||
|
||
export const { | ||
setHosts, | ||
|
@@ -113,6 +131,8 @@ export const { | |
setHeartbeatCritical, | ||
setHostListDeregisterable, | ||
setHostNotDeregisterable, | ||
setHostDeregistering, | ||
setHostNotDeregistering, | ||
startHostsLoading, | ||
stopHostsLoading, | ||
removeHost, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we extract this to a named function in the component?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a big fan of creating functions for such trivial things (2 lines in fact), as it forces the user to scroll up and down in the code, to find out such a simple thing.
Anyway, for the sake of a request and thumbs up, i will apply the change hehe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CDimonaco This is how it looks like now: 3614c2e
Personally, I find it uglier (specially, because the functions are still inside the component). What do you think?