Skip to content

Commit

Permalink
add migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Feb 26, 2021
1 parent 9218ccc commit f8cc389
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const toSelectedOptions = (
return [];
};

const toComboBoxOptions = (options: IdsWithTitle) =>
options.map(({ title, id }) => ({ label: title, id }));

export const ComboBoxSelect = ({
onIndexChange,
onModeChange,
Expand All @@ -53,9 +56,6 @@ export const ComboBoxSelect = ({
[onIndexChange]
);

const toComboBoxOptions = (options: IdsWithTitle) =>
options.map(({ title, id }) => ({ label: title, id }));

useEffect(() => {
async function fetchIndexes() {
setAvailableIndexes(await getDataStart().indexPatterns.getIdsWithTitle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,16 @@ export const LegacyModePopover = ({ index }: LegacyModePopoverProps) => {

useEffect(() => {
async function retrieveIndex() {
const shouldShowExtraCallOuts = Boolean(index);
let hasIndex = false;
if (index) {

if (shouldShowExtraCallOuts) {
const { indexPatterns } = getDataStart();
hasIndex = Boolean((await indexPatterns.find(index)).find((i) => i.title === index));
}

setShowReadyToMigrateCallOut(Boolean(index) && hasIndex);
setNoMatchedIndicesCallOut(Boolean(index) && !hasIndex);
setShowReadyToMigrateCallOut(shouldShowExtraCallOuts && hasIndex);
setNoMatchedIndicesCallOut(shouldShowExtraCallOuts && !hasIndex);
}

retrieveIndex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,35 @@ const removeTSVBSearchSource: SavedObjectMigrationFn<any, any> = (doc) => {
return doc;
};

const addSupportOfDualIndexSelectionModeInTSVB: SavedObjectMigrationFn<any, any> = (doc) => {
const visStateJSON = get(doc, 'attributes.visState');
let visState;

if (visStateJSON) {
try {
visState = JSON.parse(visStateJSON);
} catch (e) {
// Let it go, the data is invalid and we'll leave it as is
}
if (visState && visState.type === 'metrics') {
const { params } = visState;

if (typeof params?.index_pattern === 'string') {
params.use_kibana_indexes = false;
}

return {
...doc,
attributes: {
...doc.attributes,
visState: JSON.stringify(visState),
},
};
}
}
return doc;
};

// [Data table visualization] Enable toolbar by default
const enableDataTableVisToolbar: SavedObjectMigrationFn<any, any> = (doc) => {
let visState;
Expand Down Expand Up @@ -884,4 +913,5 @@ export const visualizationSavedObjectTypeMigrations = {
'7.10.0': flow(migrateFilterRatioQuery, removeTSVBSearchSource),
'7.11.0': flow(enableDataTableVisToolbar),
'7.12.0': flow(migrateVislibAreaLineBarTypes),
'7.13.0': flow(addSupportOfDualIndexSelectionModeInTSVB),
};

0 comments on commit f8cc389

Please sign in to comment.