From cb03b05ced9ffd9b7c550459d08f7705c2858f4b Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Fri, 1 Apr 2022 16:34:08 +0200 Subject: [PATCH] Alerting: Add yaml editor to cloud rules (#46533) * ruleinspector component * Adding yaml component * setvalues * update yarn.lock * bump types * chore: update lockfile * move apply button position * move button back to tab Co-authored-by: gillesdemey --- .yarn/releases/yarn-3.2.0.cjs | 0 package.json | 2 + .../components/rule-editor/AlertRuleForm.tsx | 23 ++- .../components/rule-editor/RuleInspector.tsx | 131 ++++++++++++++++++ yarn.lock | 9 ++ 5 files changed, 163 insertions(+), 2 deletions(-) mode change 100755 => 100644 .yarn/releases/yarn-3.2.0.cjs create mode 100644 public/app/features/alerting/unified/components/rule-editor/RuleInspector.tsx diff --git a/.yarn/releases/yarn-3.2.0.cjs b/.yarn/releases/yarn-3.2.0.cjs old mode 100755 new mode 100644 diff --git a/package.json b/package.json index 18841313fa1..45aef980c42 100644 --- a/package.json +++ b/package.json @@ -128,6 +128,7 @@ "@types/hoist-non-react-statics": "3.3.1", "@types/jest": "27.4.1", "@types/jquery": "3.5.14", + "@types/js-yaml": "^4.0.5", "@types/jsurl": "^1.2.28", "@types/lingui__macro": "^3", "@types/lodash": "4.14.181", @@ -311,6 +312,7 @@ "immer": "9.0.12", "immutable": "4.0.0", "jquery": "3.6.0", + "js-yaml": "^4.1.0", "json-source-map": "0.6.1", "jsurl": "^0.1.5", "lezer-promql": "0.22.0", diff --git a/public/app/features/alerting/unified/components/rule-editor/AlertRuleForm.tsx b/public/app/features/alerting/unified/components/rule-editor/AlertRuleForm.tsx index 8de196cbd47..ee51d1bba84 100644 --- a/public/app/features/alerting/unified/components/rule-editor/AlertRuleForm.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/AlertRuleForm.tsx @@ -6,7 +6,7 @@ import { css } from '@emotion/css'; import { AlertTypeStep } from './AlertTypeStep'; import { DetailsStep } from './DetailsStep'; import { QueryStep } from './QueryStep'; -import { useForm, FormProvider } from 'react-hook-form'; +import { useForm, FormProvider, UseFormWatch } from 'react-hook-form'; import { RuleFormType, RuleFormValues } from '../../types/rule-form'; import { useUnifiedAlertingSelector } from '../../hooks/useUnifiedAlertingSelector'; @@ -23,6 +23,7 @@ import { useAppNotification } from 'app/core/copy/appNotification'; import { CloudConditionsStep } from './CloudConditionsStep'; import { GrafanaConditionsStep } from './GrafanaConditionsStep'; import * as ruleId from '../../utils/rule-id'; +import { RuleInspector } from './RuleInspector'; type Props = { existing?: RuleWithLocation; @@ -33,6 +34,7 @@ export const AlertRuleForm: FC = ({ existing }) => { const dispatch = useDispatch(); const notifyApp = useAppNotification(); const [queryParams] = useQueryParams(); + const [showEditYaml, setShowEditYaml] = useState(false); const returnTo: string = (queryParams['returnTo'] as string | undefined) ?? '/alerting/list'; const [showDeleteModal, setShowDeleteModal] = useState(false); @@ -106,7 +108,7 @@ export const AlertRuleForm: FC = ({ existing }) => { return (
e.preventDefault()} className={styles.form}> - + ) : null} + {isCortexLokiOrRecordingRule(watch) && ( + + )} + + +
+ + {({ height }) => ( + + )} + +
+ + ); +}; + +const yamlTabStyle = (theme: GrafanaTheme2) => ({ + content: css` + flex-grow: 1; + height: 100%; + padding-bottom: 16px; + margin-bottom: ${theme.spacing(2)}; + `, + applyButton: css` + display: flex; + flex-grow: 0; + `, +}); + +const drawerStyles = () => ({ + subtitle: css` + display: flex; + align-items: center; + justify-content: space-between; + `, +}); diff --git a/yarn.lock b/yarn.lock index 12821098b79..b60021e7062 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10112,6 +10112,13 @@ __metadata: languageName: node linkType: hard +"@types/js-yaml@npm:^4.0.5": + version: 4.0.5 + resolution: "@types/js-yaml@npm:4.0.5" + checksum: 7dcac8c50fec31643cc9d6444b5503239a861414cdfaa7ae9a38bc22597c4d850c4b8cec3d82d73b3fbca408348ce223b0408d598b32e094470dfffc6d486b4d + languageName: node + linkType: hard + "@types/json-schema@npm:*, @types/json-schema@npm:^7.0.4, @types/json-schema@npm:^7.0.5, @types/json-schema@npm:^7.0.7, @types/json-schema@npm:^7.0.8, @types/json-schema@npm:^7.0.9": version: 7.0.9 resolution: "@types/json-schema@npm:7.0.9" @@ -20496,6 +20503,7 @@ __metadata: "@types/hoist-non-react-statics": 3.3.1 "@types/jest": 27.4.1 "@types/jquery": 3.5.14 + "@types/js-yaml": ^4.0.5 "@types/jsurl": ^1.2.28 "@types/lingui__macro": ^3 "@types/lodash": 4.14.181 @@ -20604,6 +20612,7 @@ __metadata: jest-matcher-utils: 27.5.1 jest-mock-console: 1.2.3 jquery: 3.6.0 + js-yaml: ^4.1.0 json-source-map: 0.6.1 jsurl: ^0.1.5 lerna: ^4.0.0