Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage telemetry opt-in via a dedicated document #22268

Merged
merged 20 commits into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,27 @@ exports[`AdvancedSettings should render normally 1`] = `
],
}
}
showNoResultsMessage={true}
/>
<advanced_settings_page_footer
onQueryMatchChange={[Function]}
query={
Query {
"ast": _AST {
"_clauses": Array [],
"_indexedClauses": Object {
"field": Object {},
"is": Object {},
"term": Array [],
},
},
"syntax": Object {
"parse": [Function],
"print": [Function],
},
"text": "",
}
}
/>
</div>
`;
Expand Down Expand Up @@ -420,6 +441,45 @@ exports[`AdvancedSettings should render specific setting if given setting key 1`
],
}
}
showNoResultsMessage={true}
/>
<advanced_settings_page_footer
onQueryMatchChange={[Function]}
query={
Query {
"ast": _AST {
"_clauses": Array [
Object {
"field": "ariaName",
"match": "must",
"operator": "eq",
"type": "field",
"value": "test string setting",
},
],
"_indexedClauses": Object {
"field": Object {
"ariaName": Array [
Object {
"field": "ariaName",
"match": "must",
"operator": "eq",
"type": "field",
"value": "test string setting",
},
],
},
"is": Object {},
"term": Array [],
},
},
"syntax": Object {
"parse": [Function],
"print": [Function],
},
"text": "ariaName:\\"test string setting\\"",
}
}
/>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { Form } from './components/form';
import { getAriaName, toEditableConfig, DEFAULT_CATEGORY } from './lib';

import './advanced_settings.less';
import { registerDefaultComponents, PAGE_TITLE_COMPONENT } from './components/default_component_registry';
import { registerDefaultComponents, PAGE_TITLE_COMPONENT, PAGE_FOOTER_COMPONENT } from './components/default_component_registry';
import { getSettingsComponent } from './components/component_registry';

