Skip to content

Commit

Permalink
Mock shareCallback to test UI on AIConfigEditor
Browse files Browse the repository at this point in the history
TSIA, just adding code so we can mock the UI
  • Loading branch information
Rossdan Craig rossdan@lastmileai.dev committed Jan 29, 2024
1 parent 7ddfc1d commit 099ecd8
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions python/src/aiconfig/editor/client/src/LocalEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const useStyles = createStyles(() => ({
},
}));


const MODE = "local";

export default function LocalEditor() {
Expand Down Expand Up @@ -75,7 +74,7 @@ export default function LocalEditor() {
sessionSampleRate: 100,
});

datadogLogs.setGlobalContextProperty('mode', MODE);
datadogLogs.setGlobalContextProperty("mode", MODE);
}
}, []);

Expand Down Expand Up @@ -239,12 +238,37 @@ export default function LocalEditor() {
[]
);

const mockDownload = useCallback((config: AIConfig) => {
return new Promise<void>((resolve, _reject) => {
setTimeout(() => {
console.log(config);
resolve();
// uncomment & comment out resolve to test error handling
// reject("message");
}, 2000);
});
}, []);

const mockShare = useCallback(() => {
return new Promise<{ share_url: string }>((resolve, _reject) => {
setTimeout(() => {
resolve({
share_url:
"https://lastmileai.dev/aiconfig/clrv28cop00enpelzgbk61xs2",
});
// uncomment & comment out resolve to test error handling
// reject("message");
}, 2000);
});
}, []);

const callbacks: AIConfigCallbacks = useMemo(
() => ({
addPrompt,
cancel,
clearOutputs,
deletePrompt,
download: mockDownload,
getModels,
getServerStatus,
logEventHandler,
Expand All @@ -253,6 +277,7 @@ export default function LocalEditor() {
setConfigDescription,
setConfigName,
setParameters,
share: mockShare,
updateModel,
updatePrompt,
}),
Expand All @@ -269,6 +294,8 @@ export default function LocalEditor() {
setConfigDescription,
setConfigName,
setParameters,
mockDownload,
mockShare,
updateModel,
updatePrompt,
]
Expand All @@ -289,11 +316,7 @@ export default function LocalEditor() {
<Loader size="xl" />
</Flex>
) : (
<AIConfigEditor
aiconfig={aiconfig}
callbacks={callbacks}
mode={MODE}
/>
<AIConfigEditor aiconfig={aiconfig} callbacks={callbacks} mode={MODE} />
)}
</div>
);
Expand Down

0 comments on commit 099ecd8

Please sign in to comment.