geido commented on code in PR #33255:
URL: https://github.com/apache/superset/pull/33255#discussion_r2098091538


##########
superset-frontend/src/pages/Login/index.tsx:
##########
@@ -0,0 +1,211 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { SupersetClient, styled, t, css } from '@superset-ui/core';
+import {
+  Button,
+  Card,
+  Flex,
+  Form,
+  Input,
+  Typography,
+  Icons,
+} from 'src/components';
+import { useState } from 'react';
+import { capitalize } from 'lodash/fp';
+import getBootstrapData from 'src/utils/getBootstrapData';
+
+type OAuthProvider = {
+  name: string;
+  icon: string;
+};
+
+type OIDProvider = {
+  name: string;
+  url: string;
+};
+
+type Provider = OAuthProvider | OIDProvider;
+
+interface LoginForm {
+  username: string;
+  password: string;
+}
+
+enum AuthType {
+  AuthOID = 0,
+  AuthDB = 1,
+  AuthLDAP = 2,
+  AuthOauth = 4,
+}
+
+const AuthIconMap: Record<string, React.JSX.Element> = {
+  github: <Icons.GithubOutlined />,
+  google: <Icons.GoogleOutlined />,
+  facebook: <Icons.FacebookOutlined />,
+};
+
+const LoginContainer = styled(Flex)`
+  width: 100%;
+`;
+
+const StyledCard = styled(Card)`
+  ${({ theme }) => css`
+    width: 40%;
+    margin-top: ${theme.marginXL}px;
+    background: ${theme.colorBgBase};
+    .antd5-form-item-label label {
+      color: ${theme.colorPrimary};
+    }
+  `}
+`;
+
+const StyledLabel = styled(Typography.Text)`
+  ${({ theme }) => css`
+    font-size: ${theme.fontSizeSM}px;
+  `}
+`;
+
+export default function Login() {
+  const [form] = Form.useForm<LoginForm>();
+  const [loading, setLoading] = useState(false);
+
+  const bootstrapData = getBootstrapData();
+
+  const authType: AuthType = bootstrapData.common.conf.AUTH_TYPE;
+  const providers: Provider[] = bootstrapData.common.conf.AUTH_PROVIDERS;
+  const authRegistration: boolean =
+    bootstrapData.common.conf.AUTH_USER_REGISTRATION;
+
+  const onFinish = (values: LoginForm) => {
+    setLoading(true);
+    SupersetClient.postForm('/login', values, '').finally(() => {
+      setLoading(false);
+    });
+  };
+
+  return (
+    <LoginContainer justify="center" data-test="login-form">
+      <StyledCard title={t('Sign in')} padded>
+        {authType === AuthType.AuthOID && (
+          <Flex justify="center" vertical gap="middle">
+            <Form layout="vertical" requiredMark="optional" form={form}>
+              {providers.map((provider: OIDProvider) => (
+                <Form.Item<LoginForm>>
+                  <Button
+                    href={`/login/${provider.name}`}
+                    block
+                    iconPosition="start"
+                    icon={AuthIconMap[provider.name]}

Review Comment:
   Can new providers be introduced? What happens if the icon isn't available?



##########
superset-frontend/src/pages/Login/index.tsx:
##########
@@ -0,0 +1,211 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { SupersetClient, styled, t, css } from '@superset-ui/core';
+import {
+  Button,
+  Card,
+  Flex,
+  Form,
+  Input,
+  Typography,
+  Icons,
+} from 'src/components';
+import { useState } from 'react';
+import { capitalize } from 'lodash/fp';
+import getBootstrapData from 'src/utils/getBootstrapData';
+
+type OAuthProvider = {
+  name: string;
+  icon: string;
+};
+
+type OIDProvider = {
+  name: string;
+  url: string;
+};
+
+type Provider = OAuthProvider | OIDProvider;
+
+interface LoginForm {
+  username: string;
+  password: string;
+}
+
+enum AuthType {
+  AuthOID = 0,
+  AuthDB = 1,
+  AuthLDAP = 2,
+  AuthOauth = 4,
+}
+
+const AuthIconMap: Record<string, React.JSX.Element> = {
+  github: <Icons.GithubOutlined />,
+  google: <Icons.GoogleOutlined />,
+  facebook: <Icons.FacebookOutlined />,
+};
+
+const LoginContainer = styled(Flex)`
+  width: 100%;
+`;
+
+const StyledCard = styled(Card)`
+  ${({ theme }) => css`
+    width: 40%;
+    margin-top: ${theme.marginXL}px;
+    background: ${theme.colorBgBase};
+    .antd5-form-item-label label {
+      color: ${theme.colorPrimary};
+    }
+  `}
+`;
+
+const StyledLabel = styled(Typography.Text)`
+  ${({ theme }) => css`
+    font-size: ${theme.fontSizeSM}px;
+  `}
+`;
+
+export default function Login() {
+  const [form] = Form.useForm<LoginForm>();
+  const [loading, setLoading] = useState(false);
+
+  const bootstrapData = getBootstrapData();
+
+  const authType: AuthType = bootstrapData.common.conf.AUTH_TYPE;
+  const providers: Provider[] = bootstrapData.common.conf.AUTH_PROVIDERS;
+  const authRegistration: boolean =
+    bootstrapData.common.conf.AUTH_USER_REGISTRATION;
+
+  const onFinish = (values: LoginForm) => {
+    setLoading(true);
+    SupersetClient.postForm('/login', values, '').finally(() => {
+      setLoading(false);
+    });
+  };
+
+  return (
+    <LoginContainer justify="center" data-test="login-form">
+      <StyledCard title={t('Sign in')} padded>
+        {authType === AuthType.AuthOID && (
+          <Flex justify="center" vertical gap="middle">
+            <Form layout="vertical" requiredMark="optional" form={form}>
+              {providers.map((provider: OIDProvider) => (
+                <Form.Item<LoginForm>>
+                  <Button
+                    href={`/login/${provider.name}`}
+                    block
+                    iconPosition="start"
+                    icon={AuthIconMap[provider.name]}
+                  >
+                    {t('Sign in with')} {capitalize(provider.name)}
+                  </Button>
+                </Form.Item>
+              ))}
+            </Form>
+          </Flex>
+        )}
+        {authType === AuthType.AuthOauth && (
+          <Flex justify="center" gap={0} vertical>
+            <Form layout="vertical" requiredMark="optional" form={form}>
+              {providers.map((provider: OAuthProvider) => (
+                <Form.Item<LoginForm>>
+                  <Button
+                    href={`/login/${provider.name}`}
+                    block
+                    iconPosition="start"
+                    icon={AuthIconMap[provider.name]}
+                  >
+                    {t('Sign in with')} {capitalize(provider.name)}
+                  </Button>
+                </Form.Item>
+              ))}
+            </Form>
+          </Flex>
+        )}
+
+        {(authType === AuthType.AuthDB || authType === AuthType.AuthLDAP) && (
+          <Flex justify="center" vertical gap="middle">
+            <Typography.Text type="secondary">
+              {t('Enter your login and password below:')}
+            </Typography.Text>
+            <Form
+              layout="vertical"
+              requiredMark="optional"
+              form={form}
+              onFinish={onFinish}
+            >
+              <Form.Item<LoginForm>
+                label={<StyledLabel>{t('Username:')}</StyledLabel>}
+                name="username"
+                rules={[
+                  { required: true, message: t('Please enter your username') },
+                ]}
+              >
+                <Input
+                  prefix={<Icons.UserOutlined iconSize="l" />}
+                  data-test="username-input"
+                />
+              </Form.Item>
+              <Form.Item<LoginForm>
+                label={<StyledLabel>{t('Password:')}</StyledLabel>}
+                name="password"
+                rules={[
+                  { required: true, message: t('Please enter your password') },
+                ]}
+              >
+                <Input.Password
+                  prefix={<Icons.KeyOutlined iconSize="l" />}
+                  data-test="password-input"
+                />
+              </Form.Item>
+              <Form.Item label={null}>
+                <Flex

Review Comment:
   You have a `LoginContainer` that is the same as this. I prefer inline, so 
maybe we can get rid of `LoginContainer`?



##########
superset-frontend/cypress-base/cypress/support/e2e.ts:
##########
@@ -70,13 +70,19 @@ Cypress.Commands.add('loadDashboardFixtures', () =>
 );
 
 before(() => {
+  if (Cypress.currentTest.title.toLowerCase().includes('login')) {

Review Comment:
   Can we make a small util for this?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to