Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
AMoo-Miki authored Dec 12, 2022
2 parents 0a2d713 + 8732b1c commit f4db069
Show file tree
Hide file tree
Showing 14 changed files with 285 additions and 26 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/build_and_test_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ jobs:
npm uninstall -g yarn
npm i -g yarn@1.22.10
# image has the latest chrome v99
- name: Setup chromedriver
run: yarn add --dev chromedriver@99.0.0
run: node scripts/upgrade_chromedriver.js

- name: Run bootstrap
run: yarn osd bootstrap
Expand Down Expand Up @@ -204,9 +203,8 @@ jobs:
npm uninstall -g yarn
npm i -g yarn@1.22.10
# image has the latest chrome v99
- name: Setup chromedriver
run: yarn add --dev chromedriver@106.0.1
run: node scripts/upgrade_chromedriver.js

- name: Run bootstrap
run: yarn osd bootstrap
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.ackrc
/.opensearch
/.chromium
/package.json.bak
.DS_Store
.node_binaries
.native_modules
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,18 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Vis Builder] Fix empty workspace animation does not work in firefox ([#2853](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2853))
- Bumped `del` version to fix MacOS race condition ([#2847](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2873))
- [Build] Fixed "Last Access Time" not being set by `scanCopy` on Windows ([#2964](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2964))
- [Vis Builder] Add global data persistence for vis builder #2896 ([#2896](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2896))
- Update `leaflet-vega` and fix its usage ([#3005](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3005))


### 🚞 Infrastructure

- Add CHANGELOG.md and related workflows ([#2414](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2414))
- Update backport custom branch name to utilize head template ([#2766](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2766))
- Re-enable CI workflows for feature branckes ([#2908](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2908))
- Add Windows CI workflows ([#2966](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2966))
- Add automatic selection of the appropriate version of chrome driver to run functional tests ([#2990](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2990))


### 📝 Documentation

Expand All @@ -104,6 +108,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [BWC Tests] Add BWC tests for 2.5.0 ([#2890](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2890))
- Fix incorrect validation of time values in JUnit Reporter ([#2965](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2965))
- Make tests covering plugin installation on cluster snapshots work across platforms ([#2994](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2994))
- Correct the linting logic for `no-restricted-path` to ignore trailing slashes ([#3020](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3020))

## [2.x]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function traverseToTopFolder(src, pattern) {
const srcIdx = src.lastIndexOf(path.sep);
src = src.slice(0, srcIdx);
}
return src.replace(/\\/g, '/');
return src.replace(/\\/g, '/').replace(/\/$/, '');
}

function isSameFolderOrDescendent(src, imported, pattern) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ ruleTester.run('@osd/eslint/no-restricted-paths', rule, {
},
],
},
{
code: 'import b from "testfiles/no_restricted_paths/server/deep/deeper/e.js"',
filename: path.join(__dirname, 'testfiles/no_restricted_paths/server/deep/d.js'),
options: [
{
basePath: __dirname,
zones: [
{
target: 'testfiles/**/server/**/*',
from: 'testfiles/**/server/**/*',
allowSameFolder: true,
},
],
},
],
},

// irrelevant function calls
{
Expand Down
122 changes: 122 additions & 0 deletions scripts/upgrade_chromedriver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

/**
* Upgrades the chromedriver dev-dependency to the one supported by the version of Google Chrome
* installed on the machine.
*
* Usage: node scripts/upgrade_chromedriver.js [--install]
*/

/* eslint no-restricted-syntax: 0 */
const { execSync, spawnSync } = require('child_process');
const { createReadStream, createWriteStream, unlinkSync, renameSync, existsSync } = require('fs');
const { createInterface } = require('readline');

if (!process.argv.includes(__filename)) {
console.error('Usage: node scripts/upgrade_chromedriver.js [--install]');
process.exit(1);
}

const versionCheckCommands = [];

switch (process.platform) {
case 'win32':
versionCheckCommands.push(
'powershell "(Get-Item \\"$Env:Programfiles/Google/Chrome/Application/chrome.exe\\").VersionInfo.FileVersion"'
);
break;

case 'darwin':
versionCheckCommands.push(
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome --version'
);
break;

default:
versionCheckCommands.push(
...[
'/usr/bin',
'/usr/local/bin',
'/usr/sbin',
'/usr/local/sbin',
'/opt/bin',
'/usr/bin/X11',
'/usr/X11R6/bin',
].flatMap((loc) =>
[
'google-chrome --version',
'google-chrome-stable --version',
'chromium --version',
'chromium-browser --version',
].map((cmd) => `${loc}/${cmd}`)
)
);
}

let versionCheckOutput;
versionCheckCommands.some((cmd) => {
try {
console.log(cmd);
versionCheckOutput = execSync(cmd, { encoding: 'utf8' })?.trim?.();
return true;
} catch (e) {
console.log('Failed to get version using', cmd);
}
});

// Versions 90+
const majorVersion = versionCheckOutput?.match?.(/(?:^|\s)(9\d|\d{3})\./)?.[1];

if (majorVersion) {
if (process.argv.includes('--install')) {
console.log(`Installing chromedriver@^${majorVersion}`);

spawnSync(`yarn add --dev chromedriver@^${majorVersion}`, {
stdio: 'inherit',
cwd: process.cwd(),
shell: true,
});
} else {
console.log(`Upgrading to chromedriver@^${majorVersion}`);

let upgraded = false;
const writeStream = createWriteStream('package.json.upgrading-chromedriver', { flags: 'w' });
const rl = createInterface({
input: createReadStream('package.json'),
crlfDelay: Infinity,
});
rl.on('line', (line) => {
if (line.includes('"chromedriver": "')) {
line = line.replace(
/"chromedriver":\s*"[~^]?\d[\d.]*\d"/,
`"chromedriver": "^${majorVersion}"`
);
upgraded = true;
}
writeStream.write(line + '\n', 'utf8');
});
rl.on('close', () => {
writeStream.end();
if (upgraded) {
// Remove any previous backups
if (existsSync('package.json.bak')) unlinkSync('package.json.bak');

renameSync('package.json', 'package.json.bak');
renameSync('package.json.upgrading-chromedriver', 'package.json');

console.log(`Backed up package.json and updated chromedriver to ${majorVersion}`);
} else {
unlinkSync('package.json.upgrading-chromedriver');
console.error(
`Failed to update chromedriver to ${majorVersion}. Try adding the \`--install\` switch.`
);
}
});
}
} else {
console.debug(versionCheckOutput);
console.error(`Failed to extract the version of the installed Google Chrome.`);
}
24 changes: 23 additions & 1 deletion src/plugins/vis_builder/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,39 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import React, { useEffect } from 'react';
import { I18nProvider } from '@osd/i18n/react';
import { EuiPage, EuiResizableContainer } from '@elastic/eui';
import { useLocation } from 'react-router-dom';
import { DragDropProvider } from './utils/drag_drop/drag_drop_context';
import { LeftNav } from './components/left_nav';
import { TopNav } from './components/top_nav';
import { Workspace } from './components/workspace';
import './app.scss';
import { RightNav } from './components/right_nav';
import { useOpenSearchDashboards } from '../../../opensearch_dashboards_react/public';
import { VisBuilderServices } from '../types';
import { syncQueryStateWithUrl } from '../../../data/public';

export const VisBuilderApp = () => {
const {
services: {
data: { query },
osdUrlStateStorage,
},
} = useOpenSearchDashboards<VisBuilderServices>();
const { pathname } = useLocation();

useEffect(() => {
// syncs `_g` portion of url with query services
const { stop } = syncQueryStateWithUrl(query, osdUrlStateStorage);

return () => stop();

// this effect should re-run when pathname is changed to preserve querystring part,
// so the global state is always preserved
}, [query, osdUrlStateStorage, pathname]);

// Render the application DOM.
return (
<I18nProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export const TopNav = () => {
const savedVisBuilderVis = useSavedVisBuilderVis(visualizationIdFromUrl);
const { selected: indexPattern } = useIndexPatterns();
const [config, setConfig] = useState<TopNavMenuData[] | undefined>();
const originatingApp = useTypedSelector((state) => {
return state.metadata.originatingApp;
});

useEffect(() => {
const getConfig = () => {
Expand All @@ -47,6 +50,7 @@ export const TopNav = () => {
savedVisBuilderVis: saveStateToSavedObject(savedVisBuilderVis, rootState, indexPattern),
saveDisabledReason,
dispatch,
originatingApp,
},
services
);
Expand All @@ -61,6 +65,7 @@ export const TopNav = () => {
saveDisabledReason,
dispatch,
indexPattern,
originatingApp,
]);

// reset validity before component destroyed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,24 @@ export interface TopNavConfigParams {
savedVisBuilderVis: VisBuilderVisSavedObject;
saveDisabledReason?: string;
dispatch: AppDispatch;
originatingApp?: string;
}

export const getTopNavConfig = (
{ visualizationIdFromUrl, savedVisBuilderVis, saveDisabledReason, dispatch }: TopNavConfigParams,
{
visualizationIdFromUrl,
savedVisBuilderVis,
saveDisabledReason,
dispatch,
originatingApp,
}: TopNavConfigParams,
services: VisBuilderServices
) => {
const {
i18n: { Context: I18nContext },
embeddable,
scopedHistory,
} = services;

const { originatingApp, embeddableId } =
embeddable
.getStateTransfer(scopedHistory)
.getIncomingEditorState({ keysToRemoveAfterFetch: ['id', 'input'] }) || {};
const stateTransfer = embeddable.getStateTransfer();

const topNavConfig: TopNavMenuData[] = [
Expand Down Expand Up @@ -105,7 +107,7 @@ export const getTopNavConfig = (
showSaveModal(saveModal, I18nContext);
},
},
...(originatingApp && ((savedVisBuilderVis && savedVisBuilderVis.id) || embeddableId)
...(originatingApp && savedVisBuilderVis && savedVisBuilderVis.id
? [
{
id: 'saveAndReturn',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,28 @@ export interface MetadataState {
};
state: EditorState;
};
originatingApp?: string;
}

const initialState: MetadataState = {
editor: {
validity: {},
state: 'loading',
},
originatingApp: undefined,
};

export const getPreloadedState = async ({
types,
data,
embeddable,
scopedHistory,
}: VisBuilderServices): Promise<MetadataState> => {
const preloadedState = { ...initialState };
const { originatingApp } =
embeddable
.getStateTransfer(scopedHistory)
.getIncomingEditorState({ keysToRemoveAfterFetch: ['id', 'input'] }) || {};
const preloadedState = { ...initialState, originatingApp };

return preloadedState;
};
Expand All @@ -50,11 +58,14 @@ export const slice = createSlice({
setEditorState: (state, action: PayloadAction<{ state: EditorState }>) => {
state.editor.state = action.payload.state;
},
setOriginatingApp: (state, action: PayloadAction<{ state?: string }>) => {
state.originatingApp = action.payload.state;
},
setState: (_state, action: PayloadAction<MetadataState>) => {
return action.payload;
},
},
});

export const { reducer } = slice;
export const { setValidity, setEditorState, setState } = slice.actions;
export const { setValidity, setEditorState, setOriginatingApp, setState } = slice.actions;
1 change: 1 addition & 0 deletions src/plugins/vis_builder/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('VisBuilderPlugin', () => {
const setupDeps = {
visualizations: visualizationsPluginMock.createSetupContract(),
embeddable: embeddablePluginMock.createSetupContract(),
data: dataPluginMock.createSetupContract(),
};

const setup = plugin.setup(coreSetup, setupDeps);
Expand Down
Loading

0 comments on commit f4db069

Please sign in to comment.