- Notifications
You must be signed in to change notification settings - Fork1k
refactor: move required external auth buttons to the submit side#18586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
da84dd6
refactor: move required external auth buttons to the submit side
BrunoQuaresmadb8a91b
fmt
BrunoQuaresma8a12f60
Apply asher's review comments
BrunoQuaresmaa6ff685
Add retry
BrunoQuaresma2c2be53
fmt
BrunoQuaresmad294d9b
Apply Asher's comments
BrunoQuaresmaFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2,13 +2,12 @@ import Skeleton from "@mui/material/Skeleton"; | ||
import { API } from "api/api"; | ||
import { getErrorDetail, getErrorMessage } from "api/errors"; | ||
import { disabledRefetchOptions } from "api/queries/util"; | ||
import type { Template, TemplateVersionExternalAuth } from "api/typesGenerated"; | ||
import { ErrorAlert } from "components/Alert/ErrorAlert"; | ||
import { Avatar } from "components/Avatar/Avatar"; | ||
import { AvatarData } from "components/Avatar/AvatarData"; | ||
import { AvatarDataSkeleton } from "components/Avatar/AvatarDataSkeleton"; | ||
import { Button } from "components/Button/Button"; | ||
import { displayError } from "components/GlobalSnackbar/utils"; | ||
import { Margins } from "components/Margins/Margins"; | ||
import { | ||
@@ -37,9 +36,16 @@ import { | ||
TableRowSkeleton, | ||
} from "components/TableLoader/TableLoader"; | ||
import { ExternalImage } from "components/ExternalImage/ExternalImage"; | ||
import { | ||
Tooltip, | ||
TooltipContent, | ||
TooltipProvider, | ||
TooltipTrigger, | ||
} from "components/Tooltip/Tooltip"; | ||
import { useAuthenticated } from "hooks"; | ||
import { useExternalAuth } from "hooks/useExternalAuth"; | ||
import {RedoIcon,RotateCcwIcon, SendIcon } from "lucide-react"; | ||
import { AI_PROMPT_PARAMETER_NAME, type Task } from "modules/tasks/tasks"; | ||
import { WorkspaceAppStatus } from "modules/workspaces/WorkspaceAppStatus/WorkspaceAppStatus"; | ||
import { generateWorkspaceName } from "modules/workspaces/generateWorkspaceName"; | ||
@@ -50,12 +56,12 @@ import { Link as RouterLink } from "react-router-dom"; | ||
import TextareaAutosize from "react-textarea-autosize"; | ||
import { pageTitle } from "utils/page"; | ||
import { relativeTime } from "utils/time"; | ||
import { type UserOption, UsersCombobox } from "./UsersCombobox"; | ||
type TasksFilter = { | ||
user: UserOption | undefined; | ||
}; | ||
const TasksPage: FC = () => { | ||
const { user, permissions } = useAuthenticated(); | ||
const [filter, setFilter] = useState<TasksFilter>({ | ||
@@ -201,21 +207,24 @@ type TaskFormProps = { | ||
const TaskForm: FC<TaskFormProps> = ({ templates }) => { | ||
const { user } = useAuthenticated(); | ||
const queryClient = useQueryClient(); | ||
const [selectedTemplateId, setSelectedTemplateId] = useState<string>( | ||
templates[0].id, | ||
); | ||
const selectedTemplate = templates.find( | ||
(t) => t.id === selectedTemplateId, | ||
) as Template; | ||
const { | ||
externalAuth, | ||
externalAuthError, | ||
isPollingExternalAuth, | ||
isLoadingExternalAuth, | ||
} = useExternalAuth(selectedTemplate.active_version_id); | ||
const missedExternalAuth = externalAuth?.filter( | ||
(auth) => !auth.optional && !auth.authenticated, | ||
); | ||
const isMissingExternalAuth = missedExternalAuth | ||
? missedExternalAuth.length > 0 | ||
: true; | ||
const createTaskMutation = useMutation({ | ||
mutationFn: async ({ prompt, templateId }: CreateTaskMutationFnProps) => | ||
@@ -235,10 +244,6 @@ const TaskForm: FC<TaskFormProps> = ({ templates }) => { | ||
const prompt = formData.get("prompt") as string; | ||
const templateID = formData.get("templateID") as string; | ||
try { | ||
await createTaskMutation.mutateAsync({ | ||
prompt, | ||
@@ -253,8 +258,12 @@ const TaskForm: FC<TaskFormProps> = ({ templates }) => { | ||
}; | ||
return ( | ||
<form | ||
onSubmit={onSubmit} | ||
aria-label="Create AI task" | ||
className="flex flex-col gap-4" | ||
> | ||
{externalAuthError && <ErrorAlert error={externalAuthError} />} | ||
<fieldset | ||
className="border border-border border-solid rounded-lg p-4" | ||
@@ -274,7 +283,7 @@ const TaskForm: FC<TaskFormProps> = ({ templates }) => { | ||
<div className="flex items-center justify-between pt-2"> | ||
<Select | ||
name="templateID" | ||
onValueChange={(value) =>setSelectedTemplateId(value)} | ||
defaultValue={templates[0].id} | ||
required | ||
> | ||
@@ -294,43 +303,93 @@ const TaskForm: FC<TaskFormProps> = ({ templates }) => { | ||
</SelectContent> | ||
</Select> | ||
<div className="flex items-center gap-2"> | ||
{missedExternalAuth && ( | ||
<ExternalAuthButtons | ||
template={selectedTemplate} | ||
missedExternalAuth={missedExternalAuth} | ||
/> | ||
)} | ||
<Button size="sm" type="submit" disabled={isMissingExternalAuth}> | ||
<Spinner | ||
loading={ | ||
isLoadingExternalAuth || | ||
isPollingExternalAuth || | ||
createTaskMutation.isPending | ||
} | ||
> | ||
<SendIcon /> | ||
</Spinner> | ||
Run task | ||
</Button> | ||
</div> | ||
</div> | ||
</fieldset> | ||
</form> | ||
); | ||
}; | ||
type ExternalAuthButtonProps = { | ||
template: Template; | ||
missedExternalAuth: TemplateVersionExternalAuth[]; | ||
}; | ||
const ExternalAuthButtons: FC<ExternalAuthButtonProps> = ({ | ||
code-asher marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
template, | ||
missedExternalAuth, | ||
}) => { | ||
const { | ||
startPollingExternalAuth, | ||
isPollingExternalAuth, | ||
externalAuthPollingState, | ||
} = useExternalAuth(template.active_version_id); | ||
const shouldRetry = externalAuthPollingState === "abandoned"; | ||
return missedExternalAuth.map((auth) => { | ||
return ( | ||
<div className="flex items-center gap-2" key={auth.id}> | ||
<Button | ||
variant="outline" | ||
size="sm" | ||
disabled={isPollingExternalAuth || auth.authenticated} | ||
onClick={() => { | ||
window.open( | ||
auth.authenticate_url, | ||
"_blank", | ||
"width=900,height=600", | ||
); | ||
startPollingExternalAuth(); | ||
}} | ||
> | ||
<Spinner loading={isPollingExternalAuth}> | ||
<ExternalImage src={auth.display_icon} /> | ||
</Spinner> | ||
Connect to {auth.display_name} | ||
</Button> | ||
{shouldRetry && !auth.authenticated && ( | ||
<TooltipProvider> | ||
<Tooltip delayDuration={100}> | ||
<TooltipTrigger asChild> | ||
<Button | ||
variant="outline" | ||
size="icon" | ||
onClick={startPollingExternalAuth} | ||
> | ||
<RedoIcon /> | ||
<span className="sr-only">Refresh external auth</span> | ||
</Button> | ||
</TooltipTrigger> | ||
<TooltipContent> | ||
Retry connecting to {auth.display_name} | ||
</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
)} | ||
</div> | ||
); | ||
}); | ||
}; | ||
type TasksFilterProps = { | ||
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.