Add ability to open KCL samples in-app (#3912)
* 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>
This commit is contained in:
@ -6,8 +6,8 @@ import { CommandArgument, CommandArgumentOption } from 'lib/commandTypes'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { AnyStateMachine, StateFrom } from 'xstate'
|
||||
|
||||
const contextSelector = (snapshot: StateFrom<AnyStateMachine>) =>
|
||||
snapshot.context
|
||||
const contextSelector = (snapshot: StateFrom<AnyStateMachine> | undefined) =>
|
||||
snapshot?.context
|
||||
|
||||
function CommandArgOptionInput({
|
||||
arg,
|
||||
|
@ -140,7 +140,11 @@ function CommandBarHeader({ children }: React.PropsWithChildren<{}>) {
|
||||
JSON.stringify(argValue)
|
||||
)
|
||||
) : (
|
||||
<em>{argValue}</em>
|
||||
<em>
|
||||
{arg.valueSummary
|
||||
? arg.valueSummary(argValue)
|
||||
: argValue}
|
||||
</em>
|
||||
)
|
||||
) : null}
|
||||
</span>
|
||||
|
@ -58,7 +58,17 @@ function CommandBarReview({ stepBack }: { stepBack: () => void }) {
|
||||
|
||||
return (
|
||||
<CommandBarHeader>
|
||||
<p className="px-4">Confirm {selectedCommand?.name}</p>
|
||||
<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"
|
||||
|
@ -31,8 +31,8 @@ function getSemanticSelectionType(selectionType: Array<Selection['type']>) {
|
||||
return Array.from(semanticSelectionType)
|
||||
}
|
||||
|
||||
const selectionSelector = (snapshot: StateFrom<typeof modelingMachine>) =>
|
||||
snapshot.context.selectionRanges
|
||||
const selectionSelector = (snapshot?: StateFrom<typeof modelingMachine>) =>
|
||||
snapshot?.context.selectionRanges
|
||||
|
||||
function CommandBarSelectionInput({
|
||||
arg,
|
||||
@ -49,7 +49,7 @@ function CommandBarSelectionInput({
|
||||
const [hasSubmitted, setHasSubmitted] = useState(false)
|
||||
const selection = useSelector(arg.machineActor, selectionSelector)
|
||||
const selectionsByType = useMemo(() => {
|
||||
const selectionRangeEnd = selection.codeBasedSelections[0]?.range[1]
|
||||
const selectionRangeEnd = selection?.codeBasedSelections[0]?.range[1]
|
||||
return !selectionRangeEnd || selectionRangeEnd === code.length
|
||||
? 'none'
|
||||
: getSelectionType(selection)
|
||||
|
Reference in New Issue
Block a user