diff --git a/public/app/features/alerting/.eslintrc b/public/app/features/alerting/.eslintrc index 2d9d9cbfe7be..5b235f3f531c 100644 --- a/public/app/features/alerting/.eslintrc +++ b/public/app/features/alerting/.eslintrc @@ -1,6 +1,7 @@ { "plugins": ["testing-library"], "rules": { + "dot-notation": "error", "prefer-const": "error", "react/no-unused-prop-types": "error", }, diff --git a/public/app/features/alerting/unified/NotificationPolicies.tsx b/public/app/features/alerting/unified/NotificationPolicies.tsx index d59f23bd3aea..e58f634d258b 100644 --- a/public/app/features/alerting/unified/NotificationPolicies.tsx +++ b/public/app/features/alerting/unified/NotificationPolicies.tsx @@ -392,11 +392,11 @@ interface QueryParamValues { function getActiveTabFromUrl(queryParams: UrlQueryMap): QueryParamValues { let tab = ActiveTab.NotificationPolicies; // default tab - if (queryParams['tab'] === ActiveTab.NotificationPolicies) { + if (queryParams.tab === ActiveTab.NotificationPolicies) { tab = ActiveTab.NotificationPolicies; } - if (queryParams['tab'] === ActiveTab.MuteTimings) { + if (queryParams.tab === ActiveTab.MuteTimings) { tab = ActiveTab.MuteTimings; } diff --git a/public/app/features/alerting/unified/RuleList.test.tsx b/public/app/features/alerting/unified/RuleList.test.tsx index 91a647f7f315..2e3e8e56ea48 100644 --- a/public/app/features/alerting/unified/RuleList.test.tsx +++ b/public/app/features/alerting/unified/RuleList.test.tsx @@ -760,7 +760,7 @@ describe('RuleList', () => { { dataSourceName: testDatasources.prom.name, apiVersion: 'legacy' }, 'super namespace', { - ...someRulerRules['namespace1'][0], + ...someRulerRules.namespace1[0], name: 'super group', interval: '5m', } @@ -769,7 +769,7 @@ describe('RuleList', () => { 2, { dataSourceName: testDatasources.prom.name, apiVersion: 'legacy' }, 'super namespace', - someRulerRules['namespace1'][1] + someRulerRules.namespace1[1] ); expect(mocks.api.deleteNamespace).toHaveBeenLastCalledWith( { dataSourceName: testDatasources.prom.name, apiVersion: 'legacy' }, @@ -799,7 +799,7 @@ describe('RuleList', () => { { dataSourceName: testDatasources.prom.name, apiVersion: 'legacy' }, 'namespace1', { - ...someRulerRules['namespace1'][0], + ...someRulerRules.namespace1[0], name: 'super group', interval: '5m', } @@ -830,7 +830,7 @@ describe('RuleList', () => { { dataSourceName: testDatasources.prom.name, apiVersion: 'legacy' }, 'namespace1', { - ...someRulerRules['namespace1'][0], + ...someRulerRules.namespace1[0], interval: '5m', } ); diff --git a/public/app/features/alerting/unified/components/expressions/Expression.test.tsx b/public/app/features/alerting/unified/components/expressions/Expression.test.tsx index 7f87e514ba67..f427d133c30f 100644 --- a/public/app/features/alerting/unified/components/expressions/Expression.test.tsx +++ b/public/app/features/alerting/unified/components/expressions/Expression.test.tsx @@ -94,8 +94,8 @@ describe('getGroupedByStateAndSeriesCount', () => { const { groupedByState, seriesCount } = getGroupedByStateAndSeriesCount(series); - expect(groupedByState['firing']).toEqual([series[0], series[3]]); - expect(groupedByState['inactive']).toEqual([series[2]]); + expect(groupedByState.firing).toEqual([series[0], series[3]]); + expect(groupedByState.inactive).toEqual([series[2]]); expect(seriesCount).toEqual(3); }); @@ -119,8 +119,8 @@ describe('getGroupedByStateAndSeriesCount', () => { const { groupedByState, seriesCount } = getGroupedByStateAndSeriesCount(series); - expect(groupedByState['firing']).toEqual([]); - expect(groupedByState['inactive']).toEqual([]); + expect(groupedByState.firing).toEqual([]); + expect(groupedByState.inactive).toEqual([]); expect(seriesCount).toEqual(0); }); @@ -133,8 +133,8 @@ describe('getGroupedByStateAndSeriesCount', () => { const { groupedByState, seriesCount } = getGroupedByStateAndSeriesCount(series); - expect(groupedByState['firing']).toEqual([]); - expect(groupedByState['inactive']).toEqual(series); + expect(groupedByState.firing).toEqual([]); + expect(groupedByState.inactive).toEqual(series); expect(seriesCount).toEqual(series.length); }); @@ -147,8 +147,8 @@ describe('getGroupedByStateAndSeriesCount', () => { const { groupedByState, seriesCount } = getGroupedByStateAndSeriesCount(series); - expect(groupedByState['firing']).toEqual(series); - expect(groupedByState['inactive']).toEqual([]); + expect(groupedByState.firing).toEqual(series); + expect(groupedByState.inactive).toEqual([]); expect(seriesCount).toEqual(series.length); }); }); diff --git a/public/app/features/alerting/unified/components/receivers/AlertInstanceModalSelector.tsx b/public/app/features/alerting/unified/components/receivers/AlertInstanceModalSelector.tsx index bb32d6d8f15d..9a75b7b2a0ba 100644 --- a/public/app/features/alerting/unified/components/receivers/AlertInstanceModalSelector.tsx +++ b/public/app/features/alerting/unified/components/receivers/AlertInstanceModalSelector.tsx @@ -56,10 +56,10 @@ export function AlertInstanceModalSelector({ const rules: Record = {}; if (!loading && result) { result.forEach((instance) => { - if (!rules[instance.labels['alertname']]) { - rules[instance.labels['alertname']] = []; + if (!rules[instance.labels.alertname]) { + rules[instance.labels.alertname] = []; } - rules[instance.labels['alertname']].push(instance); + rules[instance.labels.alertname].push(instance); }); } return rules; @@ -106,7 +106,7 @@ export function AlertInstanceModalSelector({
{ruleName}
<> - {filteredRules[ruleName][0].labels['grafana_folder'] ?? ''} + {filteredRules[ruleName][0].labels.grafana_folder ?? ''}
@@ -151,7 +151,7 @@ export function AlertInstanceModalSelector({ })} onClick={handleSelectInstances} > -
+
{JSON.stringify(alert, null, 2)}} theme={'info'}>
{tags.map((tag, index) => ( diff --git a/public/app/features/alerting/unified/components/receivers/form/ChannelSubForm.tsx b/public/app/features/alerting/unified/components/receivers/form/ChannelSubForm.tsx index b9f5c32374ee..fea7c9e191d2 100644 --- a/public/app/features/alerting/unified/components/receivers/form/ChannelSubForm.tsx +++ b/public/app/features/alerting/unified/components/receivers/form/ChannelSubForm.tsx @@ -83,7 +83,7 @@ export function ChannelSubForm({ name === fieldName('settings.integration_type') && value === OnCallIntegrationType.ExistingIntegration ) { - setValue(fieldName('settings.url'), initialValues.settings['url']); + setValue(fieldName('settings.url'), initialValues.settings.url); } }); diff --git a/public/app/features/alerting/unified/components/receivers/grafanaAppReceivers/onCall/useOnCallIntegration.test.ts b/public/app/features/alerting/unified/components/receivers/grafanaAppReceivers/onCall/useOnCallIntegration.test.ts index be07341b87c2..a45bfd7fd88e 100644 --- a/public/app/features/alerting/unified/components/receivers/grafanaAppReceivers/onCall/useOnCallIntegration.test.ts +++ b/public/app/features/alerting/unified/components/receivers/grafanaAppReceivers/onCall/useOnCallIntegration.test.ts @@ -58,7 +58,7 @@ describe('useOnCallIntegration', () => { OnCallIntegrationType.ExistingIntegration ); expect(receiverConfig.settings[OnCallIntegrationSetting.IntegrationName]).toBeUndefined(); - expect(receiverConfig.settings['url']).toBe('https://oncall-endpoint.example.com'); + expect(receiverConfig.settings.url).toBe('https://oncall-endpoint.example.com'); }); it('createOnCallIntegrations should provide integration name and url validators', async () => { diff --git a/public/app/features/alerting/unified/components/receivers/grafanaAppReceivers/onCall/useOnCallIntegration.ts b/public/app/features/alerting/unified/components/receivers/grafanaAppReceivers/onCall/useOnCallIntegration.ts index 69b8bc944545..9ea8bad77007 100644 --- a/public/app/features/alerting/unified/components/receivers/grafanaAppReceivers/onCall/useOnCallIntegration.ts +++ b/public/app/features/alerting/unified/components/receivers/grafanaAppReceivers/onCall/useOnCallIntegration.ts @@ -153,7 +153,7 @@ export function useOnCallIntegration() { verbal_name: c.settings[OnCallIntegrationSetting.IntegrationName], }).unwrap(); - c.settings['url'] = newIntegration.integration_url; + c.settings.url = newIntegration.integration_url; }); await Promise.all(createNewOnCallIntegrationJobs); diff --git a/public/app/features/alerting/unified/components/rule-editor/FolderAndGroup.tsx b/public/app/features/alerting/unified/components/rule-editor/FolderAndGroup.tsx index d0cdc0b5ab9b..44da084962eb 100644 --- a/public/app/features/alerting/unified/components/rule-editor/FolderAndGroup.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/FolderAndGroup.tsx @@ -236,7 +236,7 @@ export function FolderAndGroup({ getOptionLabel={(option: SelectableValue) => (
{option.label} - {option['isProvisioned'] && ( + {option.isProvisioned && ( <> {' '} diff --git a/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/AlertRuleForm.tsx b/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/AlertRuleForm.tsx index 8c80bdaecd71..f80caf01d839 100644 --- a/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/AlertRuleForm.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/AlertRuleForm.tsx @@ -72,7 +72,7 @@ export const AlertRuleForm = ({ existing, prefill }: Props) => { const ruleType = translateRouteParamToRuleType(routeParams.type); const uidFromParams = routeParams.id; - const returnTo = !queryParams['returnTo'] ? '/alerting/list' : String(queryParams['returnTo']); + const returnTo = !queryParams.returnTo ? '/alerting/list' : String(queryParams.returnTo); const [showDeleteModal, setShowDeleteModal] = useState(false); const defaultValues: RuleFormValues = useMemo(() => { @@ -84,8 +84,8 @@ export const AlertRuleForm = ({ existing, prefill }: Props) => { return formValuesFromPrefill(prefill); } - if (typeof queryParams['defaults'] === 'string') { - return formValuesFromQueryParams(queryParams['defaults'], ruleType); + if (typeof queryParams.defaults === 'string') { + return formValuesFromQueryParams(queryParams.defaults, ruleType); } return { diff --git a/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/ModifyExportRuleForm.tsx b/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/ModifyExportRuleForm.tsx index 3304bd0e9d88..79eef1831289 100644 --- a/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/ModifyExportRuleForm.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/ModifyExportRuleForm.tsx @@ -43,7 +43,7 @@ export function ModifyExportRuleForm({ ruleForm, alertUid }: ModifyExportRuleFor const existing = Boolean(ruleForm); // always should be true const notifyApp = useAppNotification(); - const returnTo = !queryParams['returnTo'] ? '/alerting/list' : String(queryParams['returnTo']); + const returnTo = !queryParams.returnTo ? '/alerting/list' : String(queryParams.returnTo); const [exportData, setExportData] = useState(undefined); diff --git a/public/app/features/alerting/unified/components/rule-list/EvaluationGroupWithRules.tsx b/public/app/features/alerting/unified/components/rule-list/EvaluationGroupWithRules.tsx index ec52fe3c4a1d..56337eeeee2c 100644 --- a/public/app/features/alerting/unified/components/rule-list/EvaluationGroupWithRules.tsx +++ b/public/app/features/alerting/unified/components/rule-list/EvaluationGroupWithRules.tsx @@ -45,7 +45,7 @@ export const EvaluationGroupWithRules = ({ group, rulesSource }: EvaluationGroup evaluationInterval={group.interval} instancesCount={isAlertingPromRule ? size(promRule.alerts) : undefined} href={createViewLink(rulesSource, rule)} - summary={annotations?.['summary']} + summary={annotations?.summary} /> ); } @@ -81,7 +81,7 @@ export const EvaluationGroupWithRules = ({ group, rulesSource }: EvaluationGroup evaluationInterval={group.interval} instancesCount={isAlertingPromRule ? size(promRule.alerts) : undefined} href={createViewLink(rulesSource, rule)} - summary={rule.annotations?.['summary']} + summary={rule.annotations?.summary} isProvisioned={Boolean(rulerRule.grafana_alert.provenance)} contactPoint={contactPoint} /> diff --git a/public/app/features/alerting/unified/components/rule-list/RuleList.v1.tsx b/public/app/features/alerting/unified/components/rule-list/RuleList.v1.tsx index 5e56084b6d66..a61e94cfd9bf 100644 --- a/public/app/features/alerting/unified/components/rule-list/RuleList.v1.tsx +++ b/public/app/features/alerting/unified/components/rule-list/RuleList.v1.tsx @@ -46,7 +46,7 @@ const RuleList = withErrorBoundary( const [queryParams] = useQueryParams(); const { filterState, hasActiveFilters } = useRulesFilter(); - const queryParamView = queryParams['view'] as keyof typeof VIEWS; + const queryParamView = queryParams.view as keyof typeof VIEWS; const view = VIEWS[queryParamView] ? queryParamView : 'groups'; const ViewComponent = VIEWS[view]; diff --git a/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.tsx b/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.tsx index 605601103bb0..3f71b0b9e951 100644 --- a/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.tsx +++ b/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.tsx @@ -265,7 +265,7 @@ export const isErrorHealth = (health?: RuleHealth) => health === 'error' || heal export function useActiveTab(): [ActiveTab, (tab: ActiveTab) => void] { const [queryParams, setQueryParams] = useQueryParams(); - const tabFromQuery = queryParams['tab']; + const tabFromQuery = queryParams.tab; const activeTab = isValidTab(tabFromQuery) ? tabFromQuery : ActiveTab.Query; diff --git a/public/app/features/alerting/unified/components/rules/GrafanaRules.tsx b/public/app/features/alerting/unified/components/rules/GrafanaRules.tsx index d7c5f1879377..a6269dd55dc9 100644 --- a/public/app/features/alerting/unified/components/rules/GrafanaRules.tsx +++ b/public/app/features/alerting/unified/components/rules/GrafanaRules.tsx @@ -40,7 +40,7 @@ export const GrafanaRules = ({ namespaces, expandAll }: Props) => { const loading = prom.loading || ruler.loading; const hasResult = !!prom.result || !!ruler.result; - const wantsListView = queryParams['view'] === 'list'; + const wantsListView = queryParams.view === 'list'; const namespacesFormat = wantsListView ? flattenGrafanaManagedRules(namespaces) : namespaces; const groupsWithNamespaces = useCombinedGroupNamespace(namespacesFormat); diff --git a/public/app/features/alerting/unified/components/rules/central-state-history/EventListSceneObject.tsx b/public/app/features/alerting/unified/components/rules/central-state-history/EventListSceneObject.tsx index 2f358a3b273a..0ba6f9d4e7a7 100644 --- a/public/app/features/alerting/unified/components/rules/central-state-history/EventListSceneObject.tsx +++ b/public/app/features/alerting/unified/components/rules/central-state-history/EventListSceneObject.tsx @@ -232,7 +232,7 @@ function AlertRuleName({ labels, ruleUID }: AlertRuleNameProps) { const styles = useStyles2(getStyles); const { pathname, search } = useLocation(); const returnTo = `${pathname}${search}`; - const alertRuleName = labels['alertname']; + const alertRuleName = labels.alertname; if (!ruleUID) { return ( diff --git a/public/app/features/alerting/unified/hooks/useCombinedRuleNamespaces.ts b/public/app/features/alerting/unified/hooks/useCombinedRuleNamespaces.ts index 4aef92130ab2..7085c0ee0b98 100644 --- a/public/app/features/alerting/unified/hooks/useCombinedRuleNamespaces.ts +++ b/public/app/features/alerting/unified/hooks/useCombinedRuleNamespaces.ts @@ -288,11 +288,11 @@ export function calculateRuleTotals(rule: Pick): Rec } export const getFiltersFromUrlParams = (queryParams: UrlQueryMap): FilterState => { - const queryString = queryParams['queryString'] === undefined ? undefined : String(queryParams['queryString']); - const alertState = queryParams['alertState'] === undefined ? undefined : String(queryParams['alertState']); - const dataSource = queryParams['dataSource'] === undefined ? undefined : String(queryParams['dataSource']); - const ruleType = queryParams['ruleType'] === undefined ? undefined : String(queryParams['ruleType']); - const groupBy = queryParams['groupBy'] === undefined ? undefined : String(queryParams['groupBy']).split(','); + const queryString = queryParams.queryString === undefined ? undefined : String(queryParams.queryString); + const alertState = queryParams.alertState === undefined ? undefined : String(queryParams.alertState); + const dataSource = queryParams.dataSource === undefined ? undefined : String(queryParams.dataSource); + const ruleType = queryParams.ruleType === undefined ? undefined : String(queryParams.ruleType); + const groupBy = queryParams.groupBy === undefined ? undefined : String(queryParams.groupBy).split(','); return { queryString, alertState, dataSource, groupBy, ruleType }; }; @@ -91,8 +91,8 @@ export const getNotificationPoliciesFilters = (searchParams: URLSearchParams) => }; export const getSilenceFiltersFromUrlParams = (queryParams: UrlQueryMap): SilenceFilterState => { - const queryString = queryParams['queryString'] === undefined ? undefined : String(queryParams['queryString']); - const silenceState = queryParams['silenceState'] === undefined ? undefined : String(queryParams['silenceState']); + const queryString = queryParams.queryString === undefined ? undefined : String(queryParams.queryString); + const silenceState = queryParams.silenceState === undefined ? undefined : String(queryParams.silenceState); return { queryString, silenceState }; }; diff --git a/public/app/features/alerting/unified/utils/rules.ts b/public/app/features/alerting/unified/utils/rules.ts index 1de6d2fbce20..c0830d19dc92 100644 --- a/public/app/features/alerting/unified/utils/rules.ts +++ b/public/app/features/alerting/unified/utils/rules.ts @@ -148,7 +148,7 @@ export function getRulePluginOrigin(rule: CombinedRule): RulePluginOrigin | unde return undefined; } - const pluginId = match.groups['pluginId']; + const pluginId = match.groups.pluginId; const pluginInstalled = isPluginInstalled(pluginId); if (!pluginInstalled) {