Commit 3245b2b7 by feitianbubu Committed by GitHub

fix(model-pricing): refresh tiered expression editor when switching models (#5752)

Switching models in the pricing editor kept the previous model's tiers and prices in the expression panel: TieredPricingEditor seeds its internal visual/raw state only on mount, and the initRef guard never re-ran on prop changes, so only the model name updated.

Bump a reload token in the same effect that seeds billingExpr and use it as the editor's key, so a freshly loaded model remounts the editor and re-parses its expression. The token changes in lockstep with billingExpr, and user edits (which only touch state) do not trigger it.

Closes #5750
parent 79396745
......@@ -153,6 +153,7 @@ export const ModelPricingEditorPanel = forwardRef<
})
const [billingExpr, setBillingExpr] = useState('')
const [requestRuleExpr, setRequestRuleExpr] = useState('')
const [editorReloadToken, setEditorReloadToken] = useState(0)
const isEditMode = !!editData
const form = useForm<ModelPricingFormValues>({
......@@ -214,6 +215,7 @@ export const ModelPricingEditorPanel = forwardRef<
setPromptPrice(nextLaneState.promptPrice)
setLanePrices(nextLaneState.prices)
setLaneEnabled(nextLaneState.enabled)
setEditorReloadToken((token) => token + 1)
}, [editData, form])
const setFormValue = (field: keyof ModelPricingFormValues, value: string) => {
......@@ -638,6 +640,7 @@ export const ModelPricingEditorPanel = forwardRef<
<TabsContent value='tiered_expr' className='pt-0'>
<FieldGroup className='gap-5'>
<TieredPricingEditor
key={editorReloadToken}
modelName={watchedValues.name}
billingExpr={billingExpr}
requestRuleExpr={requestRuleExpr}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment