Skip to content

Commit

Permalink
[CANVAS] Gets ride of chrome/ui for advanced settings (elastic#61865) (
Browse files Browse the repository at this point in the history
…elastic#62168)

* Gets ride of chrome/ui for advanced settings

* Mock new platform for test

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
Corey Robertson and elasticmachine committed Apr 8, 2020
1 parent 2ae38b7 commit 827a581
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { openSans } from '../../../common/lib/fonts';
import header from './header.png';
import { AdvancedSettings } from '../../../public/lib/kibana_advanced_settings';
import { getAdvancedSettings } from '../../../public/lib/kibana_advanced_settings';

import { ElementFactory } from '../../../types';
export const metric: ElementFactory = () => ({
Expand All @@ -23,6 +23,6 @@ export const metric: ElementFactory = () => ({
| metric "Countries"
metricFont={font size=48 family="${openSans.value}" color="#000000" align="center" lHeight=48}
labelFont={font size=14 family="${openSans.value}" color="#000000" align="center"}
metricFormat="${AdvancedSettings.get('format:number:defaultPattern')}"
metricFormat="${getAdvancedSettings().get('format:number:defaultPattern')}"
| render`,
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
*/

import React from 'react';
import { AdvancedSettings } from '../../../../public/lib/kibana_advanced_settings';
import { getAdvancedSettings } from '../../../../public/lib/kibana_advanced_settings';
import { TimeFilter as Component, Props } from './time_filter';

export const TimeFilter = (props: Props) => {
const customQuickRanges = (AdvancedSettings.get('timepicker:quickRanges') || []).map(
const customQuickRanges = (getAdvancedSettings().get('timepicker:quickRanges') || []).map(
({ from, to, display }: { from: string; to: string; display: string }) => ({
start: from,
end: to,
label: display,
})
);

const customDateFormat = AdvancedSettings.get('dateFormat');
const customDateFormat = getAdvancedSettings().get('dateFormat');

return (
<Component {...props} commonlyUsedRanges={customQuickRanges} dateFormat={customDateFormat} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
import { compose, withProps } from 'recompose';
import moment from 'moment';
import { DateFormatArgInput as Component, Props as ComponentProps } from './date_format';
import { AdvancedSettings } from '../../../../public/lib/kibana_advanced_settings';
import { getAdvancedSettings } from '../../../../public/lib/kibana_advanced_settings';
// @ts-ignore untyped local lib
import { templateFromReactComponent } from '../../../../public/lib/template_from_react_component';
import { ArgumentFactory } from '../../../../types/arguments';
import { ArgumentStrings } from '../../../../i18n';

const { DateFormat: strings } = ArgumentStrings;

const formatMap = {
DEFAULT: AdvancedSettings.get('dateFormat'),
NANOS: AdvancedSettings.get('dateNanosFormat'),
const getFormatMap = () => ({
DEFAULT: getAdvancedSettings().get('dateFormat'),
NANOS: getAdvancedSettings().get('dateNanosFormat'),
ISO8601: '',
LOCAL_LONG: 'LLLL',
LOCAL_SHORT: 'LLL',
LOCAL_DATE: 'l',
LOCAL_TIME_WITH_SECONDS: 'LTS',
};
});

const now = moment();

const dateFormats = Object.values(formatMap).map(format => ({
const dateFormats = Object.values(getFormatMap()).map(format => ({
value: format,
text: moment.utc(now).format(format),
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,36 @@

import { compose, withProps } from 'recompose';
import { NumberFormatArgInput as Component, Props as ComponentProps } from './number_format';
import { AdvancedSettings } from '../../../../public/lib/kibana_advanced_settings';
import { getAdvancedSettings } from '../../../../public/lib/kibana_advanced_settings';
// @ts-ignore untyped local lib
import { templateFromReactComponent } from '../../../../public/lib/template_from_react_component';
import { ArgumentFactory } from '../../../../types/arguments';
import { ArgumentStrings } from '../../../../i18n';

const { NumberFormat: strings } = ArgumentStrings;

const formatMap = {
NUMBER: AdvancedSettings.get('format:number:defaultPattern'),
PERCENT: AdvancedSettings.get('format:percent:defaultPattern'),
CURRENCY: AdvancedSettings.get('format:currency:defaultPattern'),
const getFormatMap = () => ({
NUMBER: getAdvancedSettings().get('format:number:defaultPattern'),
PERCENT: getAdvancedSettings().get('format:percent:defaultPattern'),
CURRENCY: getAdvancedSettings().get('format:currency:defaultPattern'),
DURATION: '00:00:00',
BYTES: AdvancedSettings.get('format:bytes:defaultPattern'),
};
BYTES: getAdvancedSettings().get('format:bytes:defaultPattern'),
});

const numberFormats = [
{ value: formatMap.NUMBER, text: strings.getFormatNumber() },
{ value: formatMap.PERCENT, text: strings.getFormatPercent() },
{ value: formatMap.CURRENCY, text: strings.getFormatCurrency() },
{ value: formatMap.DURATION, text: strings.getFormatDuration() },
{ value: formatMap.BYTES, text: strings.getFormatBytes() },
];
const getNumberFormats = () => {
const formatMap = getFormatMap();
return [
{ value: formatMap.NUMBER, text: strings.getFormatNumber() },
{ value: formatMap.PERCENT, text: strings.getFormatPercent() },
{ value: formatMap.CURRENCY, text: strings.getFormatCurrency() },
{ value: formatMap.DURATION, text: strings.getFormatDuration() },
{ value: formatMap.BYTES, text: strings.getFormatBytes() },
];
};

export const NumberFormatArgInput = compose<ComponentProps, null>(withProps({ numberFormats }))(
Component
);
export const NumberFormatArgInput = compose<ComponentProps, null>(
withProps({ numberFormats: getNumberFormats() })
)(Component);

export const numberFormat: ArgumentFactory<ComponentProps> = () => ({
name: 'numberFormat',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { openSans } from '../../../common/lib/fonts';
import { AdvancedSettings } from '../../../public/lib/kibana_advanced_settings';
import { getAdvancedSettings } from '../../../public/lib/kibana_advanced_settings';
import { ViewStrings } from '../../../i18n';

const { Metric: strings } = ViewStrings;
Expand All @@ -21,7 +21,7 @@ export const metric = () => ({
displayName: strings.getMetricFormatDisplayName(),
help: strings.getMetricFormatHelp(),
argType: 'numberFormat',
default: `"${AdvancedSettings.get('format:number:defaultPattern')}"`,
default: `"${getAdvancedSettings().get('format:number:defaultPattern')}"`,
},
{
name: '_',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

jest.mock('ui/new_platform');
import { getElementStrings } from './element_strings';
import { elementSpecs } from '../../canvas_plugin_src/elements';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import { ConfirmModal } from '../confirm_modal';
import { Link } from '../link';
import { Paginate } from '../paginate';
import { ComponentStrings } from '../../../i18n';
import { AdvancedSettings } from '../../lib/kibana_advanced_settings';
import { getAdvancedSettings } from '../../lib/kibana_advanced_settings';
import { WorkpadDropzone } from './workpad_dropzone';
import { WorkpadCreate } from './workpad_create';
import { WorkpadSearch } from './workpad_search';
import { uploadWorkpad } from './upload_workpad';

const { WorkpadLoader: strings } = ComponentStrings;

const formatDate = date => date && moment(date).format(AdvancedSettings.get('dateFormat'));
const formatDate = date => date && moment(date).format(getAdvancedSettings().get('dateFormat'));

const getDisplayName = (name, workpad, loadedWorkpad) => {
const workpadName = name.length ? name : <em>{workpad.id}</em>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import chrome from 'ui/chrome';
import { getCoreStart } from '../legacy';

export const AdvancedSettings = chrome.getUiSettingsClient();
export const getAdvancedSettings = () => getCoreStart().uiSettings;

0 comments on commit 827a581

Please sign in to comment.