[Data] Move the rest of the datatable utility functions to the related service (#134562)

* Move date histogram column meta utility function to the datatable utilities service
* Move number histogram interval utility function to the datatable utilities service
* Move precision error check to the datatable utility service
This commit is contained in:
Michael Dokolin 2022-06-20 10:25:37 +02:00 committed by GitHub
parent 161e9df8c3
commit f13d321c9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 453 additions and 293 deletions

View file

@ -14,7 +14,7 @@ import {
getTimeScale,
getDatatable,
} from '../../common/expressions';
import { getFormatFactory, getTimeZoneFactory } from './utils';
import { getDatatableUtilitiesFactory, getFormatFactory, getTimeZoneFactory } from './utils';
import type { PluginStartContract } from '../plugin';
@ -27,6 +27,6 @@ export const setupExpressions = (
formatColumn,
renameColumns,
getDatatable(getFormatFactory(core)),
getTimeScale(getTimeZoneFactory(core)),
getTimeScale(getDatatableUtilitiesFactory(core), getTimeZoneFactory(core)),
].forEach((expressionFn) => expressions.registerFunction(expressionFn));
};

View file

@ -43,3 +43,20 @@ export const getTimeZoneFactory =
/** if `Browser`, hardcode it to 'UTC' so the export has data that makes sense **/
return timezone === 'Browser' ? 'UTC' : timezone;
};
/** @internal **/
export const getDatatableUtilitiesFactory =
(core: CoreSetup<PluginStartContract>) => async (context: ExecutionContext) => {
const kibanaRequest = context.getKibanaRequest?.();
if (!kibanaRequest) {
throw new Error('expression function cannot be executed without a KibanaRequest');
}
const [{ elasticsearch, savedObjects }, { data }] = await core.getStartServices();
const elasticsearchClient = elasticsearch.client.asScoped(kibanaRequest).asCurrentUser;
const savedObjectsClient = savedObjects.getScopedClient(kibanaRequest);
const { datatableUtilities } = data;
return datatableUtilities.asScopedToClient(savedObjectsClient, elasticsearchClient);
};