-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Fleet] Fail gracefully on agent count retrieval #200590
Changes from 2 commits
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 |
---|---|---|
|
@@ -25,53 +25,65 @@ const ConfirmTitle = () => ( | |
|
||
interface ConfirmDeleteDescriptionProps { | ||
downloadSource: DownloadSource; | ||
agentCount: number; | ||
agentPolicyCount: number; | ||
agentCount?: number; | ||
agentPolicyCount?: number; | ||
} | ||
|
||
const ConfirmDeleteDescription: React.FunctionComponent<ConfirmDeleteDescriptionProps> = ({ | ||
downloadSource, | ||
agentCount, | ||
agentPolicyCount, | ||
}) => ( | ||
<FormattedMessage | ||
id="xpack.fleet.settings.deleteDowloadSource.confirmModalText" | ||
defaultMessage="This action will delete {downloadSourceName} agent binary source. It will update {policies} and {agents}. This action can not be undone. Are you sure you wish to continue?" | ||
values={{ | ||
downloadSourceName: <strong>{downloadSource.name}</strong>, | ||
agents: ( | ||
<strong> | ||
<FormattedMessage | ||
id="xpack.fleet.settings.deleteDowloadSource.agentsCount" | ||
defaultMessage="{agentCount, plural, one {# agent} other {# agents}}" | ||
values={{ | ||
agentCount, | ||
}} | ||
/> | ||
</strong> | ||
), | ||
policies: ( | ||
<strong> | ||
<FormattedMessage | ||
id="xpack.fleet.settings.deleteDowloadSource.agentPolicyCount" | ||
defaultMessage="{agentPolicyCount, plural, one {# agent policy} other {# agent policies}}" | ||
values={{ | ||
agentPolicyCount, | ||
}} | ||
/> | ||
</strong> | ||
), | ||
}} | ||
/> | ||
); | ||
}) => | ||
agentCount !== undefined && agentPolicyCount !== undefined ? ( | ||
<FormattedMessage | ||
id="xpack.fleet.settings.deleteDowloadSource.confirmModalText" | ||
defaultMessage="This action will delete {downloadSourceName} agent binary source. It will update {policies} and {agents}. This action can not be undone. Are you sure you wish to continue?" | ||
values={{ | ||
downloadSourceName: <strong>{downloadSource.name}</strong>, | ||
agents: ( | ||
<strong> | ||
<FormattedMessage | ||
id="xpack.fleet.settings.deleteDowloadSource.agentsCount" | ||
defaultMessage="{agentCount, plural, one {# agent} other {# agents}}" | ||
values={{ | ||
agentCount, | ||
}} | ||
/> | ||
</strong> | ||
), | ||
policies: ( | ||
<strong> | ||
<FormattedMessage | ||
id="xpack.fleet.settings.deleteDowloadSource.agentPolicyCount" | ||
defaultMessage="{agentPolicyCount, plural, one {# agent policy} other {# agent policies}}" | ||
values={{ | ||
agentPolicyCount, | ||
}} | ||
/> | ||
</strong> | ||
), | ||
}} | ||
/> | ||
) : ( | ||
<FormattedMessage | ||
id="xpack.fleet.settings.deleteDowloadSource.confirmModalTextWithoutCount" | ||
defaultMessage="This action will delete {downloadSourceName} agent binary source. It will update related policies and agents. This action can not be undone. Are you sure you wish to continue?" | ||
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'd suggest: 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. Thanks, this sounds better I will made the change |
||
values={{ | ||
downloadSourceName: <strong>{downloadSource.name}</strong>, | ||
}} | ||
/> | ||
); | ||
|
||
export function useDeleteDownloadSource(onSuccess: () => void) { | ||
const { confirm } = useConfirmModal(); | ||
const { notifications } = useStartServices(); | ||
const deleteDownloadSource = useCallback( | ||
async (downloadSource: DownloadSource) => { | ||
try { | ||
const { agentCount, agentPolicyCount } = await getCountsForDownloadSource(downloadSource); | ||
const { agentCount, agentPolicyCount } = await getCountsForDownloadSource( | ||
downloadSource | ||
// Fail gracefully when counts are not available | ||
).catch(() => ({ agentCount: undefined, agentPolicyCount: undefined })); | ||
|
||
const isConfirmed = await confirm( | ||
<ConfirmTitle />, | ||
|
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 think that repeating the
will update
part twice sounds a bit strange here. Could we change to something like this instead?This action will update {downloadSourceName} agent binary source, its related policies and agents. This action can not be undone. Are you sure you wish to continue?