Skip to content

Commit 800965d

Browse files
Merge branch 'master' into index_pattern_management_ui_kibana_platform
2 parents 497638c + 404743a commit 800965d

File tree

19 files changed

+314
-164
lines changed

19 files changed

+314
-164
lines changed

src/plugins/saved_objects_management/public/lib/create_field_list.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ describe('createFieldList', () => {
5959
"type": "boolean",
6060
"value": true,
6161
},
62+
Object {
63+
"name": "references",
64+
"type": "array",
65+
"value": "[]",
66+
},
6267
]
6368
`);
6469
});
@@ -76,6 +81,11 @@ describe('createFieldList', () => {
7681
\\"data\\": \\"value\\"
7782
}",
7883
},
84+
Object {
85+
"name": "references",
86+
"type": "array",
87+
"value": "[]",
88+
},
7989
]
8090
`);
8191
});
@@ -93,6 +103,48 @@ describe('createFieldList', () => {
93103
1,
94104
2,
95105
3
106+
]",
107+
},
108+
Object {
109+
"name": "references",
110+
"type": "array",
111+
"value": "[]",
112+
},
113+
]
114+
`);
115+
});
116+
117+
it(`generates a field for the object's references`, () => {
118+
const obj = createObject(
119+
{
120+
someString: 'foo',
121+
},
122+
[
123+
{ id: 'ref1', type: 'type', name: 'Ref 1' },
124+
{ id: 'ref12', type: 'other-type', name: 'Ref 2' },
125+
]
126+
);
127+
expect(createFieldList(obj)).toMatchInlineSnapshot(`
128+
Array [
129+
Object {
130+
"name": "someString",
131+
"type": "text",
132+
"value": "foo",
133+
},
134+
Object {
135+
"name": "references",
136+
"type": "array",
137+
"value": "[
138+
{
139+
\\"id\\": \\"ref1\\",
140+
\\"type\\": \\"type\\",
141+
\\"name\\": \\"Ref 1\\"
142+
},
143+
{
144+
\\"id\\": \\"ref12\\",
145+
\\"type\\": \\"other-type\\",
146+
\\"name\\": \\"Ref 2\\"
147+
}
96148
]",
97149
},
98150
]
@@ -126,6 +178,11 @@ describe('createFieldList', () => {
126178
"type": "text",
127179
"value": "B",
128180
},
181+
Object {
182+
"name": "references",
183+
"type": "array",
184+
"value": "[]",
185+
},
129186
]
130187
`);
131188
});

src/plugins/saved_objects_management/public/lib/create_field_list.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ export function createFieldList(
2929
object: SimpleSavedObject,
3030
service?: SavedObjectLoader
3131
): ObjectField[] {
32-
const fields = Object.entries(object.attributes as Record<string, any>).reduce(
32+
let fields = Object.entries(object.attributes as Record<string, any>).reduce(
3333
(objFields, [key, value]) => {
34-
return [...objFields, ...recursiveCreateFields(key, value)];
34+
return [...objFields, ...createFields(key, value)];
3535
},
3636
[] as ObjectField[]
3737
);
38+
// Special handling for references which isn't within "attributes"
39+
fields = [...fields, ...createFields('references', object.references)];
40+
3841
if (service && (service as any).Class) {
3942
addFieldsFromClass((service as any).Class, fields);
4043
}
@@ -53,7 +56,7 @@ export function createFieldList(
5356
* @param {array} parents The parent keys to the field
5457
* @returns {array}
5558
*/
56-
const recursiveCreateFields = (key: string, value: any, parents: string[] = []): ObjectField[] => {
59+
const createFields = (key: string, value: any, parents: string[] = []): ObjectField[] => {
5760
const path = [...parents, key];
5861
if (path.length > maxRecursiveIterations) {
5962
return [];
@@ -78,7 +81,7 @@ const recursiveCreateFields = (key: string, value: any, parents: string[] = []):
7881
} else if (isPlainObject(field.value)) {
7982
let fields: ObjectField[] = [];
8083
forOwn(field.value, (childValue, childKey) => {
81-
fields = [...fields, ...recursiveCreateFields(childKey as string, childValue, path)];
84+
fields = [...fields, ...createFields(childKey as string, childValue, path)];
8285
});
8386
return fields;
8487
}

src/plugins/saved_objects_management/public/management_section/object_view/components/field.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export class Field extends PureComponent<FieldProps> {
120120
return (
121121
<div data-test-subj={`savedObjects-editField-${name}`}>
122122
<EuiCodeEditor
123+
name={`savedObjects-editField-${name}-aceEditor`}
123124
mode="json"
124125
theme="textmate"
125126
value={currentValue}

src/plugins/saved_objects_management/public/management_section/object_view/components/form.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ export class Form extends Component<FormProps, FormState> {
171171
set(source, field.name, value);
172172
});
173173

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

176177
await onSave({ attributes, references });

test/functional/apps/dashboard/dashboard_clone.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,7 @@ export default function({ getService, getPageObjects }) {
4242
await PageObjects.dashboard.clickClone();
4343
await PageObjects.dashboard.confirmClone();
4444
await PageObjects.dashboard.gotoDashboardLandingPage();
45-
const countOfDashboards = await listingTable.searchAndGetItemsCount(
46-
'dashboard',
47-
clonedDashboardName
48-
);
49-
50-
expect(countOfDashboards).to.equal(1);
45+
await listingTable.searchAndExpectItemsCount('dashboard', clonedDashboardName, 1);
5146
});
5247

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

78-
const countOfDashboards = await listingTable.searchAndGetItemsCount(
79-
'dashboard',
80-
dashboardName
81-
);
82-
expect(countOfDashboards).to.equal(1);
73+
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 1);
8374
});
8475

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

95-
const countOfDashboards = await listingTable.searchAndGetItemsCount(
96-
'dashboard',
97-
dashboardName + ' Copy'
98-
);
99-
expect(countOfDashboards).to.equal(2);
86+
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName + ' Copy', 2);
10087
});
10188
});
10289
}

