Skip to content

Commit

Permalink
Merge branch 'master' into index_pattern_management_ui_kibana_platform
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored May 18, 2020
2 parents 497638c + 404743a commit 800965d
Show file tree
Hide file tree
Showing 19 changed files with 314 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ describe('createFieldList', () => {
"type": "boolean",
"value": true,
},
Object {
"name": "references",
"type": "array",
"value": "[]",
},
]
`);
});
Expand All @@ -76,6 +81,11 @@ describe('createFieldList', () => {
\\"data\\": \\"value\\"
}",
},
Object {
"name": "references",
"type": "array",
"value": "[]",
},
]
`);
});
Expand All @@ -93,6 +103,48 @@ describe('createFieldList', () => {
1,
2,
3
]",
},
Object {
"name": "references",
"type": "array",
"value": "[]",
},
]
`);
});

it(`generates a field for the object's references`, () => {
const obj = createObject(
{
someString: 'foo',
},
[
{ id: 'ref1', type: 'type', name: 'Ref 1' },
{ id: 'ref12', type: 'other-type', name: 'Ref 2' },
]
);
expect(createFieldList(obj)).toMatchInlineSnapshot(`
Array [
Object {
"name": "someString",
"type": "text",
"value": "foo",
},
Object {
"name": "references",
"type": "array",
"value": "[
{
\\"id\\": \\"ref1\\",
\\"type\\": \\"type\\",
\\"name\\": \\"Ref 1\\"
},
{
\\"id\\": \\"ref12\\",
\\"type\\": \\"other-type\\",
\\"name\\": \\"Ref 2\\"
}
]",
},
]
Expand Down Expand Up @@ -126,6 +178,11 @@ describe('createFieldList', () => {
"type": "text",
"value": "B",
},
Object {
"name": "references",
"type": "array",
"value": "[]",
},
]
`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ export function createFieldList(
object: SimpleSavedObject,
service?: SavedObjectLoader
): ObjectField[] {
const fields = Object.entries(object.attributes as Record<string, any>).reduce(
let fields = Object.entries(object.attributes as Record<string, any>).reduce(
(objFields, [key, value]) => {
return [...objFields, ...recursiveCreateFields(key, value)];
return [...objFields, ...createFields(key, value)];
},
[] as ObjectField[]
);
// Special handling for references which isn't within "attributes"
fields = [...fields, ...createFields('references', object.references)];

if (service && (service as any).Class) {
addFieldsFromClass((service as any).Class, fields);
}
Expand All @@ -53,7 +56,7 @@ export function createFieldList(
* @param {array} parents The parent keys to the field
* @returns {array}
*/
const recursiveCreateFields = (key: string, value: any, parents: string[] = []): ObjectField[] => {
const createFields = (key: string, value: any, parents: string[] = []): ObjectField[] => {
const path = [...parents, key];
if (path.length > maxRecursiveIterations) {
return [];
Expand All @@ -78,7 +81,7 @@ const recursiveCreateFields = (key: string, value: any, parents: string[] = []):
} else if (isPlainObject(field.value)) {
let fields: ObjectField[] = [];
forOwn(field.value, (childValue, childKey) => {
fields = [...fields, ...recursiveCreateFields(childKey as string, childValue, path)];
fields = [...fields, ...createFields(childKey as string, childValue, path)];
});
return fields;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class Field extends PureComponent<FieldProps> {
return (
<div data-test-subj={`savedObjects-editField-${name}`}>
<EuiCodeEditor
name={`savedObjects-editField-${name}-aceEditor`}
mode="json"
theme="textmate"
value={currentValue}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export class Form extends Component<FormProps, FormState> {
set(source, field.name, value);
});

// we extract the `references` field that does not belong to attributes
const { references, ...attributes } = source;

await onSave({ attributes, references });
Expand Down
19 changes: 3 additions & 16 deletions test/functional/apps/dashboard/dashboard_clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ export default function({ getService, getPageObjects }) {
await PageObjects.dashboard.clickClone();
await PageObjects.dashboard.confirmClone();
await PageObjects.dashboard.gotoDashboardLandingPage();
const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
clonedDashboardName
);

expect(countOfDashboards).to.equal(1);
await listingTable.searchAndExpectItemsCount('dashboard', clonedDashboardName, 1);
});

it('the copy should have all the same visualizations', async function() {
Expand Down Expand Up @@ -75,11 +70,7 @@ export default function({ getService, getPageObjects }) {
await PageObjects.dashboard.cancelClone();
await PageObjects.dashboard.gotoDashboardLandingPage();

const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
dashboardName
);
expect(countOfDashboards).to.equal(1);
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 1);
});

it('Clones on confirm duplicate title warning', async function() {
Expand All @@ -92,11 +83,7 @@ export default function({ getService, getPageObjects }) {
await PageObjects.dashboard.waitForRenderComplete();
await PageObjects.dashboard.gotoDashboardLandingPage();

const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
dashboardName + ' Copy'
);
expect(countOfDashboards).to.equal(2);
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName + ' Copy', 2);
});
});
}
42 changes: 10 additions & 32 deletions test/functional/apps/dashboard/dashboard_listing.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ export default function({ getService, getPageObjects }) {
await PageObjects.dashboard.saveDashboard(dashboardName);

await PageObjects.dashboard.gotoDashboardLandingPage();
const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
dashboardName
);
expect(countOfDashboards).to.equal(1);
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 1);
});

