* Add a shell script to get the list of KCL samples into the app * Add support for overwriting current file with sample * Move these KCL commands down into FileMachineProvider * Add support for creating a new file on desktop * Make it so these files aren't set to "renaming mode" right away * Add support for initializing default values that are functions * Add E2E tests * Add a code menu item to load a sample * Fix tsc issues * Remove `yarn fetch:samples` from `yarn postinstall` * Remove change to arg initialization logic, I was holding it wrong * Switch to use new manifest file from kcl-samples repo * Update tests now that we use proper sample titles * Remove double-load from units menu test * @jtran feedback * Don't encode `https://` that's silly * fmt * Update e2e/playwright/testing-samples-loading.spec.ts Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch> * Test feedback * Add a test step to actually check the file contents were written to (@Irev-Dev feedback) --------- Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch>
104 lines
2.7 KiB
TypeScript
104 lines
2.7 KiB
TypeScript
import { useCommandsContext } from 'hooks/useCommandsContext'
|
|
import CommandBarHeader from './CommandBarHeader'
|
|
import { useHotkeys } from 'react-hotkeys-hook'
|
|
|
|
function CommandBarReview({ stepBack }: { stepBack: () => void }) {
|
|
const { commandBarState, commandBarSend } = useCommandsContext()
|
|
const {
|
|
context: { argumentsToSubmit, selectedCommand },
|
|
} = commandBarState
|
|
|
|
useHotkeys('backspace', stepBack, {
|
|
enableOnFormTags: true,
|
|
enableOnContentEditable: true,
|
|
})
|
|
|
|
useHotkeys(
|
|
[
|
|
'alt+1',
|
|
'alt+2',
|
|
'alt+3',
|
|
'alt+4',
|
|
'alt+5',
|
|
'alt+6',
|
|
'alt+7',
|
|
'alt+8',
|
|
'alt+9',
|
|
'alt+0',
|
|
],
|
|
(_, b) => {
|
|
if (b.keys && !Number.isNaN(parseInt(b.keys[0], 10))) {
|
|
if (!selectedCommand?.args) return
|
|
const argName = Object.keys(selectedCommand.args)[
|
|
parseInt(b.keys[0], 10) - 1
|
|
]
|
|
const arg = selectedCommand?.args[argName]
|
|
commandBarSend({
|
|
type: 'Edit argument',
|
|
data: { arg: { ...arg, name: argName } },
|
|
})
|
|
}
|
|
},
|
|
{ keyup: true, enableOnFormTags: true, enableOnContentEditable: true },
|
|
[argumentsToSubmit, selectedCommand]
|
|
)
|
|
|
|
Object.keys(argumentsToSubmit).forEach((key, i) => {
|
|
const arg = selectedCommand?.args ? selectedCommand?.args[key] : undefined
|
|
if (!arg) return
|
|
})
|
|
|
|
function submitCommand(e: React.FormEvent<HTMLFormElement>) {
|
|
e.preventDefault()
|
|
commandBarSend({
|
|
type: 'Submit command',
|
|
output: argumentsToSubmit,
|
|
})
|
|
}
|
|
|
|
return (
|
|
<CommandBarHeader>
|
|
<p className="px-4">
|
|
{selectedCommand?.reviewMessage ? (
|
|
selectedCommand.reviewMessage instanceof Function ? (
|
|
selectedCommand.reviewMessage(commandBarState.context)
|
|
) : (
|
|
selectedCommand.reviewMessage
|
|
)
|
|
) : (
|
|
<>Confirm {selectedCommand?.name}</>
|
|
)}
|
|
</p>
|
|
<form
|
|
id="review-form"
|
|
className="absolute opacity-0 inset-0 pointer-events-none"
|
|
onSubmit={submitCommand}
|
|
>
|
|
{Object.entries(argumentsToSubmit).map(([key, value], i) => {
|
|
const arg = selectedCommand?.args
|
|
? selectedCommand?.args[key]
|
|
: undefined
|
|
if (!arg) return null
|
|
|
|
return (
|
|
<input
|
|
id={key}
|
|
name={key}
|
|
key={key}
|
|
type="text"
|
|
defaultValue={
|
|
typeof value === 'object'
|
|
? JSON.stringify(value)
|
|
: (value as string)
|
|
}
|
|
hidden
|
|
/>
|
|
)
|
|
})}
|
|
</form>
|
|
</CommandBarHeader>
|
|
)
|
|
}
|
|
|
|
export default CommandBarReview
|