Skip to content

Commit

Permalink
Merge branch 'master' into templates-refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kurund authored Jan 3, 2025
2 parents f2aca7c + f061508 commit 161c74e
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/assets/images/icons/ExpandContent.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions src/components/UI/Form/Input/Input.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
font-weight: 400;
}

.Multiline {
padding-bottom: 35px;
}

.Resend {
color: #119656;
font-weight: bold;
Expand Down
2 changes: 1 addition & 1 deletion src/components/UI/Form/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const Input = ({ textArea = false, disabled = false, inputLabel = null, .
inputComponent={editor ? editor.inputComponent : undefined}
inputProps={editor ? editor.inputProps : inputProp}
type={fieldType}
classes={{ multiline: styles.Multiline, input: !textArea ? inputStyles : '' }}
classes={{ input: !textArea ? inputStyles : '' }}
disabled={disabled}
error={showError}
multiline={textArea}
Expand Down
24 changes: 24 additions & 0 deletions src/containers/Assistants/Assistants.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,27 @@ test('it should show errors for invalid value in temperature', async () => {
expect(screen.getByText('Temperature value should be between 0-2')).toBeInTheDocument();
});
});

test('it opens the instruction dialog box', async () => {
render(assistantsComponent());

await waitFor(() => {
expect(screen.getByText('Assistants')).toBeInTheDocument();
expect(screen.getByText('Assistant-1')).toBeInTheDocument();
});

await waitFor(() => {
expect(screen.getByTestId('expandIcon')).toBeInTheDocument();
});

fireEvent.click(screen.getByTestId('expandIcon'));
fireEvent.click(screen.getByTestId('cancel-button'));
fireEvent.click(screen.getByTestId('expandIcon'));

fireEvent.change(screen.getByRole('textbox'), { target: { value: 'test instructions' } });
fireEvent.click(screen.getByTestId('save-button'));

await waitFor(() => {
expect(screen.getByText('test instructions')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,56 @@
.DeleteIcon {
margin-right: 0.5rem;
}

.Expand {
height: 100%;
display: flex;
align-items: end;
max-height: none;
}

.ExpandButton {
cursor: pointer;
}

.ExpandButton:hover {
background-color: #00000017;
border-radius: 0.5rem;
}

.InstructionsBox {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}

.Instructions {
background-color: #fff;
width: 50%;
padding: 1rem;
border-radius: 1rem;
}

.Instructions h5 {
margin: 0;
font-size: 18px;
font-weight: 500;
line-height: 1.4;
}

.Instructions {
display: flex;
flex-direction: column;
gap: 1rem;
}

.Input {
width: 100%;
}

.InstructionButtons {
width: 100%;
display: flex;
justify-content: end;
}
40 changes: 39 additions & 1 deletion src/containers/Assistants/CreateAssistant/CreateAssistant.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useLazyQuery, useMutation, useQuery } from '@apollo/client';
import { Typography } from '@mui/material';
import { InputAdornment, Modal, OutlinedInput, Typography } from '@mui/material';
import { Field, FormikProvider, useFormik } from 'formik';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand All @@ -19,6 +19,7 @@ import { DELETE_ASSISTANT, UPDATE_ASSISTANT } from 'graphql/mutations/Assistant'

import CopyIcon from 'assets/images/CopyGreen.svg?react';
import DeleteIcon from 'assets/images/icons/Delete/White.svg?react';
import ExpandIcon from 'assets/images/icons/ExpandContent.svg?react';

import { AssistantOptions } from '../AssistantOptions/AssistantOptions';

Expand All @@ -38,6 +39,7 @@ export const CreateAssistant = ({ currentId, setUpdateList, setCurrentId, update
const [instructions, setInstructions] = useState('');
const [options, setOptions] = useState({ fileSearch: true, temperature: 1 });
const [showConfirmation, setShowConfirmation] = useState(false);
const [openInstructions, setOpenInstructions] = useState(false);
const { t } = useTranslation();

const states = {
Expand Down Expand Up @@ -109,6 +111,12 @@ export const CreateAssistant = ({ currentId, setUpdateList, setCurrentId, update
});
};

const expandIcon = (
<InputAdornment className={styles.Expand} position="end">
<ExpandIcon data-testid="expandIcon" onClick={() => setOpenInstructions(true)} className={styles.ExpandButton} />
</InputAdornment>
);

const formFields: any = [
{
component: AutoComplete,
Expand Down Expand Up @@ -145,6 +153,7 @@ export const CreateAssistant = ({ currentId, setUpdateList, setCurrentId, update
textArea: true,
helperText: t('Set the instructions according to your requirements.'),
onChange: (value: any) => setInstructions(value),
endAdornment: expandIcon,
},
{
component: AssistantOptions,
Expand Down Expand Up @@ -187,6 +196,7 @@ export const CreateAssistant = ({ currentId, setUpdateList, setCurrentId, update
};

let dialog;
let instructionsDialog;
if (showConfirmation) {
dialog = (
<DialogBox
Expand All @@ -204,6 +214,33 @@ export const CreateAssistant = ({ currentId, setUpdateList, setCurrentId, update
</DialogBox>
);
}
if (openInstructions) {
instructionsDialog = (
<Modal open={openInstructions} onClose={() => setOpenInstructions(false)}>
<div className={styles.InstructionsBox}>
<div className={styles.Instructions}>
<h5>Edit system instructions</h5>
<OutlinedInput
name="expand-instructions"
onChange={(event) => setInstructions(event.target.value)}
value={instructions}
className={styles.Input}
multiline
rows={16}
/>
<div className={styles.InstructionButtons}>
<Button data-testid="cancel-button" onClick={() => setOpenInstructions(false)} variant="outlined">
Cancel
</Button>
<Button data-testid="save-button" onClick={() => setOpenInstructions(false)} variant="contained">
Save
</Button>
</div>
</div>
</div>
</Modal>
);
}

if (loading || listLoading) {
return <Loading />;
Expand Down Expand Up @@ -243,6 +280,7 @@ export const CreateAssistant = ({ currentId, setUpdateList, setCurrentId, update
</div>
</form>
{dialog}
{instructionsDialog}
</div>
</FormikProvider>
);
Expand Down

0 comments on commit 161c74e

Please sign in to comment.