test/functional/apps/dashboard/dashboard_listing.js

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@ export default function({ getService, getPageObjects }) {
4242
await PageObjects.dashboard.saveDashboard(dashboardName);
4343

4444
await PageObjects.dashboard.gotoDashboardLandingPage();
45-
const countOfDashboards = await listingTable.searchAndGetItemsCount(
46-
'dashboard',
47-
dashboardName
48-
);
49-
expect(countOfDashboards).to.equal(1);
45+
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 1);
5046
});
5147

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

5753
it('is not shown when there are no dashboards shown during a search', async function() {
58-
const countOfDashboards = await listingTable.searchAndGetItemsCount(
59-
'dashboard',
60-
'gobeldeguck'
61-
);
62-
expect(countOfDashboards).to.equal(0);
54+
await listingTable.searchAndExpectItemsCount('dashboard', 'gobeldeguck', 0);
6355

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

7971
await PageObjects.common.expectConfirmModalOpenState(false);
8072

81-
const countOfDashboards = await listingTable.searchAndGetItemsCount(
82-
'dashboard',
83-
dashboardName
84-
);
85-
expect(countOfDashboards).to.equal(1);
73+
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 1);
8674
});
8775

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

9280
await PageObjects.common.clickConfirmOnModal();
9381

94-
const countOfDashboards = await listingTable.searchAndGetItemsCount(
95-
'dashboard',
96-
dashboardName
97-
);
98-
expect(countOfDashboards).to.equal(0);
82+
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 0);
9983
});
10084
});
10185

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

11094
it('matches on the first word', async function() {
11195
await listingTable.searchForItemWithName('Two');
112-
const countOfDashboards = await listingTable.getItemsCount('dashboard');
113-
expect(countOfDashboards).to.equal(1);
96+
await listingTable.expectItemsCount('dashboard', 1);
11497
});
11598

11699
it('matches the second word', async function() {
117100
await listingTable.searchForItemWithName('Words');
118-
const countOfDashboards = await listingTable.getItemsCount('dashboard');
119-
expect(countOfDashboards).to.equal(1);
101+
await listingTable.expectItemsCount('dashboard', 1);
120102
});
121103

122104
it('matches the second word prefix', async function() {
123105
await listingTable.searchForItemWithName('Wor');
124-
const countOfDashboards = await listingTable.getItemsCount('dashboard');
125-
expect(countOfDashboards).to.equal(1);
106+
await listingTable.expectItemsCount('dashboard', 1);
126107
});
127108

128109
it('does not match mid word', async function() {
129110
await listingTable.searchForItemWithName('ords');
130-
const countOfDashboards = await listingTable.getItemsCount('dashboard');
131-
expect(countOfDashboards).to.equal(0);
111+
await listingTable.expectItemsCount('dashboard', 0);
132112
});
133113

134114
it('is case insensitive', async function() {
135115
await listingTable.searchForItemWithName('two words');
136-
const countOfDashboards = await listingTable.getItemsCount('dashboard');
137-
expect(countOfDashboards).to.equal(1);
116+
await listingTable.expectItemsCount('dashboard', 1);
138117
});
139118

140119
it('is using AND operator', async function() {
141120
await listingTable.searchForItemWithName('three words');
142-
const countOfDashboards = await listingTable.getItemsCount('dashboard');
143-
expect(countOfDashboards).to.equal(0);
121+
await listingTable.expectItemsCount('dashboard', 0);
144122
});
145123
});
146124

test/functional/apps/dashboard/dashboard_save.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
import expect from '@kbn/expect';
21-
2220
export default function({ getPageObjects, getService }) {
2321
const PageObjects = getPageObjects(['dashboard', 'header']);
2422
const listingTable = getService('listingTable');
@@ -50,11 +48,7 @@ export default function({ getPageObjects, getService }) {
5048
await PageObjects.dashboard.cancelSave();
5149
await PageObjects.dashboard.gotoDashboardLandingPage();
5250

53-
const countOfDashboards = await listingTable.searchAndGetItemsCount(
54-
'dashboard',
55-
dashboardName
56-
);
57-
expect(countOfDashboards).to.equal(1);
51+
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 1);
5852
});
5953

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

76-
const countOfDashboards = await listingTable.searchAndGetItemsCount(
77-
'dashboard',
78-
dashboardName
79-
);
80-
expect(countOfDashboards).to.equal(2);
70+
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 2);
8171
});
8272

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

131-
const countOfDashboards = await listingTable.searchAndGetItemsCount(
132-
'dashboard',
133-
dashboardNameEnterKey
134-
);
135-
expect(countOfDashboards).to.equal(1);
121+
await listingTable.searchAndExpectItemsCount('dashboard', dashboardNameEnterKey, 1);
136122
});
137123
});
138124
}

0 commit comments

Comments
 (0)