Skip to content

Commit 21615c1

Browse files
authored
SO management: fix legacy import index pattern selection being reset when switching page (#81621)
* fix legacy import index pattern selection being reset when switching pages * update snapshots
1 parent 2aeeb6e commit 21615c1

File tree

5 files changed

+204
-26
lines changed

5 files changed

+204
-26
lines changed

src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/flyout.test.tsx.snap

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.tsx

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export interface FlyoutState {
8888
conflictedSavedObjectsLinkedToSavedSearches?: any[];
8989
conflictedSearchDocs?: any[];
9090
unmatchedReferences?: ProcessedImportResponse['unmatchedReferences'];
91+
unmatchedReferencesTablePagination: { pageIndex: number; pageSize: number };
9192
failedImports?: ProcessedImportResponse['failedImports'];
9293
successfulImports?: ProcessedImportResponse['successfulImports'];
9394
conflictingRecord?: ConflictingRecord;
@@ -115,6 +116,10 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> {
115116
conflictedSavedObjectsLinkedToSavedSearches: undefined,
116117
conflictedSearchDocs: undefined,
117118
unmatchedReferences: undefined,
119+
unmatchedReferencesTablePagination: {
120+
pageIndex: 0,
121+
pageSize: 5,
122+
},
118123
conflictingRecord: undefined,
119124
error: undefined,
120125
file: undefined,
@@ -467,7 +472,7 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> {
467472
};
468473

469474
renderUnmatchedReferences() {
470-
const { unmatchedReferences } = this.state;
475+
const { unmatchedReferences, unmatchedReferencesTablePagination: tablePagination } = this.state;
471476

472477
if (!unmatchedReferences) {
473478
return null;
@@ -527,22 +532,28 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> {
527532
{ defaultMessage: 'New index pattern' }
528533
),
529534
render: (id: string) => {
530-
const options = this.state.indexPatterns!.map(
531-
(indexPattern) =>
532-
({
533-
text: indexPattern.title,
534-
value: indexPattern.id,
535-
'data-test-subj': `indexPatternOption-${indexPattern.title}`,
536-
} as { text: string; value: string; 'data-test-subj'?: string })
537-
);
538-
539-
options.unshift({
540-
text: '-- Skip Import --',
541-
value: '',
542-
});
535+
const options = [
536+
{
537+
text: '-- Skip Import --',
538+
value: '',
539+
},
540+
...this.state.indexPatterns!.map(
541+
(indexPattern) =>
542+
({
543+
text: indexPattern.title,
544+
value: indexPattern.id,
545+
'data-test-subj': `indexPatternOption-${indexPattern.title}`,
546+
} as { text: string; value: string; 'data-test-subj'?: string })
547+
),
548+
];
549+
550+
const selectedValue =
551+
unmatchedReferences?.find((unmatchedRef) => unmatchedRef.existingIndexPatternId === id)
552+
?.newIndexPatternId ?? '';
543553

544554
return (
545555
<EuiSelect
556+
value={selectedValue}
546557
data-test-subj={`managementChangeIndexSelection-${id}`}
547558
onChange={(e) => this.onIndexChanged(id, e)}
548559
options={options}
@@ -553,6 +564,7 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> {
553564
];
554565

555566
const pagination = {
567+
...tablePagination,
556568
pageSizeOptions: [5, 10, 25],
557569
};
558570

@@ -561,6 +573,16 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> {
561573
items={unmatchedReferences as any[]}
562574
columns={columns}
563575
pagination={pagination}
576+
onTableChange={({ page }) => {
577+
if (page) {
578+
this.setState({
579+
unmatchedReferencesTablePagination: {
580+
pageSize: page.size,
581+
pageIndex: page.index,
582+
},
583+
});
584+
}
585+
}}
564586
/>
565587
);
566588
}

test/functional/apps/management/_import_objects.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -421,21 +421,40 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
421421
expect(isSavedObjectImported).to.be(true);
422422
});
423423

424-
it('should import saved objects with index patterns when index patterns does not exists', async () => {
425-
// First, we need to delete the index pattern
426-
await PageObjects.savedObjects.clickCheckboxByTitle('logstash-*');
427-
await PageObjects.savedObjects.clickDelete();
428-
429-
// Then, import the objects
424+
it('should preserve index patterns selection when switching between pages', async () => {
430425
await PageObjects.savedObjects.importFile(
431-
path.join(__dirname, 'exports', '_import_objects_with_index_patterns.json')
426+
path.join(__dirname, 'exports', '_import_objects_missing_all_index_patterns.json')
432427
);
433-
await PageObjects.savedObjects.checkImportSucceeded();
434-
await PageObjects.savedObjects.clickImportDone();
435428

436-
const objects = await PageObjects.savedObjects.getRowTitles();
437-
const isSavedObjectImported = objects.includes('saved object imported with index pattern');
438-
expect(isSavedObjectImported).to.be(true);
429+
await PageObjects.savedObjects.setOverriddenIndexPatternValue(
430+
'missing-index-pattern-1',
431+
'index-pattern-test-1'
432+
);
433+
434+
await testSubjects.click('pagination-button-next');
435+
436+
await PageObjects.savedObjects.setOverriddenIndexPatternValue(
437+
'missing-index-pattern-7',
438+
'index-pattern-test-2'
439+
);
440+
441+
await testSubjects.click('pagination-button-previous');
442+
443+
const selectedIdForMissingIndexPattern1 = await testSubjects.getAttribute(
444+
'managementChangeIndexSelection-missing-index-pattern-1',
445+
'value'
446+
);
447+
448+
expect(selectedIdForMissingIndexPattern1).to.eql('f1e4c910-a2e6-11e7-bb30-233be9be6a20');
449+
450+
await testSubjects.click('pagination-button-next');
451+
452+
const selectedIdForMissingIndexPattern7 = await testSubjects.getAttribute(
453+
'managementChangeIndexSelection-missing-index-pattern-7',
454+
'value'
455+
);
456+
457+
expect(selectedIdForMissingIndexPattern7).to.eql('f1e4c910-a2e6-11e7-bb30-233be9be6a87');
439458
});
440459
});
441460
});
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
[
2+
{
3+
"_id": "test-vis-1",
4+
"_type": "visualization",
5+
"_source": {
6+
"title": "Test VIS 1",
7+
"visState": "{\"title\":\"test vis 1\",\"type\":\"histogram\"}",
8+
"uiStateJSON": "{}",
9+
"description": "",
10+
"version": 1,
11+
"kibanaSavedObjectMeta": {
12+
"searchSourceJSON": "{\"index\":\"missing-index-pattern-1\",\"query\":{}}"
13+
}
14+
},
15+
"_meta": {
16+
"savedObjectVersion": 2
17+
}
18+
},
19+
{
20+
"_id": "test-vis-2",
21+
"_type": "visualization",
22+
"_source": {
23+
"title": "Test VIS 2",
24+
"visState": "{\"title\":\"test vis 2\",\"type\":\"histogram\"}",
25+
"uiStateJSON": "{}",
26+
"description": "",
27+
"version": 1,
28+
"kibanaSavedObjectMeta": {
29+
"searchSourceJSON": "{\"index\":\"missing-index-pattern-2\",\"query\":{}}"
30+
}
31+
},
32+
"_meta": {
33+
"savedObjectVersion": 2
34+
}
35+
},
36+
{
37+
"_id": "test-vis-3",
38+
"_type": "visualization",
39+
"_source": {
40+
"title": "Test VIS 3",
41+
"visState": "{\"title\":\"test vis 3\",\"type\":\"histogram\"}",
42+
"uiStateJSON": "{}",
43+
"description": "",
44+
"version": 1,
45+
"kibanaSavedObjectMeta": {
46+
"searchSourceJSON": "{\"index\":\"missing-index-pattern-3\",\"query\":{}}"
47+
}
48+
},
49+
"_meta": {
50+
"savedObjectVersion": 2
51+
}
52+
},
53+
{
54+
"_id": "test-vis-4",
55+
"_type": "visualization",
56+
"_source": {
57+
"title": "Test VIS 4",
58+
"visState": "{\"title\":\"test vis 4\",\"type\":\"histogram\"}",
59+
"uiStateJSON": "{}",
60+
"description": "",
61+
"version": 1,
62+
"kibanaSavedObjectMeta": {
63+
"searchSourceJSON": "{\"index\":\"missing-index-pattern-4\",\"query\":{}}"
64+
}
65+
},
66+
"_meta": {
67+
"savedObjectVersion": 2
68+
}
69+
},
70+
{
71+
"_id": "test-vis-5",
72+
"_type": "visualization",
73+
"_source": {
74+
"title": "Test VIS 5",
75+
"visState": "{\"title\":\"test vis 5\",\"type\":\"histogram\"}",
76+
"uiStateJSON": "{}",
77+
"description": "",
78+
"version": 1,
79+
"kibanaSavedObjectMeta": {
80+
"searchSourceJSON": "{\"index\":\"missing-index-pattern-5\",\"query\":{}}"
81+
}
82+
},
83+
"_meta": {
84+
"savedObjectVersion": 2
85+
}
86+
},
87+
{
88+
"_id": "test-vis-6",
89+
"_type": "visualization",
90+
"_source": {
91+
"title": "Test VIS 6",
92+
"visState": "{\"title\":\"test vis 6\",\"type\":\"histogram\"}",
93+
"uiStateJSON": "{}",
94+
"description": "",
95+
"version": 1,
96+
"kibanaSavedObjectMeta": {
97+
"searchSourceJSON": "{\"index\":\"missing-index-pattern-6\",\"query\":{}}"
98+
}
99+
},
100+
"_meta": {
101+
"savedObjectVersion": 2
102+
}
103+
},
104+
{
105+
"_id": "test-vis-7",
106+
"_type": "visualization",
107+
"_source": {
108+
"title": "Test VIS 7",
109+
"visState": "{\"title\":\"test vis 7\",\"type\":\"histogram\"}",
110+
"uiStateJSON": "{}",
111+
"description": "",
112+
"version": 1,
113+
"kibanaSavedObjectMeta": {
114+
"searchSourceJSON": "{\"index\":\"missing-index-pattern-7\",\"query\":{}}"
115+
}
116+
},
117+
"_meta": {
118+
"savedObjectVersion": 2
119+
}
120+
}
121+
]

test/functional/page_objects/management/saved_objects_page.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ export function SavedObjectsPageProvider({ getService, getPageObjects }: FtrProv
126126
}
127127
}
128128

129+
async setOverriddenIndexPatternValue(oldName: string, newName: string) {
130+
const select = await testSubjects.find(`managementChangeIndexSelection-${oldName}`);
131+
const option = await testSubjects.findDescendant(`indexPatternOption-${newName}`, select);
132+
await option.click();
133+
}
134+
129135
async clickCopyToSpaceByTitle(title: string) {
130136
const table = keyBy(await this.getElementsInTable(), 'title');
131137
// should we check if table size > 0 and log error if not?

0 commit comments

Comments
 (0)