mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Fix duplicating tags after importing from 7.12 Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
b627dca3ba
commit
6209ec4578
4 changed files with 37 additions and 6 deletions
|
@ -135,10 +135,12 @@ export const createExtract = (
|
|||
});
|
||||
|
||||
// We're going to prefix the names of the references so that we don't end up with dupes (from visualizations for instance)
|
||||
const prefixedReferences = panelReferences.map((reference) => ({
|
||||
...reference,
|
||||
name: `${prefix}${reference.name}`,
|
||||
}));
|
||||
const prefixedReferences = panelReferences
|
||||
.filter((reference) => reference.type !== 'tag') // panel references should never contain tags. If they do, they must be removed
|
||||
.map((reference) => ({
|
||||
...reference,
|
||||
name: `${prefix}${reference.name}`,
|
||||
}));
|
||||
|
||||
references.push(...prefixedReferences);
|
||||
|
||||
|
|
|
@ -81,4 +81,20 @@ describe('extractTagReferences', () => {
|
|||
expect(resultRefs).toEqual([refA, refB]);
|
||||
expect(resultAttrs).toEqual({ someString: 'foo', someNumber: 42 });
|
||||
});
|
||||
|
||||
it('removes duplicated tags', () => {
|
||||
const attributes = {
|
||||
__tags: ['tag-id-1', 'tag-id-1', 'tag-id-1', 'tag-id-1', 'tag-id-2'],
|
||||
};
|
||||
|
||||
const { references: resultRefs } = extractTagReferences({
|
||||
attributes,
|
||||
references: [] as SavedObjectReference[],
|
||||
});
|
||||
|
||||
expect(resultRefs).toEqual([
|
||||
{ id: 'tag-id-1', name: 'tag-tag-id-1', type: 'tag' },
|
||||
{ id: 'tag-id-2', name: 'tag-tag-id-2', type: 'tag' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -18,7 +18,7 @@ export const extractTagReferences: Required<SavedObjectConfig>['extractReference
|
|||
references,
|
||||
}) => {
|
||||
const { __tags, ...otherAttributes } = attributes;
|
||||
const tags = (__tags as string[]) ?? [];
|
||||
const tags = [...new Set(__tags as string[])] ?? [];
|
||||
return {
|
||||
attributes: otherAttributes,
|
||||
references: [
|
||||
|
|
|
@ -18,7 +18,20 @@ export const inject: EmbeddableRegistryDefinition['inject'] = (state, references
|
|||
const typedState = state as LensEmbeddablePersistableState;
|
||||
|
||||
if ('attributes' in typedState && typedState.attributes !== undefined) {
|
||||
typedState.attributes.references = references as unknown as Serializable[];
|
||||
// match references based on name, so only references associated with this lens panel are injected.
|
||||
const matchedReferences: SavedObjectReference[] = [];
|
||||
|
||||
if (Array.isArray(typedState.attributes.references)) {
|
||||
typedState.attributes.references.forEach((serializableRef) => {
|
||||
const internalReference = serializableRef as unknown as SavedObjectReference;
|
||||
const matchedReference = references.find(
|
||||
(reference) => reference.name === internalReference.name
|
||||
);
|
||||
if (matchedReference) matchedReferences.push(matchedReference);
|
||||
});
|
||||
}
|
||||
|
||||
typedState.attributes.references = matchedReferences as unknown as Serializable[];
|
||||
}
|
||||
|
||||
return typedState;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue