Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
imghost
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Janne Mareike Koschinski
imghost
Commits
cd5c35f9
Verified
Commit
cd5c35f9
authored
3 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Implement error handling
parent
25bfa7ff
Branches
Branches containing commit
No related tags found
1 merge request
!1
Replace entire project structure
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
ui/src/components/ErrorAlert.tsx
+18
-0
18 additions, 0 deletions
ui/src/components/ErrorAlert.tsx
ui/src/components/ErrorContext.tsx
+42
-0
42 additions, 0 deletions
ui/src/components/ErrorContext.tsx
ui/src/components/UploadView.tsx
+11
-3
11 additions, 3 deletions
ui/src/components/UploadView.tsx
with
71 additions
and
3 deletions
ui/src/components/ErrorAlert.tsx
0 → 100644
+
18
−
0
View file @
cd5c35f9
import
{
Paper
}
from
"
@material-ui/core
"
;
export
interface
ErrorAlertProps
{
severity
:
string
,
error
:
unknown
,
}
export
function
ErrorAlert
({
severity
,
error
}:
ErrorAlertProps
)
{
if
(
!
error
)
{
return
null
;
}
return
(
<
Paper
variant
=
"outlined"
color
=
{
severity
}
>
<
strong
>
Error
</
strong
>
:
{
""
+
error
}
</
Paper
>
)
}
This diff is collapsed.
Click to expand it.
ui/src/components/ErrorContext.tsx
0 → 100644
+
42
−
0
View file @
cd5c35f9
import
{
createContext
,
FC
,
FunctionComponent
,
PropsWithChildren
,
useCallback
,
useContext
,
useState
}
from
"
react
"
;
import
{
createPortal
}
from
"
react-dom
"
;
type
ChildrenComponent
=
FunctionComponent
<
PropsWithChildren
<
{}
>>
;
const
ErrorContext
=
createContext
<
ChildrenComponent
|
null
>
(
null
);
export
function
useErrorDisplay
():
[
FC
,
ChildrenComponent
]
{
const
[
ref
,
setRef
]
=
useState
<
HTMLDivElement
|
null
>
(
null
);
const
errorDisplay
=
useCallback
(
()
=>
(
<
div
ref
=
{
setRef
}
/>
),
[]
);
const
errorRenderer
:
ChildrenComponent
=
useCallback
(
({
children
}:
PropsWithChildren
<
{}
>
)
=>
ref
&&
createPortal
(
children
,
ref
),
[
ref
]
);
const
errorWrapper
=
useCallback
(
({
children
}:
PropsWithChildren
<
{}
>
)
=>
(
<
ErrorContext
.
Provider
value
=
{
errorRenderer
}
>
{
children
}
</
ErrorContext
.
Provider
>
),
[
errorRenderer
]
);
return
[
errorDisplay
,
errorWrapper
];
}
export
const
ErrorPortal
:
ChildrenComponent
=
(
props
:
PropsWithChildren
<
{}
>
)
=>
{
const
errorRenderer
=
useContext
(
ErrorContext
);
if
(
!
errorRenderer
)
{
return
null
;
}
return
errorRenderer
(
props
);
}
This diff is collapsed.
Click to expand it.
ui/src/components/UploadView.tsx
+
11
−
3
View file @
cd5c35f9
import
{
useUploadImage
}
from
"
../api/useUploadImage
"
;
import
{
ErrorPortal
}
from
"
./ErrorContext
"
;
import
{
ErrorAlert
}
from
"
./ErrorAlert
"
;
import
{
LinearProgress
}
from
"
@material-ui/core
"
;
export
default
function
UploadView
()
{
const
{
mutate
:
upload
,
error
:
uploadError
,
isLoading
:
upload
Loading
}
=
useUploadImage
();
const
{
mutate
:
upload
,
error
,
is
Loading
}
=
useUploadImage
();
return
(
<
div
>
<
pre
>
Error:
{
JSON
.
stringify
(
uploadError
,
null
,
2
)
}
</
pre
>
<
pre
>
Loading:
{
JSON
.
stringify
(
uploadLoading
,
null
,
2
)
}
</
pre
>
{
isLoading
&&
(
<
LinearProgress
/>
)
}
<
ErrorPortal
>
<
ErrorAlert
severity
=
"error"
error
=
{
error
}
/>
</
ErrorPortal
>
<
input
type
=
"file"
disabled
=
{
isLoading
}
onChange
=
{
async
({
target
})
=>
{
if
(
target
.
files
)
{
await
upload
(
target
.
files
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment