Make Modify with Text-to-CAD selection arg optional by honoring skip: false on non-required args (#6992)

* Make "skip = false" non-required args appear in header

* Make non-required, unskippable selection args work

* Make prompt-to-edit's selection arg optional but non-skippable

* Update src/components/CommandBar/CommandBarSelectionInput.tsx

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>

* Fix dumb logic bug

Thanks for user testing @Irev-dev

* Update mixed input to show selection

Feel free to revert @Irev-Dev if this is the wrong move, but I found it
odd that this component doesn't show the current selection in the text
like the other selection input does, so I copied that over.

* Merge branch 'main' into franknoirot/adhoc/optional-selection-args

* Merge branch 'main' into franknoirot/adhoc/optional-selection-args

* Merge remote-tracking branch 'origin' into franknoirot/adhoc/optional-selection-args

* fix tests

* change copy again

* Update src/components/CommandBar/CommandBarSelectionMixedInput.tsx

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
This commit is contained in:
Frank Noirot
2025-05-16 05:15:52 -04:00
committed by GitHub
parent 28a8cd2421
commit ebf048478d
7 changed files with 67 additions and 15 deletions

View File

@ -8,6 +8,7 @@ import {
canSubmitSelectionArg,
getSelectionCountByType,
getSelectionTypeDisplayText,
type Selections,
} from '@src/lib/selections'
import { engineCommandManager, kclManager } from '@src/lib/singletons'
import { reportRejection } from '@src/lib/trap'
@ -56,9 +57,13 @@ function CommandBarSelectionInput({
const selectionsByType = useMemo(() => {
return getSelectionCountByType(selection)
}, [selection])
const isArgRequired =
arg.required instanceof Function
? arg.required(commandBarState.context)
: arg.required
const canSubmitSelection = useMemo<boolean>(
() => canSubmitSelectionArg(selectionsByType, arg),
[selectionsByType]
() => !isArgRequired || canSubmitSelectionArg(selectionsByType, arg),
[selectionsByType, arg, isArgRequired]
)
useEffect(() => {
@ -110,7 +115,18 @@ function CommandBarSelectionInput({
return
}
onSubmit(selection)
/**
* Now that arguments like this can be optional, we need to
* construct an empty selection if it's not required to get it past our validation.
*/
const resolvedSelection: Selections | undefined = isArgRequired
? selection
: selection || {
graphSelections: [],
otherSelections: [],
}
onSubmit(resolvedSelection)
}
// Clear selection if needed