import Box from '@mui/material/Box' import IconButton from '@mui/material/IconButton' import Typography from '@mui/material/Typography' import PauseIcon from '@mui/icons-material/Pause' import { CommandShape } from '@seleniumhq/side-model' import { PlaybackEventShapes } from '@seleniumhq/side-runtime' import { camelToTitleCase } from '@seleniumhq/side-api/dist/helpers/string' import ReorderableListItem from 'browser/components/ReorderableListItem' import React from 'react' import { ReorderPreview } from 'browser/hooks/useReorderPreview' import CommandOverlay from './TestCommandOverlay' const { state: { updateStepSelection }, tests: { updateStep }, } = window.sideAPI type ColorMode = 'light' | 'dark' export const colorFromCommandState = ( state: PlaybackEventShapes['COMMAND_STATE_CHANGED']['state'] | undefined, mode: ColorMode ) => { switch (state) { case 'skipped': case 'undetermined': return `warning.${mode}` case 'executing': return `info.${mode}` case 'pending': return `secondary.${mode}` case 'errored': case 'failed': return `error.${mode}` case 'passed': return `success.${mode}` default: return 'transparent' } } const commandIndexTextFormat = { color: 'primary.main' } const commandTextFormat = { color: 'primary.main', typography: 'body2' } const commentTextFormat = { color: 'info.main', typography: 'subtitle2', } const argTextFormat = { color: 'secondary.main', typography: 'subtitle2', ml: 2, } const errorTextFormat = { color: 'error.main', typography: 'caption', ml: 2, } interface CommandRowProps { activeTest: string commandState: PlaybackEventShapes['COMMAND_STATE_CHANGED'] command: CommandShape disabled?: boolean index: number reorderPreview: ReorderPreview resetPreview: () => void selected: boolean } const updateIsBreakpoint = ( testID: string, commandID: string, isBreakpoint: boolean ) => { updateStep(testID, commandID, { isBreakpoint, }) } const CommandRow: React.FC = ({ activeTest, commandState, command: { command, comment, id, isBreakpoint, target, value }, disabled = false, index, reorderPreview, resetPreview, selected, }) => { if (typeof command != 'string') { command = '//unknown - could not process' } const state = commandState?.state ?? null const toggleBreakpoint = () => updateIsBreakpoint(activeTest, id, !isBreakpoint) if (state === 'executing') { window.scrollTo(0, 20 * index) } const isDisabled = command.startsWith('//') const commandText = isDisabled ? command.slice(2) : command const mainClass = ['pos-rel width-100'] .concat(isDisabled ? ['o-50'] : []) .join(' ') const message = commandState?.message ?? '' return ( { await updateStepSelection(index, false, true, false) await window.sideAPI.menus.open('testEditor', id) }} onClick={async (e) => { const selectBatch = e.shiftKey const addEntry = !e.altKey && (e.ctrlKey || e.metaKey || e.shiftKey) const clearSelection = !e.altKey && !e.shiftKey && !e.ctrlKey await updateStepSelection(index, selectBatch, addEntry, clearSelection) }} disablePadding reorder={(_, newIndex) => reorderPreview({ newIndex })} reorderConfirm={(_, newIndex) => window.sideAPI.tests.reorderSteps(activeTest, newIndex) } reorderReset={resetPreview} selected={selected} select={updateStepSelection} secondaryAction={ } > {comment && (   // {comment} )} {index + 1} {camelToTitleCase(commandText)} {isDisabled ? '[Disabled]' : ''} {target} {value} {message && ( {message} )} ) } export default CommandRow