forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Embeddables/migrations (elastic#82296)
- Loading branch information
Showing
37 changed files
with
364 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
...ons/public/kibana-plugin-plugins-expressions-public.executor.migratetolatest.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
.../kibana-plugin-plugins-expressions-public.expressionsservice.migratetolatest.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
...ons/server/kibana-plugin-plugins-expressions-server.executor.migratetolatest.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { CommonEmbeddableStartContract, EmbeddableStateWithType } from '../types'; | ||
import { extractBaseEmbeddableInput } from './migrate_base_input'; | ||
import { SerializableState } from '../../../kibana_utils/common/persistable_state'; | ||
|
||
export const getExtractFunction = (embeddables: CommonEmbeddableStartContract) => { | ||
return (state: EmbeddableStateWithType) => { | ||
const enhancements = state.enhancements || {}; | ||
const factory = embeddables.getEmbeddableFactory(state.type); | ||
|
||
const baseResponse = extractBaseEmbeddableInput(state); | ||
let updatedInput = baseResponse.state; | ||
const refs = baseResponse.references; | ||
|
||
if (factory) { | ||
const factoryResponse = factory.extract(state); | ||
updatedInput = factoryResponse.state; | ||
refs.push(...factoryResponse.references); | ||
} | ||
|
||
updatedInput.enhancements = {}; | ||
Object.keys(enhancements).forEach((key) => { | ||
if (!enhancements[key]) return; | ||
const enhancementResult = embeddables | ||
.getEnhancement(key) | ||
.extract(enhancements[key] as SerializableState); | ||
refs.push(...enhancementResult.references); | ||
updatedInput.enhancements![key] = enhancementResult.state; | ||
}); | ||
|
||
return { | ||
state: updatedInput, | ||
references: refs, | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export * from './extract'; | ||
export * from './inject'; | ||
export * from './migrate'; | ||
export * from './migrate_base_input'; | ||
export * from './telemetry'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { CommonEmbeddableStartContract, EmbeddableStateWithType } from '../types'; | ||
import { SavedObjectReference } from '../../../../core/types'; | ||
import { injectBaseEmbeddableInput } from './migrate_base_input'; | ||
import { SerializableState } from '../../../kibana_utils/common/persistable_state'; | ||
|
||
export const getInjectFunction = (embeddables: CommonEmbeddableStartContract) => { | ||
return (state: EmbeddableStateWithType, references: SavedObjectReference[]) => { | ||
const enhancements = state.enhancements || {}; | ||
const factory = embeddables.getEmbeddableFactory(state.type); | ||
|
||
let updatedInput = injectBaseEmbeddableInput(state, references); | ||
|
||
if (factory) { | ||
updatedInput = factory.inject(updatedInput, references); | ||
} | ||
|
||
updatedInput.enhancements = {}; | ||
Object.keys(enhancements).forEach((key) => { | ||
if (!enhancements[key]) return; | ||
updatedInput.enhancements![key] = embeddables | ||
.getEnhancement(key) | ||
.inject(enhancements[key] as SerializableState, references); | ||
}); | ||
|
||
return updatedInput; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { CommonEmbeddableStartContract } from '../types'; | ||
import { baseEmbeddableMigrations } from './migrate_base_input'; | ||
import { SerializableState } from '../../../kibana_utils/common/persistable_state'; | ||
|
||
export const getMigrateFunction = (embeddables: CommonEmbeddableStartContract) => { | ||
return (state: SerializableState, version: string) => { | ||
const enhancements = (state.enhancements as SerializableState) || {}; | ||
const factory = embeddables.getEmbeddableFactory(state.type as string); | ||
|
||
let updatedInput = baseEmbeddableMigrations[version] | ||
? baseEmbeddableMigrations[version](state) | ||
: state; | ||
|
||
if (factory && factory.migrations[version]) { | ||
updatedInput = factory.migrations[version](updatedInput); | ||
} | ||
|
||
updatedInput.enhancements = {}; | ||
Object.keys(enhancements).forEach((key) => { | ||
if (!enhancements[key]) return; | ||
(updatedInput.enhancements! as Record<string, any>)[key] = embeddables | ||
.getEnhancement(key) | ||
.migrations[version](enhancements[key] as SerializableState); | ||
}); | ||
|
||
return updatedInput; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.