Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Headlamp
Commits
c6fa8aec
Commit
c6fa8aec
authored
4 years ago
by
René Dudfield
Browse files
Options
Download
Email Patches
Plain Diff
frontend: add src/components/account/Auth stories.
parent
21ce708b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/components/account/Auth.tsx
+69
-23
frontend/src/components/account/Auth.tsx
frontend/src/components/account/AuthToken.stories.tsx
+34
-0
frontend/src/components/account/AuthToken.stories.tsx
with
103 additions
and
23 deletions
+103
-23
frontend/src/components/account/Auth.tsx
+
69
-
23
View file @
c6fa8aec
...
...
@@ -19,7 +19,7 @@ interface ReactRouterLocationStateIface {
from
?:
Location
;
}
function
Auth
()
{
export
default
function
Auth
Token
()
{
const
history
=
useHistory
();
const
clusterConf
=
useClustersConf
();
const
[
token
,
setToken
]
=
React
.
useState
(
''
);
...
...
@@ -27,10 +27,14 @@ function Auth() {
const
clusters
=
useClustersConf
();
function
onAuthClicked
()
{
loginWithToken
(
token
).
then
(
code
=>
{
loginWithToken
(
token
).
then
(
(
code
)
=>
{
// If successful, redirect.
if
(
code
===
200
)
{
history
.
replace
(
generatePath
(
getClusterPrefixedPath
(),
{
cluster
:
getCluster
()
as
string
}));
history
.
replace
(
generatePath
(
getClusterPrefixedPath
(),
{
cluster
:
getCluster
()
as
string
,
})
);
}
else
{
setToken
(
''
);
setShowError
(
true
);
...
...
@@ -38,16 +42,60 @@ function Auth() {
});
}
return
(
<
PureAuthToken
onCancel
=
{
()
=>
history
.
replace
(
'
/
'
)
}
title
=
{
Object
.
keys
(
clusterConf
||
{}).
length
>
1
?
`Authentication:
${
getCluster
()}
`
:
'
Authentication
'
}
token
=
{
token
}
showError
=
{
showError
}
showActions
=
{
Object
.
keys
(
clusters
||
{}).
length
>
1
}
onChangeToken
=
{
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
setToken
(
event
.
target
.
value
)
}
onAuthClicked
=
{
onAuthClicked
}
onCloseError
=
{
()
=>
{
setShowError
(
false
);
}
}
/>
);
}
interface
clickCallbackType
{
(
event
:
React
.
MouseEvent
<
HTMLElement
>
):
void
;
}
interface
changeCallbackType
{
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
):
void
;
}
export
interface
PureAuthTokenProps
{
title
:
string
;
token
:
string
;
showActions
:
boolean
;
showError
:
boolean
;
onCancel
:
clickCallbackType
;
onChangeToken
:
changeCallbackType
;
onAuthClicked
:
clickCallbackType
;
onCloseError
:
(
event
:
React
.
SyntheticEvent
<
any
,
Event
>
,
reason
:
string
)
=>
void
;
}
export
function
PureAuthToken
({
title
,
token
,
showActions
,
showError
,
onCancel
,
onAuthClicked
,
onChangeToken
,
onCloseError
,
}:
PureAuthTokenProps
)
{
return
(
<
Box
>
<
ClusterDialog
useCover
disableEscapeKeyDown
disableBackdropClick
>
<
DialogTitle
id
=
"responsive-dialog-title"
>
{
Object
.
keys
(
clusterConf
||
{}).
length
>
1
?
`Authentication:
${
getCluster
()}
`
:
'
Authentication
'
}
</
DialogTitle
>
<
ClusterDialog
useCover
disableEscapeKeyDown
disableBackdropClick
>
<
DialogTitle
id
=
"responsive-dialog-title"
>
{
title
}
</
DialogTitle
>
<
DialogContent
>
<
DialogContentText
>
Please paste your authentication token.
...
...
@@ -59,19 +107,19 @@ function Auth() {
label
=
"ID token"
type
=
"password"
value
=
{
token
}
onChange
=
{
event
=>
setToken
(
event
.
target
.
value
)
}
onChange
=
{
onChangeToken
}
fullWidth
/>
</
DialogContent
>
<
DialogActions
>
{
Object
.
keys
(
clusters
||
{}).
length
>
1
&&
<>
<
Button
onClick
=
{
()
=>
history
.
replace
(
'
/
'
)
}
color
=
"primary"
>
Cancel
</
Button
>
<
div
style
=
{
{
flex
:
'
1 0 0
'
}
}
/>
</>
}
{
showActions
&&
(
<>
<
Button
onClick
=
{
onCancel
}
color
=
"primary"
>
Cancel
</
Button
>
<
div
style
=
{
{
flex
:
'
1 0 0
'
}
}
/>
</>
)
}
<
Button
onClick
=
{
onAuthClicked
}
color
=
"primary"
>
Authenticate
</
Button
>
...
...
@@ -84,7 +132,7 @@ function Auth() {
}
}
open
=
{
showError
}
autoHideDuration
=
{
5000
}
onClose
=
{
()
=>
{
setShowError
(
false
);
}
}
onClose
=
{
onCloseError
}
ContentProps
=
{
{
'
aria-describedby
'
:
'
message-id
'
,
}
}
...
...
@@ -112,5 +160,3 @@ async function loginWithToken(token: string) {
return
err
.
status
;
}
}
export
default
Auth
;
This diff is collapsed.
Click to expand it.
frontend/src/components/account/AuthToken.stories.tsx
0 → 100644
+
34
-
0
View file @
c6fa8aec
import
{
Meta
,
Story
}
from
'
@storybook/react/types-6-0
'
;
import
React
from
'
react
'
;
import
{
PureAuthToken
,
PureAuthTokenProps
}
from
'
./Auth
'
;
export
default
{
title
:
'
AuthToken
'
,
component
:
PureAuthToken
,
argTypes
:
{
onCancel
:
{
action
:
'
cancel clicked
'
},
onAuthClicked
:
{
action
:
'
auth clicked
'
},
onChangeToken
:
{
action
:
'
token changed
'
},
onCloseError
:
{
action
:
'
error closed
'
},
},
}
as
Meta
;
const
Template
:
Story
<
PureAuthTokenProps
>
=
(
args
)
=>
(
<
PureAuthToken
{
...
args
}
/>
);
export
const
ShowError
=
Template
.
bind
({});
ShowError
.
args
=
{
title
:
'
a title
'
,
token
:
'
a token
'
,
showError
:
true
,
showActions
:
false
,
};
export
const
ShowActions
=
Template
.
bind
({});
ShowActions
.
args
=
{
title
:
'
a title
'
,
token
:
'
a token
'
,
showError
:
false
,
showActions
:
true
,
};
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help