import { CommandShape } from '@seleniumhq/side-model' import { CommandsStateShape } from '@seleniumhq/side-api' import useReorderPreview from 'browser/hooks/useReorderPreview' import React, { FC } from 'react' import CommandRow from './TestCommandRow' import EditorToolbar from '../../../../components/Drawer/EditorToolbar' import makeKeyboundNav from 'browser/hooks/useKeyboundNav' import ReorderableList from 'browser/components/ReorderableList' import { Box } from '@mui/material' import { useIntl } from 'react-intl' import languageMap from 'browser/I18N/keys' export interface CommandListProps { activeTest: string commands: CommandShape[] commandStates: CommandsStateShape disabled?: boolean selectedCommandIndexes: number[] } const useKeyboundNav = makeKeyboundNav(window.sideAPI.state.updateStepSelection) const CommandList: FC = ({ activeTest, commandStates, commands, disabled, selectedCommandIndexes, }) => { const intl = useIntl() const [preview, reorderPreview, resetPreview] = useReorderPreview( commands, selectedCommandIndexes, (c) => c.id ) useKeyboundNav(commands, selectedCommandIndexes) return ( <> window.sideAPI.tests.addSteps( activeTest, Math.max(selectedCommandIndexes.slice(-1)[0], 0) ) } addText={intl.formatMessage({ id: languageMap.testCore.addCommand })} onRemove={ commands.length > 1 ? () => window.sideAPI.tests.removeSteps( activeTest, selectedCommandIndexes ) : undefined } removeText={intl.formatMessage({ id: languageMap.testCore.removeCommand, })} >   {intl.formatMessage({ id: languageMap.testCore.tabCommand })} {intl.formatMessage({ id: languageMap.testCore.tabTarget })} {intl.formatMessage({ id: languageMap.testCore.tabValue })} {preview.map(([command, origIndex], index) => { if (!command) { return null } const { id } = command return ( ) })} ) } export default CommandList