* Add multiple selections and editor selections for promptToEdit * remove unused * re-enable prompt to edit tests * add test for manual code selection * at test for multi-selection * clean up * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * typo --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
118 lines
2.8 KiB
TypeScript
118 lines
2.8 KiB
TypeScript
import CommandArgOptionInput from './CommandArgOptionInput'
|
|
import CommandBarBasicInput from './CommandBarBasicInput'
|
|
import CommandBarSelectionInput from './CommandBarSelectionInput'
|
|
import CommandBarSelectionMixedInput from './CommandBarSelectionMixedInput'
|
|
import { CommandArgument } from 'lib/commandTypes'
|
|
import CommandBarHeader from './CommandBarHeader'
|
|
import CommandBarKclInput from './CommandBarKclInput'
|
|
import CommandBarTextareaInput from './CommandBarTextareaInput'
|
|
import { commandBarActor, useCommandBarState } from 'machines/commandBarMachine'
|
|
|
|
function CommandBarArgument({ stepBack }: { stepBack: () => void }) {
|
|
const commandBarState = useCommandBarState()
|
|
const {
|
|
context: { currentArgument },
|
|
} = commandBarState
|
|
|
|
function onSubmit(data: unknown) {
|
|
if (!currentArgument) return
|
|
|
|
commandBarActor.send({
|
|
type: 'Submit argument',
|
|
data: {
|
|
[currentArgument.name]: data,
|
|
},
|
|
})
|
|
}
|
|
|
|
return (
|
|
currentArgument && (
|
|
<CommandBarHeader>
|
|
<ArgumentInput
|
|
arg={currentArgument}
|
|
stepBack={stepBack}
|
|
onSubmit={onSubmit}
|
|
/>
|
|
</CommandBarHeader>
|
|
)
|
|
)
|
|
}
|
|
|
|
export default CommandBarArgument
|
|
|
|
function ArgumentInput({
|
|
arg,
|
|
stepBack,
|
|
onSubmit,
|
|
}: {
|
|
arg: CommandArgument<unknown> & { name: string }
|
|
stepBack: () => void
|
|
onSubmit: (event: any) => void
|
|
}) {
|
|
switch (arg.inputType) {
|
|
case 'options':
|
|
return (
|
|
<CommandArgOptionInput
|
|
arg={arg}
|
|
argName={arg.name}
|
|
stepBack={stepBack}
|
|
onSubmit={onSubmit}
|
|
placeholder="Select an option"
|
|
/>
|
|
)
|
|
case 'boolean':
|
|
return (
|
|
<CommandArgOptionInput
|
|
arg={{
|
|
...arg,
|
|
inputType: 'options',
|
|
options: [
|
|
{ name: 'On', value: true },
|
|
{ name: 'Off', value: false },
|
|
],
|
|
}}
|
|
argName={arg.name}
|
|
stepBack={stepBack}
|
|
onSubmit={onSubmit}
|
|
placeholder="Select an option"
|
|
/>
|
|
)
|
|
case 'selection':
|
|
return (
|
|
<CommandBarSelectionInput
|
|
arg={arg}
|
|
stepBack={stepBack}
|
|
onSubmit={onSubmit}
|
|
/>
|
|
)
|
|
case 'selectionMixed':
|
|
return (
|
|
<CommandBarSelectionMixedInput
|
|
arg={arg}
|
|
stepBack={stepBack}
|
|
onSubmit={onSubmit}
|
|
/>
|
|
)
|
|
case 'kcl':
|
|
return (
|
|
<CommandBarKclInput arg={arg} stepBack={stepBack} onSubmit={onSubmit} />
|
|
)
|
|
case 'text':
|
|
return (
|
|
<CommandBarTextareaInput
|
|
arg={arg}
|
|
stepBack={stepBack}
|
|
onSubmit={onSubmit}
|
|
/>
|
|
)
|
|
default:
|
|
return (
|
|
<CommandBarBasicInput
|
|
arg={arg}
|
|
stepBack={stepBack}
|
|
onSubmit={onSubmit}
|
|
/>
|
|
)
|
|
}
|
|
}
|