Skip to content

Commit

Permalink
add attribute name settings for capture data path
Browse files Browse the repository at this point in the history
  • Loading branch information
last-hit-b committed Jun 5, 2020
1 parent ae0b811 commit dd467c4
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 36 deletions.
10 changes: 6 additions & 4 deletions main/recorder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,10 @@ class Recorder {
'launch-puppeteer',
async (
event: IpcMainEvent,
arg: { url: string; device: Device; flowKey: string; uuid: string }
arg: { url: string; device: Device; flowKey: string; uuid: string, dataAttrName?: string }
) => {
const { url, device, flowKey, uuid } = arg;
const { url, device, flowKey, uuid, dataAttrName } = arg;
PageHelper.setDataAttrName(dataAttrName);
const {
viewport: { width, height }
} = device;
Expand Down Expand Up @@ -521,8 +522,9 @@ class Recorder {
private handleSwitchToRecord(): void {
ipcMain.on(
'switch-puppeteer',
async (event: IpcMainEvent, arg: { storyName: string; flowName: string }) => {
const { storyName, flowName } = arg;
async (event: IpcMainEvent, arg: { storyName: string; flowName: string, dataAttrName?: string }) => {
const { storyName, flowName, dataAttrName } = arg;
PageHelper.setDataAttrName(dataAttrName);
const flowKey = this.generateKeyByString(storyName, flowName);
const replayer = this.getReplayer().abandon(storyName, flowName);
const browser = replayer.getBrowser();
Expand Down
17 changes: 14 additions & 3 deletions main/recorder/page-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ const ignoredIdRegexps = [
/^react-select.+-.+$/
];
const idShouldIgnore = (id: string): boolean => ignoredIdRegexps.some(regexp => regexp.test(id));

export default class PageHelper {
private static dataAttrName: string | null | undefined = null;

public static setDataAttrName(dataAttrName?: string): void {
PageHelper.dataAttrName = dataAttrName;
}

private static async createCDPClient(page: Page): Promise<CDPSession> {
return await page.target().createCDPSession();
}
Expand Down Expand Up @@ -441,7 +446,7 @@ export default class PageHelper {
) {
console.log('xpath contains svg dom node.');
const newXpath = xpath.replace(/^(.*button.*)\/svg.*$/, '$1');
const newCssPaath = csspath.replace(/^(.*button.*)\s>\ssvg.*$/, '$1');
const newCssPath = csspath.replace(/^(.*button.*)\s>\ssvg.*$/, '$1');
console.log(`new xpath after svg cut-off is ${newXpath}.`);
if (newXpath !== xpath) {
// replaced
Expand All @@ -451,7 +456,7 @@ export default class PageHelper {
}
element = parent;
xpath = newXpath;
csspath = newCssPaath;
csspath = newCssPath;
}
}

Expand Down Expand Up @@ -804,6 +809,12 @@ export default class PageHelper {
if (onSwitchFromReplayToRecord) {
await page.evaluate(() => window.$lhOnSwitchFromReplayToRecord = true);
}
if (PageHelper.dataAttrName) {
await page.evaluate((dataAttrName: string) => window.$lhDataAttrName = dataAttrName, PageHelper.dataAttrName);
} else {
// clear when not given
await page.evaluate(() => window.$lhDataAttrName = null);
}
await page.evaluateOnNewDocument(god);
await page.evaluate(god);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "last-hit",
"version": "0.9.15",
"version": "0.9.16",
"description": "last hit on enterprise web",
"main": "runtime/main/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion renderer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "last-hit-appearance",
"version": "0.9.14",
"version": "0.9.16",
"homepage": "./",
"dependencies": {
"@blueprintjs/core": "^3.17.2",
Expand Down
16 changes: 8 additions & 8 deletions renderer/src/active/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@ export class ActiveWorkspace {
}
}

let actived: ActiveWorkspace | null = null;
let active: ActiveWorkspace | null = null;

export const activeWorkspace = (
workspace: Workspace,
settings: WorkspaceSettings,
structure: WorkspaceStructure
): void => {
actived = new ActiveWorkspace(workspace, settings, structure);
active = new ActiveWorkspace(workspace, settings, structure);
};

export const getActiveWorkspace = (): ActiveWorkspace | null => {
return actived;
return active;
};

export const hasActiveWorkspace = (): boolean => {
return actived != null;
return active != null;
};

export const deactiveWorkspace = (): ActiveWorkspace | null => {
const previousActived = actived;
actived = null;
return previousActived;
export const deactivateWorkspace = (): ActiveWorkspace | null => {
const previousActive = active;
active = null;
return previousActive;
};
10 changes: 5 additions & 5 deletions renderer/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FocusStyleManager } from '@blueprintjs/core';
import React from 'react';
import { Redirect, Route, Router, Switch } from 'react-router-dom';
import styled from 'styled-components';
import { deactiveWorkspace, hasActiveWorkspace } from './active';
import { deactivateWorkspace, hasActiveWorkspace } from './active';
import UIContext, { context } from './common/context';
import history from './common/history';
import paths from './common/paths';
Expand All @@ -12,7 +12,7 @@ import { GlobalStyles } from './common/styles';
FocusStyleManager.onlyShowFocusOnTabs();

const Splash = React.lazy(() => import(/* webpackChunkName: "splash" */ './splash'));
const CreateWorspace = React.lazy(() =>
const CreateWorkspace = React.lazy(() =>
import(/* webpackChunkName: "create-workspace" */ './workspace/create')
);
const OpenedWorkspace = React.lazy(() =>
Expand All @@ -38,15 +38,15 @@ const App = () => {
if (hasActiveWorkspace()) {
return <OpenedWorkspace />;
} else {
// for ensure deactive
deactiveWorkspace();
// for ensure deactivate
deactivateWorkspace();
return <Redirect to={paths.SPLASH} />;
}
}}
/>
<Route
path={paths.CREATE_WORKSPACE}
render={() => <CreateWorspace />}
render={() => <CreateWorkspace />}
/>
<Route path={paths.SPLASH} render={() => <Splash />} />
<Route
Expand Down
9 changes: 9 additions & 0 deletions renderer/src/common/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export interface IUIEventEmitter {
emit(event: EventTypes.ASK_OPEN_ENV): boolean;
emit(event: EventTypes.CLOSE_ENV_DIALOG): boolean;

emit(event: EventTypes.ASK_OPEN_WORKSPACE_SETTINGS): boolean;
emit(event: EventTypes.CLOSE_WORKSPACE_SETTINGS_DIALOG): boolean;

emit(event: EventTypes.ASK_OPEN_UPDATE, current: string, latest: string): boolean;
emit(event: EventTypes.CLOSE_UPDATE_DIALOG): boolean;

Expand Down Expand Up @@ -122,6 +125,9 @@ export interface IUIEventEmitter {
on(event: EventTypes.ASK_OPEN_ENV, listener: NoArgListener): this;
on(event: EventTypes.CLOSE_ENV_DIALOG, listener: NoArgListener): this;

on(event: EventTypes.ASK_OPEN_WORKSPACE_SETTINGS, listener: NoArgListener): this;
on(event: EventTypes.CLOSE_WORKSPACE_SETTINGS_DIALOG, listener: NoArgListener): this;

on(
event: EventTypes.ASK_OPEN_UPDATE,
listener: (current: string, latest: string) => void
Expand Down Expand Up @@ -184,6 +190,9 @@ export interface IUIEventEmitter {
off(event: EventTypes.ASK_OPEN_ENV, listener: NoArgListener): this;
off(event: EventTypes.CLOSE_ENV_DIALOG, listener: NoArgListener): this;

off(event: EventTypes.ASK_OPEN_WORKSPACE_SETTINGS, listener: NoArgListener): this;
off(event: EventTypes.CLOSE_WORKSPACE_SETTINGS_DIALOG, listener: NoArgListener): this;

off(
event: EventTypes.ASK_OPEN_UPDATE,
listener: (current: string, latest: string) => void
Expand Down
3 changes: 3 additions & 0 deletions renderer/src/events/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export enum EventTypes {
ASK_OPEN_ENV = 'ask-open-env',
CLOSE_ENV_DIALOG = 'close-env-dialog',

ASK_OPEN_WORKSPACE_SETTINGS = 'ask-open-workspace-settings',
CLOSE_WORKSPACE_SETTINGS_DIALOG = 'close-workspace-settings-dialog',

ASK_OPEN_UPDATE = 'ask-open-update',
CLOSE_UPDATE_DIALOG = 'close-update-dialog',

Expand Down
4 changes: 2 additions & 2 deletions renderer/src/files/workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs';
import jsonfile from 'jsonfile';
import { Flow, Story } from 'last-hit-types';
import path from 'path';
import { activeWorkspace, deactiveWorkspace, getActiveWorkspace } from '../active';
import { activeWorkspace, deactivateWorkspace, getActiveWorkspace } from '../active';
import history from '../common/history';
import IDESettings, { WorkspaceFileExt } from '../common/ide-settings';
import paths from '../common/paths';
Expand Down Expand Up @@ -133,7 +133,7 @@ const loadWorkspaceStructure = (settings: WorkspaceSettings): WorkspaceStructure
};

export const closeCurrentWorkspace = (): void => {
deactiveWorkspace();
deactivateWorkspace();

history.replace(paths.ROOT);

Expand Down
1 change: 1 addition & 0 deletions renderer/src/types/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type ExecuteEnv = Environment;
export type WorkspaceSettings = {
name: string;
workspaceFile: string;
dataAttrName?: string;
envs?: ExecuteEnv[];
};

Expand Down
18 changes: 10 additions & 8 deletions renderer/src/workspace/flow/record-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Flow, StartStep, StepType, Story } from 'last-hit-types';
import React from 'react';
import styled from 'styled-components';
import uuidv4 from 'uuid/v4';
import { getActiveWorkspace } from '../../active';
import UIContext from '../../common/context';
import Devices from '../../common/device-descriptors';
import { EventTypes } from '../../events';
Expand All @@ -26,7 +27,7 @@ const TheDialog = (props: {
};

// force render
const [ignored, forceUpdate] = React.useReducer(x => x + 1, 0);
const [ ignored, forceUpdate ] = React.useReducer(x => x + 1, 0);

const handleRecording = (): void => {
const flowKey = asFlowKey(flow, story);
Expand Down Expand Up @@ -110,9 +111,10 @@ const TheDialog = (props: {
const options = {
url: step.url,
device: step.device || Devices[0],
uuid: uuidv4()
uuid: uuidv4(),
dataAttrName: getActiveWorkspace()!.getSettings().dataAttrName
};
flow.steps = [{ type: 'start', stepIndex: 0, stepUuid: uuidv4(), ...options }];
flow.steps = [ { type: 'start', stepIndex: 0, stepUuid: uuidv4(), ...options } ];
emitter.emit(EventTypes.ASK_SAVE_FLOW, story, flow);
forceUpdate(ignored);
ipcRenderer.send('launch-puppeteer', {
Expand All @@ -121,7 +123,7 @@ const TheDialog = (props: {
});
}
// eslint-disable-next-line
}, [0]);
}, [ 0 ]);

const onCaptureScreenshotClicked = (): void => {
const flowKey = asFlowKey(flow, story);
Expand Down Expand Up @@ -191,12 +193,12 @@ const TheDialog = (props: {
#{flow.steps!.length} {getStepTypeText(flow.steps![flow.steps!.length - 1])}
</h4>
</div>
<div className="overlay-placeholder" />
<div className="overlay-placeholder"/>
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
<Button onClick={onStopClicked} intent="danger">
Stop
</Button>
<Placeholder />
<Placeholder/>
<Button onClick={onCaptureScreenshotClicked} intent="primary">
Capture Screenshot
</Button>
Expand All @@ -212,7 +214,7 @@ const TheDialog = (props: {
export default (): JSX.Element => {
const { emitter } = React.useContext(UIContext);

const [data, setData] = React.useState(
const [ data, setData ] = React.useState(
null as { story: Story; flow: Flow; isSwitchedFromReplay: boolean } | null
);
React.useEffect(() => {
Expand All @@ -233,6 +235,6 @@ export default (): JSX.Element => {
if (data != null) {
return <TheDialog {...data} />;
} else {
return <React.Fragment />;
return <React.Fragment/>;
}
};
6 changes: 5 additions & 1 deletion renderer/src/workspace/flow/replay-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ const ReplayDialog = (props: {
emitter.emit(EventTypes.ASK_FLOW_RECORD, story, flow, true);
close();
});
ipcRenderer.send('switch-puppeteer', { storyName: story.name, flowName: flow.name });
ipcRenderer.send('switch-puppeteer', {
storyName: story.name,
flowName: flow.name,
dataAttrName: getActiveWorkspace()!.getSettings().dataAttrName
});
});
ipcRenderer.send(`continue-replay-step-${flowKey}`, {
command: 'switch-to-record'
Expand Down
2 changes: 2 additions & 0 deletions renderer/src/workspace/open/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import StoryDelete from '../story/delete';
import StoryRenameDialog from '../story/rename-dialog';
import BottomBar from './bottom-bar';
import EnvDialog from './env-dialog';
import WorkspaceSettingsDialog from './workspace-settings-dialog'
import MainContent from './main-content';
import UpdateDialog from './update-dialog';

Expand Down Expand Up @@ -81,6 +82,7 @@ export default (): JSX.Element => {
<ScriptsHelperDrawer />
<StepSearchDrawer />
<EnvDialog />
<WorkspaceSettingsDialog />
<UpdateDialog />
</Container>
);
Expand Down
12 changes: 9 additions & 3 deletions renderer/src/workspace/open/left-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default () => {
.replace('v', '')
.split('.')
.map((x: string) => (x ? (x as any) * 1 : 0));
// console.log('latest veresion', major, minor, patch);
// console.log('latest version', major, minor, patch);
if (
myMajor < major ||
(myMajor === major && myMinor < minor) ||
Expand All @@ -83,7 +83,7 @@ export default () => {
checkUpdate();
// eslint-disable-next-line
}, [0]);
const onToggleNagivatorClicked = (): void => {
const onToggleNavigatorClicked = (): void => {
emitter.emit(EventTypes.ASK_TOGGLE_NAVIGATOR);
};
const onStepSearchClicked = (): void => {
Expand All @@ -92,6 +92,9 @@ export default () => {
const onEnvClicked = (): void => {
emitter.emit(EventTypes.ASK_OPEN_ENV);
};
const onWorkspaceSettingsClicked = () : void => {
emitter.emit(EventTypes.ASK_OPEN_WORKSPACE_SETTINGS);
}
const onUpdateClicked = (): void => {
if (update.has) {
setUpdate({ has: false, current: update.current, latest: update.latest });
Expand All @@ -107,7 +110,7 @@ export default () => {
minimal={true}
icon="inbox"
large={true}
onClick={onToggleNagivatorClicked}
onClick={onToggleNavigatorClicked}
/>
</Segment>
<Segment title="Step Search">
Expand All @@ -116,6 +119,9 @@ export default () => {
<Segment title="Environments">
<Button minimal={true} icon="heat-grid" large={true} onClick={onEnvClicked} />
</Segment>
<Segment title="Workspace Settings">
<Button minimal={true} icon="settings" large={true} onClick={onWorkspaceSettingsClicked} />
</Segment>
<Segment title="Update">
<UpdateButton
minimal={true}
Expand Down
Loading

0 comments on commit dd467c4

Please sign in to comment.