Compare commits

...

4 Commits

Author SHA1 Message Date
737dd206cd Sectional default update in point-and-click sweep 2025-05-14 12:38:47 -04:00
d7bd0c937d Keep test toast messages around for longer (#6930)
* Keep test toast messages around for longer

* Check for at least two locators

I wasn't able to reproduce, but it's possible one stuck around from a previous test.
2025-05-14 12:24:38 -04:00
d3b2483f4f Clear errors when leaving file to avoid seeing previous files errors (#6928)
Clear errors when leaving file to avoid seeing previous files errors when opening new project

Co-authored-by: Jace Browning <jacebrowning@gmail.com>
2025-05-14 17:20:04 +02:00
7838b7c9fd Fix "include settings" setting to have an effect (#6917)
* Fix "include settings" setting to have an effect

I'm not sold on if we should have this setting, but this fixes it for
now. The issue is was that the new callback actor approach was using a
stale version of the settings every time it received an "update" event:
JS closure problems. Now it receives the new settings as an event
payload.

* Update src/machines/settingsMachine.ts

---------

Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
2025-05-14 15:14:33 +00:00
7 changed files with 88 additions and 20 deletions

View File

@ -545,7 +545,8 @@ extrude002 = extrude(profile002, length = 150)
expect(alreadyExportingToastMessage).not.toBeVisible(),
])
await expect(successToastMessage).toHaveCount(2)
const count = await successToastMessage.count()
await expect(count).toBeGreaterThanOrEqual(2)
})
})

View File

