diff --git a/.eslintrc.js b/.eslintrc.js index ba931513ee0a4..6305e654b5657 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1566,13 +1566,6 @@ module.exports = { plugins: ['react', '@typescript-eslint'], rules: { 'import/no-nodejs-modules': 'error', - 'no-restricted-imports': [ - 'error', - { - // prevents UI code from importing server side code and then webpack including it when doing builds - patterns: ['**/server/*'], - }, - ], 'react/boolean-prop-naming': 'error', 'react/button-has-type': 'error', 'react/display-name': 'error', @@ -1636,10 +1629,6 @@ module.exports = { 'no-restricted-imports': [ 'error', { - // prevents code from importing files that contain the name "legacy" within their name. This is a mechanism - // to help deprecation and prevent accidental re-use/continued use of code we plan on removing. If you are - // finding yourself turning this off a lot for "new code" consider renaming the file and functions if it is has valid uses. - patterns: ['*legacy*'], paths: [ { name: 'react-router-dom', diff --git a/package.json b/package.json index f5e201b0a98ec..30c640e71cbed 100644 --- a/package.json +++ b/package.json @@ -1845,4 +1845,4 @@ "zod-to-json-schema": "^3.23.0" }, "packageManager": "yarn@1.22.21" -} +} \ No newline at end of file diff --git a/x-pack/plugins/alerting/server/alerts_client/alerts_client.ts b/x-pack/plugins/alerting/server/alerts_client/alerts_client.ts index 477f309be27f0..ef13343f509f3 100644 --- a/x-pack/plugins/alerting/server/alerts_client/alerts_client.ts +++ b/x-pack/plugins/alerting/server/alerts_client/alerts_client.ts @@ -28,11 +28,11 @@ import type { WithoutReservedActionGroups, DataStreamAdapter, } from '../types'; + import { LegacyAlertsClient } from './legacy_alerts_client'; import type { IIndexPatternString } from '../alerts_service/resource_installer_utils'; import { getIndexTemplateAndPattern } from '../alerts_service/resource_installer_utils'; import type { CreateAlertsClientParams } from '../alerts_service/alerts_service'; -import type { AlertRule, LogAlertsOpts, ProcessAlertsOpts, SearchResult } from './types'; import type { IAlertsClient, InitializeExecutionOpts, @@ -43,6 +43,10 @@ import type { GetSummarizedAlertsParams, GetMaintenanceWindowScopedQueryAlertsParams, ScopedQueryAggregationResult, + AlertRule, + LogAlertsOpts, + ProcessAlertsOpts, + SearchResult, } from './types'; import { buildNewAlert, @@ -326,7 +330,7 @@ export class AlertsClient< // Persist alerts first await this.persistAlertsHelper(); - return await this.updatePersistedAlertsWithMaintenanceWindowIds(); + return this.updatePersistedAlertsWithMaintenanceWindowIds(); } public getAlertsToSerialize() { diff --git a/x-pack/plugins/alerting/server/alerts_service/alerts_service.test.ts b/x-pack/plugins/alerting/server/alerts_service/alerts_service.test.ts index e43ff7e40b431..db9760e46410c 100644 --- a/x-pack/plugins/alerting/server/alerts_service/alerts_service.test.ts +++ b/x-pack/plugins/alerting/server/alerts_service/alerts_service.test.ts @@ -1974,7 +1974,7 @@ describe('Alerts Service', () => { await new Promise((r) => setTimeout(r, delayMs)); } - return await alertsService.createAlertsClient({ + return alertsService.createAlertsClient({ alertingEventLogger, logger, request: fakeRequest, @@ -2081,7 +2081,7 @@ describe('Alerts Service', () => { await new Promise((r) => setTimeout(r, delayMs)); } - return await alertsService.createAlertsClient({ + return alertsService.createAlertsClient({ alertingEventLogger, logger, request: fakeRequest, diff --git a/x-pack/plugins/alerting/server/alerts_service/alerts_service.ts b/x-pack/plugins/alerting/server/alerts_service/alerts_service.ts index 4d3497d6d8d39..51afd98388edf 100644 --- a/x-pack/plugins/alerting/server/alerts_service/alerts_service.ts +++ b/x-pack/plugins/alerting/server/alerts_service/alerts_service.ts @@ -369,7 +369,7 @@ export class AlertsService implements IAlertsService { await Promise.all( initFns.map((fn) => installWithTimeout({ - installFn: async () => await fn(), + installFn: async () => fn(), pluginStop$: this.options.pluginStop$, logger: this.options.logger, timeoutMs, @@ -430,14 +430,13 @@ export class AlertsService implements IAlertsService { dynamic: mappings.dynamic, context, }); - initFns.push( - async () => - await createOrUpdateComponentTemplate({ - logger: this.options.logger, - esClient, - template: componentTemplate, - totalFieldsLimit: TOTAL_FIELDS_LIMIT, - }) + initFns.push(async () => + createOrUpdateComponentTemplate({ + logger: this.options.logger, + esClient, + template: componentTemplate, + totalFieldsLimit: TOTAL_FIELDS_LIMIT, + }) ); componentTemplateRefs.push(componentTemplate.name); } @@ -453,7 +452,7 @@ export class AlertsService implements IAlertsService { // Context specific initialization installs index template and write index initFns = initFns.concat([ async () => - await createOrUpdateIndexTemplate({ + createOrUpdateIndexTemplate({ logger: this.options.logger, esClient, template: getIndexTemplate({ @@ -467,7 +466,7 @@ export class AlertsService implements IAlertsService { }), }), async () => - await createConcreteWriteIndex({ + createConcreteWriteIndex({ logger: this.options.logger, esClient, totalFieldsLimit: TOTAL_FIELDS_LIMIT, @@ -481,7 +480,7 @@ export class AlertsService implements IAlertsService { // the component template. for (const fn of initFns) { await installWithTimeout({ - installFn: async () => await fn(), + installFn: async () => fn(), pluginStop$: this.options.pluginStop$, logger: this.options.logger, timeoutMs, diff --git a/x-pack/plugins/alerting/server/alerts_service/test_utils.ts b/x-pack/plugins/alerting/server/alerts_service/test_utils.ts index 1d710caf57670..17f940fc0954f 100644 --- a/x-pack/plugins/alerting/server/alerts_service/test_utils.ts +++ b/x-pack/plugins/alerting/server/alerts_service/test_utils.ts @@ -15,9 +15,10 @@ export const retryUntil = async ( count: number = RETRY_UNTIL_DEFAULT_COUNT, wait: number = RETRY_UNTIL_DEFAULT_WAIT ): Promise => { + let _count = count; await delay(wait); - while (count > 0) { - count--; + while (_count > 0) { + _count--; if (await fn()) return true; @@ -31,4 +32,4 @@ export const retryUntil = async ( return false; }; -const delay = async (millis: number) => await new Promise((resolve) => setTimeout(resolve, millis)); +const delay = async (millis: number) => new Promise((resolve) => setTimeout(resolve, millis)); diff --git a/x-pack/plugins/alerting/server/application/backfill/methods/delete/delete_backfill.ts b/x-pack/plugins/alerting/server/application/backfill/methods/delete/delete_backfill.ts index 545fd6f3b24d4..9a9d595d29363 100644 --- a/x-pack/plugins/alerting/server/application/backfill/methods/delete/delete_backfill.ts +++ b/x-pack/plugins/alerting/server/application/backfill/methods/delete/delete_backfill.ts @@ -17,10 +17,8 @@ import { } from '../../../../rules_client/common/audit_events'; export async function deleteBackfill(context: RulesClientContext, id: string): Promise<{}> { - return await retryIfConflicts( - context.logger, - `rulesClient.deleteBackfill('${id}')`, - async () => await deleteWithOCC(context, { id }) + return retryIfConflicts(context.logger, `rulesClient.deleteBackfill('${id}')`, async () => + deleteWithOCC(context, { id }) ); } diff --git a/x-pack/plugins/alerting/server/application/backfill/methods/schedule/schedule_backfill.ts b/x-pack/plugins/alerting/server/application/backfill/methods/schedule/schedule_backfill.ts index 67f629d4be274..e23cdc0d4e6b1 100644 --- a/x-pack/plugins/alerting/server/application/backfill/methods/schedule/schedule_backfill.ts +++ b/x-pack/plugins/alerting/server/application/backfill/methods/schedule/schedule_backfill.ts @@ -145,7 +145,7 @@ export async function scheduleBackfill( } const actionsClient = await context.getActionsClient(); - return await context.backfillClient.bulkQueue({ + return context.backfillClient.bulkQueue({ auditLogger: context.auditLogger, params, rules: rulesToSchedule.map(({ id, attributes, references }) => { diff --git a/x-pack/plugins/alerting/server/application/maintenance_window/methods/archive/archive_maintenance_window.ts b/x-pack/plugins/alerting/server/application/maintenance_window/methods/archive/archive_maintenance_window.ts index 461f88288ced3..9822562bbd2f9 100644 --- a/x-pack/plugins/alerting/server/application/maintenance_window/methods/archive/archive_maintenance_window.ts +++ b/x-pack/plugins/alerting/server/application/maintenance_window/methods/archive/archive_maintenance_window.ts @@ -36,11 +36,11 @@ export async function archiveMaintenanceWindow( context: MaintenanceWindowClientContext, params: ArchiveMaintenanceWindowParams ): Promise { - return await retryIfConflicts( + return retryIfConflicts( context.logger, `maintenanceWindowClient.archive('${params.id})`, async () => { - return await archiveWithOCC(context, params); + return archiveWithOCC(context, params); } ); } diff --git a/x-pack/plugins/alerting/server/application/maintenance_window/methods/delete/delete_maintenance_window.ts b/x-pack/plugins/alerting/server/application/maintenance_window/methods/delete/delete_maintenance_window.ts index 44bcdd9f55049..60fe42580b201 100644 --- a/x-pack/plugins/alerting/server/application/maintenance_window/methods/delete/delete_maintenance_window.ts +++ b/x-pack/plugins/alerting/server/application/maintenance_window/methods/delete/delete_maintenance_window.ts @@ -16,10 +16,10 @@ export async function deleteMaintenanceWindow( context: MaintenanceWindowClientContext, params: DeleteMaintenanceWindowParams ): Promise<{}> { - return await retryIfConflicts( + return retryIfConflicts( context.logger, `maintenanceWindowClient.delete('${params.id}')`, - async () => await deleteWithOCC(context, params) + async () => deleteWithOCC(context, params) ); } diff --git a/x-pack/plugins/alerting/server/application/maintenance_window/methods/finish/finish_maintenance_window.ts b/x-pack/plugins/alerting/server/application/maintenance_window/methods/finish/finish_maintenance_window.ts index e7ef970ba4c0b..3ce917f7858ec 100644 --- a/x-pack/plugins/alerting/server/application/maintenance_window/methods/finish/finish_maintenance_window.ts +++ b/x-pack/plugins/alerting/server/application/maintenance_window/methods/finish/finish_maintenance_window.ts @@ -31,11 +31,11 @@ export async function finishMaintenanceWindow( context: MaintenanceWindowClientContext, params: FinishMaintenanceWindowParams ): Promise { - return await retryIfConflicts( + return retryIfConflicts( context.logger, `maintenanceWindowClient.finish('${params.id})`, async () => { - return await finishWithOCC(context, params); + return finishWithOCC(context, params); } ); } diff --git a/x-pack/plugins/alerting/server/application/maintenance_window/methods/update/update_maintenance_window.ts b/x-pack/plugins/alerting/server/application/maintenance_window/methods/update/update_maintenance_window.ts index 09fa2efe36075..444d2fce0b291 100644 --- a/x-pack/plugins/alerting/server/application/maintenance_window/methods/update/update_maintenance_window.ts +++ b/x-pack/plugins/alerting/server/application/maintenance_window/methods/update/update_maintenance_window.ts @@ -34,11 +34,11 @@ export async function updateMaintenanceWindow( context: MaintenanceWindowClientContext, params: UpdateMaintenanceWindowParams ): Promise { - return await retryIfConflicts( + return retryIfConflicts( context.logger, `maintenanceWindowClient.update('${params.id})`, async () => { - return await updateWithOCC(context, params); + return updateWithOCC(context, params); } ); } diff --git a/x-pack/plugins/alerting/server/application/rule/methods/bulk_delete/bulk_delete_rules.test.ts b/x-pack/plugins/alerting/server/application/rule/methods/bulk_delete/bulk_delete_rules.test.ts index 9fd1709d5f5ff..1c5016c5fefdf 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/bulk_delete/bulk_delete_rules.test.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/bulk_delete/bulk_delete_rules.test.ts @@ -16,10 +16,9 @@ import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks'; import { schema } from '@kbn/config-schema'; import { encryptedSavedObjectsMock } from '@kbn/encrypted-saved-objects-plugin/server/mocks'; import { actionsAuthorizationMock } from '@kbn/actions-plugin/server/mocks'; -import type { ActionsAuthorization } from '@kbn/actions-plugin/server'; +import type { ActionsAuthorization, ActionsClient } from '@kbn/actions-plugin/server'; import { auditLoggerMock } from '@kbn/security-plugin/server/audit/mocks'; import { loggerMock } from '@kbn/logging-mocks'; -import type { ActionsClient } from '@kbn/actions-plugin/server'; import { ruleTypeRegistryMock } from '../../../../rule_type_registry.mock'; import { alertingAuthorizationMock } from '../../../../authorization/alerting_authorization.mock'; import { RecoveredActionGroup } from '../../../../../common'; diff --git a/x-pack/plugins/alerting/server/application/rule/methods/bulk_delete/bulk_delete_rules.ts b/x-pack/plugins/alerting/server/application/rule/methods/bulk_delete/bulk_delete_rules.ts index c7899a60d014f..0a21d3f76de55 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/bulk_delete/bulk_delete_rules.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/bulk_delete/bulk_delete_rules.ts @@ -14,16 +14,17 @@ import { RULE_SAVED_OBJECT_TYPE } from '../../../../saved_objects'; import { convertRuleIdsToKueryNode } from '../../../../lib'; import { bulkMarkApiKeysForInvalidation } from '../../../../invalidate_pending_api_keys/bulk_mark_api_keys_for_invalidation'; import { ruleAuditEvent, RuleAuditAction } from '../../../../rules_client/common/audit_events'; -import { tryToRemoveTasks } from '../../../../rules_client/common'; import { API_KEY_GENERATE_CONCURRENCY } from '../../../../rules_client/common/constants'; import { getAuthorizationFilter, checkAuthorizationAndGetTotal, migrateLegacyActions, + untrackRuleAlerts, } from '../../../../rules_client/lib'; import { retryIfBulkOperationConflicts, buildKueryNodeFilter, + tryToRemoveTasks, } from '../../../../rules_client/common'; import type { RulesClientContext } from '../../../../rules_client/types'; import type { @@ -37,7 +38,6 @@ import { transformRuleAttributesToRuleDomain, transformRuleDomainToRule } from ' import { ruleDomainSchema } from '../../schemas'; import type { RuleParams, RuleDomain } from '../../types'; import type { RawRule, SanitizedRule } from '../../../../types'; -import { untrackRuleAlerts } from '../../../../rules_client/lib'; export const bulkDeleteRules = async ( context: RulesClientContext, diff --git a/x-pack/plugins/alerting/server/application/rule/methods/bulk_disable/bulk_disable_rules.ts b/x-pack/plugins/alerting/server/application/rule/methods/bulk_disable/bulk_disable_rules.ts index 27138456456e8..d72aa4ee92492 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/bulk_disable/bulk_disable_rules.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/bulk_disable/bulk_disable_rules.ts @@ -6,11 +6,14 @@ */ import type { KueryNode } from '@kbn/es-query'; import { nodeBuilder } from '@kbn/es-query'; -import type { SavedObjectsBulkUpdateObject, SavedObjectsBulkCreateObject } from '@kbn/core/server'; +import type { + SavedObjectsBulkUpdateObject, + SavedObjectsBulkCreateObject, + Logger, +} from '@kbn/core/server'; import Boom from '@hapi/boom'; import { withSpan } from '@kbn/apm-utils'; import pMap from 'p-map'; -import type { Logger } from '@kbn/core/server'; import type { TaskManagerStartContract } from '@kbn/task-manager-plugin/server'; import { RULE_SAVED_OBJECT_TYPE } from '../../../../saved_objects'; import type { RawRule, SanitizedRule, RawRuleAction } from '../../../../types'; @@ -306,7 +309,7 @@ const tryToDisableTasks = async ({ logger: Logger; taskManager: TaskManagerStartContract; }) => { - return await withSpan({ name: 'taskManager.bulkDisable', type: 'rules' }, async () => { + return withSpan({ name: 'taskManager.bulkDisable', type: 'rules' }, async () => { if (taskIdsToDisable.length > 0) { try { const resultFromDisablingTasks = await taskManager.bulkDisable( diff --git a/x-pack/plugins/alerting/server/application/rule/methods/bulk_edit/bulk_edit_rules.test.ts b/x-pack/plugins/alerting/server/application/rule/methods/bulk_edit/bulk_edit_rules.test.ts index c0ebac41a7831..006df337eecdf 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/bulk_edit/bulk_edit_rules.test.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/bulk_edit/bulk_edit_rules.test.ts @@ -36,6 +36,7 @@ import { siemRule2, } from '../../../../rules_client/tests/test_helpers'; import { migrateLegacyActions } from '../../../../rules_client/lib'; + import { migrateLegacyActionsMock } from '../../../../rules_client/lib/siem_legacy_actions/retrieve_migrated_legacy_actions.mock'; import { ConnectorAdapterRegistry } from '../../../../connector_adapters/connector_adapter_registry'; import type { ConnectorAdapter } from '../../../../connector_adapters/types'; @@ -1878,6 +1879,7 @@ describe('bulkEdit()', () => { expect(unsecuredSavedObjectsClient.bulkCreate).toHaveBeenCalledTimes(0); expect(bulkMarkApiKeysForInvalidation).toHaveBeenCalledTimes(0); + // eslint-disable-next-line require-atomic-updates bulkEditOperationsSchema.validate = originalValidate; }); }); diff --git a/x-pack/plugins/alerting/server/application/rule/methods/bulk_edit/bulk_edit_rules.ts b/x-pack/plugins/alerting/server/application/rule/methods/bulk_edit/bulk_edit_rules.ts index 7683c4017a468..cfd462d63b940 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/bulk_edit/bulk_edit_rules.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/bulk_edit/bulk_edit_rules.ts @@ -20,7 +20,6 @@ import { validateAndAuthorizeSystemActions } from '../../../../lib/validate_auth import type { Rule, RuleAction, RuleSystemAction } from '../../../../../common'; import { RULE_SAVED_OBJECT_TYPE } from '../../../../saved_objects'; import type { BulkActionSkipResult } from '../../../../../common/bulk_edit'; -import type { RuleTypeRegistry } from '../../../../types'; import { validateRuleTypeParams, getRuleNotifyWhenType, @@ -53,6 +52,7 @@ import { updateMeta, addGeneratedActionValues, createNewAPIKeySet, + migrateLegacyActions, } from '../../../../rules_client/lib'; import type { BulkOperationError, @@ -61,7 +61,6 @@ import type { NormalizedAlertActionWithGeneratedValues, NormalizedAlertAction, } from '../../../../rules_client/types'; -import { migrateLegacyActions } from '../../../../rules_client/lib'; import type { BulkEditFields, BulkEditOperation, @@ -70,7 +69,7 @@ import type { ParamsModifier, ShouldIncrementRevision, } from './types'; -import type { RawRuleAction, RawRule, SanitizedRule } from '../../../../types'; +import type { RawRuleAction, RawRule, SanitizedRule, RuleTypeRegistry } from '../../../../types'; import { ruleNotifyWhen } from '../../constants'; import { actionRequestSchema, ruleDomainSchema, systemActionRequestSchema } from '../../schemas'; import type { RuleParams, RuleDomain, RuleSnoozeSchedule } from '../../types'; diff --git a/x-pack/plugins/alerting/server/application/rule/methods/bulk_enable/bulk_enable_rules.test.ts b/x-pack/plugins/alerting/server/application/rule/methods/bulk_enable/bulk_enable_rules.test.ts index 9c7723a3c550f..ef44775ceeb49 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/bulk_enable/bulk_enable_rules.test.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/bulk_enable/bulk_enable_rules.test.ts @@ -18,12 +18,11 @@ import { alertingAuthorizationMock } from '../../../../authorization/alerting_au import { encryptedSavedObjectsMock } from '@kbn/encrypted-saved-objects-plugin/server/mocks'; import { actionsAuthorizationMock } from '@kbn/actions-plugin/server/mocks'; import type { AlertingAuthorization } from '../../../../authorization/alerting_authorization'; -import type { ActionsAuthorization } from '@kbn/actions-plugin/server'; +import type { ActionsAuthorization, ActionsClient } from '@kbn/actions-plugin/server'; import { auditLoggerMock } from '@kbn/security-plugin/server/audit/mocks'; import { getBeforeSetup, setGlobalDate } from '../../../../rules_client/tests/lib'; import { loggerMock } from '@kbn/logging-mocks'; import type { BulkUpdateTaskResult } from '@kbn/task-manager-plugin/server/task_scheduling'; -import type { ActionsClient } from '@kbn/actions-plugin/server'; import { disabledRule1, disabledRule2, diff --git a/x-pack/plugins/alerting/server/application/rule/methods/bulk_enable/bulk_enable_rules.ts b/x-pack/plugins/alerting/server/application/rule/methods/bulk_enable/bulk_enable_rules.ts index c351fe21ed66e..2fedd53b647c1 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/bulk_enable/bulk_enable_rules.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/bulk_enable/bulk_enable_rules.ts @@ -13,9 +13,9 @@ import type { SavedObjectsBulkCreateObject, SavedObjectsBulkUpdateObject, SavedObjectsFindResult, + Logger, } from '@kbn/core/server'; import { withSpan } from '@kbn/apm-utils'; -import type { Logger } from '@kbn/core/server'; import type { TaskManagerStartContract } from '@kbn/task-manager-plugin/server'; import { TaskStatus } from '@kbn/task-manager-plugin/server'; import type { TaskInstanceWithDeprecatedFields } from '@kbn/task-manager-plugin/server/task'; @@ -161,14 +161,12 @@ const bulkEnableRulesWithOCC = async ( type: 'rules', }, async () => - await context.encryptedSavedObjectsClient.createPointInTimeFinderDecryptedAsInternalUser( - { - filter, - type: RULE_SAVED_OBJECT_TYPE, - perPage: 100, - ...(context.namespace ? { namespaces: [context.namespace] } : undefined), - } - ) + context.encryptedSavedObjectsClient.createPointInTimeFinderDecryptedAsInternalUser({ + filter, + type: RULE_SAVED_OBJECT_TYPE, + perPage: 100, + ...(context.namespace ? { namespaces: [context.namespace] } : undefined), + }) ); const rulesFinderRules: Array> = []; diff --git a/x-pack/plugins/alerting/server/application/rule/methods/bulk_untrack/bulk_untrack_alerts.ts b/x-pack/plugins/alerting/server/application/rule/methods/bulk_untrack/bulk_untrack_alerts.ts index c34d3c8e7835b..125005a9733b5 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/bulk_untrack/bulk_untrack_alerts.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/bulk_untrack/bulk_untrack_alerts.ts @@ -29,10 +29,10 @@ export async function bulkUntrackAlerts( throw Boom.badRequest(`Failed to validate params: ${error.message}`); } - return await retryIfConflicts( + return retryIfConflicts( context.logger, `rulesClient.bulkUntrack('${params.alertUuids}')`, - async () => await bulkUntrackAlertsWithOCC(context, params) + async () => bulkUntrackAlertsWithOCC(context, params) ); } @@ -54,7 +54,7 @@ async function bulkUntrackAlertsWithOCC(context: RulesClientContext, params: Bul ruleTypeId: string; consumer: string; }) => - await withSpan({ name: 'authorization.ensureAuthorized', type: 'alerts' }, () => + withSpan({ name: 'authorization.ensureAuthorized', type: 'alerts' }, () => context.authorization.ensureAuthorized({ ruleTypeId, consumer, diff --git a/x-pack/plugins/alerting/server/application/rule/methods/create/create_rule.test.ts b/x-pack/plugins/alerting/server/application/rule/methods/create/create_rule.test.ts index 9411c08b5d3e2..441481b8552b1 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/create/create_rule.test.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/create/create_rule.test.ts @@ -3066,8 +3066,8 @@ describe('create()', () => { rulesClientParams.createAPIKey.mockImplementation(() => { throw new Error('no'); }); - await expect( - async () => await rulesClient.create({ data }) + await expect(async () => + rulesClient.create({ data }) ).rejects.toThrowErrorMatchingInlineSnapshot( `"Error creating rule: could not create API key - no"` ); diff --git a/x-pack/plugins/alerting/server/application/rule/methods/create/create_rule.ts b/x-pack/plugins/alerting/server/application/rule/methods/create/create_rule.ts index 8d932a885b5df..dd235049bd799 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/create/create_rule.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/create/create_rule.ts @@ -23,6 +23,7 @@ import { extractReferences, validateActions, addGeneratedActionValues, + createRuleSavedObject, } from '../../../../rules_client/lib'; import { generateAPIKeyName, apiKeyAsRuleDomainProperties } from '../../../../rules_client/common'; import { ruleAuditEvent, RuleAuditAction } from '../../../../rules_client/common/audit_events'; @@ -37,7 +38,6 @@ import { import { ruleDomainSchema } from '../../schemas'; import type { CreateRuleData } from './types'; import { createRuleDataSchema } from './schemas'; -import { createRuleSavedObject } from '../../../../rules_client/lib'; import type { ValidateScheduleLimitResult } from '../get_schedule_frequency'; import { validateScheduleLimit } from '../get_schedule_frequency'; diff --git a/x-pack/plugins/alerting/server/application/rule/methods/delete/delete_rule.ts b/x-pack/plugins/alerting/server/application/rule/methods/delete/delete_rule.ts index 2e92665f5fb2f..f7e910732ff1e 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/delete/delete_rule.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/delete/delete_rule.ts @@ -28,10 +28,8 @@ export async function deleteRule(context: RulesClientContext, params: DeleteRule const { id } = params; - return await retryIfConflicts( - context.logger, - `rulesClient.delete('${id}')`, - async () => await deleteRuleWithOCC(context, { id }) + return retryIfConflicts(context.logger, `rulesClient.delete('${id}')`, async () => + deleteRuleWithOCC(context, { id }) ); } diff --git a/x-pack/plugins/alerting/server/application/rule/methods/disable/disable_rule.test.ts b/x-pack/plugins/alerting/server/application/rule/methods/disable/disable_rule.test.ts index 200032812ceb1..2c47661f20822 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/disable/disable_rule.test.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/disable/disable_rule.test.ts @@ -26,6 +26,7 @@ import { getBeforeSetup, setGlobalDate } from '../../../../rules_client/tests/li import { eventLoggerMock } from '@kbn/event-log-plugin/server/event_logger.mock'; import { TaskStatus } from '@kbn/task-manager-plugin/server'; import { migrateLegacyActions } from '../../../../rules_client/lib'; + import { migrateLegacyActionsMock } from '../../../../rules_client/lib/siem_legacy_actions/retrieve_migrated_legacy_actions.mock'; import { ConnectorAdapterRegistry } from '../../../../connector_adapters/connector_adapter_registry'; import { RULE_SAVED_OBJECT_TYPE } from '../../../../saved_objects'; diff --git a/x-pack/plugins/alerting/server/application/rule/methods/disable/disable_rule.ts b/x-pack/plugins/alerting/server/application/rule/methods/disable/disable_rule.ts index 03dae00237f5f..87ade0d54841d 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/disable/disable_rule.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/disable/disable_rule.ts @@ -21,10 +21,8 @@ export async function disableRule( context: RulesClientContext, { id, untrack = false }: DisableRuleParams ): Promise { - return await retryIfConflicts( - context.logger, - `rulesClient.disableRule('${id}')`, - async () => await disableWithOCC(context, { id, untrack }) + return retryIfConflicts(context.logger, `rulesClient.disableRule('${id}')`, async () => + disableWithOCC(context, { id, untrack }) ); } diff --git a/x-pack/plugins/alerting/server/application/rule/methods/enable_rule/enable_rule.test.ts b/x-pack/plugins/alerting/server/application/rule/methods/enable_rule/enable_rule.test.ts index 90f1bdef9155f..cb10c7d321a67 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/enable_rule/enable_rule.test.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/enable_rule/enable_rule.test.ts @@ -25,6 +25,7 @@ import { TaskStatus } from '@kbn/task-manager-plugin/server'; import { auditLoggerMock } from '@kbn/security-plugin/server/audit/mocks'; import { getBeforeSetup, setGlobalDate } from '../../../../rules_client/tests/lib'; import { migrateLegacyActions } from '../../../../rules_client/lib'; + import { migrateLegacyActionsMock } from '../../../../rules_client/lib/siem_legacy_actions/retrieve_migrated_legacy_actions.mock'; import { ConnectorAdapterRegistry } from '../../../../connector_adapters/connector_adapter_registry'; import { @@ -427,8 +428,8 @@ describe('enable()', () => { rulesClientParams.createAPIKey.mockImplementation(() => { throw new Error('no'); }); - await expect( - async () => await rulesClient.enableRule({ id: '1' }) + await expect(async () => + rulesClient.enableRule({ id: '1' }) ).rejects.toThrowErrorMatchingInlineSnapshot(`"Error creating API key for rule - no"`); expect(taskManager.bulkEnable).not.toHaveBeenCalled(); }); @@ -436,7 +437,7 @@ describe('enable()', () => { test('throws an error if API params do not match the schema', async () => { await expect( // @ts-ignore: this is what we are testing - async () => await rulesClient.enableRule({ id: 1 }) + async () => rulesClient.enableRule({ id: 1 }) ).rejects.toThrowErrorMatchingInlineSnapshot( `"Error validating enable rule parameters - [id]: expected value of type [string] but got [number]"` ); diff --git a/x-pack/plugins/alerting/server/application/rule/methods/enable_rule/enable_rule.ts b/x-pack/plugins/alerting/server/application/rule/methods/enable_rule/enable_rule.ts index 4daafd6cf53d6..5328825ecb670 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/enable_rule/enable_rule.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/enable_rule/enable_rule.ts @@ -29,10 +29,8 @@ export async function enableRule( context: RulesClientContext, { id }: EnableRuleParams ): Promise { - return await retryIfConflicts( - context.logger, - `rulesClient.enableRule('${id}')`, - async () => await enableWithOCC(context, { id }) + return retryIfConflicts(context.logger, `rulesClient.enableRule('${id}')`, async () => + enableWithOCC(context, { id }) ); } @@ -160,37 +158,33 @@ async function enableWithOCC(context: RulesClientContext, params: EnableRulePara }, }); - try { - // to mitigate AAD issues(actions property is not used for encrypting API key in partial SO update) - // we call create with overwrite=true - if (migratedActions.hasLegacyActions) { - await context.unsecuredSavedObjectsClient.create( - RULE_SAVED_OBJECT_TYPE, - { - ...updateAttributes, - actions: migratedActions.resultedActions, - throttle: undefined, - notifyWhen: undefined, - }, - { - id, - overwrite: true, - version, - references: migratedActions.resultedReferences, - } - ); - } else { - await context.unsecuredSavedObjectsClient.update( - RULE_SAVED_OBJECT_TYPE, + // to mitigate AAD issues(actions property is not used for encrypting API key in partial SO update) + // we call create with overwrite=true + if (migratedActions.hasLegacyActions) { + await context.unsecuredSavedObjectsClient.create( + RULE_SAVED_OBJECT_TYPE, + { + ...updateAttributes, + actions: migratedActions.resultedActions, + throttle: undefined, + notifyWhen: undefined, + }, + { id, - updateAttributes, - { - version, - } - ); - } - } catch (e) { - throw e; + overwrite: true, + version, + references: migratedActions.resultedReferences, + } + ); + } else { + await context.unsecuredSavedObjectsClient.update( + RULE_SAVED_OBJECT_TYPE, + id, + updateAttributes, + { + version, + } + ); } } diff --git a/x-pack/plugins/alerting/server/application/rule/methods/find/find_rules.test.ts b/x-pack/plugins/alerting/server/application/rule/methods/find/find_rules.test.ts index 90d87b2b13891..9538bbeddc278 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/find/find_rules.test.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/find/find_rules.test.ts @@ -1038,7 +1038,7 @@ describe('find()', () => { }), }); - await expect(async () => await rulesClient.find()).rejects.toThrow(); + await expect(async () => rulesClient.find()).rejects.toThrow(); expect(auditLogger.log).toHaveBeenCalledWith( expect.objectContaining({ event: expect.objectContaining({ diff --git a/x-pack/plugins/alerting/server/application/rule/methods/mute_alert/mute_instance.ts b/x-pack/plugins/alerting/server/application/rule/methods/mute_alert/mute_instance.ts index 72dde6e74fb7a..f595a57c0e5a4 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/mute_alert/mute_instance.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/mute_alert/mute_instance.ts @@ -28,10 +28,8 @@ export async function muteInstance( throw Boom.badRequest(`Failed to validate params: ${error.message}`); } - return await retryIfConflicts( - context.logger, - `rulesClient.muteInstance('${ruleId}')`, - async () => await muteInstanceWithOCC(context, params) + return retryIfConflicts(context.logger, `rulesClient.muteInstance('${ruleId}')`, async () => + muteInstanceWithOCC(context, params) ); } diff --git a/x-pack/plugins/alerting/server/application/rule/methods/mute_all/mute_all.ts b/x-pack/plugins/alerting/server/application/rule/methods/mute_all/mute_all.ts index a9b92699acec8..8c456af15cff2 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/mute_all/mute_all.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/mute_all/mute_all.ts @@ -21,10 +21,8 @@ export async function muteAll( context: RulesClientContext, { id }: MuteAllRuleParams ): Promise { - return await retryIfConflicts( - context.logger, - `rulesClient.muteAll('${id}')`, - async () => await muteAllWithOCC(context, { id }) + return retryIfConflicts(context.logger, `rulesClient.muteAll('${id}')`, async () => + muteAllWithOCC(context, { id }) ); } diff --git a/x-pack/plugins/alerting/server/application/rule/methods/resolve/resolve_rule.ts b/x-pack/plugins/alerting/server/application/rule/methods/resolve/resolve_rule.ts index 78b0a3177e72f..443b4a6da9707 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/resolve/resolve_rule.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/resolve/resolve_rule.ts @@ -8,17 +8,15 @@ import Boom from '@hapi/boom'; import { withSpan } from '@kbn/apm-utils'; import { AlertConsumers } from '@kbn/rule-data-utils'; import { RULE_SAVED_OBJECT_TYPE } from '../../../../saved_objects'; -import { resolveRuleSavedObject } from '../../../../rules_client/lib'; +import { resolveRuleSavedObject, formatLegacyActions } from '../../../../rules_client/lib'; import { ruleAuditEvent, RuleAuditAction } from '../../../../rules_client/common/audit_events'; -import type { RuleTypeParams } from '../../../../types'; +import type { RuleTypeParams, ResolvedSanitizedRule } from '../../../../types'; import { ReadOperations, AlertingAuthorizationEntity } from '../../../../authorization'; import type { RulesClientContext } from '../../../../rules_client/types'; -import { formatLegacyActions } from '../../../../rules_client/lib'; import { transformRuleAttributesToRuleDomain, transformRuleDomainToRule } from '../../transforms'; import type { Rule } from '../../types'; import { ruleSchema } from '../../schemas'; import { resolveRuleParamsSchema } from './schemas'; -import type { ResolvedSanitizedRule } from '../../../../types'; export interface ResolveParams { id: string; diff --git a/x-pack/plugins/alerting/server/application/rule/methods/rule_types/rule_types.ts b/x-pack/plugins/alerting/server/application/rule/methods/rule_types/rule_types.ts index 9f51f0651462a..514e3fa19dc2b 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/rule_types/rule_types.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/rule_types/rule_types.ts @@ -13,7 +13,7 @@ import { import type { RulesClientContext } from '../../../../rules_client/types'; export async function listRuleTypes(context: RulesClientContext) { - return await context.authorization.filterByRuleTypeAuthorization( + return context.authorization.filterByRuleTypeAuthorization( context.ruleTypeRegistry.list(), [ReadOperations.Get, WriteOperations.Create], AlertingAuthorizationEntity.Rule diff --git a/x-pack/plugins/alerting/server/application/rule/methods/snooze/snooze_rule.ts b/x-pack/plugins/alerting/server/application/rule/methods/snooze/snooze_rule.ts index e79b67285f09e..9349a910a4e05 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/snooze/snooze_rule.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/snooze/snooze_rule.ts @@ -38,10 +38,10 @@ export async function snoozeRule( throw new RuleMutedError(snoozeDateValidationMsg); } - return await retryIfConflicts( + return retryIfConflicts( context.logger, `rulesClient.snooze('${id}', ${JSON.stringify(snoozeSchedule, null, 4)})`, - async () => await snoozeWithOCC(context, { id, snoozeSchedule }) + async () => snoozeWithOCC(context, { id, snoozeSchedule }) ); } diff --git a/x-pack/plugins/alerting/server/application/rule/methods/unmute_alert/unmute_instance.ts b/x-pack/plugins/alerting/server/application/rule/methods/unmute_alert/unmute_instance.ts index d3936cab1c9ae..2810a8e5ea8db 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/unmute_alert/unmute_instance.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/unmute_alert/unmute_instance.ts @@ -28,10 +28,8 @@ export async function unmuteInstance( throw Boom.badRequest(`Failed to validate params: ${error.message}`); } - return await retryIfConflicts( - context.logger, - `rulesClient.unmuteInstance('${ruleId}')`, - async () => await unmuteInstanceWithOCC(context, params) + return retryIfConflicts(context.logger, `rulesClient.unmuteInstance('${ruleId}')`, async () => + unmuteInstanceWithOCC(context, params) ); } diff --git a/x-pack/plugins/alerting/server/application/rule/methods/unmute_all/unmute_all.ts b/x-pack/plugins/alerting/server/application/rule/methods/unmute_all/unmute_all.ts index 556a2614c77f5..503722a69ff7a 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/unmute_all/unmute_all.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/unmute_all/unmute_all.ts @@ -21,10 +21,8 @@ export async function unmuteAll( context: RulesClientContext, { id }: UnmuteAllRuleParams ): Promise { - return await retryIfConflicts( - context.logger, - `rulesClient.unmuteAll('${id}')`, - async () => await unmuteAllWithOCC(context, { id }) + return retryIfConflicts(context.logger, `rulesClient.unmuteAll('${id}')`, async () => + unmuteAllWithOCC(context, { id }) ); } diff --git a/x-pack/plugins/alerting/server/application/rule/methods/unsnooze/unsnooze_rule.ts b/x-pack/plugins/alerting/server/application/rule/methods/unsnooze/unsnooze_rule.ts index e1e1ae723d97c..b4e3277849aa7 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/unsnooze/unsnooze_rule.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/unsnooze/unsnooze_rule.ts @@ -27,10 +27,8 @@ export async function unsnoozeRule( context: RulesClientContext, { id, scheduleIds }: UnsnoozeParams ): Promise { - return await retryIfConflicts( - context.logger, - `rulesClient.unsnooze('${id}')`, - async () => await unsnoozeWithOCC(context, { id, scheduleIds }) + return retryIfConflicts(context.logger, `rulesClient.unsnooze('${id}')`, async () => + unsnoozeWithOCC(context, { id, scheduleIds }) ); } diff --git a/x-pack/plugins/alerting/server/application/rule/methods/update/update_rule.test.ts b/x-pack/plugins/alerting/server/application/rule/methods/update/update_rule.test.ts index b72adfb187049..2cf46ca077ff6 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/update/update_rule.test.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/update/update_rule.test.ts @@ -1621,44 +1621,43 @@ describe('update()', () => { rulesClientParams.createAPIKey.mockImplementation(() => { throw new Error('no'); }); - await expect( - async () => - await rulesClient.update({ - id: '1', - data: { - schedule: { interval: '1m' }, - name: 'abc', - tags: ['foo'], - params: { - bar: true, - }, - throttle: null, - notifyWhen: 'onActiveAlert', - actions: [ - { - group: 'default', - id: '1', - params: { - foo: true, - }, + await expect(async () => + rulesClient.update({ + id: '1', + data: { + schedule: { interval: '1m' }, + name: 'abc', + tags: ['foo'], + params: { + bar: true, + }, + throttle: null, + notifyWhen: 'onActiveAlert', + actions: [ + { + group: 'default', + id: '1', + params: { + foo: true, }, - { - group: 'default', - id: '1', - params: { - foo: true, - }, + }, + { + group: 'default', + id: '1', + params: { + foo: true, }, - { - group: 'default', - id: '2', - params: { - foo: true, - }, + }, + { + group: 'default', + id: '2', + params: { + foo: true, }, - ], - }, - }) + }, + ], + }, + }) ).rejects.toThrowErrorMatchingInlineSnapshot( `"Error updating rule: could not create API key - no"` ); diff --git a/x-pack/plugins/alerting/server/application/rule/methods/update/update_rule.ts b/x-pack/plugins/alerting/server/application/rule/methods/update/update_rule.ts index 8cd814f155ddb..af6e0015918ce 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/update/update_rule.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/update/update_rule.ts @@ -85,10 +85,8 @@ export async function updateRule( context: RulesClientContext, updateParams: UpdateRuleParams ): Promise> { - return await retryIfConflicts( - context.logger, - `rulesClient.update('${updateParams.id}')`, - async () => await updateWithOCC(context, updateParams) + return retryIfConflicts(context.logger, `rulesClient.update('${updateParams.id}')`, async () => + updateWithOCC(context, updateParams) ); } diff --git a/x-pack/plugins/alerting/server/application/rule/methods/update_api_key/update_rule_api_key.test.ts b/x-pack/plugins/alerting/server/application/rule/methods/update_api_key/update_rule_api_key.test.ts index a486ae5bbabe4..e15ffe3250e13 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/update_api_key/update_rule_api_key.test.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/update_api_key/update_rule_api_key.test.ts @@ -294,8 +294,8 @@ describe('updateRuleApiKey()', () => { rulesClientParams.createAPIKey.mockImplementation(() => { throw new Error('no'); }); - await expect( - async () => await rulesClient.updateRuleApiKey({ id: '1' }) + await expect(async () => + rulesClient.updateRuleApiKey({ id: '1' }) ).rejects.toThrowErrorMatchingInlineSnapshot( `"Error updating API key for rule: could not create API key - no"` ); @@ -304,7 +304,7 @@ describe('updateRuleApiKey()', () => { test('throws an error if API params do not match the schema', async () => { await expect( // @ts-ignore: this is what we are testing - async () => await rulesClient.updateRuleApiKey({ id: 1 }) + async () => rulesClient.updateRuleApiKey({ id: 1 }) ).rejects.toThrowErrorMatchingInlineSnapshot( `"Error validating update api key parameters - [id]: expected value of type [string] but got [number]"` ); diff --git a/x-pack/plugins/alerting/server/application/rule/methods/update_api_key/update_rule_api_key.ts b/x-pack/plugins/alerting/server/application/rule/methods/update_api_key/update_rule_api_key.ts index 7f37583019ada..65e9c61811273 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/update_api_key/update_rule_api_key.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/update_api_key/update_rule_api_key.ts @@ -21,10 +21,8 @@ export async function updateRuleApiKey( context: RulesClientContext, { id }: UpdateApiKeyParams ): Promise { - return await retryIfConflicts( - context.logger, - `rulesClient.updateRuleApiKey('${id}')`, - async () => await updateApiKeyWithOCC(context, { id }) + return retryIfConflicts(context.logger, `rulesClient.updateRuleApiKey('${id}')`, async () => + updateApiKeyWithOCC(context, { id }) ); } diff --git a/x-pack/plugins/alerting/server/application/rule/transforms/transform_rule_attributes_to_rule_domain.ts b/x-pack/plugins/alerting/server/application/rule/transforms/transform_rule_attributes_to_rule_domain.ts index 885538ee81ee8..3d77f86e41622 100644 --- a/x-pack/plugins/alerting/server/application/rule/transforms/transform_rule_attributes_to_rule_domain.ts +++ b/x-pack/plugins/alerting/server/application/rule/transforms/transform_rule_attributes_to_rule_domain.ts @@ -5,8 +5,7 @@ * 2.0. */ import { isEmpty } from 'lodash'; -import type { Logger } from '@kbn/core/server'; -import type { SavedObjectReference } from '@kbn/core/server'; +import type { Logger, SavedObjectReference } from '@kbn/core/server'; import { ruleExecutionStatusValues } from '../constants'; import { getRuleSnoozeEndTime } from '../../../lib'; import type { RuleDomain, Monitoring, RuleParams } from '../types'; diff --git a/x-pack/plugins/alerting/server/authorization/alerting_authorization.ts b/x-pack/plugins/alerting/server/authorization/alerting_authorization.ts index d2e30e778ae67..9bfd46ec03c2a 100644 --- a/x-pack/plugins/alerting/server/authorization/alerting_authorization.ts +++ b/x-pack/plugins/alerting/server/authorization/alerting_authorization.ts @@ -123,7 +123,7 @@ export class AlertingAuthorization { // ignore features which are disabled in the user's space !disabledFeatures.has(id) && // ignore features which don't grant privileges to alerting - (alerting?.length ?? 0 > 0) + Boolean(alerting?.length) ) .map((feature) => feature.id) ) diff --git a/x-pack/plugins/alerting/server/integration_tests/lib/setup_test_servers.ts b/x-pack/plugins/alerting/server/integration_tests/lib/setup_test_servers.ts index 4b722d5460213..3082634691dd7 100644 --- a/x-pack/plugins/alerting/server/integration_tests/lib/setup_test_servers.ts +++ b/x-pack/plugins/alerting/server/integration_tests/lib/setup_test_servers.ts @@ -31,7 +31,7 @@ export async function setupTestServers(settings = {}) { root, coreSetup, coreStart, - stop: async () => await root.shutdown(), + stop: async () => root.shutdown(), }, }; } diff --git a/x-pack/plugins/alerting/server/lib/errors/rule_muted.ts b/x-pack/plugins/alerting/server/lib/errors/rule_muted.ts index 13c04df0be045..4d279a3af5e2d 100644 --- a/x-pack/plugins/alerting/server/lib/errors/rule_muted.ts +++ b/x-pack/plugins/alerting/server/lib/errors/rule_muted.ts @@ -9,10 +9,6 @@ import type { KibanaResponseFactory } from '@kbn/core/server'; import type { ErrorThatHandlesItsOwnResponse } from './types'; export class RuleMutedError extends Error implements ErrorThatHandlesItsOwnResponse { - constructor(message: string) { - super(message); - } - public sendResponse(res: KibanaResponseFactory) { return res.badRequest({ body: { message: this.message } }); } diff --git a/x-pack/plugins/alerting/server/lib/retry_if_conflicts.test.ts b/x-pack/plugins/alerting/server/lib/retry_if_conflicts.test.ts index d1af51e179233..6166061c0a208 100644 --- a/x-pack/plugins/alerting/server/lib/retry_if_conflicts.test.ts +++ b/x-pack/plugins/alerting/server/lib/retry_if_conflicts.test.ts @@ -71,9 +71,10 @@ async function OperationFailure() { } function getOperationConflictsTimes(times: number) { + let _times = times; return async function OperationConflictsTimes() { - times--; - if (times >= 0) { + _times--; + if (_times >= 0) { throw SavedObjectsErrorHelpers.createConflictError(RULE_SAVED_OBJECT_TYPE, MockAlertId); } diff --git a/x-pack/plugins/alerting/server/lib/retry_if_conflicts.ts b/x-pack/plugins/alerting/server/lib/retry_if_conflicts.ts index 7327d2b9d1952..c01815df0aea6 100644 --- a/x-pack/plugins/alerting/server/lib/retry_if_conflicts.ts +++ b/x-pack/plugins/alerting/server/lib/retry_if_conflicts.ts @@ -49,7 +49,7 @@ export async function retryIfConflicts( // delay a bit before retrying logger.debug(`${name} conflict, retrying ...`); await waitBeforeNextRetry(); - return await retryIfConflicts(logger, name, operation, retries - 1); + return retryIfConflicts(logger, name, operation, retries - 1); } } diff --git a/x-pack/plugins/alerting/server/lib/track_legacy_route_usage.test.ts b/x-pack/plugins/alerting/server/lib/track_legacy_route_usage.test.ts index 1c48cdd902111..72770ee2c0716 100644 --- a/x-pack/plugins/alerting/server/lib/track_legacy_route_usage.test.ts +++ b/x-pack/plugins/alerting/server/lib/track_legacy_route_usage.test.ts @@ -5,6 +5,7 @@ * 2.0. */ import { usageCountersServiceMock } from '@kbn/usage-collection-plugin/server/usage_counters/usage_counters_service.mock'; + import { trackLegacyRouteUsage } from './track_legacy_route_usage'; describe('trackLegacyRouteUsage', () => { diff --git a/x-pack/plugins/alerting/server/lib/wrap_scoped_cluster_client.test.ts b/x-pack/plugins/alerting/server/lib/wrap_scoped_cluster_client.test.ts index a3d3ab7294e2b..f9bbf0be281ca 100644 --- a/x-pack/plugins/alerting/server/lib/wrap_scoped_cluster_client.test.ts +++ b/x-pack/plugins/alerting/server/lib/wrap_scoped_cluster_client.test.ts @@ -6,8 +6,7 @@ */ import type { Client } from '@elastic/elasticsearch'; -import { loggingSystemMock } from '@kbn/core/server/mocks'; -import { elasticsearchServiceMock } from '@kbn/core/server/mocks'; +import { loggingSystemMock, elasticsearchServiceMock } from '@kbn/core/server/mocks'; import { createWrappedScopedClusterClientFactory } from './wrap_scoped_cluster_client'; const esQuery = { diff --git a/x-pack/plugins/alerting/server/plugin.ts b/x-pack/plugins/alerting/server/plugin.ts index 2dc103ddb6127..b745e14a9d42e 100644 --- a/x-pack/plugins/alerting/server/plugin.ts +++ b/x-pack/plugins/alerting/server/plugin.ts @@ -11,7 +11,10 @@ import { BehaviorSubject, ReplaySubject, map, distinctUntilChanged } from 'rxjs' import { pick } from 'lodash'; import type { UsageCollectionSetup, UsageCounter } from '@kbn/usage-collection-plugin/server'; import type { SecurityPluginSetup, SecurityPluginStart } from '@kbn/security-plugin/server'; -import type { PluginSetup as DataPluginSetup } from '@kbn/data-plugin/server'; +import type { + PluginSetup as DataPluginSetup, + PluginStart as DataPluginStart, +} from '@kbn/data-plugin/server'; import type { PluginStart as DataViewsPluginStart } from '@kbn/data-views-plugin/server'; import type { EncryptedSavedObjectsPluginSetup, @@ -49,7 +52,6 @@ import type { } from '@kbn/event-log-plugin/server'; import type { FeaturesPluginStart, FeaturesPluginSetup } from '@kbn/features-plugin/server'; import type { PluginSetup as UnifiedSearchServerPluginSetup } from '@kbn/unified-search-plugin/server'; -import type { PluginStart as DataPluginStart } from '@kbn/data-plugin/server'; import type { MonitoringCollectionSetup } from '@kbn/monitoring-collection-plugin/server'; import type { SharePluginStart } from '@kbn/share-plugin/server'; import type { ServerlessPluginSetup } from '@kbn/serverless/server'; @@ -65,7 +67,6 @@ import { import { MaintenanceWindowClientFactory } from './maintenance_window_client_factory'; import type { ILicenseState } from './lib/license_state'; import { LicenseState } from './lib/license_state'; -import type { AlertingRequestHandlerContext, RuleAlertData } from './types'; import { ALERTING_FEATURE_ID } from './types'; import { defineRoutes } from './routes'; import type { @@ -76,6 +77,8 @@ import type { RuleTypeParams, RuleTypeState, RulesClientApi, + AlertingRequestHandlerContext, + RuleAlertData, } from './types'; import { registerAlertingUsageCollector } from './usage'; import { initializeAlertingTelemetry, scheduleAlertingTelemetry } from './usage/task'; @@ -454,7 +457,7 @@ export class AlertingPlugin { ruleTypeRegistry.register(ruleType); }, getSecurityHealth: async () => { - return await getSecurityHealth( + return getSecurityHealth( async () => (this.licenseState ? this.licenseState.getIsSecurityEnabled() : null), async () => plugins.encryptedSavedObjects.canEncrypt, async () => { @@ -630,7 +633,7 @@ export class AlertingPlugin { const client = getRulesClientWithRequest(request); return (objects?: SavedObjectsBulkGetObject[]) => objects - ? Promise.all(objects.map(async (objectItem) => await client.get({ id: objectItem.id }))) + ? Promise.all(objects.map(async (objectItem) => client.get({ id: objectItem.id }))) : Promise.resolve([]); }); @@ -653,7 +656,7 @@ export class AlertingPlugin { getAlertingAuthorizationWithRequest, getRulesClientWithRequest, getFrameworkHealth: async () => - await getHealth(core.savedObjects.createInternalRepository([RULE_SAVED_OBJECT_TYPE])), + getHealth(core.savedObjects.createInternalRepository([RULE_SAVED_OBJECT_TYPE])), }; } @@ -683,7 +686,7 @@ export class AlertingPlugin { }, listTypes: ruleTypeRegistry!.list.bind(ruleTypeRegistry!), getFrameworkHealth: async () => - await getHealth(savedObjects.createInternalRepository([RULE_SAVED_OBJECT_TYPE])), + getHealth(savedObjects.createInternalRepository([RULE_SAVED_OBJECT_TYPE])), areApiKeysEnabled: async () => { const [, { security }] = await core.getStartServices(); return security?.authc.apiKeys.areAPIKeysEnabled() ?? false; diff --git a/x-pack/plugins/alerting/server/rules_client_conflict_retries.test.ts b/x-pack/plugins/alerting/server/rules_client_conflict_retries.test.ts index 0a958466bd854..8830efb15b7ec 100644 --- a/x-pack/plugins/alerting/server/rules_client_conflict_retries.test.ts +++ b/x-pack/plugins/alerting/server/rules_client_conflict_retries.test.ts @@ -252,7 +252,7 @@ function expectConflict(success: boolean, err: Error, method: 'update' | 'create // wrapper to call the test function with a it's own name function testFn(fn: (success: boolean) => unknown, success: boolean) { - test(`${fn.name}`, async () => await fn(success)); + test(`${fn.name}`, async () => fn(success)); } // set up mocks for update or create (the update() method uses create!) diff --git a/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts b/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts index 0cd67d873ae97..6a593db801af8 100644 --- a/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts +++ b/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts @@ -265,7 +265,7 @@ export class AdHocTaskRunner implements CancellableTask { */ private async prepareToRun(): Promise { this.runDate = new Date(); - return await this.timer.runWithTimer(TaskRunnerTimerSpan.PrepareRule, async () => { + return this.timer.runWithTimer(TaskRunnerTimerSpan.PrepareRule, async () => { const { params: { adHocRunParamsId, spaceId }, startedAt, diff --git a/x-pack/plugins/cases/public/common/test_utils.tsx b/x-pack/plugins/cases/public/common/test_utils.tsx index 1cbf5e2a5d454..b1ba64bd446de 100644 --- a/x-pack/plugins/cases/public/common/test_utils.tsx +++ b/x-pack/plugins/cases/public/common/test_utils.tsx @@ -52,7 +52,6 @@ interface FormTestComponentProps { children: React.ReactNode; } -// eslint-disable-next-line react/display-name export const FormTestComponent: FC> = ({ children, onSubmit, diff --git a/x-pack/plugins/cases/public/common/translations.ts b/x-pack/plugins/cases/public/common/translations.ts index 7fa5b54db00ec..0ac3025b543bd 100644 --- a/x-pack/plugins/cases/public/common/translations.ts +++ b/x-pack/plugins/cases/public/common/translations.ts @@ -15,7 +15,7 @@ export const CANCEL = i18n.translate('xpack.cases.caseView.cancel', { defaultMessage: 'Cancel', }); -export const DELETE_CASE = (quantity: number = 1) => +export const DELETE_CASE = (quantity = 1) => i18n.translate('xpack.cases.confirmDeleteCase.deleteCase', { values: { quantity }, defaultMessage: `Delete {quantity, plural, =1 {case} other {{quantity} cases}}`, @@ -322,7 +322,7 @@ export const CASE_SUCCESS_TOAST = (title: string) => defaultMessage: '{title} has been updated', }); -export const CASE_ALERT_SUCCESS_TOAST = (title: string, quantity: number = 1) => +export const CASE_ALERT_SUCCESS_TOAST = (title: string, quantity = 1) => i18n.translate('xpack.cases.actions.caseAlertSuccessToast', { values: { quantity, title }, defaultMessage: '{quantity, plural, =1 {An alert was} other {Alerts were}} added to "{title}"', diff --git a/x-pack/plugins/cases/public/components/add_comment/index.tsx b/x-pack/plugins/cases/public/components/add_comment/index.tsx index c84f799b1c899..810d0fbbe2b3a 100644 --- a/x-pack/plugins/cases/public/components/add_comment/index.tsx +++ b/x-pack/plugins/cases/public/components/add_comment/index.tsx @@ -180,7 +180,7 @@ export const AddComment = React.memo( return ( - {isLoading && showLoading && ( + {isLoading && showLoading ? ( - )} - {permissions.create && ( + ) : null} + {permissions.create ? (
- {statusActionButton && ( + {statusActionButton ? ( {statusActionButton} - )} + ) : null} - )} + ) : null}
); } diff --git a/x-pack/plugins/cases/public/components/all_cases/columns_popover.tsx b/x-pack/plugins/cases/public/components/all_cases/columns_popover.tsx index 25c4de69b731d..90aa638f183f7 100644 --- a/x-pack/plugins/cases/public/components/all_cases/columns_popover.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/columns_popover.tsx @@ -182,7 +182,7 @@ export const ColumnsPopover: React.FC = ({ }} /> - {isDragEnabled && ( + {isDragEnabled ? ( = ({ - )} + ) : null} )} diff --git a/x-pack/plugins/cases/public/components/all_cases/multi_select_filter.tsx b/x-pack/plugins/cases/public/components/all_cases/multi_select_filter.tsx index eb299ee59250b..c0e7233b8e820 100644 --- a/x-pack/plugins/cases/public/components/all_cases/multi_select_filter.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/multi_select_filter.tsx @@ -159,7 +159,7 @@ export const MultiSelectFilter = ({ }} data-test-subj={`options-filter-popover-${id}`} > - {isInvalid && ( + {isInvalid ? ( <> ({ /> - )} + ) : null} > options={options} searchable diff --git a/x-pack/plugins/cases/public/components/all_cases/nav_buttons.tsx b/x-pack/plugins/cases/public/components/all_cases/nav_buttons.tsx index 310340f0366eb..8ca27d2e29417 100644 --- a/x-pack/plugins/cases/public/components/all_cases/nav_buttons.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/nav_buttons.tsx @@ -50,7 +50,7 @@ export const NavButtons: FunctionComponent = ({ actionsErrors }) => { } `} > - {permissions.settings && ( + {permissions.settings ? ( = ({ actionsErrors }) => { titleTooltip={!isEmpty(actionsErrors) ? actionsErrors[0].title : ''} /> - )} - {permissions.create && ( + ) : null} + {permissions.create ? ( = ({ actionsErrors }) => { {i18n.CREATE_CASE_TITLE} - )} + ) : null} ); diff --git a/x-pack/plugins/cases/public/components/all_cases/table.tsx b/x-pack/plugins/cases/public/components/all_cases/table.tsx index c95059660b3e4..577f3ce440c4c 100644 --- a/x-pack/plugins/cases/public/components/all_cases/table.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/table.tsx @@ -79,45 +79,43 @@ export const CasesTable: FunctionComponent = ({ ) : ( - <> - {i18n.NO_CASES}} - titleSize="xs" - body={permissions.create ? i18n.NO_CASES_BODY : i18n.NO_CASES_BODY_READ_ONLY} - actions={ - permissions.create && ( - - {i18n.CREATE_CASE_TITLE} - - ) - } - /> - } - onChange={onChange} - pagination={pagination} - ref={tableRef} - rowProps={tableRowProps} - selection={!isSelectorView ? selection : undefined} - sorting={sorting} - /> - + {i18n.NO_CASES}} + titleSize="xs" + body={permissions.create ? i18n.NO_CASES_BODY : i18n.NO_CASES_BODY_READ_ONLY} + actions={ + permissions.create ? ( + + {i18n.CREATE_CASE_TITLE} + + ) : null + } + /> + } + onChange={onChange} + pagination={pagination} + ref={tableRef} + rowProps={tableRowProps} + selection={!isSelectorView ? selection : undefined} + sorting={sorting} + /> ); }; CasesTable.displayName = 'CasesTable'; diff --git a/x-pack/plugins/cases/public/components/all_cases/use_all_cases_state.tsx b/x-pack/plugins/cases/public/components/all_cases/use_all_cases_state.tsx index 094c5605edbe0..ccb0f2f0cd0f8 100644 --- a/x-pack/plugins/cases/public/components/all_cases/use_all_cases_state.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/use_all_cases_state.tsx @@ -33,7 +33,7 @@ interface UseAllCasesStateReturn { queryParams: QueryParams; } -export function useAllCasesState(isModalView: boolean = false): UseAllCasesStateReturn { +export function useAllCasesState(isModalView = false): UseAllCasesStateReturn { const isStateLoadedFromLocalStorage = useRef(false); const isFirstRun = useRef(false); const [tableState, setTableState] = useState(DEFAULT_CASES_TABLE_STATE); diff --git a/x-pack/plugins/cases/public/components/all_cases/use_cases_columns.tsx b/x-pack/plugins/cases/public/components/all_cases/use_cases_columns.tsx index efdc443366886..dd45961345877 100644 --- a/x-pack/plugins/cases/public/components/all_cases/use_cases_columns.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/use_cases_columns.tsx @@ -409,7 +409,7 @@ export const ExternalServiceColumn: React.FC = ({ theCase, connectors }) return (

- {actions.read && ( + {actions.read ? ( = ({ theCase, connectors }) data-test-subj="cases-table-connector-icon" /> - )} + ) : null} = React.memo( - {!isSelectorView && showBulkActions && ( + {!isSelectorView && showBulkActions ? ( <> @@ -202,7 +202,7 @@ export const CasesTableUtilityBar: FunctionComponent = React.memo( - )} + ) : null} = React.memo( {modals} {flyouts} - {hasReachedMaxCases && !isMessageDismissed && !doNotShowAgain && ( + {hasReachedMaxCases && !isMessageDismissed && !doNotShowAgain ? ( <> @@ -259,7 +259,7 @@ export const CasesTableUtilityBar: FunctionComponent = React.memo( - )} + ) : null} ); } diff --git a/x-pack/plugins/cases/public/components/all_cases/utils/stringify_url_params.tsx b/x-pack/plugins/cases/public/components/all_cases/utils/stringify_url_params.tsx index 8c43112c093aa..ad037d40a027c 100644 --- a/x-pack/plugins/cases/public/components/all_cases/utils/stringify_url_params.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/utils/stringify_url_params.tsx @@ -11,7 +11,7 @@ import type { AllCasesURLQueryParams } from '../types'; export function stringifyUrlParams( allCasesUrlParams: AllCasesURLQueryParams, - currentSearch: string = '' + currentSearch = '' ): string { const encodedUrlParams = encode({ ...allCasesUrlParams }); diff --git a/x-pack/plugins/cases/public/components/case_view/case_view_page.tsx b/x-pack/plugins/cases/public/components/case_view/case_view_page.tsx index add85202d0e55..a3fa89c034f25 100644 --- a/x-pack/plugins/cases/public/components/case_view/case_view_page.tsx +++ b/x-pack/plugins/cases/public/components/case_view/case_view_page.tsx @@ -89,7 +89,7 @@ export const CaseViewPage = React.memo( data-test-subj="case-view-title" titleNode={ @@ -98,7 +98,7 @@ export const CaseViewPage = React.memo( > @@ -118,9 +118,9 @@ export const CaseViewPage = React.memo( useFetchAlertData={useFetchAlertData} /> )} - {activeTabId === CASE_VIEW_PAGE_TABS.ALERTS && features.alerts.enabled && ( + {activeTabId === CASE_VIEW_PAGE_TABS.ALERTS && features.alerts.enabled ? ( - )} + ) : null} {activeTabId === CASE_VIEW_PAGE_TABS.FILES && } diff --git a/x-pack/plugins/cases/public/components/case_view/case_view_tabs.tsx b/x-pack/plugins/cases/public/components/case_view/case_view_tabs.tsx index 1dbfbad2c2630..203dea53f212b 100644 --- a/x-pack/plugins/cases/public/components/case_view/case_view_tabs.tsx +++ b/x-pack/plugins/cases/public/components/case_view/case_view_tabs.tsx @@ -45,7 +45,7 @@ const FilesBadge = ({ euiTheme: EuiThemeComputed<{}>; }) => ( <> - {!isLoading && fileStatsData && ( + {!isLoading && fileStatsData ? ( {fileStatsData.total > 0 ? fileStatsData.total : 0} - )} + ) : null} ); @@ -82,7 +82,7 @@ const AlertsBadge = ({ > {totalAlerts || 0} - {isExperimental && ( + {isExperimental ? ( - )} + ) : null} ); diff --git a/x-pack/plugins/cases/public/components/case_view/components/assign_users.tsx b/x-pack/plugins/cases/public/components/case_view/components/assign_users.tsx index 6b29a9df14d91..e764ff1f31442 100644 --- a/x-pack/plugins/cases/public/components/case_view/components/assign_users.tsx +++ b/x-pack/plugins/cases/public/components/case_view/components/assign_users.tsx @@ -52,22 +52,22 @@ const AssigneesList: React.FC = ({

{i18n.NO_ASSIGNEES} - {permissions.update && ( + {permissions.update ? ( <>
{i18n.ASSIGN_A_USER} - )} - {currentUserProfile && permissions.update && ( + ) : null} + {currentUserProfile && permissions.update ? ( <> {i18n.SPACED_OR} {i18n.ASSIGN_YOURSELF} - )} + ) : null}

@@ -179,8 +179,10 @@ const AssignUsersComponent: React.FC = ({ - {isLoading && } - {!isLoading && permissions.update && ( + {isLoading ? ( + + ) : null} + {!isLoading && permissions.update ? ( = ({ togglePopover={togglePopover} /> - )} + ) : null} - {(isLoadingUserActionsStats || isLoadingCaseConnectors || isLoadingCaseUsers) && ( + {isLoadingUserActionsStats || isLoadingCaseConnectors || isLoadingCaseUsers ? ( - )} + ) : null} {showUserActions ? ( @@ -231,7 +231,7 @@ export const CaseViewActivity = ({ ) : null } @@ -249,19 +249,17 @@ export const CaseViewActivity = ({ {caseAssignmentAuthorized ? ( - <> - - + ) : null} @@ -285,12 +283,12 @@ export const CaseViewActivity = ({ {showConnectorSidebar ? ( {i18n.CATEGORY} - {isLoadingAll && } - {!isLoadingAll && permissions.update && ( + {isLoadingAll ? : null} + {!isLoadingAll && permissions.update ? ( - )} + ) : null} @@ -151,7 +151,7 @@ export const EditCategory = React.memo(({ isLoading, onSubmit, category }: EditC )} )} - {isEditCategory && ( + {isEditCategory ? ( - )} + ) : null} ); diff --git a/x-pack/plugins/cases/public/components/case_view/components/edit_tags.tsx b/x-pack/plugins/cases/public/components/case_view/components/edit_tags.tsx index d8c98e42f2e38..aac202833455b 100644 --- a/x-pack/plugins/cases/public/components/case_view/components/edit_tags.tsx +++ b/x-pack/plugins/cases/public/components/case_view/components/edit_tags.tsx @@ -83,8 +83,8 @@ export const EditTags = React.memo(({ isLoading, onSubmit, tags }: EditTagsProps

{i18n.TAGS}

- {isLoading && } - {!isLoading && permissions.update && ( + {isLoading ? : null} + {!isLoading && permissions.update ? ( setIsEditTags(true)} /> - )} + ) : null} )} - {isEditTags && ( + {isEditTags ? ( - )} + ) : null} ); diff --git a/x-pack/plugins/cases/public/components/case_view/components/user_list.tsx b/x-pack/plugins/cases/public/components/case_view/components/user_list.tsx index 445974fcd2916..5864be3035456 100644 --- a/x-pack/plugins/cases/public/components/case_view/components/user_list.tsx +++ b/x-pack/plugins/cases/public/components/case_view/components/user_list.tsx @@ -108,13 +108,13 @@ export const UserList: React.FC = React.memo(

{headline}

- {loading && ( + {loading ? ( - )} + ) : null} {renderUsers(orderedUsers, handleSendEmail, euiTheme)} ); diff --git a/x-pack/plugins/cases/public/components/configure_cases/closure_options.tsx b/x-pack/plugins/cases/public/components/configure_cases/closure_options.tsx index 9073988783889..374d26c71dad2 100644 --- a/x-pack/plugins/cases/public/components/configure_cases/closure_options.tsx +++ b/x-pack/plugins/cases/public/components/configure_cases/closure_options.tsx @@ -26,11 +26,7 @@ const ClosureOptionsComponent: React.FC = ({ {i18n.CASE_CLOSURE_OPTIONS_TITLE}} - description={ - <> -

{i18n.CASE_CLOSURE_OPTIONS_DESC}

- - } + description={

{i18n.CASE_CLOSURE_OPTIONS_DESC}

} data-test-subj="case-closure-options-form-group" > = ({ [connectorsName, handleShowEditFlyout, updateConnectorDisabled] ); return ( - <> - {i18n.INCIDENT_MANAGEMENT_SYSTEM_TITLE}} + description={i18n.INCIDENT_MANAGEMENT_SYSTEM_DESC} + data-test-subj="case-connectors-form-group" + > + {i18n.INCIDENT_MANAGEMENT_SYSTEM_TITLE}} - description={i18n.INCIDENT_MANAGEMENT_SYSTEM_DESC} - data-test-subj="case-connectors-form-group" + label={dropDownLabel} + data-test-subj="case-connectors-form-row" + labelAppend={ + canSave ? ( + + {i18n.ADD_CONNECTOR} + + ) : null + } > - - {i18n.ADD_CONNECTOR} - - ) : null - } - > - + + + {canUseConnectors ? ( + + ) : ( + + {i18n.READ_ACTIONS_PERMISSIONS_ERROR_MSG} + + )} + + {selectedConnector.type !== ConnectorTypes.none && isDeprecatedConnector(connector) && ( - {canUseConnectors ? ( - - ) : ( - - {i18n.READ_ACTIONS_PERMISSIONS_ERROR_MSG} - - )} + - {selectedConnector.type !== ConnectorTypes.none && isDeprecatedConnector(connector) && ( - - - - )} - {selectedConnector.type !== ConnectorTypes.none ? ( - - - - ) : null} - - - - + )} + {selectedConnector.type !== ConnectorTypes.none ? ( + + + + ) : null} + + +
); }; ConnectorsComponent.displayName = 'Connectors'; diff --git a/x-pack/plugins/cases/public/components/configure_cases/index.tsx b/x-pack/plugins/cases/public/components/configure_cases/index.tsx index 641482ceca4fe..b939e399cf76a 100644 --- a/x-pack/plugins/cases/public/components/configure_cases/index.tsx +++ b/x-pack/plugins/cases/public/components/configure_cases/index.tsx @@ -535,7 +535,7 @@ export const ConfigureCases: React.FC = React.memo(() => { />
- {hasMinimumLicensePermissions && ( + {hasMinimumLicensePermissions ? ( <> {!connectorIsValid && ( <> @@ -586,7 +586,7 @@ export const ConfigureCases: React.FC = React.memo(() => {
- )} + ) : null}
= ({ co
diff --git a/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_itsm_case_fields.tsx b/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_itsm_case_fields.tsx index 7d6981fda05e4..99051585bdd55 100644 --- a/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_itsm_case_fields.tsx +++ b/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_itsm_case_fields.tsx @@ -95,13 +95,13 @@ const ServiceNowITSMFieldsComponent: React.FunctionComponent - {showConnectorWarning && ( + {showConnectorWarning ? ( - )} + ) : null} diff --git a/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_itsm_case_fields_preview.tsx b/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_itsm_case_fields_preview.tsx index c88960b15f94f..52febf7bb67ad 100644 --- a/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_itsm_case_fields_preview.tsx +++ b/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_itsm_case_fields_preview.tsx @@ -151,13 +151,13 @@ const ServiceNowITSMFieldsPreviewComponent: React.FunctionComponent< return ( <> - {showConnectorWarning && ( + {showConnectorWarning ? ( - )} + ) : null} - {showConnectorWarning && ( + {showConnectorWarning ? ( - )} + ) : null} diff --git a/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_sir_case_fields_preview.tsx b/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_sir_case_fields_preview.tsx index e89bff6251718..e72305c1c60c7 100644 --- a/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_sir_case_fields_preview.tsx +++ b/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_sir_case_fields_preview.tsx @@ -157,13 +157,13 @@ const ServiceNowSIRFieldsPreviewComponent: React.FunctionComponent< return ( <> - {showConnectorWarning && ( + {showConnectorWarning ? ( - )} + ) : null} = ( return ( <> - {showMappingWarning && ( + {showMappingWarning ? ( = ( > {i18n.EMPTY_MAPPING_WARNING_DESC} - )} + ) : null} ); }; diff --git a/x-pack/plugins/cases/public/components/connectors/swimlane/case_fields_preview.tsx b/x-pack/plugins/cases/public/components/connectors/swimlane/case_fields_preview.tsx index 29ae2d2d8e7fb..3f125050041ed 100644 --- a/x-pack/plugins/cases/public/components/connectors/swimlane/case_fields_preview.tsx +++ b/x-pack/plugins/cases/public/components/connectors/swimlane/case_fields_preview.tsx @@ -28,7 +28,7 @@ const SwimlaneFieldsPreviewComponent: React.FunctionComponent< listItems={[]} title={connector.name} /> - {showMappingWarning && ( + {showMappingWarning ? ( {i18n.EMPTY_MAPPING_WARNING_DESC} - )} + ) : null} ); }; diff --git a/x-pack/plugins/cases/public/components/create/flyout/create_case_flyout.tsx b/x-pack/plugins/cases/public/components/create/flyout/create_case_flyout.tsx index 12566025520f7..9b4a991f4b194 100644 --- a/x-pack/plugins/cases/public/components/create/flyout/create_case_flyout.tsx +++ b/x-pack/plugins/cases/public/components/create/flyout/create_case_flyout.tsx @@ -50,7 +50,7 @@ export const CreateCaseFlyout = React.memo(

{i18n.CREATE_CASE_TITLE}

- {headerContent && headerContent} + {headerContent ? headerContent : null} return ( <> - {shouldShowOwnerSelector && ( + {shouldShowOwnerSelector ? ( - )} + ) : null} = React.memo( > {i18n.CANCEL} - {showConfirmationModal && ( + {showConfirmationModal ? ( - )} + ) : null}
diff --git a/x-pack/plugins/cases/public/components/create/form_fields.tsx b/x-pack/plugins/cases/public/components/create/form_fields.tsx index 62e1876b2adf3..f2810f7376d9e 100644 --- a/x-pack/plugins/cases/public/components/create/form_fields.tsx +++ b/x-pack/plugins/cases/public/components/create/form_fields.tsx @@ -167,7 +167,7 @@ export const CreateCaseFormFields: React.FC = React.m return ( <> - {isSubmitting && ( + {isSubmitting ? ( = React.m data-test-subj="create-case-loading-spinner" size="xl" /> - )} + ) : null} {withSteps ? ( = React.m {secondStep.children}
- {isSyncAlertsEnabled && ( + {isSyncAlertsEnabled ? ( @@ -214,7 +214,7 @@ export const CreateCaseFormFields: React.FC = React.m {thirdStep.children} - )} + ) : null} diff --git a/x-pack/plugins/cases/public/components/custom_fields/custom_fields_list/index.tsx b/x-pack/plugins/cases/public/components/custom_fields/custom_fields_list/index.tsx index 90f6687141eda..d5aec4e348d13 100644 --- a/x-pack/plugins/cases/public/components/custom_fields/custom_fields_list/index.tsx +++ b/x-pack/plugins/cases/public/components/custom_fields/custom_fields_list/index.tsx @@ -76,9 +76,9 @@ const CustomFieldsListComponent: React.FC = (props) => { {renderTypeLabel(customField.type)} - {customField.required && ( + {customField.required ? ( {i18n.REQUIRED} - )} + ) : null}
diff --git a/x-pack/plugins/cases/public/components/custom_fields/index.tsx b/x-pack/plugins/cases/public/components/custom_fields/index.tsx index d749a7aba9bea..a771784640bec 100644 --- a/x-pack/plugins/cases/public/components/custom_fields/index.tsx +++ b/x-pack/plugins/cases/public/components/custom_fields/index.tsx @@ -74,13 +74,11 @@ const CustomFieldsComponent: React.FC = ({ > {customFields.length ? ( - <> - - + ) : null} {!customFields.length ? ( diff --git a/x-pack/plugins/cases/public/components/custom_fields/number/edit.tsx b/x-pack/plugins/cases/public/components/custom_fields/number/edit.tsx index 3ebb65a9dab8e..2f9bc656259f9 100644 --- a/x-pack/plugins/cases/public/components/custom_fields/number/edit.tsx +++ b/x-pack/plugins/cases/public/components/custom_fields/number/edit.tsx @@ -93,7 +93,7 @@ const FormWrapperComponent: React.FC = ({ path="value" config={formFieldConfig} component={NumericField} - helpText={populatedWithDefault && POPULATED_WITH_DEFAULT} + helpText={populatedWithDefault ? POPULATED_WITH_DEFAULT : null} componentProps={{ euiFieldProps: { fullWidth: true, @@ -167,12 +167,12 @@ const EditComponent: CustomFieldType['Edit'] = ({

{title}

- {isLoading && ( + {isLoading ? ( - )} - {!isLoading && canUpdate && ( + ) : null} + {!isLoading && canUpdate ? ( ['Edit'] = ({ onClick={onEdit} /> - )} + ) : null}
['Edit'] = ({ {!isCustomFieldValueDefined && !isEdit && (

{NO_CUSTOM_FIELD_SET}

)} - {!isEdit && isCustomFieldValueDefined && ( + {!isEdit && isCustomFieldValueDefined ? ( - )} - {isEdit && canUpdate && ( + ) : null} + {isEdit && canUpdate ? ( ['Edit'] = ({
- )} + ) : null}
); diff --git a/x-pack/plugins/cases/public/components/custom_fields/text/edit.tsx b/x-pack/plugins/cases/public/components/custom_fields/text/edit.tsx index 4fc7c2dde9af4..f16f50eb0fcd6 100644 --- a/x-pack/plugins/cases/public/components/custom_fields/text/edit.tsx +++ b/x-pack/plugins/cases/public/components/custom_fields/text/edit.tsx @@ -89,7 +89,7 @@ const FormWrapperComponent: React.FC = ({ path="value" config={formFieldConfig} component={TextField} - helpText={populatedWithDefault && POPULATED_WITH_DEFAULT} + helpText={populatedWithDefault ? POPULATED_WITH_DEFAULT : null} componentProps={{ euiFieldProps: { fullWidth: true, @@ -164,12 +164,12 @@ const EditComponent: CustomFieldType['Edit'] = ({

{title}

- {isLoading && ( + {isLoading ? ( - )} - {!isLoading && canUpdate && ( + ) : null} + {!isLoading && canUpdate ? ( ['Edit'] = ({ onClick={onEdit} /> - )} + ) : null}
['Edit'] = ({ {!isCustomFieldValueDefined && !isEdit && (

{NO_CUSTOM_FIELD_SET}

)} - {!isEdit && isCustomFieldValueDefined && ( + {!isEdit && isCustomFieldValueDefined ? ( - )} - {isEdit && canUpdate && ( + ) : null} + {isEdit && canUpdate ? ( ['Edit'] = ({
- )} + ) : null} ); diff --git a/x-pack/plugins/cases/public/components/edit_connector/index.tsx b/x-pack/plugins/cases/public/components/edit_connector/index.tsx index e375ddfc295aa..a776486f620ff 100644 --- a/x-pack/plugins/cases/public/components/edit_connector/index.tsx +++ b/x-pack/plugins/cases/public/components/edit_connector/index.tsx @@ -125,7 +125,7 @@ export const EditConnector = React.memo( - {!isLoading && !isEdit && hasErrorMessages && canUseConnectors && ( + {!isLoading && !isEdit && hasErrorMessages && canUseConnectors ? ( - )} + ) : null} {!canUseConnectors && ( {i18n.READ_ACTIONS_PERMISSIONS_ERROR_MSG} )} - {canUseConnectors && !isEdit && ( + {canUseConnectors && !isEdit ? ( - )} - {canUseConnectors && isEdit && ( + ) : null} + {canUseConnectors && isEdit ? ( - )} - {!hasErrorMessages && !isLoading && !isEdit && hasPushPermissions && canUseConnectors && ( + ) : null} + {!hasErrorMessages && !isLoading && !isEdit && hasPushPermissions && canUseConnectors ? ( - )} + ) : null} ); diff --git a/x-pack/plugins/cases/public/components/files/add_file.tsx b/x-pack/plugins/cases/public/components/files/add_file.tsx index 7b91879834a78..5b0475f0cc841 100644 --- a/x-pack/plugins/cases/public/components/files/add_file.tsx +++ b/x-pack/plugins/cases/public/components/files/add_file.tsx @@ -118,7 +118,7 @@ const AddFileComponent: React.FC = ({ caseId }) => { > {i18n.ADD_FILE} - {isModalVisible && ( + {isModalVisible ? ( {i18n.ADD_FILE} @@ -132,7 +132,7 @@ const AddFileComponent: React.FC = ({ caseId }) => { /> - )} + ) : null} ) : null; }; diff --git a/x-pack/plugins/cases/public/components/files/file_actions_popover_button.tsx b/x-pack/plugins/cases/public/components/files/file_actions_popover_button.tsx index 691174717af00..b52ae5e82ac9a 100644 --- a/x-pack/plugins/cases/public/components/files/file_actions_popover_button.tsx +++ b/x-pack/plugins/cases/public/components/files/file_actions_popover_button.tsx @@ -175,14 +175,14 @@ export const FileActionsPopoverButton: React.FC<{ caseId: string; theFile: FileJ data-test-subj={'cases-files-popover-context-menu'} /> - {showDeletionModal && ( + {showDeletionModal ? ( - )} + ) : null} ); }; diff --git a/x-pack/plugins/cases/public/components/files/file_attachment_event.tsx b/x-pack/plugins/cases/public/components/files/file_attachment_event.tsx index 443ab1c612bfb..5f9eceb763d22 100644 --- a/x-pack/plugins/cases/public/components/files/file_attachment_event.tsx +++ b/x-pack/plugins/cases/public/components/files/file_attachment_event.tsx @@ -20,7 +20,7 @@ export const FileAttachmentEvent = ({ file }: { file: DownloadableFile }) => { <> {i18n.ADDED} - {isPreviewVisible && } + {isPreviewVisible ? : null} ); }; diff --git a/x-pack/plugins/cases/public/components/files/files_table.tsx b/x-pack/plugins/cases/public/components/files/files_table.tsx index ace1f5cef24fe..5834543b56dba 100644 --- a/x-pack/plugins/cases/public/components/files/files_table.tsx +++ b/x-pack/plugins/cases/public/components/files/files_table.tsx @@ -82,9 +82,9 @@ export const FilesTable = ({ caseId, items, pagination, onChange, isLoading }: F noItemsMessage={} rowProps={filesTableRowProps} /> - {isPreviewVisible && selectedFile !== undefined && ( + {isPreviewVisible && selectedFile !== undefined ? ( - )} + ) : null} ); }; diff --git a/x-pack/plugins/cases/public/components/header_page/editable_title.tsx b/x-pack/plugins/cases/public/components/header_page/editable_title.tsx index fc438ecb571b4..a70142b10573b 100644 --- a/x-pack/plugins/cases/public/components/header_page/editable_title.tsx +++ b/x-pack/plugins/cases/public/components/header_page/editable_title.tsx @@ -61,10 +61,11 @@ const EditableTitleComponent: React.FC = ({ onSubmit, isLoad = ({ display: block; `} > - {showBackButton && ( + {showBackButton ? (
= ({ {i18n.BACK_TO_ALL}
- )} + ) : null} {titleNode || } - {border && isLoading && <EuiProgress size="xs" color="accent" />} + {border && isLoading ? <EuiProgress size="xs" color="accent" /> : null} </EuiFlexItem> - {children && ( + {children ? ( <EuiFlexItem data-test-subj="header-page-supplements" css={css` @@ -107,7 +107,7 @@ const HeaderPageComponent: React.FC<HeaderPageProps> = ({ > {children} </EuiFlexItem> - )} + ) : null} </EuiFlexGroup> </header> ); diff --git a/x-pack/plugins/cases/public/components/links/index.tsx b/x-pack/plugins/cases/public/components/links/index.tsx index 9b610db63ed10..2c4b95624aa5f 100644 --- a/x-pack/plugins/cases/public/components/links/index.tsx +++ b/x-pack/plugins/cases/public/components/links/index.tsx @@ -31,7 +31,7 @@ export const LinkButton: LinkButtonProps = ({ children, isEmpty, ...props }) => LinkButton.displayName = 'LinkButton'; // TODO: Fix this manually. Issue #123375 -// eslint-disable-next-line react/display-name + export const LinkAnchor: React.FC<EuiLinkProps> = ({ children, ...props }) => ( <EuiLink {...props}>{children}</EuiLink> ); @@ -43,7 +43,7 @@ export interface CaseDetailsLinkProps { } // TODO: Fix this manually. Issue #123375 -// eslint-disable-next-line react/display-name + const CaseDetailsLinkComponent: React.FC<CaseDetailsLinkProps> = ({ children, detailName, @@ -81,7 +81,7 @@ export interface ConfigureCaseButtonProps { } // TODO: Fix this manually. Issue #123375 -// eslint-disable-next-line react/display-name + const ConfigureCaseButtonComponent: React.FC<ConfigureCaseButtonProps> = ({ label, msgTooltip, diff --git a/x-pack/plugins/cases/public/components/markdown_editor/eui_form.tsx b/x-pack/plugins/cases/public/components/markdown_editor/eui_form.tsx index b1437e2e2a253..e2cae01f31c99 100644 --- a/x-pack/plugins/cases/public/components/markdown_editor/eui_form.tsx +++ b/x-pack/plugins/cases/public/components/markdown_editor/eui_form.tsx @@ -100,7 +100,7 @@ export const MarkdownEditorForm = React.memo( data-test-subj={`${dataTestSubj}-markdown-editor`} /> </EuiFormRow> - {bottomRightContent && ( + {bottomRightContent ? ( <EuiFlexGroup css={css` padding: ${euiTheme.size.m} 0; @@ -109,13 +109,13 @@ export const MarkdownEditorForm = React.memo( > <EuiFlexItem grow={false}> <EuiText color="danger" size="s"> - {hasConflicts && conflictWarningText} + {hasConflicts ? conflictWarningText : null} </EuiText> <EuiSpacer size="s" /> {bottomRightContent} </EuiFlexItem> </EuiFlexGroup> - )} + ) : null} </CommentEditorContext.Provider> ); } diff --git a/x-pack/plugins/cases/public/components/recent_cases/recent_cases.tsx b/x-pack/plugins/cases/public/components/recent_cases/recent_cases.tsx index f3a276d66a9c0..ab7207c93b56a 100644 --- a/x-pack/plugins/cases/public/components/recent_cases/recent_cases.tsx +++ b/x-pack/plugins/cases/public/components/recent_cases/recent_cases.tsx @@ -75,7 +75,7 @@ export const RecentCasesComp = React.memo<RecentCasesProps>( </CaseDetailsLink> </EuiText> <EuiSpacer size="xs" /> - {c.description && c.description.length && ( + {c.description && c.description.length ? ( <div css={getMarkdownContainerCss(euiTheme)}> <div css={getTruncateCompCss}> <MarkdownRenderer disableLinks={true} textSize="relative"> @@ -83,7 +83,7 @@ export const RecentCasesComp = React.memo<RecentCasesProps>( </MarkdownRenderer> </div> </div> - )} + ) : null} <EuiSpacer size="xs" /> <EuiFlexGroup gutterSize="s"> <EuiFlexItem grow={false}> diff --git a/x-pack/plugins/cases/public/components/removable_item/removable_item.tsx b/x-pack/plugins/cases/public/components/removable_item/removable_item.tsx index 8cc9138511086..5e0a30f1a44fa 100644 --- a/x-pack/plugins/cases/public/components/removable_item/removable_item.tsx +++ b/x-pack/plugins/cases/public/components/removable_item/removable_item.tsx @@ -42,7 +42,7 @@ const RemovableItemComponent: React.FC<Props> = ({ data-test-subj={`${dataTestSubj}group`} > <EuiFlexItem grow={false}>{children}</EuiFlexItem> - {permissions.update && ( + {permissions.update ? ( <EuiFlexItem grow={false}> <EuiToolTip position="left" @@ -64,7 +64,7 @@ const RemovableItemComponent: React.FC<Props> = ({ /> </EuiToolTip> </EuiFlexItem> - )} + ) : null} </EuiFlexGroup> ); }; diff --git a/x-pack/plugins/cases/public/components/templates/index.tsx b/x-pack/plugins/cases/public/components/templates/index.tsx index 479101d2889ad..14ed8db752afd 100644 --- a/x-pack/plugins/cases/public/components/templates/index.tsx +++ b/x-pack/plugins/cases/public/components/templates/index.tsx @@ -86,13 +86,11 @@ const TemplatesComponent: React.FC<Props> = ({ > <EuiPanel paddingSize="s" color="subdued" hasBorder={false} hasShadow={false}> {templates.length ? ( - <> - <TemplatesList - templates={templates} - onEditTemplate={handleEditTemplate} - onDeleteTemplate={handleDeleteTemplate} - /> - </> + <TemplatesList + templates={templates} + onEditTemplate={handleEditTemplate} + onDeleteTemplate={handleDeleteTemplate} + /> ) : null} <EuiSpacer size="s" /> {!templates.length ? ( diff --git a/x-pack/plugins/cases/public/components/timeline_context/index.tsx b/x-pack/plugins/cases/public/components/timeline_context/index.tsx index 5968e2ea87fc9..11843a23b715f 100644 --- a/x-pack/plugins/cases/public/components/timeline_context/index.tsx +++ b/x-pack/plugins/cases/public/components/timeline_context/index.tsx @@ -55,7 +55,7 @@ export const CasesTimelineIntegrationProvider: FC< }> > = // TODO: Fix this manually. Issue #123375 - // eslint-disable-next-line react/display-name + ({ children, timelineIntegration }) => { const [activeTimelineIntegration] = useState(timelineIntegration ?? null); diff --git a/x-pack/plugins/cases/public/components/use_push_to_service/callout/callout.tsx b/x-pack/plugins/cases/public/components/use_push_to_service/callout/callout.tsx index a3326b3cb90f4..c24f5522aa3b9 100644 --- a/x-pack/plugins/cases/public/components/use_push_to_service/callout/callout.tsx +++ b/x-pack/plugins/cases/public/components/use_push_to_service/callout/callout.tsx @@ -60,7 +60,7 @@ const CallOutComponent = ({ size="s" > <EuiDescriptionList data-test-subj={`callout-messages-${id}`} listItems={messages} /> - {!isCaseClosed && !hasLicenseError && permissions.settings && ( + {!isCaseClosed && !hasLicenseError && permissions.settings ? ( <EuiButton data-test-subj={`callout-onclick-${id}`} color={type === 'success' ? 'success' : type} @@ -68,7 +68,7 @@ const CallOutComponent = ({ > {i18n.ADD_CONNECTOR} </EuiButton> - )} + ) : null} </EuiCallOut> ) : null; }; diff --git a/x-pack/plugins/cases/public/components/use_push_to_service/callout/helpers.tsx b/x-pack/plugins/cases/public/components/use_push_to_service/callout/helpers.tsx index e83d215c61ed9..b0105125c2987 100644 --- a/x-pack/plugins/cases/public/components/use_push_to_service/callout/helpers.tsx +++ b/x-pack/plugins/cases/public/components/use_push_to_service/callout/helpers.tsx @@ -7,5 +7,5 @@ import { sha256 } from 'js-sha256'; -export const createCalloutId = (ids: string[], delimiter: string = '|'): string => +export const createCalloutId = (ids: string[], delimiter = '|'): string => sha256(ids.join(delimiter)); diff --git a/x-pack/plugins/cases/public/components/user_actions/comment/comment.tsx b/x-pack/plugins/cases/public/components/user_actions/comment/comment.tsx index 36dd0c5325e48..4e5796ca44544 100644 --- a/x-pack/plugins/cases/public/components/user_actions/comment/comment.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/comment/comment.tsx @@ -173,7 +173,7 @@ const getCreateCommentUserAction = ({ >): EuiCommentProps[] => { switch (comment.type) { case AttachmentType.user: - const userBuilder = createUserAttachmentUserActionBuilder({ + return createUserAttachmentUserActionBuilder({ appId, userProfiles, comment, @@ -187,12 +187,10 @@ const getCreateCommentUserAction = ({ handleSaveComment, handleManageQuote, handleDeleteComment, - }); - - return userBuilder.build(); + }).build(); case AttachmentType.alert: - const alertBuilder = createAlertAttachmentUserActionBuilder({ + return createAlertAttachmentUserActionBuilder({ userProfiles, alertData, comment, @@ -203,22 +201,18 @@ const getCreateCommentUserAction = ({ onShowAlertDetails, handleDeleteComment, loadingCommentIds, - }); - - return alertBuilder.build(); + }).build(); case AttachmentType.actions: - const actionBuilder = createActionAttachmentUserActionBuilder({ + return createActionAttachmentUserActionBuilder({ userProfiles, userAction, comment, actionsNavigation, - }); - - return actionBuilder.build(); + }).build(); case AttachmentType.externalReference: - const externalReferenceBuilder = createExternalReferenceAttachmentUserActionBuilder({ + return createExternalReferenceAttachmentUserActionBuilder({ userAction, userProfiles, comment, @@ -226,12 +220,10 @@ const getCreateCommentUserAction = ({ caseData, isLoading: loadingCommentIds.includes(comment.id), handleDeleteComment, - }); - - return externalReferenceBuilder.build(); + }).build(); case AttachmentType.persistableState: - const persistableBuilder = createPersistableStateAttachmentUserActionBuilder({ + return createPersistableStateAttachmentUserActionBuilder({ userAction, userProfiles, comment, @@ -239,9 +231,8 @@ const getCreateCommentUserAction = ({ caseData, isLoading: loadingCommentIds.includes(comment.id), handleDeleteComment, - }); + }).build(); - return persistableBuilder.build(); default: return []; } diff --git a/x-pack/plugins/cases/public/components/user_actions/index.tsx b/x-pack/plugins/cases/public/components/user_actions/index.tsx index a17dee7423fe3..2f98dc46c8847 100644 --- a/x-pack/plugins/cases/public/components/user_actions/index.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/index.tsx @@ -187,9 +187,9 @@ export const UserActions = React.memo((props: UserActionTreeProps) => { bottomActions={lastPage <= 1 ? bottomActions : []} isExpandable /> - {hasNextPage && ( + {hasNextPage ? ( <ShowMoreButton onShowMoreClick={handleShowMore} isLoading={isFetchingNextPage} /> - )} + ) : null} {lastPageUserActions?.length ? ( <EuiFlexItem {...(!hasNextPage diff --git a/x-pack/plugins/cases/public/components/user_actions/timestamp.tsx b/x-pack/plugins/cases/public/components/user_actions/timestamp.tsx index a8c38657d1ee8..51cbe04b212b8 100644 --- a/x-pack/plugins/cases/public/components/user_actions/timestamp.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/timestamp.tsx @@ -25,7 +25,7 @@ const UserActionTimestampComponent = ({ createdAt, updatedAt }: UserActionAvatar value={createdAt} /> </LocalizedDateTooltip> - {updatedAt && ( + {updatedAt ? ( <EuiTextColor color="subdued"> {/* be careful of the extra space at the beginning of the parenthesis */} {' ('} @@ -38,7 +38,7 @@ const UserActionTimestampComponent = ({ createdAt, updatedAt }: UserActionAvatar </LocalizedDateTooltip> {')'} </EuiTextColor> - )} + ) : null} </> ); UserActionTimestampComponent.displayName = 'UserActionTimestamp'; diff --git a/x-pack/plugins/cases/public/components/user_profiles/user_tooltip.tsx b/x-pack/plugins/cases/public/components/user_profiles/user_tooltip.tsx index 6b9549fe4d618..e58ccd32fabea 100644 --- a/x-pack/plugins/cases/public/components/user_profiles/user_tooltip.tsx +++ b/x-pack/plugins/cases/public/components/user_profiles/user_tooltip.tsx @@ -66,7 +66,7 @@ const UserFullRepresentationComponent: React.FC<UserFullRepresentationProps> = ( <EuiFlexItem> <UserFullInformation userInfo={userInfo} /> </EuiFlexItem> - {userInfo?.user && displayEmail(userInfo) && ( + {userInfo?.user && displayEmail(userInfo) ? ( <EuiFlexItem grow={false}> <EuiText size="s" @@ -76,7 +76,7 @@ const UserFullRepresentationComponent: React.FC<UserFullRepresentationProps> = ( {userInfo.user.email} </EuiText> </EuiFlexItem> - )} + ) : null} </EuiFlexGroup> </EuiFlexItem> </EuiFlexGroup> diff --git a/x-pack/plugins/cases/public/components/visualizations/lens_renderer.tsx b/x-pack/plugins/cases/public/components/visualizations/lens_renderer.tsx index 8596b8f8bd30f..386847639b957 100644 --- a/x-pack/plugins/cases/public/components/visualizations/lens_renderer.tsx +++ b/x-pack/plugins/cases/public/components/visualizations/lens_renderer.tsx @@ -26,12 +26,12 @@ const LensRendererComponent: React.FC<LensProps> = ({ attributes, timeRange, met return ( <> - {metadata && metadata.description && ( + {metadata && metadata.description ? ( <> {metadata.description} <EuiSpacer size="s" /> </> - )} + ) : null} <div css={css` min-height: ${LENS_VISUALIZATION_HEIGHT}px; diff --git a/x-pack/plugins/cases/public/containers/__mocks__/api.ts b/x-pack/plugins/cases/public/containers/__mocks__/api.ts index a24c8b5b677c5..111007a739efb 100644 --- a/x-pack/plugins/cases/public/containers/__mocks__/api.ts +++ b/x-pack/plugins/cases/public/containers/__mocks__/api.ts @@ -54,13 +54,13 @@ import { getCaseConnectorsMockResponse } from '../../common/mock/connectors'; export const getCase = async ( caseId: string, - includeComments: boolean = true, + includeComments = true, signal: AbortSignal ): Promise<CaseUI> => Promise.resolve(basicCase); export const resolveCase = async ( caseId: string, - includeComments: boolean = true, + includeComments = true, signal: AbortSignal ): Promise<ResolvedCase> => Promise.resolve(basicResolvedCase); diff --git a/x-pack/plugins/cases/public/containers/api.ts b/x-pack/plugins/cases/public/containers/api.ts index 020a4629552f4..d84a19d5f5e86 100644 --- a/x-pack/plugins/cases/public/containers/api.ts +++ b/x-pack/plugins/cases/public/containers/api.ts @@ -97,7 +97,7 @@ import { decodeCasesFindResponse } from '../api/decoders'; export const getCase = async ( caseId: string, - includeComments: boolean = true, + includeComments = true, signal: AbortSignal ): Promise<CaseUI> => { const response = await KibanaServices.get().http.fetch<Case>(getCaseDetailsUrl(caseId), { diff --git a/x-pack/plugins/cases/public/containers/user_profiles/use_get_current_user_profile.test.ts b/x-pack/plugins/cases/public/containers/user_profiles/use_get_current_user_profile.test.ts index c26a6af826548..377b0d50efd99 100644 --- a/x-pack/plugins/cases/public/containers/user_profiles/use_get_current_user_profile.test.ts +++ b/x-pack/plugins/cases/public/containers/user_profiles/use_get_current_user_profile.test.ts @@ -93,7 +93,7 @@ class MockServerError extends Error { statusCode: number; }; - constructor(message?: string, statusCode: number = 200) { + constructor(message?: string, statusCode = 200) { super(message); this.name = this.constructor.name; this.body = { statusCode }; diff --git a/x-pack/plugins/cases/server/plugin.ts b/x-pack/plugins/cases/server/plugin.ts index b40089ff75050..27134a4ba91d2 100644 --- a/x-pack/plugins/cases/server/plugin.ts +++ b/x-pack/plugins/cases/server/plugin.ts @@ -184,7 +184,7 @@ export class CasePlugin this.userProfileService.initialize({ spaces: plugins.spaces, // securityPluginSetup will be set to a defined value in the setup() function - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + securityPluginSetup: this.securityPluginSetup!, securityPluginStart: plugins.security, licensingPluginStart: plugins.licensing, @@ -192,7 +192,7 @@ export class CasePlugin this.clientFactory.initialize({ // securityPluginSetup will be set to a defined value in the setup() function - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + securityPluginSetup: this.securityPluginSetup!, securityPluginStart: plugins.security, securityServiceStart: core.security, @@ -204,7 +204,7 @@ export class CasePlugin * Lens will be always defined as * it is declared as required plugin in kibana.json */ - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + lensEmbeddableFactory: this.lensEmbeddableFactory!, persistableStateAttachmentTypeRegistry: this.persistableStateAttachmentTypeRegistry, externalReferenceAttachmentTypeRegistry: this.externalReferenceAttachmentTypeRegistry,