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 30, 2024
1 parent 8e860f6 commit b1ecf73
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 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(() => {
return new Promise<void>((resolve, _reject) => {
setTimeout(() => {
console.log("downloaded");
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
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default function AIConfigEditor({
aiconfig: initialAIConfig,
callbacks,
mode,
readOnly = false,
readOnly = true,
themeMode,
}: Props) {
const [isSaving, setIsSaving] = useState(false);
Expand Down

0 comments on commit b1ecf73

Please sign in to comment.