Skip to content

Commit

Permalink
fix: reset playground i/o data on namespace change (#1543)
Browse files Browse the repository at this point in the history
To test this this toolkit version could be used for cloud
`0.107.0-rc.15`

Because

- changing namespace on model playground did not reset the i/o forms
data

This commit

- now it do reset it


https://github.com/user-attachments/assets/f058e1ed-804f-4d53-bcf9-03286eea226a
  • Loading branch information
orangecoloured authored Oct 18, 2024
1 parent 7d78d4e commit de2ae66
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions packages/toolkit/src/view/model/view-model/ModelPlayground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const defaultCurrentOperationIdPollingData = {
timeoutRunning: false,
isRendered: false,
modelVersion: null,
targetNamespace: null,
};

export const ModelPlayground = ({
Expand All @@ -96,6 +97,7 @@ export const ModelPlayground = ({
timeoutRunning: boolean;
isRendered: boolean;
modelVersion: Nullable<string>;
targetNamespace: Nullable<string>;
}>(defaultCurrentOperationIdPollingData);
const { toast } = useToast();
const { amplitudeIsInit } = useAmplitudeCtx();
Expand Down Expand Up @@ -210,15 +212,22 @@ export const ModelPlayground = ({
}, OPERATION_POLL_TIMEOUT);
}, [model?.name, queryClient, existingModelTriggerResult]);

const resetStatesAndCurrentOperationIdPollingData = () => {
currentOperationIdPollingData.current =
defaultCurrentOperationIdPollingData;
setExistingTriggerState(null);
setInputFromExistingResult(null);
setModelRunResult(null);
};

useEffect(() => {
if (activeVersion !== currentOperationIdPollingData.current.modelVersion) {
currentOperationIdPollingData.current =
defaultCurrentOperationIdPollingData;
setExistingTriggerState(null);
setInputFromExistingResult(null);
setModelRunResult(null);
if (
activeVersion !== currentOperationIdPollingData.current.modelVersion ||
targetNamespace !== currentOperationIdPollingData.current.targetNamespace
) {
resetStatesAndCurrentOperationIdPollingData();
}
}, [activeVersion]);
}, [activeVersion, targetNamespace]);

useEffect(() => {
if (
Expand Down Expand Up @@ -273,6 +282,10 @@ export const ModelPlayground = ({
setExistingTriggerState(existingModelTriggerResult.data.operation);
}
}
// "toast" update doesn't matter here
// and the "pollForResponse" mainly uses ref and a couple of methods that
// don't depend on the state of the data
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
existingTriggerState,
existingModelTriggerResult.isSuccess,
Expand Down Expand Up @@ -316,8 +329,10 @@ export const ModelPlayground = ({
isRendered: existingTriggerState.done,
name: existingTriggerState.name,
modelVersion: existingTriggerState.response?.request.version || null,
targetNamespace: targetNamespace?.id || null,
};
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [existingTriggerState, model]);

const triggerModel = useTriggerUserModelVersionAsync();
Expand Down

0 comments on commit de2ae66

Please sign in to comment.