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
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user