Skip to content

Commit

Permalink
Merge branch 'main' into ingest-pipelines/drag-and-drop-list-error-state
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ Cenizal committed Jul 27, 2022
2 parents 5b255d1 + c4b43f9 commit 061c788
Show file tree
Hide file tree
Showing 94 changed files with 1,496 additions and 963 deletions.
3 changes: 2 additions & 1 deletion .backportrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"repoName": "kibana",
"targetBranchChoices": [
"main",
"8.4",
"8.3",
"8.2",
"8.1",
Expand Down Expand Up @@ -40,7 +41,7 @@
"backport"
],
"branchLabelMapping": {
"^v8.4.0$": "main",
"^v8.5.0$": "main",
"^v(\\d+).(\\d+).\\d+$": "$1.$2"
},
"autoMerge": true,
Expand Down
2 changes: 1 addition & 1 deletion kbn_pm/src/lib/bazel.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function throwBazelError(log, name, code, output) {
async function runBazel(log, inputArgs, opts = undefined) {
const bazel = (await getBazelRunner()).runBazel;

const args = [...(opts?.offline ? ['--config=offline'] : []), ...inputArgs];
const args = [...inputArgs, ...(opts?.offline ? ['--config=offline'] : [])];
log.debug(`> bazel ${args.join(' ')}`);
await bazel(args, {
env: opts?.env,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dashboarding"
],
"private": true,
"version": "8.4.0",
"version": "8.5.0",
"branch": "main",
"types": "./kibana.d.ts",
"tsdocMetadata": "./build/tsdoc-metadata.json",
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-doc-links/src/get_doc_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ export const getDocLinks = ({ kibanaBranch }: GetDocLinkOptions): DocLinks => {
enterpriseSearch: {
bulkApi: `${ELASTICSEARCH_DOCS}docs-bulk.html`,
configuration: `${ENTERPRISE_SEARCH_DOCS}configuration.html`,
crawlerGettingStarted: `${ENTERPRISE_SEARCH_DOCS}crawler-getting-started.html`,
crawlerManaging: `${ENTERPRISE_SEARCH_DOCS}crawler-managing.html`,
crawlerOverview: `${ENTERPRISE_SEARCH_DOCS}crawler.html`,
languageAnalyzers: `${ELASTICSEARCH_DOCS}analysis-lang-analyzer.html`,
licenseManagement: `${ENTERPRISE_SEARCH_DOCS}license-management.html`,
mailService: `${ENTERPRISE_SEARCH_DOCS}mailer-configuration.html`,
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-doc-links/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ export interface DocLinks {
readonly enterpriseSearch: {
readonly bulkApi: string;
readonly configuration: string;
readonly crawlerGettingStarted: string;
readonly crawlerManaging: string;
readonly crawlerOverview: string;
readonly languageAnalyzers: string;
readonly licenseManagement: string;
readonly mailService: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ async function removeLogFile() {
await asyncUnlink(logFilePath).catch(() => void 0);
}

describe('migration v2', () => {
// FAILING ON 8.4: https://github.com/elastic/kibana/issues/137329
describe.skip('migration v2', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let root: Root;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ function createRoot() {
);
}

describe('migration v2', () => {
// FAILING ON 8.4: https://github.com/elastic/kibana/issues/137331
describe.skip('migration v2', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let root: Root;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ async function removeLogFile() {
await asyncUnlink(logFilePath).catch(() => void 0);
}

describe('migration v2 with corrupt saved object documents', () => {
// FAILING ON 8.4: https://github.com/elastic/kibana/issues/137330
describe.skip('migration v2 with corrupt saved object documents', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let root: Root;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,12 @@ const IndexPatternEditorFlyoutContentComponent = ({
</Form>
<Footer
onCancel={onCancel}
onSubmit={(adhoc?: boolean) => {
onSubmit={async (adhoc?: boolean) => {
const formData = form.getFormData();
if (!formData.name) {
form.updateFieldValues({ name: formData.title });
await form.getFields().name.validate();
}
form.setFieldValue('isAdHoc', adhoc || false);
form.submit();
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useMemo, useEffect, useState, useCallback } from 'react';
import usePrevious from 'react-use/lib/usePrevious';
import { isEqual } from 'lodash';
import { History } from 'history';
import { DataViewType } from '@kbn/data-views-plugin/public';
import {
isOfAggregateQueryType,
getIndexPatternFromSQLQuery,
Expand Down Expand Up @@ -257,6 +258,19 @@ export function useDiscoverState({
}
}, [initialFetchStatus, refetch$, indexPattern, savedSearch.id]);

/**
* We need to make sure the auto refresh interval is disabled for
* non-time series data or rollups since we don't show the date picker
*/
useEffect(() => {
if (
indexPattern &&
(!indexPattern.isTimeBased() || indexPattern.type === DataViewType.ROLLUP)
) {
stateContainer.pauseAutoRefreshInterval();
}
}, [indexPattern, stateContainer]);

const getResultColumns = useCallback(() => {
if (documentState.result?.length && documentState.fetchStatus === FetchStatus.COMPLETE) {
const firstRow = documentState.result[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const uiSettingsMock = {
} as IUiSettingsClient;

describe('Test discover state', () => {
let stopSync = () => {};

beforeEach(async () => {
history = createBrowserHistory();
history.push('/');
Expand All @@ -35,10 +37,11 @@ describe('Test discover state', () => {
uiSettings: uiSettingsMock,
});
await state.replaceUrlAppState({});
await state.startSync();
stopSync = state.startSync();
});
afterEach(() => {
state.stopSync();
stopSync();
stopSync = () => {};
});
test('setting app state and syncing to URL', async () => {
state.setAppState({ index: 'modified' });
Expand Down Expand Up @@ -77,6 +80,13 @@ describe('Test discover state', () => {
state.setAppState({ index: 'second' });
expect(state.getPreviousAppState()).toEqual(stateA);
});

test('pauseAutoRefreshInterval sets refreshInterval.pause to true', async () => {
history.push('/#?_g=(refreshInterval:(pause:!f,value:5000))');
expect(getCurrentUrl()).toBe('/#?_g=(refreshInterval:(pause:!f,value:5000))');
await state.pauseAutoRefreshInterval();
expect(getCurrentUrl()).toBe('/#?_g=(refreshInterval:(pause:!t,value:5000))');
});
});
describe('Test discover initial state sort handling', () => {
test('Non-empty sort in URL should not fallback to state defaults', async () => {
Expand All @@ -89,7 +99,7 @@ describe('Test discover initial state sort handling', () => {
uiSettings: uiSettingsMock,
});
await state.replaceUrlAppState({});
await state.startSync();
const stopSync = state.startSync();
expect(state.appStateContainer.getState().sort).toMatchInlineSnapshot(`
Array [
Array [
Expand All @@ -98,6 +108,7 @@ describe('Test discover initial state sort handling', () => {
],
]
`);
stopSync();
});
test('Empty sort in URL should allow fallback state defaults', async () => {
history = createBrowserHistory();
Expand All @@ -109,7 +120,7 @@ describe('Test discover initial state sort handling', () => {
uiSettings: uiSettingsMock,
});
await state.replaceUrlAppState({});
await state.startSync();
const stopSync = state.startSync();
expect(state.appStateContainer.getState().sort).toMatchInlineSnapshot(`
Array [
Array [
Expand All @@ -118,6 +129,7 @@ describe('Test discover initial state sort handling', () => {
],
]
`);
stopSync();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
connectToQueryState,
DataPublicPluginStart,
FilterManager,
QueryState,
SearchSessionInfoProvider,
syncQueryStateWithUrl,
} from '@kbn/data-plugin/public';
Expand Down Expand Up @@ -149,13 +150,9 @@ export interface GetStateReturn {
data: DataPublicPluginStart
) => () => void;
/**
* Start sync between state and URL
* Start sync between state and URL -- only used for testing
*/
startSync: () => void;
/**
* Stop sync between state and URL
*/
stopSync: () => void;
startSync: () => () => void;
/**
* Set app state to with a partial new app state
*/
Expand Down Expand Up @@ -184,8 +181,14 @@ export interface GetStateReturn {
* Reset AppState to default, discarding all changes
*/
resetAppState: () => void;
/**
* Pause the auto refresh interval without pushing an entry to history
*/
pauseAutoRefreshInterval: () => Promise<void>;
}

const APP_STATE_URL_KEY = '_a';
const GLOBAL_STATE_URL_KEY = '_g';

/**
* Builds and returns appState and globalState containers and helper functions
Expand Down Expand Up @@ -229,22 +232,43 @@ export function getState({
},
};

const { start, stop } = syncState({
storageKey: APP_STATE_URL_KEY,
stateContainer: appStateContainerModified,
stateStorage,
});
// Calling syncState from within initializeAndSync causes state syncing issues.
// syncState takes a snapshot of the initial state when it's called to compare
// against before syncing state updates. When syncState is called from outside
// of initializeAndSync, the snapshot doesn't get reset when the data view is
// changed. Then when the user presses the back button, the new state appears
// to be the same as the initial state, so syncState ignores the update.
const syncAppState = () =>
syncState({
storageKey: APP_STATE_URL_KEY,
stateContainer: appStateContainerModified,
stateStorage,
});

const replaceUrlAppState = async (newPartial: AppState = {}) => {
const state = { ...appStateContainer.getState(), ...newPartial };
await stateStorage.set(APP_STATE_URL_KEY, state, { replace: true });
};

const pauseAutoRefreshInterval = async () => {
const state = stateStorage.get<QueryState>(GLOBAL_STATE_URL_KEY);
if (state?.refreshInterval && !state.refreshInterval.pause) {
await stateStorage.set(
GLOBAL_STATE_URL_KEY,
{ ...state, refreshInterval: { ...state?.refreshInterval, pause: true } },
{ replace: true }
);
}
};

return {
kbnUrlStateStorage: stateStorage,
appStateContainer: appStateContainerModified,
startSync: start,
stopSync: stop,
startSync: () => {
const { start, stop } = syncAppState();
start();
return stop;
},
setAppState: (newPartial: AppState) => setState(appStateContainerModified, newPartial),
replaceUrlAppState,
resetInitialAppState: () => {
Expand All @@ -260,6 +284,7 @@ export function getState({
getPreviousAppState: () => previousAppState,
flushToUrl: () => stateStorage.kbnUrlControls.flush(),
isAppStateDirty: () => !isEqualState(initialAppState, appStateContainer.getState()),
pauseAutoRefreshInterval,
initializeAndSync: (
indexPattern: DataView,
filterManager: FilterManager,
Expand Down Expand Up @@ -294,6 +319,8 @@ export function getState({
stateStorage
);

const { start, stop } = syncAppState();

replaceUrlAppState({}).then(() => {
start();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { createFieldFormatter } from './create_field_formatter';
import moment from 'moment';
import { getFieldsForTerms } from '../../../../common/fields_utils';

export const convertSeriesToVars = (series, model, getConfig = null, fieldFormatMap) => {
export const convertSeriesToVars = (series, model, getConfig = null, fieldFormatMap, dataView) => {
const variables = {};
const dateFormat = getConfig?.('dateFormat') ?? 'lll';
model.series.forEach((seriesModel) => {
Expand Down Expand Up @@ -57,13 +57,21 @@ export const convertSeriesToVars = (series, model, getConfig = null, fieldFormat
const fieldsForTerms = getFieldsForTerms(seriesModel.terms_field);

if (fieldsForTerms.length === 1) {
rowLabel = createFieldFormatter(fieldsForTerms[0], fieldFormatMap)(row.label);
rowLabel = createFieldFormatter(
fieldsForTerms[0],
fieldFormatMap,
undefined,
false,
dataView
)(row.label);
}
}

set(variables, varName, data);
// label might be not purely alphanumeric, wrap in brackets to map sure it's resolved correctly
set(variables, `[${label}].label`, rowLabel);
// compatibility
set(variables, `[${label}].formatted`, rowLabel);
});
});
return variables;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@

import { isNumber } from 'lodash';
import { FIELD_FORMAT_IDS } from '@kbn/field-formats-plugin/common';
import type { FieldFormatMap } from '@kbn/data-views-plugin/common';
import type { FieldFormatMap, DataView } from '@kbn/data-views-plugin/common';
import type { FieldFormatsContentType } from '@kbn/field-formats-plugin/common';
import { isEmptyValue, DISPLAY_EMPTY_VALUE } from '../../../../common/last_value_utils';
import { getFieldFormats } from '../../../services';

const DEFAULT_FIELD_FORMAT = { id: 'number' };

export const createFieldFormatter = (
fieldName: string = '',
fieldFormatMap?: FieldFormatMap,
contextType?: FieldFormatsContentType,
hasColorRules: boolean = false
hasColorRules: boolean = false,
dataView?: DataView
) => {
const serializedFieldFormat = fieldFormatMap?.[fieldName];
// field formatting should be skipped either there's no such field format in fieldFormatMap
Expand All @@ -28,15 +27,23 @@ export const createFieldFormatter = (
!serializedFieldFormat ||
(hasColorRules && serializedFieldFormat?.id === FIELD_FORMAT_IDS.COLOR);

const fieldType = dataView?.getFieldByName(fieldName)?.type || 'number';
const defaultFieldFormat =
fieldType === 'date'
? { id: 'date' }
: fieldType === 'string'
? { id: 'string' }
: { id: 'number' };

const fieldFormat = getFieldFormats().deserialize(
shouldSkipFormatting ? DEFAULT_FIELD_FORMAT : serializedFieldFormat
shouldSkipFormatting ? defaultFieldFormat : serializedFieldFormat
);

return (value: unknown) => {
if (isEmptyValue(value)) {
return DISPLAY_EMPTY_VALUE;
}
return isNumber(value) || !shouldSkipFormatting
return fieldType !== 'number' || isNumber(value) || !shouldSkipFormatting
? fieldFormat.convert(value, contextType)
: value;
};
Expand Down
Loading

0 comments on commit 061c788

Please sign in to comment.