fix(striker-ui): duck-tape alert override update by wipe-n-create
This commit is contained in:
parent
9a6a4f8b7c
commit
1991acfa1d
@ -121,81 +121,35 @@ const getAlertOverrideRequestList = (
|
|||||||
if (!mailRecipientUuid) return [];
|
if (!mailRecipientUuid) return [];
|
||||||
|
|
||||||
return Object.values(current.alertOverrides).reduce<AlertOverrideRequest[]>(
|
return Object.values(current.alertOverrides).reduce<AlertOverrideRequest[]>(
|
||||||
(previous, value) => {
|
(previous, { remove, level, target, uuids: existingOverrides }) => {
|
||||||
if (value.delete && value.uuids) {
|
/**
|
||||||
/**
|
* There's no update, just delete every record and create the new records.
|
||||||
* 1 or more existing records marked for removal.
|
*
|
||||||
*/
|
* This is not optimal, but keep it until there's a better solution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (existingOverrides) {
|
||||||
previous.push(
|
previous.push(
|
||||||
...Object.keys(value.uuids).map<AlertOverrideRequest>((uuid) => ({
|
...Object.keys(existingOverrides).map<AlertOverrideRequest>(
|
||||||
method: 'delete',
|
(overrideUuid) => ({
|
||||||
url: `${urlPrefix}/${uuid}`,
|
method: 'delete',
|
||||||
})),
|
url: `${urlPrefix}/${overrideUuid}`,
|
||||||
);
|
}),
|
||||||
|
|
||||||
return previous;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { level, target, uuids } = value;
|
|
||||||
|
|
||||||
if (!target) return previous;
|
|
||||||
|
|
||||||
const hosts: string[] = target.subnodes ?? [target.uuid];
|
|
||||||
|
|
||||||
if (uuids) {
|
|
||||||
/**
|
|
||||||
* Found existing alert override UUIDs; the requests must be updates.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const slots: string[] = Object.keys(uuids);
|
|
||||||
|
|
||||||
const longest = Math.max(slots.length, hosts.length);
|
|
||||||
|
|
||||||
previous.push(
|
|
||||||
...Array.from({ length: longest }).map<AlertOverrideRequest>(
|
|
||||||
(ignore, i) => {
|
|
||||||
const host = hosts[i];
|
|
||||||
const slot = slots[i];
|
|
||||||
|
|
||||||
if (!slot) {
|
|
||||||
return {
|
|
||||||
body: { hostUuid: host, level, mailRecipientUuid },
|
|
||||||
method: 'post',
|
|
||||||
url: urlPrefix,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const url = `${urlPrefix}/${slot}`;
|
|
||||||
|
|
||||||
if (!host) {
|
|
||||||
return {
|
|
||||||
method: 'delete',
|
|
||||||
url,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
body: { hostUuid: host, level, mailRecipientUuid },
|
|
||||||
method: 'put',
|
|
||||||
url,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return previous;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
if (target && !remove) {
|
||||||
* No existing alert override UUIDs, meaning these are new records.
|
const newHosts: string[] = target.subnodes ?? [target.uuid];
|
||||||
*/
|
|
||||||
previous.push(
|
previous.push(
|
||||||
...hosts.map<AlertOverrideRequest>((hostUuid) => ({
|
...newHosts.map<AlertOverrideRequest>((hostUuid) => ({
|
||||||
body: { hostUuid, level, mailRecipientUuid },
|
body: { hostUuid, level, mailRecipientUuid },
|
||||||
method: 'post',
|
method: 'post',
|
||||||
url: urlPrefix,
|
url: urlPrefix,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return previous;
|
return previous;
|
||||||
},
|
},
|
||||||
@ -263,18 +217,20 @@ const AddMailRecipientForm: FC<AddMailRecipientFormProps> = (props) => {
|
|||||||
<>
|
<>
|
||||||
<FormSummary entries={mrBody} />
|
<FormSummary entries={mrBody} />
|
||||||
<FormSummary
|
<FormSummary
|
||||||
entries={Object.entries(alertOverrides).reduce<
|
entries={{
|
||||||
Record<string, { level: number; name: string }>
|
alertOverrides: Object.entries(alertOverrides).reduce<
|
||||||
>((previous, [valueId, value]) => {
|
Record<string, { level: number; name: string }>
|
||||||
if (!value.target) return previous;
|
>((previous, [valueId, value]) => {
|
||||||
|
if (value.remove || !value.target) return previous;
|
||||||
|
|
||||||
previous[valueId] = {
|
previous[valueId] = {
|
||||||
level: value.level,
|
level: value.level,
|
||||||
name: value.target.name,
|
name: value.target.name,
|
||||||
};
|
};
|
||||||
|
|
||||||
return previous;
|
return previous;
|
||||||
}, {})}
|
}, {}),
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
|
@ -47,8 +47,8 @@ const AlertOverrideInputGroup: FC<AlertOverrideInputGroupProps> = (props) => {
|
|||||||
[aoVid, mrUuid],
|
[aoVid, mrUuid],
|
||||||
);
|
);
|
||||||
|
|
||||||
const deleteChain = useMemo<string>(
|
const removeChain = useMemo<string>(
|
||||||
() => `${overrideChain}.delete`,
|
() => `${overrideChain}.remove`,
|
||||||
[overrideChain],
|
[overrideChain],
|
||||||
);
|
);
|
||||||
const targetChain = useMemo<string>(
|
const targetChain = useMemo<string>(
|
||||||
@ -116,7 +116,7 @@ const AlertOverrideInputGroup: FC<AlertOverrideInputGroupProps> = (props) => {
|
|||||||
mapPreset="delete"
|
mapPreset="delete"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (alertOverride.uuids) {
|
if (alertOverride.uuids) {
|
||||||
formik.setFieldValue(deleteChain, true, true);
|
formik.setFieldValue(removeChain, true, true);
|
||||||
} else {
|
} else {
|
||||||
formik.setValues((previous) => {
|
formik.setValues((previous) => {
|
||||||
const shallow = { ...previous };
|
const shallow = { ...previous };
|
||||||
|
@ -3,7 +3,6 @@ import { v4 as uuidv4 } from 'uuid';
|
|||||||
|
|
||||||
import AlertOverrideInputGroup from './AlertOverrideInputGroup';
|
import AlertOverrideInputGroup from './AlertOverrideInputGroup';
|
||||||
import List from '../List';
|
import List from '../List';
|
||||||
import useChecklist from '../../hooks/useChecklist';
|
|
||||||
|
|
||||||
const ManageAlertOverride: FC<ManageAlertOverrideProps> = (props) => {
|
const ManageAlertOverride: FC<ManageAlertOverrideProps> = (props) => {
|
||||||
const {
|
const {
|
||||||
@ -18,12 +17,9 @@ const ManageAlertOverride: FC<ManageAlertOverrideProps> = (props) => {
|
|||||||
} = formik;
|
} = formik;
|
||||||
const { alertOverrides } = mailRecipient;
|
const { alertOverrides } = mailRecipient;
|
||||||
|
|
||||||
const { hasChecks } = useChecklist(alertOverrides);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<List
|
<List
|
||||||
allowAddItem
|
allowAddItem
|
||||||
disableDelete={!hasChecks}
|
|
||||||
edit
|
edit
|
||||||
header="Alert override rules"
|
header="Alert override rules"
|
||||||
listEmpty="No alert overrides(s)"
|
listEmpty="No alert overrides(s)"
|
||||||
@ -48,7 +44,7 @@ const ManageAlertOverride: FC<ManageAlertOverrideProps> = (props) => {
|
|||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
renderListItem={(valueId, value) =>
|
renderListItem={(valueId, value) =>
|
||||||
!value.delete && (
|
!value.remove && (
|
||||||
<AlertOverrideInputGroup
|
<AlertOverrideInputGroup
|
||||||
alertOverrideTargetOptions={alertOverrideTargetOptions}
|
alertOverrideTargetOptions={alertOverrideTargetOptions}
|
||||||
alertOverrideValueId={valueId}
|
alertOverrideValueId={valueId}
|
||||||
|
2
striker-ui/types/ManageMailRecipient.d.ts
vendored
2
striker-ui/types/ManageMailRecipient.d.ts
vendored
@ -18,8 +18,8 @@ type AlertOverrideTarget = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type AlertOverrideFormikAlertOverride = {
|
type AlertOverrideFormikAlertOverride = {
|
||||||
delete?: boolean;
|
|
||||||
level: number;
|
level: number;
|
||||||
|
remove?: boolean;
|
||||||
target: AlertOverrideTarget | null;
|
target: AlertOverrideTarget | null;
|
||||||
uuids?: Record<string, string>;
|
uuids?: Record<string, string>;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user