Skip to content

Commit

Permalink
Merge branch 'main' into ftr/eslint-in-api-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlemeshko authored Aug 29, 2024
2 parents 696e9e6 + 19f6469 commit 4a06190
Show file tree
Hide file tree
Showing 289 changed files with 2,823 additions and 3,223 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ test/common/plugins/newsfeed @elastic/kibana-core
src/plugins/no_data_page @elastic/appex-sharedux
x-pack/plugins/notifications @elastic/appex-sharedux
packages/kbn-object-versioning @elastic/appex-sharedux
packages/kbn-object-versioning-utils @elastic/appex-sharedux
x-pack/plugins/observability_solution/observability_ai_assistant_app @elastic/obs-ai-assistant
x-pack/plugins/observability_solution/observability_ai_assistant_management @elastic/obs-ai-assistant
x-pack/plugins/observability_solution/observability_ai_assistant @elastic/obs-ai-assistant
Expand Down
8 changes: 8 additions & 0 deletions oas_docs/.spectral.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ rules:
function: pattern
functionOptions:
notMatch: /(blacklist|whitelist|execute|kill)/i
property-description:
description: Properties should have descriptions.
message: "Each property should have a description"
severity: warn
given: $.components.schemas.*.properties.*
then:
field: description
function: defined
# Examples
operation-success-examples:
formats: ['oas3_1']
Expand Down
4 changes: 4 additions & 0 deletions oas_docs/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ api-docs-serverless: ## Generate only kibana.serverless.yaml
api-docs-lint: ## Run spectral API docs linter
@npx @stoplight/spectral-cli lint "output/*.yaml" --ruleset ".spectral.yaml"

.PHONY: api-docs-lint-errs
api-docs-lint-errs: ## Run spectral API docs linter and return only errors
@npx @stoplight/spectral-cli lint "output/*.yaml" --ruleset ".spectral.yaml" -D

.PHONY: api-docs-lint-stateful
api-docs-lint-stateful: ## Run spectral API docs linter on kibana.yaml
@npx @stoplight/spectral-cli lint "output/kibana.yaml" --ruleset ".spectral.yaml"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@
"@kbn/no-data-page-plugin": "link:src/plugins/no_data_page",
"@kbn/notifications-plugin": "link:x-pack/plugins/notifications",
"@kbn/object-versioning": "link:packages/kbn-object-versioning",
"@kbn/object-versioning-utils": "link:packages/kbn-object-versioning-utils",
"@kbn/observability-ai-assistant-app-plugin": "link:x-pack/plugins/observability_solution/observability_ai_assistant_app",
"@kbn/observability-ai-assistant-management-plugin": "link:x-pack/plugins/observability_solution/observability_ai_assistant_management",
"@kbn/observability-ai-assistant-plugin": "link:x-pack/plugins/observability_solution/observability_ai_assistant",
Expand Down
27 changes: 0 additions & 27 deletions packages/kbn-io-ts-utils/src/props_to_schema/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/kbn-io-ts-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"**/*.ts"
],
"kbn_references": [
"@kbn/config-schema",
"@kbn/core",
"@kbn/datemath"
],
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-object-versioning-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/object-versioning-utils

Exports common utils from `@kbn/object-versioning` that are safe to be used both in the server and the browser.
9 changes: 9 additions & 0 deletions packages/kbn-object-versioning-utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { validateVersion } from './lib/validate_version';
13 changes: 13 additions & 0 deletions packages/kbn-object-versioning-utils/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-object-versioning-utils'],
};
5 changes: 5 additions & 0 deletions packages/kbn-object-versioning-utils/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/object-versioning-utils",
"owner": "@elastic/appex-sharedux"
}
39 changes: 39 additions & 0 deletions packages/kbn-object-versioning-utils/lib/validate_version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

// import type { Version } from '@kbn/object-versioning';
// Declaring it directly to avoid circular dependencies.
type Version = number;

