import { CodeOff, HelpCenter, OpenInNew } from '@mui/icons-material' import { Autocomplete } from '@mui/material' import { FormControl } from '@mui/material' import { TextField } from '@mui/material' import { IconButton } from '@mui/material' import { Tooltip } from '@mui/material' import React, { FC, useMemo } from 'react' import { setField, updateACField } from './utils' import { CommandSelectorProps } from '../types' import { FormattedMessage } from 'react-intl' import languageMap from 'browser/I18N/keys' const setCommandFactory = setField('command') const setOpensWindowFactory = setField('opensWindow') const updateCommand = updateACField('command') const CommandSelector: FC = ({ command, commands, disabled, isDisabled, testID, }) => { const commandsList = useMemo( () => Object.entries(commands) .map(([id, { name }]: [string, { name: string }]) => ({ id, name })) .sort((a, b) => a.name.localeCompare(b.name)), [] ) if (commandsList.length === 0) { return null } const setCommand = setCommandFactory(testID, command.id) const setOpensWindow = setOpensWindowFactory(testID, command.id) const commandOptions = commandsList.map((item) => { return { label: item.name, id: item.id } }) return ( <> option.label} options={commandOptions} renderInput={(params) => ( } /> )} size="small" value={commandOptions.find((entry) => entry.id === command.command)} isOptionEqualToValue={(option, value) => option.id === value.id} /> } placement="top-end" > setOpensWindow(!command.opensWindow)} > } placement="top-end" > setCommand(isDisabled ? command.command : `//${command.command}`) } > } placement="top-end" > ) } export default CommandSelector