Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,68 @@ import { getCountsForDownloadSource } from './services/get_count';

interface ConfirmDescriptionProps {
downloadSource: DownloadSource;
agentCount: number;
agentPolicyCount: number;
agentCount?: number;
agentPolicyCount?: number;
}

const ConfirmDescription: React.FunctionComponent<ConfirmDescriptionProps> = ({
downloadSource,
agentCount,
agentPolicyCount,
}) => (
<FormattedMessage
id="xpack.fleet.settings.updateDownloadSourceModal.confirmModalText"
data-test-subj="editDownloadSourcesConfirmModal.confirmModalText"
defaultMessage="This action will update {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.updateDownloadSourceModal.agentsCount"
defaultMessage="{agentCount, plural, one {# agent} other {# agents}}"
values={{
agentCount,
}}
/>
</strong>
),
policies: (
<strong>
<FormattedMessage
id="xpack.fleet.settings.updateDownloadSourceModal.agentPolicyCount"
defaultMessage="{agentPolicyCount, plural, one {# agent policy} other {# agent policies}}"
values={{
agentPolicyCount,
}}
/>
</strong>
),
}}
/>
);
}) =>
agentCount !== undefined && agentPolicyCount !== undefined ? (
<FormattedMessage
id="xpack.fleet.settings.updateDownloadSourceModal.confirmModalText"
data-test-subj="editDownloadSourcesConfirmModal.confirmModalText"
defaultMessage="This action will update {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.updateDownloadSourceModal.agentsCount"
defaultMessage="{agentCount, plural, one {# agent} other {# agents}}"
values={{
agentCount,
}}
/>
</strong>
),
policies: (
<strong>
<FormattedMessage
id="xpack.fleet.settings.updateDownloadSourceModal.agentPolicyCount"
defaultMessage="{agentPolicyCount, plural, one {# agent policy} other {# agent policies}}"
values={{
agentPolicyCount,
}}
/>
</strong>
),
}}
/>
) : (
<FormattedMessage
id="xpack.fleet.settings.updateDownloadSourceModal.confirmModalTextWithoutCount"
data-test-subj="editDownloadSourcesConfirmModal.confirmModalText"
defaultMessage="This action will update {downloadSourceName} agent binary source. It will update related policies and agents. This action can not be undone. Are you sure you wish to continue?"
values={{
downloadSourceName: <strong>{downloadSource.name}</strong>,
}}
/>
);

export async function confirmUpdate(
downloadSource: DownloadSource,
confirm: ReturnType<typeof useConfirmModal>['confirm']
) {
const { agentCount, agentPolicyCount } = await getCountsForDownloadSource(downloadSource);
const { agentCount, agentPolicyCount } = await getCountsForDownloadSource(downloadSource).catch(
() => ({
// Fail gracefully when counts are not avaiable
agentCount: undefined,
agentPolicyCount: undefined,
})
);
return confirm(
<FormattedMessage
id="xpack.fleet.settings.updateDownloadSourceModal.confirmModalTitle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 and it will update its related policies and agents. This action can not be undone. Are you sure you wish to continue?"
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 />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const ConfirmTitle = () => (

interface ConfirmDescriptionProps {
output: Output;
agentCount: number;
agentPolicyCount: number;
agentCount?: number;
agentPolicyCount?: number;
}

const ConfirmDescription: React.FunctionComponent<ConfirmDescriptionProps> = ({
Expand All @@ -32,36 +32,47 @@ const ConfirmDescription: React.FunctionComponent<ConfirmDescriptionProps> = ({
agentPolicyCount,
}) => (
<>
<FormattedMessage
data-test-subj="settings.outputModal"
id="xpack.fleet.settings.updateOutput.confirmModalText"
defaultMessage="This action will update {outputName} output. It will update {policies} and {agents}. This action can not be undone. Are you sure you wish to continue?"
values={{
outputName: <strong>{output.name}</strong>,
agents: (
<strong>
<FormattedMessage
id="xpack.fleet.settings.updateOutput.agentsCount"
defaultMessage="{agentCount, plural, one {# agent} other {# agents}}"
values={{
agentCount,
}}
/>
</strong>
),
policies: (
<strong>
<FormattedMessage
id="xpack.fleet.settings.updateOutput.agentPolicyCount"
defaultMessage="{agentPolicyCount, plural, one {# agent policy} other {# agent policies}}"
values={{
agentPolicyCount,
}}
/>
</strong>
),
}}
/>
{agentCount !== undefined && agentPolicyCount !== undefined ? (
<FormattedMessage
data-test-subj="settings.outputModal"
id="xpack.fleet.settings.updateOutput.confirmModalText"
defaultMessage="This action will update {outputName} output. It will update {policies} and {agents}. This action can not be undone. Are you sure you wish to continue?"
values={{
outputName: <strong>{output.name}</strong>,
agents: (
<strong>
<FormattedMessage
id="xpack.fleet.settings.updateOutput.agentsCount"
defaultMessage="{agentCount, plural, one {# agent} other {# agents}}"
values={{
agentCount,
}}
/>
</strong>
),
policies: (
<strong>
<FormattedMessage
id="xpack.fleet.settings.updateOutput.agentPolicyCount"
defaultMessage="{agentPolicyCount, plural, one {# agent policy} other {# agent policies}}"
values={{
agentPolicyCount,
}}
/>
</strong>
),
}}
/>
) : (
<FormattedMessage
data-test-subj="settings.outputModal"
id="xpack.fleet.settings.updateOutput.confirmModalTextWithoutCount"
defaultMessage="This action will update {outputName} output. It will update related policies and agents. This action can not be undone. Are you sure you wish to continue?"
values={{
outputName: <strong>{output.name}</strong>,
}}
/>
)}

{output.type === 'logstash' ? (
<>
Expand Down Expand Up @@ -91,7 +102,13 @@ export async function confirmUpdate(
output: Output,
confirm: ReturnType<typeof useConfirmModal>['confirm']
) {
const { agentCount, agentPolicyCount } = await getAgentAndPolicyCountForOutput(output);
const { agentCount, agentPolicyCount } =
// Fail gracefully if not agent and policy count not available
await getAgentAndPolicyCountForOutput(output).catch(() => ({
agentCount: undefined,
agentPolicyCount: undefined,
}));

return confirm(
<ConfirmTitle />,
<ConfirmDescription
Expand Down
Loading