export const validateVersion = (
version: unknown
): { result: true; value: Version } | { result: false; value: null } => {
if (typeof version === 'string') {
const isValid = /^\d+$/.test(version);
if (isValid) {
const parsed = parseInt(version, 10);
if (Number.isNaN(parsed)) {
return { result: false, value: null };
}
return { result: true, value: parsed };
}
return { result: false, value: null };
} else {
const isValid = Number.isInteger(version);
if (isValid) {
return {
result: true,
value: version as Version,
};
}
return {
result: false,
value: null,
};
}
};
6 changes: 6 additions & 0 deletions packages/kbn-object-versioning-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/object-versioning-utils",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
20 changes: 20 additions & 0 deletions packages/kbn-object-versioning-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
"react"
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
]
}
2 changes: 1 addition & 1 deletion packages/kbn-object-versioning/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"type": "shared-server",
"id": "@kbn/object-versioning",
"owner": "@elastic/appex-sharedux"
}
29 changes: 1 addition & 28 deletions packages/kbn-object-versioning/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import type { Type, ValidationError } from '@kbn/config-schema';
import { Version } from './types';

/**
* Validate an object based on a schema.
Expand All @@ -29,30 +28,4 @@ export const validateObj = (obj: unknown, objSchema?: Type<any>): ValidationErro
}
};

export const validateVersion = (
version: unknown
): { result: true; value: Version } | { result: false; value: null } => {
if (typeof version === 'string') {
const isValid = /^\d+$/.test(version);
if (isValid) {
const parsed = parseInt(version, 10);
if (Number.isNaN(parsed)) {
return { result: false, value: null };
}
return { result: true, value: parsed };
}
return { result: false, value: null };
} else {
const isValid = Number.isInteger(version);
if (isValid) {
return {
result: true,
value: version as Version,
};
}
return {
result: false,
value: null,
};
}
};
export { validateVersion } from '@kbn/object-versioning-utils';
1 change: 1 addition & 0 deletions packages/kbn-object-versioning/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"kbn_references": [
"@kbn/config-schema",
"@kbn/safer-lodash-set",
"@kbn/object-versioning-utils",
]
}
2 changes: 1 addition & 1 deletion packages/kbn-server-http-tools/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"type": "shared-server",
"id": "@kbn/server-http-tools",
"owner": "@elastic/kibana-core"
}
2 changes: 1 addition & 1 deletion src/plugins/content_management/common/rpc/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
import { schema } from '@kbn/config-schema';
import { validateVersion } from '@kbn/object-versioning/lib/utils';
import { validateVersion } from '@kbn/object-versioning-utils';

export const procedureNames = [
'get',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { QueryClient } from '@tanstack/react-query';
import { validateVersion } from '@kbn/object-versioning/lib/utils';
import { validateVersion } from '@kbn/object-versioning-utils';
import type { Version } from '@kbn/object-versioning';
import { createQueryObservable } from './query_observable';
import type { CrudClient } from '../crud_client';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/content_management/public/registry/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { validateVersion } from '@kbn/object-versioning/lib/utils';
import { validateVersion } from '@kbn/object-versioning-utils';

import type { ContentTypeDefinition } from './content_type_definition';
import { ContentType } from './content_type';
Expand Down
1 change: 1 addition & 0 deletions src/plugins/content_management/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@kbn/saved-objects-settings",
"@kbn/core-http-server",
"@kbn/content-management-favorites-server",
"@kbn/object-versioning-utils",
],
"exclude": [
"target/**/*",
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,8 @@
"@kbn/notifications-plugin/*": ["x-pack/plugins/notifications/*"],
"@kbn/object-versioning": ["packages/kbn-object-versioning"],
"@kbn/object-versioning/*": ["packages/kbn-object-versioning/*"],
"@kbn/object-versioning-utils": ["packages/kbn-object-versioning-utils"],
"@kbn/object-versioning-utils/*": ["packages/kbn-object-versioning-utils/*"],
"@kbn/observability-ai-assistant-app-plugin": ["x-pack/plugins/observability_solution/observability_ai_assistant_app"],
"@kbn/observability-ai-assistant-app-plugin/*": ["x-pack/plugins/observability_solution/observability_ai_assistant_app/*"],
"@kbn/observability-ai-assistant-management-plugin": ["x-pack/plugins/observability_solution/observability_ai_assistant_management"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ export const PatternAnalysisSettings: FC<PatternAnalysisSettingsProps> = ({
values={{ minimumTimeRangeOption, categoryCount }}
/>
</>
) : null}
) : (
<FormattedMessage
id="xpack.aiops.logCategorization.embeddableMenu.totalPatternsMessage2"
defaultMessage="No additional time will be added to the range you specified with the time selector."
/>
)}
</>
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import { i18n } from '@kbn/i18n';
import type { unitOfTime } from 'moment';

