mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-10-13 00:03:00 +00:00
fix: keep a custom error handler's slack argument on save
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
54eeb451e4
commit
297aa348d1
@@ -69,6 +69,8 @@
|
||||
} from 'lucide-svelte'
|
||||
import { hubPaths } from '$lib/hub'
|
||||
import { isCloudHosted } from '$lib/cloud'
|
||||
import { untrack } from 'svelte'
|
||||
import { syncSlackBotArg } from './handlerSlackArg'
|
||||
import SmtpConfigurationStatus from './common/smtp/SmtpConfigurationStatus.svelte'
|
||||
import { SettingService } from '$lib/gen'
|
||||
import { isSmtpSettingsValid } from './instanceSettings/SmtpSettings.svelte'
|
||||
@@ -316,12 +318,13 @@
|
||||
loadSmtpConfiguration()
|
||||
})
|
||||
|
||||
let builtinArgs: Record<string, any> | undefined
|
||||
$effect(() => {
|
||||
if (handlerSelected === 'slack' && isSlackHandler(handlerPath)) {
|
||||
handlerExtraArgs['slack'] = '$res:f/slack_bot/bot_token'
|
||||
} else {
|
||||
handlerExtraArgs['slack'] = undefined
|
||||
}
|
||||
const isSlackBuiltin = handlerSelected === 'slack' && isSlackHandler(handlerPath)
|
||||
const args = handlerExtraArgs
|
||||
// A replaced args object (Discard, reload) holds the stored config, not what the built-in set.
|
||||
untrack(() => syncSlackBotArg(args, isSlackBuiltin, args === builtinArgs))
|
||||
builtinArgs = isSlackBuiltin ? args : undefined
|
||||
})
|
||||
|
||||
let lastHandlerSelected: ErrorHandler | undefined = $state(undefined)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { syncSlackBotArg } from './handlerSlackArg'
|
||||
|
||||
const AUTO = '$res:f/slack_bot/bot_token'
|
||||
|
||||
describe('syncSlackBotArg', () => {
|
||||
it("leaves a custom handler's slack value alone", () => {
|
||||
const args = { slack: '$res:u/me/my_slack' }
|
||||
syncSlackBotArg(args, false, false)
|
||||
syncSlackBotArg(args, false, true)
|
||||
expect(args).toEqual({ slack: '$res:u/me/my_slack' })
|
||||
})
|
||||
|
||||
it('sets the bot token for the built-in and drops it when leaving', () => {
|
||||
const args: Record<string, any> = {}
|
||||
syncSlackBotArg(args, true, false)
|
||||
expect(args.slack).toBe(AUTO)
|
||||
syncSlackBotArg(args, false, true)
|
||||
expect(args).toStrictEqual({})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,17 @@
|
||||
import { WORKSPACE_SLACK_BOT_TOKEN_PATH } from '$lib/consts'
|
||||
|
||||
const AUTO_SLACK_ARG = '$res:' + WORKSPACE_SLACK_BOT_TOKEN_PATH
|
||||
|
||||
// `slack` belongs to the Slack built-in only while it holds the value the picker set; any other
|
||||
// value is a custom handler's own argument and must survive handler switches and reloads.
|
||||
export function syncSlackBotArg(
|
||||
args: Record<string, any>,
|
||||
isSlackBuiltin: boolean,
|
||||
wasSlackBuiltin: boolean
|
||||
) {
|
||||
if (isSlackBuiltin) {
|
||||
args.slack = AUTO_SLACK_ARG
|
||||
} else if (wasSlackBuiltin && args.slack === AUTO_SLACK_ARG) {
|
||||
delete args.slack
|
||||
}
|
||||
}
|
||||
@@ -1133,10 +1133,14 @@
|
||||
}
|
||||
|
||||
// Strip keys from extraArgs that are auto-managed by child components:
|
||||
// - 'slack': computed by ErrorOrRecoveryHandler's $effect based on handler type
|
||||
// - 'slack' while the Slack built-in is selected: set by ErrorOrRecoveryHandler's $effect
|
||||
// - 'channel_name': display metadata stripped by SchemaForm's removeExtraKey()
|
||||
function normalizeHandlerExtraArgs(args: Record<string, any>): Record<string, any> {
|
||||
const { slack: _, channel_name: __, ...rest } = args
|
||||
function normalizeHandlerExtraArgs(
|
||||
args: Record<string, any>,
|
||||
handlerSelected: ErrorHandler
|
||||
): Record<string, any> {
|
||||
const { channel_name: _, ...rest } = args
|
||||
if (handlerSelected === 'slack') delete rest.slack
|
||||
return rest
|
||||
}
|
||||
|
||||
@@ -1146,7 +1150,10 @@
|
||||
errorHandlerSelected: initialErrorHandlerSelected,
|
||||
errorHandlerScriptPath: initialErrorHandlerScriptPath,
|
||||
errorHandlerItemKind: initialErrorHandlerItemKind,
|
||||
errorHandlerExtraArgs: normalizeHandlerExtraArgs(initialErrorHandlerExtraArgs),
|
||||
errorHandlerExtraArgs: normalizeHandlerExtraArgs(
|
||||
initialErrorHandlerExtraArgs,
|
||||
initialErrorHandlerSelected
|
||||
),
|
||||
errorHandlerMutedOnCancel: initialErrorHandlerMutedOnCancel,
|
||||
errorHandlerMutedOnUserPath: initialErrorHandlerMutedOnUserPath
|
||||
}
|
||||
@@ -1155,7 +1162,7 @@
|
||||
errorHandlerSelected: errorHandlerSelected,
|
||||
errorHandlerScriptPath: errorHandlerScriptPath,
|
||||
errorHandlerItemKind: errorHandlerItemKind,
|
||||
errorHandlerExtraArgs: normalizeHandlerExtraArgs(errorHandlerExtraArgs),
|
||||
errorHandlerExtraArgs: normalizeHandlerExtraArgs(errorHandlerExtraArgs, errorHandlerSelected),
|
||||
errorHandlerMutedOnCancel: errorHandlerMutedOnCancel,
|
||||
errorHandlerMutedOnUserPath: errorHandlerMutedOnUserPath
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user