Skip to content

Commit 004f127

Browse files
committed
add new window controls
1 parent eebfd0a commit 004f127

File tree

8 files changed

+100
-59
lines changed

8 files changed

+100
-59
lines changed

packages/selenium-ide/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@seleniumhq/selenium-ide",
3-
"version": "4.0.0-alpha.42",
3+
"version": "4.0.0-alpha.43",
44
"private": true,
55
"description": "Selenium IDE electron app",
66
"author": "Todd <[email protected]>",

packages/selenium-ide/src/browser/windows/ProjectEditor/tabs/Tests/CommandFields/CommandSelector.tsx

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CodeOff, HelpCenter } from '@mui/icons-material'
1+
import { CodeOff, HelpCenter, OpenInNew } from '@mui/icons-material'
22
import { Autocomplete } from '@mui/material'
33
import { FormControl } from '@mui/material'
44
import { TextField } from '@mui/material'
@@ -9,6 +9,7 @@ import { setField, updateACField } from './utils'
99
import { CommandSelectorProps } from '../types'
1010

1111
const setCommandFactory = setField('command')
12+
const setOpensWindowFactory = setField<boolean>('opensWindow')
1213
const updateCommand = updateACField('command')
1314
const CommandSelector: FC<CommandSelectorProps> = ({
1415
command,
@@ -28,54 +29,68 @@ const CommandSelector: FC<CommandSelectorProps> = ({
2829
}
2930
const commandData = commands[command.command]
3031
const setCommand = setCommandFactory(testID, command.id)
32+
const setOpensWindow = setOpensWindowFactory(testID, command.id)
3133
const commandOptions = commandsList.map((item) => {
3234
return { label: item.name, id: item.id }
3335
})
3436

3537
return (
36-
<FormControl className="flex flex-row">
37-
<Autocomplete
38-
id='command-selector'
39-
className="flex-1"
40-
onChange={updateCommand(testID, command.id)}
41-
getOptionLabel={(option) => option.label}
42-
options={commandOptions}
43-
renderInput={(params) => (
44-
<TextField
45-
{...params}
46-
inputProps={{
47-
...params.inputProps,
48-
['data-overridearrowkeys']: true,
49-
}}
50-
label="Command"
51-
/>
52-
)}
53-
size="small"
54-
value={commandOptions.find((entry) => entry.id === command.command)}
55-
isOptionEqualToValue={(option, value) => option.id === value.id}
56-
/>
38+
<>
39+
<FormControl className="flex flex-row">
40+
<Autocomplete
41+
id="command-selector"
42+
className="flex-1"
43+
onChange={updateCommand(testID, command.id)}
44+
getOptionLabel={(option) => option.label}
45+
options={commandOptions}
46+
renderInput={(params) => (
47+
<TextField
48+
{...params}
49+
inputProps={{
50+
...params.inputProps,
51+
['data-overridearrowkeys']: true,
52+
}}
53+
label="Command"
54+
/>
55+
)}
56+
size="small"
57+
value={commandOptions.find((entry) => entry.id === command.command)}
58+
isOptionEqualToValue={(option, value) => option.id === value.id}
59+
/>
5760

58-
<Tooltip
59-
className="flex-initial ml-4 my-auto"
60-
title={`${isDisabled ? 'En' : 'Dis'}able this command`}
61-
placement="top-end"
62-
>
63-
<IconButton
64-
onClick={() =>
65-
setCommand(isDisabled ? command.command : `//${command.command}`)
66-
}
61+
<Tooltip
62+
className="flex-initial ml-4 my-auto"
63+
title={`${
64+
command.opensWindow ? 'Opens' : 'Does not open'
65+
} a new window`}
66+
placement="top-end"
6767
>
68-
<CodeOff color={isDisabled ? 'info' : 'inherit'} />
69-
</IconButton>
70-
</Tooltip>
71-
<Tooltip
72-
className="flex-initial mx-2 my-auto"
73-
title={commandData.description}
74-
placement="top-end"
75-
>
76-
<HelpCenter />
77-
</Tooltip>
78-
</FormControl>
68+
<IconButton onClick={() => setOpensWindow(!command.opensWindow)}>
69+
<OpenInNew color={command.opensWindow ? 'info' : 'inherit'} />
70+
</IconButton>
71+
</Tooltip>
72+
<Tooltip
73+
className="flex-initial ml-4 my-auto"
74+
title={`${isDisabled ? 'En' : 'Dis'}able this command`}
75+
placement="top-end"
76+
>
77+
<IconButton
78+
onClick={() =>
79+
setCommand(isDisabled ? command.command : `//${command.command}`)
80+
}
81+
>
82+
<CodeOff color={isDisabled ? 'info' : 'inherit'} />
83+
</IconButton>
84+
</Tooltip>
85+
<Tooltip
86+
className="flex-initial mx-2 my-auto"
87+
title={commandData.description}
88+
placement="top-end"
89+
>
90+
<HelpCenter />
91+
</Tooltip>
92+
</FormControl>
93+
</>
7994
)
8095
}
8196

packages/selenium-ide/src/browser/windows/ProjectEditor/tabs/Tests/CommandFields/TextField.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
import FormControl from '@mui/material/FormControl'
22
import HelpCenter from '@mui/icons-material/HelpCenter'
33
import TextField from 'browser/components/UncontrolledTextField'
4-
import capitalize from 'lodash/fp/capitalize'
4+
import startCase from 'lodash/fp/startCase'
55
import React, { FC } from 'react'
66
import { CommandFieldProps } from '../types'
77
import { updateField } from './utils'
88
import Tooltip from '@mui/material/Tooltip'
9+
import { LocatorFields } from '@seleniumhq/side-api'
910

1011
const CommandTextField: FC<CommandFieldProps> = ({
1112
commands,
1213
command,
1314
fieldName,
15+
note,
1416
testID,
1517
}) => {
16-
const FieldName = capitalize(fieldName)
18+
const FieldName = startCase(fieldName)
1719
const updateText = updateField(fieldName)
18-
const isComment = fieldName === 'comment'
19-
const fullnote = isComment ? '' : commands[command.command][fieldName]?.description ?? ''
20-
const label = fullnote ? FieldName + ' - ' + fullnote : FieldName
20+
const fullNote =
21+
(note ||
22+
commands[command.command][fieldName as LocatorFields]?.description) ??
23+
''
24+
const label = fullNote ? FieldName + ' - ' + fullNote : FieldName
2125

2226
return (
2327
<FormControl className="flex flex-row">
@@ -36,10 +40,10 @@ const CommandTextField: FC<CommandFieldProps> = ({
3640
window.sideAPI.menus.open('textField')
3741
}}
3842
size="small"
39-
value={command[fieldName]}
43+
value={command[fieldName as LocatorFields]}
4044
/>
41-
{!isComment && (
42-
<Tooltip className="mx-2 my-auto" title={fullnote} placement="top-end">
45+
{fullNote && (
46+
<Tooltip className="mx-2 my-auto" title={fullNote} placement="top-end">
4347
<HelpCenter />
4448
</Tooltip>
4549
)}

packages/selenium-ide/src/browser/windows/ProjectEditor/tabs/Tests/CommandFields/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const setField =
2-
(name: string) => (testID: string, commandID: string) => (value: string) => {
2+
<T = string>(name: string) => (testID: string, commandID: string) => (value: T) => {
33
window.sideAPI.tests.updateStep(testID, commandID, {
44
[name]: value,
55
})

packages/selenium-ide/src/browser/windows/ProjectEditor/tabs/Tests/TestCommandEditor.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,19 @@ const CommandEditor: FC<CommandEditorProps> = ({
5757
/>
5858
<ArgField command={correctedCommand} {...props} fieldName="target" />
5959
<ArgField command={correctedCommand} {...props} fieldName="value" />
60+
{command.opensWindow && (
61+
<CommandTextField
62+
command={correctedCommand}
63+
{...props}
64+
fieldName="newWindowHandle"
65+
note="Variable name to set to the new window handle"
66+
/>
67+
)}
6068
<CommandTextField
6169
command={correctedCommand}
6270
{...props}
6371
fieldName="comment"
72+
note=""
6473
/>
6574
</Stack>
6675
)

packages/selenium-ide/src/browser/windows/ProjectEditor/tabs/Tests/TestCommandListItem.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ const updateIsBreakpoint = (
4747
})
4848
}
4949

50+
export const defaultCommandState =
51+
{} as unknown as PlaybackEventShapes['COMMAND_STATE_CHANGED']
52+
5053
const CommandRow: React.FC<CommandRowProps> = ({
5154
activeTest,
52-
commandState = {},
53-
command: { command, id, isBreakpoint, target, value },
55+
commandState = defaultCommandState,
56+
command: { command, id, isBreakpoint, opensWindow, target, value },
5457
index,
5558
reorderPreview,
5659
resetPreview,
@@ -103,7 +106,9 @@ const CommandRow: React.FC<CommandRowProps> = ({
103106
disableTypography
104107
primary={
105108
<Box sx={commandTextFormat}>
106-
{camelToTitleCase(commandText)} {isDisabled ? '[Disabled]' : ''}
109+
{camelToTitleCase(commandText)}&nbsp;
110+
{opensWindow ? '(Opens window)' : ''}&nbsp;
111+
{isDisabled ? '[Disabled]' : ''}
107112
</Box>
108113
}
109114
secondary={

packages/selenium-ide/src/browser/windows/ProjectEditor/tabs/Tests/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export interface CommandArgFieldProps extends CommandEditorProps {
1616
}
1717

1818
export interface CommandFieldProps extends CommandEditorProps {
19-
fieldName: 'comment' | LocatorFields
19+
fieldName: 'comment' | 'newWindowHandle' | LocatorFields
20+
note?: string
2021
}
2122

2223
export interface MiniCommandShape {

packages/selenium-ide/src/main/session/controllers/State/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,18 @@ export default class StateController extends BaseController {
3535
async onProjectLoaded() {
3636
// If this file has been saved, fetch state
3737
if (this.session.projects.filepath) {
38-
this.state = {
38+
const storageState: StateShape = storage.get(this.getStatePath());
39+
const newState: StateShape = {
3940
...defaultState,
40-
...storage.get(this.getStatePath()),
41+
...storageState,
4142
commands: this.state.commands,
42-
}
43+
editor: {
44+
...defaultState.editor,
45+
...storageState?.editor ?? {},
46+
selectedCommandIndexes: [],
47+
}
48+
};
49+
this.state = newState
4350
}
4451
}
4552

0 commit comments

Comments
 (0)