Skip to content

Commit

Permalink
Address UI Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
BeatrixCohere committed May 23, 2024
1 parent d27210d commit cc50e45
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 42 deletions.
47 changes: 11 additions & 36 deletions src/interfaces/coral_web/src/components/EditEnvVariablesButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export const EditEnvVariablesButton: React.FC<{ className?: string }> = () => {
* @description Renders a modal to edit a selected deployment's config
*/
export const EditEnvVariablesModal: React.FC<{
onClose: () => void;
defaultDeployment: string;
}> = ({ onClose, defaultDeployment }) => {
onClose: () => void;
}> = ({defaultDeployment, onClose }) => {
const { data: deployments } = useListAllDeployments();

const [deployment, setDeployment] = useState<string | undefined>(defaultDeployment);
Expand All @@ -56,7 +56,6 @@ export const EditEnvVariablesModal: React.FC<{
);
});
const [isSubmitting, setIsSubmitting] = useState(false);
const [hasError, setHasError] = useState(false);

const { setParams } = useParamsStore();

Expand All @@ -73,10 +72,6 @@ export const EditEnvVariablesModal: React.FC<{
);

const handleDeploymentChange = (newDeployment: string) => {
if (hasError) {
setHasError(false);
}

setDeployment(newDeployment);
const selectedDeployment = deployments?.find(({ name }) => name === newDeployment);
const emptyEnvVariables =
Expand All @@ -88,34 +83,20 @@ export const EditEnvVariablesModal: React.FC<{
};

const handleEnvVariableChange = (envVar: string) => (e: React.ChangeEvent<HTMLInputElement>) => {
if (hasError) {
setHasError(false);
}

setEnvVariables({ ...envVariables, [envVar]: e.target.value });
};

const handleSubmit = async () => {
if (!deployment) return;

if (hasError) {
setHasError(false);
}

try {
setIsSubmitting(true);
setParams({
deploymentConfig: Object.entries(envVariables)
.map(([k, v]) => k + '=' + v)
.join(';'),
});
setIsSubmitting(false);
onClose();
} catch (e) {
console.error(e);
setHasError(true);
setIsSubmitting(false);
}
setIsSubmitting(true);
setParams({
deploymentConfig: Object.entries(envVariables)
.map(([k, v]) => k + '=' + v)
.join(';'),
});
setIsSubmitting(false);
onClose();
};

return (
Expand All @@ -137,16 +118,10 @@ export const EditEnvVariablesModal: React.FC<{
/>
))}

{hasError && (
<Text styleAs="p-sm" className="text-danger-500">
An error occurred. Please try again.
</Text>
)}

<span className="mt-10 flex items-center justify-between">
<BasicButton kind="minimal" size="sm" label="Cancel" onClick={onClose} />
<Button
label={isSubmitting ? 'Submitting...' : 'Submit'}
label={isSubmitting ? 'Saving...' : 'Save'}
onClick={handleSubmit}
splitIcon="arrow-right"
disabled={isSubmitting}
Expand Down
4 changes: 1 addition & 3 deletions src/interfaces/coral_web/src/pages/c/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ const ConversationPage: NextPage<Props> = () => {

useEffect(() => {
if (!deployment && allDeployments) {
var firstAvailableDeployment = allDeployments.find(function (d) {
return d.is_available;
});
const firstAvailableDeployment = allDeployments.find((d) => d.is_available);
if (firstAvailableDeployment) {
setParams({ deployment: firstAvailableDeployment.name });
}
Expand Down
4 changes: 1 addition & 3 deletions src/interfaces/coral_web/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ const ChatPage: NextPage<Props> = () => {

useEffect(() => {
if (!deployment && allDeployments) {
var firstAvailableDeployment = allDeployments.find(function (d) {
return d.is_available;
});
const firstAvailableDeployment = allDeployments.find((d) => d.is_available);
if (firstAvailableDeployment) {
setParams({ deployment: firstAvailableDeployment.name });
}
Expand Down

0 comments on commit cc50e45

Please sign in to comment.