Skip to content

Commit

Permalink
Grouping templating chatops fix (#2307)
Browse files Browse the repository at this point in the history
[css fixes, displaying chatops button visibility fix]
  • Loading branch information
Ukochka authored Jun 22, 2023
1 parent a339d80 commit 2cdab7e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
max-height: 100%;
width: 100%;
border: var(--border-strong);
padding-left: 16px;
}

.template-block-title {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const IntegrationTemplate = observer((props: IntegrationTemplateProps) => {
const [changedTemplateBody, setChangedTemplateBody] = useState<string>(templateBody);
const [resultError, setResultError] = useState<string>(undefined);
const [editorHeight, setEditorHeight] = useState<string>(undefined);
const [isRecentAlertGroupExisting, setIsRecentAlertGroupExisting] = useState<boolean>(false);

useEffect(() => {
const locationParams: any = { template: template.name };
Expand Down Expand Up @@ -109,6 +110,10 @@ const IntegrationTemplate = observer((props: IntegrationTemplateProps) => {
}
}, []);

const onLoadAlertGroupsList = useCallback((isAlertGroup: boolean) => {
setIsRecentAlertGroupExisting(isAlertGroup);
}, []);

const onSaveAndFollowLink = useCallback(
(link: string) => {
onUpdateTemplates({ [template.name]: changedTemplateBody });
Expand Down Expand Up @@ -187,6 +192,7 @@ const IntegrationTemplate = observer((props: IntegrationTemplateProps) => {
onEditPayload={onEditPayload}
onSelectAlertGroup={onSelectAlertGroup}
templates={templates}
onLoadAlertGroupsList={onLoadAlertGroupsList}
/>
{isCheatSheetVisible ? (
<CheatSheet
Expand Down Expand Up @@ -222,7 +228,7 @@ const IntegrationTemplate = observer((props: IntegrationTemplateProps) => {
alertReceiveChannelId={id}
template={template}
templateBody={changedTemplateBody}
alertGroup={undefined}
isAlertGroupExisting={isRecentAlertGroupExisting}
chatOpsPermalink={chatOpsPermalink}
payload={alertGroupPayload}
error={resultError}
Expand All @@ -239,7 +245,7 @@ interface ResultProps {
// templateName: string;
templateBody: string;
template: TemplateForEdit;
alertGroup?: Alert;
isAlertGroupExisting?: boolean;
chatOpsPermalink?: string;
payload?: JSON;
error?: string;
Expand All @@ -248,8 +254,16 @@ interface ResultProps {
}

const Result = (props: ResultProps) => {
const { alertReceiveChannelId, template, templateBody, chatOpsPermalink, payload, error, onSaveAndFollowLink } =
props;
const {
alertReceiveChannelId,
template,
templateBody,
chatOpsPermalink,
payload,
error,
isAlertGroupExisting,
onSaveAndFollowLink,
} = props;

return (
<div className={cx('template-block-result')}>
Expand Down Expand Up @@ -283,7 +297,7 @@ const Result = (props: ResultProps) => {
<Text type="secondary">{template?.additionalData.additionalDescription}</Text>
)}

{template?.additionalData?.chatOpsName && (
{template?.additionalData?.chatOpsName && isAlertGroupExisting && (
<VerticalGroup>
<Button onClick={() => onSaveAndFollowLink(chatOpsPermalink)}>
<HorizontalGroup spacing="xs" align="center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
width: 100%;
}

.message {
word-wrap: break-word;
}

.message ul {
margin-left: 24px;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@ interface TemplatesAlertGroupsListProps {
alertReceiveChannelId: AlertReceiveChannel['id'];
onSelectAlertGroup?: (alertGroup: Alert) => void;
onEditPayload?: (payload: string) => void;
onLoadAlertGroupsList?: (isRecentAlertExising: boolean) => void;
}

const TemplatesAlertGroupsList = (props: TemplatesAlertGroupsListProps) => {
const { alertReceiveChannelId, templates, onEditPayload, onSelectAlertGroup } = props;
const { alertReceiveChannelId, templates, onEditPayload, onSelectAlertGroup, onLoadAlertGroupsList } = props;
const store = useStore();
const [alertGroupsList, setAlertGroupsList] = useState(undefined);
const [selectedAlertPayload, setSelectedAlertPayload] = useState<string>(undefined);
const [selectedAlertName, setSelectedAlertName] = useState<string>(undefined);
const [isEditMode, setIsEditMode] = useState(false);

useEffect(() => {
store.alertGroupStore
.getAlertGroupsForIntegration(alertReceiveChannelId)
.then((result) => setAlertGroupsList(result.slice(0, 30)));
store.alertGroupStore.getAlertGroupsForIntegration(alertReceiveChannelId).then((result) => {
setAlertGroupsList(result.slice(0, 30));
onLoadAlertGroupsList(result.length > 0);
});
}, []);

const getCodeEditorHeight = () => {
Expand Down
1 change: 1 addition & 0 deletions grafana-plugin/src/pages/incident/Incident.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

.message {
margin-top: 16px;
word-wrap: break-word;
}

.message a {
Expand Down

0 comments on commit 2cdab7e

Please sign in to comment.