EnxDev commented on code in PR #33255: URL: https://github.com/apache/superset/pull/33255#discussion_r2079950417
########## superset-frontend/src/pages/Login/index.tsx: ########## @@ -0,0 +1,166 @@ +/** + * 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 { css } from '@emotion/react'; Review Comment: should be better to import this from `@superset-ui/core` ########## superset-frontend/src/pages/Login/index.tsx: ########## @@ -0,0 +1,166 @@ +/** + * 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 { css } from '@emotion/react'; +import { SupersetClient, styled, t } from '@superset-ui/core'; Review Comment: ```suggestion import { SupersetClient, styled, t, css} from '@superset-ui/core'; ``` ########## superset-frontend/src/pages/Login/index.tsx: ########## @@ -0,0 +1,166 @@ +/** + * 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 { css } from '@emotion/react'; +import { SupersetClient, styled, t } from '@superset-ui/core'; +import { Button, Card, Flex, Form, Input } from 'src/components'; +import { Icons } from 'src/components/Icons'; +import Typography from 'src/components/Typography'; Review Comment: should be imported from `src/components` ########## superset-frontend/src/pages/Login/index.tsx: ########## @@ -0,0 +1,166 @@ +/** + * 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 { css } from '@emotion/react'; +import { SupersetClient, styled, t } from '@superset-ui/core'; +import { Button, Card, Flex, Form, Input } from 'src/components'; Review Comment: ```suggestion import { Button, Card, Flex, Form, Input, Typography } from 'src/components'; ``` ########## superset-frontend/src/pages/Login/index.tsx: ########## @@ -0,0 +1,166 @@ +/** + * 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 { css } from '@emotion/react'; +import { SupersetClient, styled, t } from '@superset-ui/core'; +import { Button, Card, Flex, Form, Input } from 'src/components'; +import { Icons } from 'src/components/Icons'; +import Typography from 'src/components/Typography'; +import { useState } from 'react'; +import getBootstrapData from 'src/utils/getBootstrapData'; + +type LoginType = { + username: string; + password: string; +}; + +type OauthProvider = { + name: string; + icon: string; +}; + +interface LoginForm { + username: string; + password: string; +} + +enum AuthType { + AuthDB = 1, + AuthLDAP, + AuthRemoteUser, + AuthOauth, + AuthOID, +} + +const LoginContainer = styled(Flex)` + width: 100%; +`; + +const providerIcons: Record<string, React.ReactNode> = { + 'fa-google': <Icons.GoogleOutlined />, + 'fa-facebook': <Icons.FacebookOutlined />, +}; + +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 oauthProviders: OauthProvider[] = + bootstrapData.common.conf.OAUTH_PROVIDERS; + + const onFinish = (values: LoginType) => { + setLoading(true); + SupersetClient.postForm('/login/', values, '').finally(() => { + setLoading(false); + }); + }; + + return ( + <LoginContainer justify="center"> + <StyledCard title={t('Sign in')} padded variant="borderless"> + {authType === AuthType.AuthOauth && ( + <Flex justify="center" vertical gap="middle"> + <Form + layout="vertical" + requiredMark="optional" + form={form} + onFinish={onFinish} + > + {oauthProviders.map(provider => ( + <Form.Item<LoginType>> + <Button + block + type="primary" + htmlType="submit" + loading={loading} + icon={providerIcons[provider.icon]} + > + {t('Sign in with')} {provider.name} + </Button> + </Form.Item> + ))} + </Form> + </Flex> + )} + {authType === AuthType.AuthDB && ( + <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<LoginType> + label={<StyledLabel>{t('Username:')}</StyledLabel>} + name="username" + rules={[ + { required: true, message: t('Please enter your username') }, + ]} + > + <Input prefix={<Icons.UserOutlined size={1} />} /> Review Comment: Should it be one of these: 'xs', 's', 'm', 'l', 'xl', 'xxl'? -- 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]
