Files
modeling-app/src/components/SetVarNameModal.tsx

95 lines
3.1 KiB
TypeScript
Raw Normal View History

import { Dialog, Transition } from '@headlessui/react'
2023-08-18 17:14:35 -05:00
import { Fragment } from 'react'
import { CreateNewVariable } from './AvailableVarsHelpers'
import { ActionButton } from './ActionButton'
import { toast } from 'react-hot-toast'
import { type InstanceProps, create } from 'react-modal-promise'
import { useCalculateKclExpression } from 'lib/useCalculateKclExpression'
type ModalResolve = { variableName: string }
type ModalReject = boolean
type SetVarNameModalProps = InstanceProps<ModalResolve, ModalReject> & {
valueName: string
}
export const createSetVarNameModal = create<
SetVarNameModalProps,
ModalResolve,
ModalReject
>
export const SetVarNameModal = ({
isOpen,
onResolve,
onReject,
valueName,
}: SetVarNameModalProps) => {
const { isNewVariableNameUnique, newVariableName, setNewVariableName } =
Replace number command bar arg input type with kcl expression input (#1474) * Rename useCalc * Move CommandBar so it has access to settings and kcl * Create codemirror variable mention extension * Make project path a dep of TextEditor useMemo * Add incomplete KCL input for CommandBar to replace current number arg type * Add previous variables autocompletion to kcl input * Fix missed typos from merge * Working AST mods, not working variable additions * Add ability to create a new variable * Add icon and tooltip to command arg tag if a variable is added * Polish variable naming logic, preserve when going back * Allow stepping back from KCL input * Don't prevent keydown of enter, it's used by autocomplete * Round the variable value in cmd bar header * Add Playwright test * Formatting, polish TS types * More type wrangling * Needed to fmt after above type wrangling * Update snapshot tests to account for new variable name autogeneration * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * Merge branch 'main' into cmd-bar-make-variable * Update all test instances of var name with number index after merge with main * Partial revert of "Polish variable naming logic, preserve when going back" This reverts commit dddcb13c36139ef564e9601fb391b00f99e42c36. * Revert "Update all test instances of var name with number index after merge with main" This reverts commit 8c4b63b5231fd888243ff8677a1de167134bd3d2. * Revert "Update snapshot tests to account for new variable name autogeneration" This reverts commit 11bfce38326efc24bfd2d00e67df036bf87ba27a. * Retry a refactoring of findUniqueName * minor feedback from @jgomez720 - better highlighting of kcl input - consistent hotkeys - disallow invalid var names * Polish stepping back state logic * Fix tests now that keyboard shortcut changed * Remove unused imports * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * Fix tests * Trigger CI * Update src/components/ProjectSidebarMenu.test.tsx * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * re-trigger CI --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch>
2024-02-23 11:24:22 -05:00
useCalculateKclExpression({ value: '', initialVariableName: valueName })
return (
<Transition appear show={isOpen} as={Fragment}>
<Dialog
as="div"
className="fixed inset-0 z-40 overflow-y-auto p-4 pt-[25vh]"
onClose={onReject}
>
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0 translate-y-4"
enterTo="opacity-100 translate-y-0"
leave="ease-in duration-75"
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
<Dialog.Overlay className="fixed inset-0 bg-chalkboard-10/70 dark:bg-chalkboard-110/50" />
</Transition.Child>
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0 scale-95"
enterTo="opacity-100 scale-100"
leave="ease-in duration-200"
leaveFrom="opacity-100 scale-100"
leaveTo="opacity-0 scale-95"
>
<Dialog.Panel className="rounded relative mx-auto px-4 py-8 bg-chalkboard-10 dark:bg-chalkboard-100 border dark:border-chalkboard-70 max-w-xl w-full shadow-lg">
<form
onSubmit={(e) => {
e.preventDefault()
onResolve({
variableName: newVariableName,
})
toast.success(`Added variable ${newVariableName}`)
}}
>
<CreateNewVariable
setNewVariableName={setNewVariableName}
newVariableName={newVariableName}
isNewVariableNameUnique={isNewVariableNameUnique}
shouldCreateVariable={true}
showCheckbox={false}
/>
<div className="mt-8 flex justify-between">
Symbols overlay (#2033) * start of overlay work * add new icons * add constraint symbols * add three dots * add primary colours * refactor how we get constraint info for overlays * refactor how we get constraint info for overlays * get symbols working for tangential arc too * extra data on constraint info * add initial delete * fix types and circular dep issue after rebase * fix quirk with horz vert line overlays * fix setup and tear down of overlays * remove overlays that are too small * throttle overlay updates and prove tests selecting html instead of hardcoded px coords * initial show overaly on segment hover * remove overlays when tool is equipped * dounce overlay updates * tsc * make higlighting robust to small changes in source ranges * replace with variable for unconstrained values, and improve styles for popover * background tweak * make overlays unconstrain inputs * fix small regression * write query for finding related tag references * make delete segment safe * typo * un used imports * test deleteSegmentFromPipeExpression * add getConstraintInfo test * test removeSingleConstraintInfo * more tests * tsc * add tests for overlay buttons * rename tests * fmt * better naming structure * more reliablity * more test tweaks * fix selection test * add delete segments with overlays tests * dependant tag tests for segment delet * typo * test clean up * fix some perf issus * clean up * clean up * make things a little more dry * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * trigger ci * Make constraint hover popovers readable on light mode * Touch up the new variable dialog * Little touch-up to three-dot menu style * fix highlight issue * fmt * use optional chain * Revert "A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)" This reverts commit be3d61e4a303b0d9a792dddbfe8430cc58d46451. * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * disable var panel in sketch mode * fix overlay tests after mergi in main * test tweak * try fix ubuntu * fmt * more test tweaks * tweak * tweaks --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Frank Noirot <frank@kittycad.io>
2024-05-24 20:54:42 +10:00
<ActionButton Element="button" onClick={() => onReject(false)}>
Cancel
</ActionButton>
<ActionButton
Element="button"
type="submit"
disabled={!isNewVariableNameUnique}
Symbols overlay (#2033) * start of overlay work * add new icons * add constraint symbols * add three dots * add primary colours * refactor how we get constraint info for overlays * refactor how we get constraint info for overlays * get symbols working for tangential arc too * extra data on constraint info * add initial delete * fix types and circular dep issue after rebase * fix quirk with horz vert line overlays * fix setup and tear down of overlays * remove overlays that are too small * throttle overlay updates and prove tests selecting html instead of hardcoded px coords * initial show overaly on segment hover * remove overlays when tool is equipped * dounce overlay updates * tsc * make higlighting robust to small changes in source ranges * replace with variable for unconstrained values, and improve styles for popover * background tweak * make overlays unconstrain inputs * fix small regression * write query for finding related tag references * make delete segment safe * typo * un used imports * test deleteSegmentFromPipeExpression * add getConstraintInfo test * test removeSingleConstraintInfo * more tests * tsc * add tests for overlay buttons * rename tests * fmt * better naming structure * more reliablity * more test tweaks * fix selection test * add delete segments with overlays tests * dependant tag tests for segment delet * typo * test clean up * fix some perf issus * clean up * clean up * make things a little more dry * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * trigger ci * Make constraint hover popovers readable on light mode * Touch up the new variable dialog * Little touch-up to three-dot menu style * fix highlight issue * fmt * use optional chain * Revert "A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)" This reverts commit be3d61e4a303b0d9a792dddbfe8430cc58d46451. * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * disable var panel in sketch mode * fix overlay tests after mergi in main * test tweak * try fix ubuntu * fmt * more test tweaks * tweak * tweaks --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Frank Noirot <frank@kittycad.io>
2024-05-24 20:54:42 +10:00
iconStart={{ icon: 'plus' }}
>
Add variable
</ActionButton>
</div>
</form>
</Dialog.Panel>
</Transition.Child>
</Dialog>
</Transition>
)
}