Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard navigation, accessibility, miscellaneous fixes #65

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/components/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Header } from '../stories/Header/Header'
import { useNavigate, useLocation } from 'react-router-dom'
import { useNavigate, useLocation, Location } from 'react-router-dom'

function Home() {
const navigate = useNavigate()
const location: any = useLocation()
const location: Location | any = useLocation()

async function handleOnClick() {
navigate('/login')
Expand Down
184 changes: 101 additions & 83 deletions src/components/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function Login() {
size="medium"
kind="primary"
onChange={(event: any) => {
setAccountName(event.target.value)
setAccountName(event?.target?.value)
}}
/>
)
Expand All @@ -52,7 +52,7 @@ function Login() {
label="Sign In"
type="submit"
disabled={
passwordEntered.length == 0 || userNameEntered.length == 0
passwordEntered.length === 0 || userNameEntered.length === 0
}
onClick={() => {
authType.current = 'userpass'
Expand All @@ -71,7 +71,7 @@ function Login() {
})
}

const makeUserPassAuthFetch = (): Promise<any> => {
const makeUserPassAuthFetch = (): Promise<unknown> => {
let headers
if (accountName.length === 0) {
headers = {
Expand All @@ -95,77 +95,91 @@ function Login() {
const userPassAuth = () => {
makeUserPassAuthFetch()
.then((response: any) => {
if (response.status === 200) {
const rucioAuthToken =
response?.headers.get('X-Rucio-Auth-Token')
const rucioAccount = response?.headers.get(
'X-Rucio-Auth-Account',
)
setAccountName(rucioAccount)
localStorage.setItem('X-Rucio-Auth-Token', rucioAuthToken)
loginNavigateHome(rucioAccount)
} else if (response.status === 206) {
const has_accounts_header = response.headers.has(
'X-Rucio-Auth-Accounts',
)
if (!has_accounts_header) {
throw new Error(
'No X-Rucio-Auth-Accounts header found in response',
if (response) {
if (response.status === 200) {
const rucioAuthToken =
response?.headers.get('X-Rucio-Auth-Token')
const rucioAccount = response?.headers.get(
'X-Rucio-Auth-Account',
)
}
const accounts = response?.headers
.get('X-Rucio-Auth-Accounts')
.split(',')
showModal({
title: 'Select Rucio Account',
body: (
<Form
title=""
subtitle="We detected multiple accounts for
setAccountName(rucioAccount)
localStorage.setItem(
'X-Rucio-Auth-Token',
rucioAuthToken,
)
loginNavigateHome(rucioAccount)
} else if (response.status === 206) {
const has_accounts_header = response.headers.has(
'X-Rucio-Auth-Accounts',
)
if (!has_accounts_header) {
throw new Error(
'No X-Rucio-Auth-Accounts header found in response',
)
}
const accounts = response?.headers
.get('X-Rucio-Auth-Accounts')
.split(',')
showModal({
title: 'Select Rucio Account',
body: (
<Form
title=""
subtitle="We detected multiple accounts for
this user, please select the desired
one."
onSubmit={(event: any) => {
showModal({ active: false })
}}
>
{accounts.map((element: any, index: number) => (
<label key={element}>
<input
type="radio"
id={element}
value={element}
name="radio-group"
defaultChecked={false}
onChange={(event: any) => {
setAccountName(
event.target.value,
)
}}
/>
&nbsp;{element}
</label>
))}
<Button
size="large"
kind="primary"
show="block"
label="Select Account"
type="submit"
/>
</Form>
),
})
} else if (response.status === 401) {
onSubmit={() => {
showModal({ active: false })
}}
>
{accounts.map((element: string) => (
<label key={element}>
<input
type="radio"
id={element}
value={element}
name="radio-group"
defaultChecked={false}
onChange={(event: any) => {
setAccountName(
event.target.value,
)
}}
/>
&nbsp;{element}
</label>
))}
<Button
size="large"
kind="primary"
show="block"
label="Select Account"
type="submit"
/>
</Form>
),
})
} else if (response.status === 401) {
showAlert({
message: 'Invalid credentials',
variant: 'error',
})
} else {
showAlert({
message: 'Login failed.',
variant: 'error',
})
throw new Error('Login failed')
}
} else {
showAlert({
message: 'Invalid credentials',
message: 'Unable to fetch response from server.',
variant: 'error',
})
} else {
throw new Error('Login failed')
}
return response
nimishbongale marked this conversation as resolved.
Show resolved Hide resolved
})
.catch((error: any) => {
.catch((error: Error) => {
showAlert({
message: 'Unable to log in, please try again.',
variant: 'error',
Expand All @@ -176,29 +190,29 @@ function Login() {

const OAuth = () => {
getData('/auth/oidc')
.then((data: any) => {
.then(() => {
sessionStorage.setItem(
'X-Rucio-Auth-Token',
'oidc_auth_sample_token',
)
navigate('/login')
})
.catch((error: any) => {
.catch((error: Error) => {
console.error(error)
navigate('/login')
})
}

const x509Auth = () => {
getData('/auth/x509')
.then((data: any) => {
.then(() => {
sessionStorage.setItem(
'X-Rucio-Auth-Token',
'x509_sample_token',
)
navigate('/login')
})
.catch((error: any) => {
.catch((error: Error) => {
console.error(error)
navigate('/login')
})
Expand Down Expand Up @@ -292,6 +306,7 @@ function Login() {
placeholder="Enter Username"
kind="info"
size="medium"
focusByDefault
onChange={(event: any) => {
setUserNameEntered(
event.target.value,
Expand All @@ -315,21 +330,24 @@ function Login() {
{AccountInput}
{SignInButton}
</>
) : (
<>
<Button
size="large"
kind="outline"
show="block"
label="Username / Password"
onClick={() => {
setUserpassEnabled(true)
}}
/>
{AccountInput}
</>
)}
) : null}
</Form>
<br></br>
{!userpassEnabled ? (
<>
<Button
size="large"
kind="outline"
show="block"
label="Username / Password"
onClick={(event: any) => {
event.preventDefault()
setUserpassEnabled(true)
}}
/>
{AccountInput}
</>
) : null}
</div>
</div>
</div>
Expand Down
8 changes: 7 additions & 1 deletion src/stories/Alert/Alert.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactElement } from 'react'
import { ReactElement, useEffect } from 'react'
import './alert.scss'

export interface AlertProps {
Expand Down Expand Up @@ -55,6 +55,12 @@ export const Alert = ({
),
...props
}: AlertProps) => {
useEffect(() => {
window.scrollTo({
top: 0,
behavior: 'smooth',
})
})
return (
<>
{open ? (
Expand Down
2 changes: 1 addition & 1 deletion src/stories/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface ButtonProps {
type?: 'button' | 'submit' | 'reset' | undefined
selected?: boolean
disabled?: boolean
onClick?: (args: any) => void | undefined
onClick?: (args: unknown) => void | undefined
}

export const Button = ({
Expand Down
15 changes: 14 additions & 1 deletion src/stories/Form/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import './form.scss'
import { Button } from '../Button/Button'
import { useEffect } from 'react'

interface FormProps {
title?: string
subtitle?: string
children?: any
onSubmit?: (args: any) => void
onSubmit?: (args: unknown) => void
}

export const Form = ({
Expand Down Expand Up @@ -44,6 +45,18 @@ export const Form = ({
},
...props
}: FormProps) => {
useEffect(() => {
const formElements: any = document.getElementsByClassName('rucio-form')
Array.from(formElements).forEach((formElement: any) => {
formElement.onkeydown = () => {
const keyboardEvent = window?.event as KeyboardEvent
if (keyboardEvent?.key === 'Enter') {
onSubmit(keyboardEvent)
}
}
})
})

return (
<form className="rucio-form" onSubmit={onSubmit}>
<h1 className="title">{title}</h1>
Expand Down
2 changes: 1 addition & 1 deletion src/stories/Page/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type User = {
children?: any
}

export const Page: React.VFC = (children: any) => {
export const Page: React.VFC = () => {
nimishbongale marked this conversation as resolved.
Show resolved Hide resolved
const [user, setUser] = React.useState<User>()

return (
Expand Down
5 changes: 4 additions & 1 deletion src/stories/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ interface TextInputProps {
show?: 'danger' | 'warning' | 'success' | 'rounded'
size?: 'small' | 'medium' | 'large'
value?: string
onChange?: (args: any) => void
focusByDefault?: boolean
onChange?: (args: unknown) => void
}

export const TextInput = ({
Expand All @@ -21,6 +22,7 @@ export const TextInput = ({
kind = 'normal',
show,
value,
focusByDefault = false,
onChange,
...props
}: TextInputProps) => {
Expand All @@ -34,6 +36,7 @@ export const TextInput = ({
className={`rucio-textinput ${kind} ${size} ${show}`}
onChange={onChange}
value={value}
autoFocus={focusByDefault}
/>
</label>
)
Expand Down
Loading