export class AdvancedSettings extends Component {
Expand All @@ -51,6 +51,7 @@ export class AdvancedSettings extends Component {
this.init(config);
this.state = {
query: parsedQuery,
footerQueryMatched: false,
filteredSettings: this.mapSettings(Query.execute(parsedQuery, this.settings)),
};

Expand Down Expand Up @@ -129,14 +130,22 @@ export class AdvancedSettings extends Component {
clearQuery = () => {
this.setState({
query: Query.parse(''),
footerQueryMatched: false,
filteredSettings: this.groupedSettings,
});
}

onFooterQueryMatchChange = (matched) => {
this.setState({
footerQueryMatched: matched
});
}

render() {
const { filteredSettings, query } = this.state;
const { filteredSettings, query, footerQueryMatched } = this.state;

const PageTitle = getSettingsComponent(PAGE_TITLE_COMPONENT);
const PageFooter = getSettingsComponent(PAGE_FOOTER_COMPONENT);

return (
<div className="advancedSettings">
Expand All @@ -162,7 +171,9 @@ export class AdvancedSettings extends Component {
clearQuery={this.clearQuery}
save={this.saveConfig}
clear={this.clearConfig}
showNoResultsMessage={!footerQueryMatched}
/>
<PageFooter query={query} onQueryMatchChange={this.onFooterQueryMatchChange} />
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@

import { tryRegisterSettingsComponent } from './component_registry';
import { PageTitle } from './page_title';
import { PageFooter } from './page_footer';

export const PAGE_TITLE_COMPONENT = 'advanced_settings_page_title';
export const PAGE_FOOTER_COMPONENT = 'advanced_settings_page_footer';

export function registerDefaultComponents() {
tryRegisterSettingsComponent(PAGE_TITLE_COMPONENT, PageTitle);
tryRegisterSettingsComponent(PAGE_FOOTER_COMPONENT, PageFooter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class Field extends PureComponent {

getEditableValue(type, value, defVal) {
const val = (value === null || value === undefined) ? defVal : value;
switch(type) {
switch (type) {
case 'array':
return val.join(', ');
case 'boolean':
Expand All @@ -102,10 +102,10 @@ export class Field extends PureComponent {
}

getDisplayedDefaultValue(type, defVal) {
if(defVal === undefined || defVal === null || defVal === '') {
if (defVal === undefined || defVal === null || defVal === '') {
return 'null';
}
switch(type) {
switch (type) {
case 'array':
return defVal.join(', ');
default:
Expand Down Expand Up @@ -193,7 +193,7 @@ export class Field extends PureComponent {
}

onImageChange = async (files) => {
if(!files.length) {
if (!files.length) {
this.clearError();
this.setState({
unsavedValue: null,
Expand All @@ -212,18 +212,18 @@ export class Field extends PureComponent {
changeImage: true,
unsavedValue: base64Image,
});
} catch(err) {
} catch (err) {
toastNotifications.addDanger('Image could not be saved');
this.cancelChangeImage();
}
}

getImageAsBase64(file) {
if(!file instanceof File) {
if (!file instanceof File) {
return null;
}

const reader = new FileReader();
const reader = new FileReader();
reader.readAsDataURL(file);

return new Promise((resolve, reject) => {
Expand All @@ -245,7 +245,7 @@ export class Field extends PureComponent {
cancelChangeImage = () => {
const { savedValue } = this.state;

if(this.changeImageForm) {
if (this.changeImageForm) {
this.changeImageForm.fileInput.value = null;
this.changeImageForm.handleChange();
}
Expand All @@ -268,14 +268,14 @@ export class Field extends PureComponent {
const { name, defVal, type } = this.props.setting;
const { changeImage, savedValue, unsavedValue, isJsonArray } = this.state;

if(savedValue === unsavedValue) {
if (savedValue === unsavedValue) {
return;
}

let valueToSave = unsavedValue;
let isSameValue = false;

switch(type) {
switch (type) {
case 'array':
valueToSave = valueToSave.split(',').map(val => val.trim());
isSameValue = valueToSave.join(',') === defVal.join(',');
Expand All @@ -295,10 +295,10 @@ export class Field extends PureComponent {
await this.props.save(name, valueToSave);
}

if(changeImage) {
if (changeImage) {
this.cancelChangeImage();
}
} catch(e) {
} catch (e) {
toastNotifications.addDanger(`Unable to save ${name}`);
}
this.setLoading(false);
Expand All @@ -311,7 +311,7 @@ export class Field extends PureComponent {
await this.props.clear(name);
this.cancelChangeImage();
this.clearError();
} catch(e) {
} catch (e) {
toastNotifications.addDanger(`Unable to reset ${name}`);
}
this.setLoading(false);
Expand All @@ -321,7 +321,7 @@ export class Field extends PureComponent {
const { loading, changeImage, unsavedValue } = this.state;
const { name, value, type, options, isOverridden } = setting;

switch(type) {
switch (type) {
case 'boolean':
return (
<EuiSwitch
Expand Down Expand Up @@ -359,7 +359,7 @@ export class Field extends PureComponent {
</div>
);
case 'image':
if(!isDefaultValue(setting) && !changeImage) {
if (!isDefaultValue(setting) && !changeImage) {
return (
<EuiImage
allowFullScreen
Expand Down Expand Up @@ -419,7 +419,7 @@ export class Field extends PureComponent {
}

renderLabel(setting) {
return(
return (
<span aria-label={setting.ariaName}>
{setting.name}
</span>
Expand All @@ -438,7 +438,7 @@ export class Field extends PureComponent {
const defaultLink = this.renderResetToDefaultLink(setting);
const imageLink = this.renderChangeImageLink(setting);

if(defaultLink || imageLink) {
if (defaultLink || imageLink) {
return (
<span>
{defaultLink}
Expand All @@ -462,30 +462,40 @@ export class Field extends PureComponent {
}

renderDescription(setting) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the whitespace deltas in this file. The important change is here. The description used to always render html (dangerously, I might add), but now it will render a React element if one is provided. If not, then it falls back to the original behavior. I need this so that I can render EuiLinks within the usage data description

return (
<Fragment>
let description;

if (React.isValidElement(setting.description)) {
description = setting.description;
} else {
description = (
<div
/*
* Justification for dangerouslySetInnerHTML:
* Setting description may contain formatting and links to documentation.
*/
dangerouslySetInnerHTML={{ __html: setting.description }} //eslint-disable-line react/no-danger
/>
);
}

return (
<Fragment>
{description}
{this.renderDefaultValue(setting)}
</Fragment>
);
}

renderDefaultValue(setting) {
const { type, defVal } = setting;
if(isDefaultValue(setting)) {
if (isDefaultValue(setting)) {
return;
}
return (
<Fragment>
<EuiSpacer size="s" />
<EuiText size="xs">
{ type === 'json' ? (
{type === 'json' ? (
<Fragment>
Default:
<EuiCodeBlock
Expand All @@ -498,17 +508,17 @@ export class Field extends PureComponent {
</Fragment>
) : (
<Fragment>
Default: <EuiCode>{this.getDisplayedDefaultValue(type, defVal)}</EuiCode>
Default: <EuiCode>{this.getDisplayedDefaultValue(type, defVal)}</EuiCode>
</Fragment>
) }
)}
</EuiText>
</Fragment>
);
}

renderResetToDefaultLink(setting) {
const { ariaName, name } = setting;
if(isDefaultValue(setting)) {
if (isDefaultValue(setting)) {
return;
}
return (
Expand All @@ -528,7 +538,7 @@ export class Field extends PureComponent {
renderChangeImageLink(setting) {
const { changeImage } = this.state;
const { type, value, ariaName, name } = setting;
if(type !== 'image' || !value || changeImage) {
if (type !== 'image' || !value || changeImage) {
return;
}
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Form should not render no settings message when instructed not to 1`] = `<React.Fragment />`;

exports[`Form should render no settings message when there are no settings 1`] = `
<React.Fragment>
<EuiPanel
Expand Down
Loading