Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

refactor(site): refactor external auth component#11758

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
BrunoQuaresma merged 3 commits intomainfrombq/refactor-external-auth-api
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,25 +201,17 @@ describe("CreateWorkspacePage", () => {
);
});

it("external auth: errors if unauthenticated and submits", async () => {
it("external auth: errors if unauthenticated", async () => {
jest
.spyOn(API, "getTemplateVersionExternalAuth")
.mockResolvedValueOnce([MockTemplateVersionExternalAuthGithub]);

renderCreateWorkspacePage();
await waitForLoaderToBeRemoved();

const nameField = await screen.findByLabelText(nameLabelText);

// have to use fireEvent b/c userEvent isn't cleaning up properly between tests
Copy link
Member

@ParkreinerParkreinerJan 23, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I know that we have the test simplified down now, so this comment wouldn't even be relevant anymore, but do you know if we ever figured out theuserEvent issue? This is the first I've heard of it not cleaning up properly, but some digging made it sounds like it was a bug with the library

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't know, to be honest, I just removed it from here because we don't need to fill in the name input to see the error.

fireEvent.change(nameField, {
target: { value: "test" },
});

const submitButton = screen.getByText(createWorkspaceText);
await userEvent.click(submitButton);

await screen.findByText("You must authenticate to create a workspace!");
await screen.findByText(
"To create a workspace using the selected template, please ensure you are authenticated with all the external providers listed below.",
);
});

it("auto create a workspace if uses mode=auto", async () => {
Expand Down
15 changes: 11 additions & 4 deletionssite/src/pages/CreateWorkspacePage/CreateWorkspacePage.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,8 +68,12 @@ const CreateWorkspacePage: FC = () => {
? richParametersQuery.data.filter(paramsUsedToCreateWorkspace)
: undefined;

const { externalAuth, externalAuthPollingState, startPollingExternalAuth } =
useExternalAuth(realizedVersionId);
const {
externalAuth,
externalAuthPollingState,
startPollingExternalAuth,
isLoadingExternalAuth,
} = useExternalAuth(realizedVersionId);

const isLoadingFormData =
templateQuery.isLoading ||
Expand DownExpand Up@@ -118,7 +122,9 @@ const CreateWorkspacePage: FC = () => {
<title>{pageTitle(title)}</title>
</Helmet>
{loadFormDataError && <ErrorAlert error={loadFormDataError} />}
{isLoadingFormData || autoCreateWorkspaceMutation.isLoading ? (
{isLoadingFormData ||
isLoadingExternalAuth ||
autoCreateWorkspaceMutation.isLoading ? (
<Loader />
) : (
<CreateWorkspacePageView
Expand DownExpand Up@@ -169,7 +175,7 @@ const useExternalAuth = (versionId: string | undefined) => {
setExternalAuthPollingState("polling");
}, []);

const { data: externalAuth } = useQuery(
const { data: externalAuth, isLoading: isLoadingExternalAuth } = useQuery(
versionId
? {
...templateVersionExternalAuth(versionId),
Expand DownExpand Up@@ -205,6 +211,7 @@ const useExternalAuth = (versionId: string | undefined) => {
startPollingExternalAuth,
externalAuth,
externalAuthPollingState,
isLoadingExternalAuth,
};
};

Expand Down
66 changes: 16 additions & 50 deletionssite/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,12 +27,12 @@ import {
ImmutableTemplateParametersSection,
MutableTemplateParametersSection,
} from "components/TemplateParameters/TemplateParameters";
import {ExternalAuth } from "./ExternalAuth";
import {ExternalAuthButton } from "./ExternalAuthButton";
import { ErrorAlert } from "components/Alert/ErrorAlert";
import { Stack } from "components/Stack/Stack";
import {
CreateWorkspaceMode,
typeExternalAuthPollingState,
ExternalAuthPollingState,
} from "./CreateWorkspacePage";
import { useSearchParams } from "react-router-dom";
import { CreateWSPermissions } from "./permissions";
Expand DownExpand Up@@ -85,10 +85,9 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
}) => {
const theme = useTheme();
const [owner, setOwner] = useState(defaultOwner);
const { verifyExternalAuth, externalAuthErrors } =
useExternalAuthVerification(externalAuth);
const [searchParams] = useSearchParams();
const disabledParamsList = searchParams?.get("disable_params")?.split(",");
const requiresExternalAuth = externalAuth.some((auth) => !auth.authenticated);

const form: FormikContextType<TypesGen.CreateWorkspaceRequest> =
useFormik<TypesGen.CreateWorkspaceRequest>({
Expand All@@ -106,7 +105,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
}),
enableReinitialize: true,
onSubmit: (request) => {
if (!verifyExternalAuth()) {
if (requiresExternalAuth) {
return;
}

Expand DownExpand Up@@ -192,16 +191,20 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
description="This template requires authentication to external services."
>
<FormFields>
{requiresExternalAuth && (
<Alert severity="error">
To create a workspace using the selected template, please
ensure you are authenticated with all the external providers
listed below.
</Alert>
)}
{externalAuth.map((auth) => (
<ExternalAuth
<ExternalAuthButton
key={auth.id}
authenticateURL={auth.authenticate_url}
authenticated={auth.authenticated}
externalAuthPollingState={externalAuthPollingState}
startPollingExternalAuth={startPollingExternalAuth}
displayName={auth.display_name}
displayIcon={auth.display_icon}
error={externalAuthErrors[auth.id]}
auth={auth}
isLoading={externalAuthPollingState === "polling"}
onStartPolling={startPollingExternalAuth}
displayRetry={externalAuthPollingState === "abandoned"}
/>
))}
</FormFields>
Expand DownExpand Up@@ -273,43 +276,6 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
);
};

type ExternalAuthErrors = Record<string, string>;

const useExternalAuthVerification = (
externalAuth: TypesGen.TemplateVersionExternalAuth[],
) => {
const [externalAuthErrors, setExternalAuthErrors] =
useState<ExternalAuthErrors>({});

// Clear errors when externalAuth is refreshed
useEffect(() => {
setExternalAuthErrors({});
}, [externalAuth]);

const verifyExternalAuth = () => {
const errors: ExternalAuthErrors = {};

for (let i = 0; i < externalAuth.length; i++) {
const auth = externalAuth.at(i);
if (!auth) {
continue;
}
if (!auth.authenticated) {
errors[auth.id] = "You must authenticate to create a workspace!";
}
}

setExternalAuthErrors(errors);
const isValid = Object.keys(errors).length === 0;
return isValid;
};

return {
externalAuthErrors,
verifyExternalAuth,
};
};

const styles = {
hasDescription: {
paddingBottom: 16,
Expand Down
92 changes: 0 additions & 92 deletionssite/src/pages/CreateWorkspacePage/ExternalAuth.stories.tsx
View file
Open in desktop

This file was deleted.

96 changes: 0 additions & 96 deletionssite/src/pages/CreateWorkspacePage/ExternalAuth.tsx
View file
Open in desktop

This file was deleted.

Loading

[8]ページ先頭

©2009-2025 Movatter.jp