Skip to content

Commit

Permalink
Studio2Manager Publish (#40)
Browse files Browse the repository at this point in the history
* decoupled changes from testbot

* dowload transcript and callback form ui is back
  • Loading branch information
kanak8278 authored Jul 19, 2024
1 parent 5d96725 commit 7827d65
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 17 deletions.
64 changes: 58 additions & 6 deletions studio/src/components/PublishModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,54 @@
import '@/styles/components/publishModal.scss';
import { DefaultButton, Icon, Label, Modal, Stack, TextField } from '@fluentui/react';
import React from 'react';
import { sendRequest } from '../../api';

interface props {
isOpen: boolean
hideModal: Function
isOpen: boolean,
hideModal: Function,
representations: any,
dslName: string
}

const uploadProgram = (url: string, secret: string, name: string, representations: any) => {
const dslContentText = representations?.find(r => r.name == 'dsl')?.text || '{}';
const codeContent = representations?.find(r => r.name == 'code')?.text || ''
const dslContent = JSON.parse(dslContentText);
const credentials = dslContent.config_vars.map(x => x.name);
;

const requestBody = {
'name': dslContent.fsm_name,
'dsl': dslContentText,
'code': codeContent,
'requirements': '',
'required_credentials': credentials,
'index_urls':[''],
'version': '1.0.0'

}

sendRequest({
url: url,
method: "POST",
accessToken: secret,
body: JSON.stringify(requestBody),
headers: {
'Content-Type': 'application/json'
}
});
}

export const PublishModal = (props: props) => {
const [message, setMessage] = React.useState('');
const [secretKey, setSecretKey] = React.useState('');

const resetModal = () => {
setMessage('');
setSecretKey('');
props.hideModal();
}

return(
<>
<Modal
Expand All @@ -24,15 +67,21 @@ export const PublishModal = (props: props) => {
<Label htmlFor={'installationUrl'}>Installation Url</Label>
</Stack.Item>
<Stack.Item>
<TextField id={'installationUrl'} />
<TextField
id={'installationUrl'}
onChange={(e, value) => { setMessage(value || '') }}
value={message}/>
</Stack.Item>
</Stack>
<Stack horizontal className='input-fields'>
<Stack.Item>
<Label htmlFor={'jbManagerSecret'}>JB Manager Secret</Label>
</Stack.Item>
<Stack.Item>
<TextField id={'jbManagerSecret'} />
<TextField
id={'jbManagerSecret'}
onChange={(e, value) => { setSecretKey(value || '') }}
value={secretKey}/>
</Stack.Item>
</Stack>
<Stack>
Expand All @@ -53,10 +102,13 @@ before you do wide-scale release.
<Stack.Item>
<Stack horizontal className={'footer-buttons'}>
<Stack.Item>
<DefaultButton className={'primary-button'} onClick={() => props.hideModal()}>Publish</DefaultButton>
<DefaultButton className={'primary-button'} onClick={() => {
uploadProgram(message, secretKey, props.dslName, props.representations);
resetModal();
}}>Publish</DefaultButton>
</Stack.Item>
<Stack.Item>
<DefaultButton onClick={() => props.hideModal()}>Cancel</DefaultButton>
<DefaultButton onClick={() => resetModal()}>Cancel</DefaultButton>
</Stack.Item>
</Stack>
</Stack.Item>
Expand Down
33 changes: 22 additions & 11 deletions studio/src/pages/editor-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const EditorPage: React.FunctionComponent = () => {
const [inputText, setInputText] = React.useState<string>('');
const fileInput = React.createRef<HTMLInputElement>();
const [dslImportLoader, setDslImportLoader] = React.useState<boolean>(false);
const [resetTestChat, setResetTestChat] = React.useState<boolean>(false);
React.useEffect(() => {
if (token && params.id) {
sendRequest({
Expand All @@ -97,7 +98,7 @@ export const EditorPage: React.FunctionComponent = () => {
}, [params.id, token, userId])

React.useEffect(() => {
if (account && inProgress === "none") {
if (account && inProgress === "none") {
instance.acquireTokenSilent({
scopes: [import.meta.env.VITE_REACT_APP_ADD_APP_SCOPE_URI || ''],
account: account
Expand Down Expand Up @@ -260,7 +261,7 @@ export const EditorPage: React.FunctionComponent = () => {
}

const renderRep = (item: any, index: number) => {
// if (item.name !== 'code') {
if (item.name !== 'fsm_state') {
return (<Stack.Item
className={item.name === selectedRepresentation?.name ? 'rep-icon selected' : 'rep-icon'}
key={index}>
Expand All @@ -271,13 +272,13 @@ export const EditorPage: React.FunctionComponent = () => {
{item.name}
</IconButton>
</Stack.Item>)
// }
}
}

return (
<Stack className='editor-page'>
<Stack.Item>
<PublishModal isOpen={isPublishModalOpen} hideModal={hidePublishModal} />
<PublishModal isOpen={isPublishModalOpen} hideModal={hidePublishModal} representations={representations} dslName={projectDetails?.name}/>
<Modal
titleAriaId={useId('pluginStore')}
isBlocking={true}
Expand Down Expand Up @@ -414,17 +415,27 @@ export const EditorPage: React.FunctionComponent = () => {
<Stack.Item>
<OverflowSet
aria-label="Actions"
style={{ display: chatMode === 'TestMode' ? 'block': 'none' }}
overflowItems={[
{
key: 'download',
name: 'Download Transcripts',
name: 'Download Transcript',
iconProps: { iconName: 'Download' },
onClick: () => {},
}, {
key: 'callbackForm',
name: 'Callback form',
},
{
key: 'callbackFrom',
name: 'Callback From',
iconProps: { iconName: 'FormLibrary' },
onClick: () => { },
onclick: () => {}
},
{
key: 'clearData',
name: 'Start / Reset bot',
iconProps: { iconName: 'Rerun' },
onClick: () => {
setResetTestChat(true);
},
}
]}
onRenderOverflowButton={onRenderOverflowButton}
Expand All @@ -438,7 +449,7 @@ export const EditorPage: React.FunctionComponent = () => {
<DevBot inputText={inputText} setProgramState={setProgramState} refreshIR={() => setRefreshIR(refreshIR + 1) } pluginStoreToggle={showPluginStore} userId={userId} setOnlineState={setDevChatStatus} id={params.id} token={token} />
</div>
<div style={{ display: chatMode === 'TestMode' ? 'block': 'none' }}>
<TestBot userId={userId} setOnlineState={setSandboxChatStatus} id={params.id} token={token} />
<TestBot userId={userId} setOnlineState={setSandboxChatStatus} id={params.id} token={token} resetChat={resetTestChat} resetChatToggle={setResetTestChat}/>
</div>
</Stack.Item>
</Stack>
Expand All @@ -450,4 +461,4 @@ export const EditorPage: React.FunctionComponent = () => {

}

export default EditorPage;
export default EditorPage;

0 comments on commit 7827d65

Please sign in to comment.