Skip to content

Commit

Permalink
Merge branch 'main' into timeline-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Apr 5, 2024
2 parents 69a467f + cbcd154 commit ccccc5e
Show file tree
Hide file tree
Showing 88 changed files with 2,030 additions and 493 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ module.exports = {
rules: {
'@kbn/i18n/strings_should_be_translated_with_i18n': 'warn',
'@kbn/i18n/i18n_translate_should_start_with_the_right_id': 'warn',
'@kbn/i18n/formatted_message_should_start_with_the_right_id': 'warn',
},
},
{
Expand Down
3 changes: 3 additions & 0 deletions docs/management/connectors/action-types/jira.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ Title:: A title for the issue, used for searching the contents of the knowledge
Description:: The details about the incident.
Parent:: The ID or key of the parent issue. Only for `Subtask` issue types.
Additional comments:: Additional information for the client, such as how to troubleshoot the issue.
Additional fields::
An object that contains custom field identifiers and their values. These custom fields must comply with your Jira policies; they are not validated by the connector. For example, if a rule action does not include custom fields that are mandatory, the action might fail.


[float]
[[jira-connector-networking-configuration]]
Expand Down
Binary file modified docs/management/connectors/images/jira-params-test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/

import { i18n } from '@kbn/i18n';
import { EmbeddableApiContext, apiCanAddNewPanel } from '@kbn/presentation-publishing';
import { apiCanAddNewPanel } from '@kbn/presentation-containers';
import { EmbeddableApiContext } from '@kbn/presentation-publishing';
import { IncompatibleActionError, UiActionsStart } from '@kbn/ui-actions-plugin/public';
import { ADD_EUI_MARKDOWN_ACTION_ID, EUI_MARKDOWN_ID } from './constants';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/

import { i18n } from '@kbn/i18n';
import { apiCanAddNewPanel, EmbeddableApiContext } from '@kbn/presentation-publishing';
import { apiCanAddNewPanel } from '@kbn/presentation-containers';
import { EmbeddableApiContext } from '@kbn/presentation-publishing';
import { IncompatibleActionError } from '@kbn/ui-actions-plugin/public';
import { UiActionsPublicStart } from '@kbn/ui-actions-plugin/public/plugin';
import { ADD_FIELD_LIST_ACTION_ID, FIELD_LIST_ID } from './constants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import {
type UnifiedFieldListSidebarContainerProps,
} from '@kbn/unified-field-list';
import { cloneDeep } from 'lodash';
import React, { useEffect, useState } from 'react';
import { BehaviorSubject, Subscription } from 'rxjs';
import React, { useEffect } from 'react';
import { BehaviorSubject, skip, Subscription, switchMap } from 'rxjs';
import { FIELD_LIST_DATA_VIEW_REF_NAME, FIELD_LIST_ID } from './constants';
import { FieldListApi, FieldListSerializedStateState } from './types';

