* feat ui: dashboards redesign start * more cards * fix ui: more different cards... * feat ui: finish cards, all trigger, all icons * change(ui): added missin const * feature(ui): new dashboard modal * feature(ui): new dashboard modal * change(ui): new cards * change(ui): dashboard redesign * change(ui): dashboard redesign * change(ui): dashboard redesign * change(ui): modal context and alert form * change(ui): table card show more with modal * change(ui): examples * change(ui): example categorize and other improvements * change(ui): example categorize and other improvements * change(ui): performance cards * change(ui): insights card * Various style updates in dashboards and other pages. (#2308) * Various minor style updates * Various style improvements * Update ExampleCards.tsx * change(ui): fixed an issue with card create * change(ui): fixed an issue with card create * change(ui): default filters and events order * change(ui): random data * Dashboards redesign - improvments (#2313) * Various minor style updates * Various style improvements * Update ExampleCards.tsx * various minor improvements in dashbaords. * revised dashboard widget header * change(ui): sessions by user * change(ui): funnel example * change(ui): modal height and scroll * change(ui): example cards with data * change(ui): example cards with data * change(ui): funnel bar text color * change(ui): example cards overlay click * change(ui): path analysis filter card --------- Co-authored-by: Shekar Siri <sshekarsiri@gmail.com> Co-authored-by: Sudheer Salavadi <connect.uxmaster@gmail.com>
95 lines
2.5 KiB
TypeScript
95 lines
2.5 KiB
TypeScript
import React, {useEffect, useState} from 'react';
|
|
import {SlideModal} from 'UI';
|
|
import {useStore} from 'App/mstore'
|
|
import {observer} from 'mobx-react-lite'
|
|
import AlertForm from '../AlertForm';
|
|
import {SLACK, TEAMS, WEBHOOK} from 'App/constants/schedule';
|
|
import {confirm} from 'UI';
|
|
|
|
interface Select {
|
|
label: string;
|
|
value: string | number
|
|
}
|
|
|
|
|
|
interface Props {
|
|
showModal?: boolean;
|
|
metricId?: number;
|
|
onClose?: () => void;
|
|
}
|
|
|
|
function AlertFormModal(props: Props) {
|
|
const {alertsStore, settingsStore} = useStore()
|
|
const {metricId = null, showModal = false} = props;
|
|
const [showForm, setShowForm] = useState(false);
|
|
const webhooks = settingsStore.webhooks
|
|
useEffect(() => {
|
|
settingsStore.fetchWebhooks();
|
|
}, []);
|
|
|
|
|
|
const slackChannels: Select[] = []
|
|
const hooks: Select[] = []
|
|
const msTeamsChannels: Select[] = []
|
|
|
|
webhooks.forEach((hook) => {
|
|
const option = {value: hook.webhookId, label: hook.name}
|
|
if (hook.type === SLACK) {
|
|
slackChannels.push(option)
|
|
}
|
|
if (hook.type === WEBHOOK) {
|
|
hooks.push(option)
|
|
}
|
|
if (hook.type === TEAMS) {
|
|
msTeamsChannels.push(option)
|
|
}
|
|
})
|
|
|
|
const saveAlert = (instance) => {
|
|
const wasUpdating = instance.exists();
|
|
alertsStore.save(instance).then(() => {
|
|
if (!wasUpdating) {
|
|
toggleForm(null, false);
|
|
}
|
|
if (props.onClose) {
|
|
props.onClose();
|
|
}
|
|
});
|
|
};
|
|
|
|
const onDelete = async (instance) => {
|
|
if (
|
|
await confirm({
|
|
header: 'Confirm',
|
|
confirmButton: 'Yes, delete',
|
|
confirmation: `Are you sure you want to permanently delete this alert?`,
|
|
})
|
|
) {
|
|
alertsStore.remove(instance.alertId).then(() => {
|
|
toggleForm(null, false);
|
|
});
|
|
}
|
|
};
|
|
|
|
const toggleForm = (instance, state) => {
|
|
if (instance) {
|
|
alertsStore.init(instance);
|
|
}
|
|
return setShowForm(state ? state : !showForm);
|
|
};
|
|
|
|
return (
|
|
<AlertForm
|
|
metricId={metricId}
|
|
edit={alertsStore.edit}
|
|
slackChannels={slackChannels}
|
|
msTeamsChannels={msTeamsChannels}
|
|
webhooks={hooks}
|
|
onSubmit={saveAlert}
|
|
onClose={props.onClose}
|
|
onDelete={onDelete}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export default observer(AlertFormModal);
|