Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dinky
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangpeng
dinky
Commits
ed0e0485
Unverified
Commit
ed0e0485
authored
May 07, 2023
by
gaoyan
Committed by
GitHub
May 07, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add error show modal (#1948)
parent
21c1dec9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
207 additions
and
13 deletions
+207
-13
index.tsx
dinky-web/src/components/Modal/ErrorModalShow/index.tsx
+105
-0
global.ts
dinky-web/src/locales/en-US/global.ts
+4
-0
global.ts
dinky-web/src/locales/zh-CN/global.ts
+4
-0
messages.tsx
dinky-web/src/utils/messages.tsx
+45
-13
modals.tsx
dinky-web/src/utils/modals.tsx
+49
-0
No files found.
dinky-web/src/components/Modal/ErrorModalShow/index.tsx
0 → 100644
View file @
ed0e0485
/*
* 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
React
,
{
useState
}
from
'react'
;
import
{
Button
,
Modal
,
ModalFuncProps
,
Typography
}
from
'antd'
;
import
CodeShow
,
{
CodeShowFormProps
}
from
"@/components/CustomEditor/CodeShow"
;
import
{
l
}
from
"@/utils/intl"
;
import
{
MonacoEditorOptions
}
from
"@/types/Public/data"
;
const
{
Paragraph
}
=
Typography
;
/**
* In this interface, we define the props for the ShowModal component, which extends the ModalFuncProps interface. Here are the details of the props:
*
* codeShowProps (optional): An object containing properties for configuring the code editor that displays in the modal.
* This prop is optional, so it's marked with the ? character.
* content: The content to display in the modal. This prop is required and doesn't have a default value.
* */
export
interface
ShowModalProps
extends
ModalFuncProps
{
/** Properties for configuring the code editor that displays in the modal. */
codeShowProps
?:
CodeShowFormProps
;
/** The content to display in the code editor. */
content
:
string
;
}
const
ErrorShowModal
=
(
props
:
ShowModalProps
)
=>
{
const
{
/** The content of the code editor. */
content
=
"no code to show"
,
/** The width of the Modal. */
width
=
"80vh"
,
/** Control the Modal show or close */
open
=
true
,
/** The title of the Modal.*/
title
=
l
(
'global.error'
),
/** Default disable close icon at top right, it's Not needed */
closable
=
false
,
/**
* The properties of the code editor, including its default options.
*/
codeShowProps
=
{
/** Whether line numbers should be shown in the code editor. Default is "off". */
lineNumbers
:
"off"
,
/** The height of the code editor. */
height
:
"50vh"
,
/**
* The options to configure the Monaco Editor instance. The default options are specified
* in a separate object named MonacoEditorOptions, and the minimap is disabled by default.
*/
options
:
{
...
MonacoEditorOptions
,
// set default options
minimap
:
{
enabled
:
false
}
},
},
}
=
props
;
const
[
showModal
,
setShowModal
]
=
useState
<
boolean
>
(
open
);
return
(
<
Modal
{
...
props
}
width=
{
width
}
open=
{
showModal
}
title=
{
title
}
closable=
{
closable
}
footer=
{
<
Button
type=
"primary"
onClick=
{
()
=>
setShowModal
(
false
)
}
>
{
l
(
'global.notifaction.iknow'
)
}
</
Button
>
}
>
<
Paragraph
ellipsis=
{
{
rows
:
1
,
expandable
:
false
}
}
>
<
blockquote
>
{
content
}
</
blockquote
>
</
Paragraph
>
<
CodeShow
{
...
codeShowProps
}
code=
{
content
}
/>
</
Modal
>
);
};
export
default
ErrorShowModal
;
dinky-web/src/locales/en-US/global.ts
View file @
ed0e0485
...
...
@@ -147,4 +147,8 @@ export default {
'global.error'
:
'Error'
,
'global.warning'
:
'Warning'
,
'global.success'
:
'Success'
,
'global.notifaction.iknow'
:
'I understand'
,
'global.notifaction.full-error'
:
'Complete error message'
,
};
dinky-web/src/locales/zh-CN/global.ts
View file @
ed0e0485
...
...
@@ -142,4 +142,8 @@ export default {
'global.error'
:
'错误'
,
'global.warning'
:
'警告'
,
'global.success'
:
'成功'
,
'global.notifaction.iknow'
:
'我知道了'
,
'global.notifaction.full-error'
:
'完整错误信息'
,
};
dinky-web/src/utils/messages.ts
→
dinky-web/src/utils/messages.ts
x
View file @
ed0e0485
...
...
@@ -16,9 +16,13 @@
*
*/
import
{
notification
,
message
,
App
}
from
"antd"
import
{
notification
,
message
,
Button
}
from
"antd"
import
{
l
}
from
"@/utils/intl"
;
import
{
Typography
}
from
'antd'
;
import
{
InfoCircleOutlined
}
from
"@ant-design/icons"
;
import
{
ErrorModelWithCode
}
from
"@/utils/modals"
;
const
{
Paragraph
}
=
Typography
;
/**
* default params
*/
...
...
@@ -29,18 +33,46 @@ const AsyncDuration = 0.5
// ================================ About Notification Component ================================
/**
* Error handler message
* @param message
* @param description
* @param duration
* @param placement
* @constructor
*/
export
const
ErrorNotification
=
(
description
:
string
,
message
=
l
(
'global.error'
),
duration
=
defaultDuration
)
=>
notification
.
error
({
message
,
description
,
duration
,
})
* A function that displays an error notification with a short message and an option to view the full error message in a modal.
*
* @param description The short error message to display in the notification.
* @param message The title of the notification. This parameter is optional, and if no value is provided, it defaults to a string.
* @param duration The duration (in milliseconds) that the notification should be displayed for.
* This parameter is optional, and if no value is provided, it defaults to a default duration.
*/
export
const
ErrorNotification
=
(
description
:
string
,
message
=
l
(
'global.error'
),
duration
=
defaultDuration
)
=>
{
/** The title of the notification, with an icon and the provided message. */
const
title
=
(
<
div
style=
{
{
display
:
'flex'
}
}
>
<
InfoCircleOutlined
style=
{
{
marginRight
:
10
,
color
:
"red"
}
}
/>
<
b
>
{
message
}
</
b
>
</
div
>
)
/**
* A button that is displayed in the notification
* if the error message is longer than 40 characters, click it will create a Modal to show more information detail
*/
const
moreBtn
=
description
.
length
>
40
?
(
<
Button
type=
"primary"
danger
onClick=
{
()
=>
ErrorModelWithCode
(
title
,
description
)
}
>
{
l
(
'global.notifaction.full-error'
)
}
</
Button
>
)
:
(<></>);
/** Display the notification. */
notification
.
open
({
/** The title of the notification. */
message
:
title
,
/**
* The short error message to display in the notification.
* if the error message is longer than 40 characters,Parts beyond the length are hidden
*/
description
:
(<
Paragraph
ellipsis=
{
{
rows
:
2
}
}
>
{
description
}
</
Paragraph
>),
duration
:
duration
,
btn
:
moreBtn
,
})
}
/**
* Success handler message
...
...
dinky-web/src/utils/modals.tsx
0 → 100644
View file @
ed0e0485
/*
* 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.
*
*/
// ================================ About Modal Compents ================================
import
{
l
}
from
"@/utils/intl"
;
import
React
from
"react"
;
import
ErrorShowModal
from
"@/components/Modal/ErrorModalShow"
;
import
{
createRoot
}
from
"react-dom/client"
;
/**
* A function that displays a modal containing an error message in code editor.
*
* @param title The title of the modal.
* @param content The content to display in the modal.
*/
export
const
ErrorModelWithCode
=
(
title
:
any
=
l
(
'global.error'
),
content
:
string
)
=>
{
/** Create a new div element to mount the modal. */
const
modalRoot
=
document
.
createElement
(
'div'
);
/** Add the div element to the body of the document. */
document
.
body
.
appendChild
(
modalRoot
);
const
root
=
createRoot
(
modalRoot
);
root
.
render
(
<
ErrorShowModal
/** Function that runs after the modal is closed, to unmount the component and remove the modal from the DOM. */
afterClose=
{
()
=>
root
.
unmount
()
}
title=
{
title
}
content=
{
content
}
/>
)
}
Write
Preview
Markdown
is supported
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