it('is not shown when there is a dashboard', async function() {
Expand All @@ -55,11 +51,7 @@ export default function({ getService, getPageObjects }) {
});

it('is not shown when there are no dashboards shown during a search', async function() {
const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
'gobeldeguck'
);
expect(countOfDashboards).to.equal(0);
await listingTable.searchAndExpectItemsCount('dashboard', 'gobeldeguck', 0);

const promptExists = await PageObjects.dashboard.getCreateDashboardPromptExists();
expect(promptExists).to.be(false);
Expand All @@ -78,11 +70,7 @@ export default function({ getService, getPageObjects }) {

await PageObjects.common.expectConfirmModalOpenState(false);

const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
dashboardName
);
expect(countOfDashboards).to.equal(1);
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 1);
});

it('succeeds on confirmation press', async function() {
Expand All @@ -91,11 +79,7 @@ export default function({ getService, getPageObjects }) {

await PageObjects.common.clickConfirmOnModal();

const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
dashboardName
);
expect(countOfDashboards).to.equal(0);
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 0);
});
});

Expand All @@ -109,38 +93,32 @@ export default function({ getService, getPageObjects }) {

it('matches on the first word', async function() {
await listingTable.searchForItemWithName('Two');
const countOfDashboards = await listingTable.getItemsCount('dashboard');
expect(countOfDashboards).to.equal(1);
await listingTable.expectItemsCount('dashboard', 1);
});

it('matches the second word', async function() {
await listingTable.searchForItemWithName('Words');
const countOfDashboards = await listingTable.getItemsCount('dashboard');
expect(countOfDashboards).to.equal(1);
await listingTable.expectItemsCount('dashboard', 1);
});

it('matches the second word prefix', async function() {
await listingTable.searchForItemWithName('Wor');
const countOfDashboards = await listingTable.getItemsCount('dashboard');
expect(countOfDashboards).to.equal(1);
await listingTable.expectItemsCount('dashboard', 1);
});

it('does not match mid word', async function() {
await listingTable.searchForItemWithName('ords');
const countOfDashboards = await listingTable.getItemsCount('dashboard');
expect(countOfDashboards).to.equal(0);
await listingTable.expectItemsCount('dashboard', 0);
});

it('is case insensitive', async function() {
await listingTable.searchForItemWithName('two words');
const countOfDashboards = await listingTable.getItemsCount('dashboard');
expect(countOfDashboards).to.equal(1);
await listingTable.expectItemsCount('dashboard', 1);
});

it('is using AND operator', async function() {
await listingTable.searchForItemWithName('three words');
const countOfDashboards = await listingTable.getItemsCount('dashboard');
expect(countOfDashboards).to.equal(0);
await listingTable.expectItemsCount('dashboard', 0);
});
});

Expand Down
20 changes: 3 additions & 17 deletions test/functional/apps/dashboard/dashboard_save.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

import expect from '@kbn/expect';

export default function({ getPageObjects, getService }) {
const PageObjects = getPageObjects(['dashboard', 'header']);
const listingTable = getService('listingTable');
Expand Down Expand Up @@ -50,11 +48,7 @@ export default function({ getPageObjects, getService }) {
await PageObjects.dashboard.cancelSave();
await PageObjects.dashboard.gotoDashboardLandingPage();

const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
dashboardName
);
expect(countOfDashboards).to.equal(1);
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 1);
});

it('Saves on confirm duplicate title warning', async function() {
Expand All @@ -73,11 +67,7 @@ export default function({ getPageObjects, getService }) {
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.dashboard.gotoDashboardLandingPage();

const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
dashboardName
);
expect(countOfDashboards).to.equal(2);
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 2);
});

it('Does not warn when you save an existing dashboard with the title it already has, and that title is a duplicate', async function() {
Expand Down Expand Up @@ -128,11 +118,7 @@ export default function({ getPageObjects, getService }) {
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.dashboard.gotoDashboardLandingPage();

const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
dashboardNameEnterKey
);
expect(countOfDashboards).to.equal(1);
await listingTable.searchAndExpectItemsCount('dashboard', dashboardNameEnterKey, 1);
});
});
}
Loading

0 comments on commit 800965d

Please sign in to comment.