Expand Down Expand Up @@ -81,20 +81,32 @@ export const getFieldListFactory = (
const subscriptions = new Subscription();
const { titlesApi, titleComparators, serializeTitles } = initializeTitles(initialState);

const allDataViews = await dataViews.getIdsWithTitle();
const selectedDataViewId$ = new BehaviorSubject<string | undefined>(
initialState.dataViewId ?? (await dataViews.getDefaultDataView())?.id
);
// set up data views
const [allDataViews, defaultDataViewId] = await Promise.all([
dataViews.getIdsWithTitle(),
dataViews.getDefaultId(),
]);
if (!defaultDataViewId || allDataViews.length === 0) {
throw new Error(
i18n.translate('embeddableExamples.unifiedFieldList.noDefaultDataViewErrorMessage', {
defaultMessage: 'The field list must be used with at least one Data View present',
})
);
}
const initialDataViewId = initialState.dataViewId ?? defaultDataViewId;
const initialDataView = await dataViews.get(initialDataViewId);
const selectedDataViewId$ = new BehaviorSubject<string | undefined>(initialDataViewId);
const dataViews$ = new BehaviorSubject<DataView[] | undefined>([initialDataView]);

// transform data view ID into data views array.
const getDataViews = async (id?: string) => {
return id ? [await dataViews.get(id)] : undefined;
};
const dataViews$ = new BehaviorSubject<DataView[] | undefined>(
await getDataViews(initialState.dataViewId)
);
subscriptions.add(
selectedDataViewId$.subscribe(async (id) => dataViews$.next(await getDataViews(id)))
selectedDataViewId$
.pipe(
skip(1),
switchMap((dataViewId) => dataViews.get(dataViewId ?? defaultDataViewId))
)
.subscribe((nextSelectedDataView) => {
dataViews$.next([nextSelectedDataView]);
})
);

const selectedFieldNames$ = new BehaviorSubject<string[] | undefined>(
Expand All @@ -104,6 +116,7 @@ export const getFieldListFactory = (
const api = buildApi(
{
...titlesApi,
dataViews: dataViews$,
serializeState: () => {
const dataViewId = selectedDataViewId$.getValue();
const references: Reference[] = dataViewId
Expand Down Expand Up @@ -141,25 +154,12 @@ export const getFieldListFactory = (
return {
api,
Component: () => {
const [selectedDataViewId, selectedFieldNames] = useBatchedPublishingSubjects(
selectedDataViewId$,
const [renderDataViews, selectedFieldNames] = useBatchedPublishingSubjects(
dataViews$,
selectedFieldNames$
);

const [selectedDataView, setSelectedDataView] = useState<DataView | undefined>(undefined);

useEffect(() => {
if (!selectedDataViewId) return;
let mounted = true;
(async () => {
const dataView = await dataViews.get(selectedDataViewId);
if (!mounted) return;
setSelectedDataView(dataView);
})();
return () => {
mounted = false;
};
}, [selectedDataViewId]);
const selectedDataView = renderDataViews?.[0];

// On destroy
useEffect(() => {
Expand All @@ -178,7 +178,7 @@ export const getFieldListFactory = (
>
<DataViewPicker
dataViews={allDataViews}
selectedDataViewId={selectedDataViewId}
selectedDataViewId={selectedDataView?.id}
onChangeDataViewId={(nextSelection) => {
selectedDataViewId$.next(nextSelection);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
*/

import { DefaultEmbeddableApi } from '@kbn/embeddable-plugin/public';
import { SerializedTitles } from '@kbn/presentation-publishing';
import { PublishesDataViews, SerializedTitles } from '@kbn/presentation-publishing';

export type FieldListSerializedStateState = SerializedTitles & {
dataViewId?: string;
selectedFieldNames?: string[];
};

export type FieldListApi = DefaultEmbeddableApi;
export type FieldListApi = DefaultEmbeddableApi & PublishesDataViews;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* Side Public License, v 1.
*/

import { apiCanAddNewPanel, EmbeddableApiContext } from '@kbn/presentation-publishing';
import { apiCanAddNewPanel } from '@kbn/presentation-containers';
import { EmbeddableApiContext } from '@kbn/presentation-publishing';
import { IncompatibleActionError, UiActionsStart } from '@kbn/ui-actions-plugin/public';
import { ADD_SEARCH_ACTION_ID, SEARCH_EMBEDDABLE_ID } from './constants';

Expand Down
3 changes: 2 additions & 1 deletion examples/embeddable_examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@kbn/content-management-utils",
"@kbn/core-lifecycle-browser",
"@kbn/presentation-util-plugin",
"@kbn/unified-field-list"
"@kbn/unified-field-list",
"@kbn/presentation-containers"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { findKey } from 'lodash';

export function getI18nIdentifierFromFilePath(fileName: string, cwd: string) {
const { dir } = parse(fileName);

const relativePathToFile = dir.replace(cwd, '');

// We need to match the path of the file that is being worked in with the path
Expand All @@ -26,7 +27,7 @@ export function getI18nIdentifierFromFilePath(fileName: string, cwd: string) {
(el) => el === 'public' || el === 'server' || el === 'common'
);

const path = relativePathArray.slice(0, pluginNameIndex).join('/');
const path = relativePathArray.slice(0, pluginNameIndex).join('/').replace('x-pack/', '');

const xpackRC = resolve(join(__dirname, '../../../'), 'x-pack/.i18nrc.json');
const rootRC = resolve(join(__dirname, '../../../'), '.i18nrc.json');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ export function getI18nImportFixer({

// If the file doesn't have an import line for the translation package yet, we need to add it.
// Pretty safe bet to add it underneath the import line for React.
let lineIndex = sourceCode.lines.findIndex((l) => l.includes("from 'react'") || l.includes('*/'));
let lineIndex = sourceCode.lines.findIndex((l) => l.includes("from 'react'"));

if (lineIndex === -1) {
lineIndex = sourceCode.lines.findIndex((l) => l.includes('*/'));
}

if (lineIndex === -1) {
lineIndex = 0;
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-eslint-plugin-i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { StringsShouldBeTranslatedWithI18n } from './rules/strings_should_be_translated_with_i18n';
import { StringsShouldBeTranslatedWithFormattedMessage } from './rules/strings_should_be_translated_with_formatted_message';
import { I18nTranslateShouldStartWithTheRightId } from './rules/i18n_translate_should_start_with_the_right_id';
import { FormattedMessageShouldStartWithTheRightId } from './rules/formatted_message_should_start_with_the_right_id';

/**
* Custom ESLint rules, add `'@kbn/eslint-plugin-i18n'` to your eslint config to use them
Expand All @@ -19,4 +20,5 @@ export const rules = {
strings_should_be_translated_with_formatted_message:
StringsShouldBeTranslatedWithFormattedMessage,
i18n_translate_should_start_with_the_right_id: I18nTranslateShouldStartWithTheRightId,
formatted_message_should_start_with_the_right_id: FormattedMessageShouldStartWithTheRightId,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* 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 { RuleTester } from 'eslint';
import {
FormattedMessageShouldStartWithTheRightId,
RULE_WARNING_MESSAGE,
} from './formatted_message_should_start_with_the_right_id';

const tsTester = [
'@typescript-eslint/parser',
new RuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parserOptions: {
sourceType: 'module',
ecmaVersion: 2018,
ecmaFeatures: {
jsx: true,
},
},
}),
] as const;

const babelTester = [
'@babel/eslint-parser',
new RuleTester({
parser: require.resolve('@babel/eslint-parser'),
parserOptions: {
sourceType: 'module',
ecmaVersion: 2018,
requireConfigFile: false,
babelOptions: {
presets: ['@kbn/babel-preset/node_preset'],
},
},
}),
] as const;

for (const [name, tester] of [tsTester, babelTester]) {
describe(name, () => {
tester.run(
'@kbn/formatted_message_should_start_with_the_right_id',
FormattedMessageShouldStartWithTheRightId,
{
valid: [
{
name: 'When a string literal is passed to FormattedMessage the ID attribute should start with the correct i18n identifier, and if no existing defaultMessage is passed, it should add an empty default.',
filename:
'/x-pack/plugins/observability_solution/observability/public/test_component.tsx',
code: `<FormattedMessage id="xpack.observability." defaultMessage="" />`,
},
{
name: 'When a string literal is passed to FormattedMessage the ID attribute should start with the correct i18n identifier, and if an existing id and defaultMessage is passed, it should leave them alone.',
filename:
'/x-pack/plugins/observability_solution/observability/public/test_component.tsx',
code: `<FormattedMessage id="xpack.observability.testComponent" defaultMessage="foo" />`,
},
],
invalid: [
{
name: 'When a string literal is passed to FormattedMessage the ID attribute should start with the correct i18n identifier, and if no existing defaultMessage is passed, it should add an empty default.',
filename:
'/x-pack/plugins/observability_solution/observability/public/test_component.tsx',
code: `
import { FormattedMessage } from '@kbn/i18n-react';
function TestComponent() {
return <FormattedMessage id="foo.bar.baz" />;
}`,
errors: [
{
line: 5,
message: RULE_WARNING_MESSAGE,
},
],
output: `
import { FormattedMessage } from '@kbn/i18n-react';
function TestComponent() {
return <FormattedMessage id="xpack.observability.bar.baz" defaultMessage="" />;
}`,
},
{
name: 'When a string literal is passed to the ID attribute of <FormattedMessage /> and the root of the i18n identifier is not correct, it should keep the existing identifier but only update the right base app, and keep the default message if available.',
filename:
'/x-pack/plugins/observability_solution/observability/public/test_component.tsx',
code: `
import { FormattedMessage } from '@kbn/i18n-react';
function TestComponent() {
return <FormattedMessage id="foo.bar.baz" defaultMessage="giraffe" />;
}`,
errors: [
{
line: 5,
message: RULE_WARNING_MESSAGE,
},
],
output: `
import { FormattedMessage } from '@kbn/i18n-react';
function TestComponent() {
return <FormattedMessage id="xpack.observability.bar.baz" defaultMessage="giraffe" />;
}`,
},
{
name: 'When no string literal is passed to the ID attribute of <FormattedMessage /> it should start with the correct i18n identifier.',
filename:
'/x-pack/plugins/observability_solution/observability/public/test_component.tsx',
code: `
import { FormattedMessage } from '@kbn/i18n-react';
function TestComponent() {
return <FormattedMessage />;
}`,
errors: [
{
line: 5,
message: RULE_WARNING_MESSAGE,
},
],
output: `
import { FormattedMessage } from '@kbn/i18n-react';
function TestComponent() {
return <FormattedMessage id="xpack.observability.testComponent." defaultMessage="" />;
}`,
},
{
name: 'When i18n is not imported yet, the rule should add it.',
filename:
'/x-pack/plugins/observability_solution/observability/public/test_component.tsx',
code: `
function TestComponent() {
return <FormattedMessage />;
}`,
errors: [
{
line: 3,
message: RULE_WARNING_MESSAGE,
},
],
output: `
import { FormattedMessage } from '@kbn/i18n-react';
function TestComponent() {
return <FormattedMessage id="xpack.observability.testComponent." defaultMessage="" />;
}`,
},
],
}
);
});
}
Loading

0 comments on commit ccccc5e

Please sign in to comment.