@ -151,6 +151,10 @@ export class KclManager {
// These belonged to the previous file
this.lastSuccessfulOperations = []
this.lastSuccessfulVariables = {}
// Without this, when leaving a project which has errors and opening another project which doesn't,
// you'd see the errors from the previous project for a short time until the new code is executed.
this._errors = []
}
get variables() {

View File

@ -152,9 +152,10 @@ export function addSweep({
// Extra labeled args expressions
const pathExpr = createLocalName(pathDeclaration.node.declaration.id.name)
const sectionalExpr = sectional
? [createLabeledArg('sectional', createLiteral(sectional))]
: []
const sectionalExpr =
sectional == false
? [createLabeledArg('sectional', createLiteral(sectional))]
: []
const sketchesExpr = createSketchExpression(sketchesExprList)
const call = createCallExpressionStdLibKw('sweep', sketchesExpr, [

View File

@ -434,7 +434,7 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
sectional: {
inputType: 'options',
skip: true,
defaultValue: false,
defaultValue: true,
hidden: false,
required: true,
options: [

View File

@ -290,7 +290,7 @@ export const sweepValidator = async ({
const command = async () => {
// TODO: second look on defaults here
const DEFAULT_TOLERANCE: Models['LengthUnit_type'] = 1e-7
const DEFAULT_SECTIONAL = false
const DEFAULT_SECTIONAL = false // the more permissive for validation
const cmdArgs = {
target,
trajectory,

View File

@ -31,7 +31,7 @@ const save_ = async (file: ModelingAppFile, toastId: string) => {
)
toast.success(EXPORT_TOAST_MESSAGES.SUCCESS + ' [TEST]', {
id: toastId,
duration: 5_000,
duration: 10_000,
})
return
}

View File

@ -139,18 +139,20 @@ export const settingsMachine = setup({
return () => darkModeMatcher?.removeEventListener('change', listener)
}),
registerCommands: fromCallback<
{ type: 'update' },
{ type: 'update'; settings: SettingsType },
{ settings: SettingsType; actor: AnyActorRef }
>(({ input, receive, system }) => {
// This assumes this actor is running in a system with a command palette
const commandBarActor = system.get(ACTOR_IDS.COMMAND_BAR)
// If the user wants to hide the settings commands
//from the command bar don't add them.
if (settings.commandBar.includeSettings.current === false) return
if (settings.commandBar.includeSettings.current === false) {
return
}
let commands: Command[] = []
const updateCommands = () =>
settingsWithCommandConfigs(input.settings)
const updateCommands = (newSettings: SettingsType) =>
settingsWithCommandConfigs(newSettings)
.map((type) =>
createSettingsCommand({
type,
@ -175,14 +177,19 @@ export const settingsMachine = setup({
data: { commands: commands },
})
receive((event) => {
if (event.type !== 'update') return
receive(({ type, settings: newSettings }) => {
if (type !== 'update') {
return
}
removeCommands()
commands = updateCommands()
commands =
newSettings.commandBar.includeSettings.current === false
? []
: updateCommands(newSettings)
addCommands()
})
commands = updateCommands()
commands = updateCommands(settings)
addCommands()
return () => {
@ -205,7 +212,9 @@ export const settingsMachine = setup({
const sceneInfra = rootContext.sceneInfra
const sceneEntitiesManager = rootContext.sceneEntitiesManager
if (!sceneInfra || !sceneEntitiesManager) return
if (!sceneInfra || !sceneEntitiesManager) {
return
}
const opposingTheme = getOppositeTheme(context.app.theme.current)
sceneInfra.theme = opposingTheme
sceneEntitiesManager.updateSegmentBaseColor(opposingTheme)
@ -213,13 +222,17 @@ export const settingsMachine = setup({
setAllowOrbitInSketchMode: ({ context, self }) => {
const rootContext = self.system.get('root').getSnapshot().context
const sceneInfra = rootContext.sceneInfra
if (!sceneInfra.camControls) return
if (!sceneInfra.camControls) {
return
}
sceneInfra.camControls._setting_allowOrbitInSketchMode =
context.app.allowOrbitInSketchMode.current
// ModelingMachineProvider will do a use effect to trigger the camera engine sync
},
toastSuccess: ({ event }) => {
if (!('data' in event)) return
if (!('data' in event)) {
return
}
const eventParts = event.type.replace(/^set./, '').split('.') as [
keyof typeof settings,
string,
@ -435,6 +448,22 @@ export const settingsMachine = setup({
actions: ['setSettingAtLevel', 'setThemeColor'],
},
'set.commandBar.includeSettings': {
target: 'persisting settings',
actions: [
'setSettingAtLevel',
'toastSuccess',
sendTo(
'registerCommands',
({ context: { currentProject: _, ...settings } }) => ({
type: 'update',
settings,
})
),
],
},
'set.modeling.defaultUnit': {
target: 'persisting settings',
@ -497,6 +526,13 @@ export const settingsMachine = setup({
'setClientTheme',
'setAllowOrbitInSketchMode',
'sendThemeToWatcher',
sendTo(
'registerCommands',
({ context: { currentProject: _, ...settings } }) => ({
type: 'update',
settings,
})
),
],
},
@ -510,6 +546,13 @@ export const settingsMachine = setup({
'setClientTheme',
'setAllowOrbitInSketchMode',
'sendThemeToWatcher',
sendTo(
'registerCommands',
({ context: { currentProject: _, ...settings } }) => ({
type: 'update',
settings,
})
),
],
},
@ -529,7 +572,13 @@ export const settingsMachine = setup({
'clearProjectSettings',
'clearCurrentProject',
'setThemeColor',
sendTo('registerCommands', { type: 'update' }),
sendTo(
'registerCommands',
({ context: { currentProject: _, ...settings } }) => ({
type: 'update',
settings,
})
),
],
},
},
@ -582,6 +631,13 @@ export const settingsMachine = setup({
'setClientTheme',
'setAllowOrbitInSketchMode',
'sendThemeToWatcher',
sendTo(
'registerCommands',
({ context: { currentProject: _, ...settings } }) => ({
type: 'update',
settings,
})
),
],
},
onError: {
@ -612,7 +668,13 @@ export const settingsMachine = setup({
'setClientTheme',
'setAllowOrbitInSketchMode',
'sendThemeToWatcher',
sendTo('registerCommands', { type: 'update' }),
sendTo(
'registerCommands',
({ context: { currentProject: _, ...settings } }) => ({
type: 'update',
settings,
})
),
],
},
onError: 'idle',