export const DEFAULT_MINIMUM_TIME_RANGE_OPTION: MinimumTimeRangeOption = 'No minimum';

export type MinimumTimeRangeOption = 'No minimum' | '1 week' | '1 month' | '3 months' | '6 months';

type MinimumTimeRange = Record<
Expand All @@ -17,7 +19,7 @@ type MinimumTimeRange = Record<
export const MINIMUM_TIME_RANGE: MinimumTimeRange = {
'No minimum': {
label: i18n.translate('xpack.aiops.logCategorization.minimumTimeRange.noMin', {
defaultMessage: 'No minimum',
defaultMessage: 'Use range specified in time selector',
}),
factor: 0,
unit: 'w',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useStorage } from '@kbn/ml-local-storage';
import type { MappingRuntimeFields } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { useAiopsAppContext } from '../../../hooks/use_aiops_app_context';
import type { MinimumTimeRangeOption } from './minimum_time_range';
import { MINIMUM_TIME_RANGE } from './minimum_time_range';
import { DEFAULT_MINIMUM_TIME_RANGE_OPTION, MINIMUM_TIME_RANGE } from './minimum_time_range';
import type { AiOpsKey, AiOpsStorageMapped } from '../../../types/storage';
import { AIOPS_PATTERN_ANALYSIS_MINIMUM_TIME_RANGE_PREFERENCE } from '../../../types/storage';

Expand Down Expand Up @@ -85,7 +85,7 @@ export function useMinimumTimeRange() {
const [minimumTimeRangeOption, setMinimumTimeRangeOption] = useStorage<
AiOpsKey,
AiOpsStorageMapped<typeof AIOPS_PATTERN_ANALYSIS_MINIMUM_TIME_RANGE_PREFERENCE>
>(AIOPS_PATTERN_ANALYSIS_MINIMUM_TIME_RANGE_PREFERENCE, '1 week');
>(AIOPS_PATTERN_ANALYSIS_MINIMUM_TIME_RANGE_PREFERENCE, DEFAULT_MINIMUM_TIME_RANGE_OPTION);

const cancelRequest = useCallback(() => {
abortController.current.abort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ import {
DEFAULT_PROBABILITY,
RANDOM_SAMPLER_OPTION,
} from '../../components/log_categorization/sampling_menu/random_sampler';
import type { MinimumTimeRangeOption } from '../../components/log_categorization/log_categorization_for_embeddable/minimum_time_range';
import {
DEFAULT_MINIMUM_TIME_RANGE_OPTION,
type MinimumTimeRangeOption,
} from '../../components/log_categorization/log_categorization_for_embeddable/minimum_time_range';
import { getMessageField } from '../../components/log_categorization/utils';
import { FieldSelector } from '../../components/log_categorization/log_categorization_for_embeddable/field_selector';
import { SamplingPanel } from '../../components/log_categorization/sampling_menu/sampling_panel';
Expand Down Expand Up @@ -67,7 +70,7 @@ export const PatternAnalysisEmbeddableInitializer: FC<PatternAnalysisInitializer
const [formInput, setFormInput] = useState<PatternAnalysisEmbeddableRuntimeState>(
pick(
initialInput ?? {
minimumTimeRangeOption: '1 week',
minimumTimeRangeOption: DEFAULT_MINIMUM_TIME_RANGE_OPTION,
randomSamplerMode: RANDOM_SAMPLER_OPTION.ON_AUTOMATIC,
randomSamplerProbability: DEFAULT_PROBABILITY,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,18 @@ describe('EditAssigneesSelectable', () => {
],
});
});

it('renders even with no assignee set yet', async () => {
const selectedCases = [{ ...basicCase, assignees: [] }];
const result = appMock.render(
<EditAssigneesSelectable {...props} selectedCases={selectedCases} />
);

await waitFor(() => {
expect(result.getByTestId('cases-actions-assignees-edit-selectable')).toBeInTheDocument();
});

expect(result.getByPlaceholderText('Find a user')).toBeInTheDocument();
expect(result.getByText('Selected: 0')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const EditAssigneesSelectableComponent: React.FC<Props> = ({
[selectedCases]
);

const { data, isLoading: isLoadingUserProfiles } = useBulkGetUserProfiles({
const { data, isFetching: isLoadingUserProfiles } = useBulkGetUserProfiles({
uids: Array.from(assignees.values()),
});

Expand Down
Loading

0 comments on commit 4a06190

Please sign in to comment.