Skip to content

Commit

Permalink
refactored code
Browse files Browse the repository at this point in the history
Signed-off-by: Amardeepsingh Siglani <[email protected]>
  • Loading branch information
amsiglan committed Apr 3, 2024
1 parent b852466 commit 25d8851
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 31 deletions.
4 changes: 2 additions & 2 deletions public/pages/CreateTrigger/components/Action/Action.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from '../../utils/constants';
import NotificationsCallOut from '../NotificationsCallOut';
import MinimalAccordion from '../../../../components/FeatureAnywhereContextMenu/MinimalAccordion';
import { MANAGE_CHANNELS_URL } from '../../../../utils/constants';
import { getManageChannelsUrl } from '../../../../utils/helpers';

const Action = ({
action,
Expand Down Expand Up @@ -167,7 +167,7 @@ const Action = ({
disabled={!hasNotificationPlugin}
iconType="popout"
iconSide="right"
onClick={() => window.open(MANAGE_CHANNELS_URL)}
onClick={() => window.open(getManageChannelsUrl())}
>
Manage channels
</ManageButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React from 'react';
import { EuiButton, EuiEmptyPrompt, EuiText } from '@elastic/eui';
import AddActionButton from '../AddActionButton';
import { MANAGE_CHANNELS_URL } from '../../../../utils/constants';
import { getManageChannelsUrl } from '../../../../utils/helpers';

const actionEmptyText = 'Add an action to perform when this trigger is triggered.';
const destinationEmptyText = 'There are no existing channels. Add a channel to create an action.';
Expand Down Expand Up @@ -38,7 +38,7 @@ const ActionEmptyPrompt = ({
disabled={!hasNotificationPlugin}
iconType="popout"
iconSide="right"
onClick={() => window.open(MANAGE_CHANNELS_URL)}
onClick={() => window.open(getManageChannelsUrl())}
>
Manage channels
</EuiButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import _ from 'lodash';
import { FORMIK_INITIAL_ACTION_VALUES } from '../../utils/constants';
import { NOTIFY_OPTIONS_VALUES } from '../../components/Action/actions/Message';
import { required } from '../../../../utils/validate';
import { MANAGE_CHANNELS_URL } from '../../../../utils/constants';
import { getManageChannelsUrl } from '../../../../utils/helpers';

const TriggerNotificationsContent = ({
action,
Expand Down Expand Up @@ -98,7 +98,7 @@ const TriggerNotificationsContent = ({
iconType={'popout'}
style={{ marginTop: '22px' }}
disabled={!hasNotifications}
onClick={() => window.open(MANAGE_CHANNELS_URL)}
onClick={() => window.open(getManageChannelsUrl())}
>
Manage channels
</EuiButtonEmpty>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { EuiButton, EuiEmptyPrompt, EuiLink, EuiText } from '@elastic/eui';
import { MANAGE_CHANNELS_URL } from '../../../../../utils/constants';
import { getManageChannelsUrl } from '../../../../../utils/helpers';

const filterText = (hasNotificationPlugin) =>
hasNotificationPlugin ? (
Expand All @@ -17,7 +17,7 @@ const filterText = (hasNotificationPlugin) =>
</p>
<p>
Migrated destinations can be found in&nbsp;
{<EuiLink href={MANAGE_CHANNELS_URL}>Notifications</EuiLink>}
{<EuiLink href={getManageChannelsUrl()}>Notifications</EuiLink>}
</p>
</>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React from 'react';
import { EuiButton, EuiEmptyPrompt, EuiLink, EuiPanel, EuiText } from '@elastic/eui';
import { NOTIFICATIONS_LEARN_MORE_HREF } from '../../utils/constants';
import { MANAGE_CHANNELS_URL } from '../../../../utils/constants';
import { getManageChannelsUrl } from '../../../../utils/helpers';

const noNotificationsTitle = 'Destinations will become channels in Notifications';
const noNotificationsText = (
Expand Down Expand Up @@ -40,20 +40,23 @@ const hasNotificationsText = (
</p>
</EuiText>
);
const hasNotificationsButton = (
<EuiButton fill href={MANAGE_CHANNELS_URL}>
View in Notifications
</EuiButton>
);

const FullPageNotificationsInfoCallOut = ({ hasNotificationPlugin }) => (
<EuiPanel>
<EuiEmptyPrompt
title={<h2>{hasNotificationPlugin ? hasNotificationsTitle : noNotificationsTitle}</h2>}
body={hasNotificationPlugin ? hasNotificationsText : noNotificationsText}
actions={hasNotificationPlugin ? hasNotificationsButton : noNotificationsButton}
/>
</EuiPanel>
);
const FullPageNotificationsInfoCallOut = ({ hasNotificationPlugin }) => {
const hasNotificationsButton = (
<EuiButton fill href={getManageChannelsUrl()}>
View in Notifications
</EuiButton>
);

return (
<EuiPanel>
<EuiEmptyPrompt
title={<h2>{hasNotificationPlugin ? hasNotificationsTitle : noNotificationsTitle}</h2>}
body={hasNotificationPlugin ? hasNotificationsText : noNotificationsText}
actions={hasNotificationPlugin ? hasNotificationsButton : noNotificationsButton}
/>
</EuiPanel>
);
}

export default FullPageNotificationsInfoCallOut;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React from 'react';
import { EuiCallOut, EuiButton, EuiLink, EuiSpacer } from '@elastic/eui';
import { NOTIFICATIONS_LEARN_MORE_HREF } from '../../utils/constants';
import { MANAGE_CHANNELS_URL } from '../../../../utils/constants';
import { getManageChannelsUrl } from '../../../../utils/helpers';

const noNotificationsTitle = 'Unable to send notifications. Notifications plugin is required.';
const noNotificationsBodyText = (
Expand Down Expand Up @@ -42,11 +42,12 @@ const hasNotificationsBodyText = (
</EuiLink>
</p>
);
const hasNotificationsButton = (
<EuiButton href={MANAGE_CHANNELS_URL}>View in Notifications</EuiButton>
);

const NotificationsInfoCallOut = ({ hasNotificationPlugin }) => {
const hasNotificationsButton = (
<EuiButton href={getManageChannelsUrl()}>View in Notifications</EuiButton>
);

return (
<div>
<EuiCallOut
Expand Down
3 changes: 0 additions & 3 deletions public/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,3 @@ export const PLUGIN_AUGMENTATION_ENABLE_SETTING = 'visualization:enablePluginAug

export const PLUGIN_AUGMENTATION_MAX_OBJECTS_SETTING =
'visualization:enablePluginAugmentation.maxPluginObjects';

// This is updated to include the server.basepath during plugin's first render inside app.js using `initManageChannelsUrl` function
export let MANAGE_CHANNELS_URL = '/app/notifications-dashboards#/channels';
8 changes: 7 additions & 1 deletion public/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
filterActiveAlerts,
} from '../pages/Dashboard/utils/helpers';
import _ from 'lodash';
import { MANAGE_CHANNELS_URL } from './constants';

export const makeId = htmlIdGenerator();

Expand Down Expand Up @@ -138,7 +137,14 @@ export const titleTemplate = (title, subTitle) => (
</>
);

// This is updated to include the server.basepath during plugin's first render inside app.js using `initManageChannelsUrl` function
export let MANAGE_CHANNELS_URL = '/app/notifications-dashboards#/channels';

export function initManageChannelsUrl(httpClient) {
const manageChannelsRelativePath = `/app/notifications-dashboards#/channels`;
MANAGE_CHANNELS_URL = httpClient.basePath.prepend(manageChannelsRelativePath);
}

export function getManageChannelsUrl() {
return MANAGE_CHANNELS_URL;
}

0 comments on commit 25d8851

Please sign in to comment.