-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from skbkontur/semke/redesign-modals
Semke/redesign modals
- Loading branch information
Showing
19 changed files
with
307 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,28 @@ | ||
import { CopyIcon16Regular } from "@skbkontur/icons/CopyIcon16Regular"; | ||
import { Link, Toast } from "@skbkontur/react-ui"; | ||
import copy from "copy-to-clipboard"; | ||
import React, { PropsWithChildren } from "react"; | ||
|
||
import { StringUtils } from "../Domain/Utils/StringUtils"; | ||
|
||
export class CopyToClipboardToast { | ||
public static copyText(value: string): void { | ||
copy(value); | ||
navigator.clipboard.writeText(value); | ||
Toast.push("Скопировано в буфер"); | ||
} | ||
} | ||
|
||
export class AllowCopyToClipboard extends React.Component<PropsWithChildren<{}>> { | ||
public children: null | HTMLSpanElement = null; | ||
export const AllowCopyToClipboard = ({ children }: PropsWithChildren<{}>): React.JSX.Element => { | ||
const childrenRef = React.useRef<HTMLSpanElement | null>(null); | ||
|
||
public render(): React.ReactElement { | ||
return ( | ||
<span> | ||
<span ref={x => (this.children = x)}>{this.props.children}</span>{" "} | ||
<Link icon={<CopyIcon16Regular />} onClick={this.handleCopy} /> | ||
</span> | ||
); | ||
} | ||
|
||
private readonly handleCopy = () => { | ||
if (this.children && !StringUtils.isNullOrWhitespace(this.children.innerText)) { | ||
CopyToClipboardToast.copyText(this.children.innerText); | ||
const handleCopy = (): void => { | ||
if (childrenRef.current && !StringUtils.isNullOrWhitespace(childrenRef.current.innerText)) { | ||
CopyToClipboardToast.copyText(childrenRef.current.innerText); | ||
} | ||
}; | ||
} | ||
return ( | ||
<span> | ||
<span ref={childrenRef}>{children}</span> | ||
<Link icon={<CopyIcon16Regular />} onClick={handleCopy} /> | ||
</span> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 12 additions & 141 deletions
153
db-viewer-ui/src/Components/ErrorHandling/ErrorHandlingContainerModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,152 +1,23 @@ | ||
import { CopyIcon16Regular } from "@skbkontur/icons/CopyIcon16Regular"; | ||
import { Fit, RowStack } from "@skbkontur/react-stack-layout"; | ||
import { Button, Link, Modal, ThemeContext } from "@skbkontur/react-ui"; | ||
import { Theme } from "@skbkontur/react-ui/lib/theming/Theme"; | ||
import React from "react"; | ||
|
||
import { CopyToClipboardToast } from "../AllowCopyToClipboard"; | ||
|
||
import { jsStyles } from "./ErrorHandlingContainer.styles"; | ||
|
||
interface ErrorHandlingContainerModalState { | ||
showStack: boolean; | ||
} | ||
import { ErrorMiniModal } from "./ErrorMiniModal"; | ||
import { ErrorModal } from "./ErrorModal"; | ||
import { useDeveloperMode } from "./useDeveloperMode"; | ||
|
||
interface ErrorHandlingContainerModalProps { | ||
canClose: boolean; | ||
onClose: () => void; | ||
message: string; | ||
stack: Nullable<string>; | ||
serverStack: Nullable<string>; | ||
} | ||
|
||
export class ErrorHandlingContainerModal extends React.Component< | ||
ErrorHandlingContainerModalProps, | ||
ErrorHandlingContainerModalState | ||
> { | ||
public state: ErrorHandlingContainerModalState = { showStack: false }; | ||
private theme!: Theme; | ||
|
||
public componentDidMount(): void { | ||
window.addEventListener("keypress", this.handleKeyPress); | ||
} | ||
|
||
public componentWillUnmount(): void { | ||
window.removeEventListener("keypress", this.handleKeyPress); | ||
} | ||
|
||
private handleKeyPress = (e: KeyboardEvent) => { | ||
if (e.key === "h") { | ||
this.setState({ showStack: true }); | ||
} | ||
}; | ||
|
||
private handleCopyStack = () => { | ||
const { stack } = this.props; | ||
this.copyData(stack); | ||
}; | ||
|
||
private handleCopyServerStack = () => { | ||
const { serverStack } = this.props; | ||
this.copyData(serverStack); | ||
}; | ||
|
||
public render(): React.ReactElement { | ||
return ( | ||
<ThemeContext.Consumer> | ||
{theme => { | ||
this.theme = theme; | ||
return this.renderMain(); | ||
}} | ||
</ThemeContext.Consumer> | ||
); | ||
} | ||
|
||
private renderMain(): React.ReactElement { | ||
const { canClose, message, onClose, serverStack, stack } = this.props; | ||
|
||
const { showStack } = this.state; | ||
onClose(): void; | ||
} | ||
|
||
return ( | ||
<Modal data-tid="ErrorHandlingContainerModal" onClose={canClose ? onClose : undefined} noClose={!canClose}> | ||
<Modal.Header data-tid="Header"> | ||
<span className={jsStyles.modalText(this.theme)}>Произошла непредвиденная ошибка</span> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<div className={jsStyles.modalText(this.theme)}> | ||
<div className={jsStyles.userMessage()}> | ||
<div data-tid="CallToActionInErrorMessage"> | ||
<div className={jsStyles.content()}> | ||
<p>Попробуйте повторить запрос или обновить страницу через некоторое время.</p> | ||
</div> | ||
</div> | ||
</div> | ||
{showStack && ( | ||
<div> | ||
<hr /> | ||
<div className={jsStyles.errorMessageWrap()} data-tid="ErrorMessage"> | ||
{message} | ||
</div> | ||
</div> | ||
)} | ||
{showStack && ( | ||
<div className={jsStyles.stackTraces()}> | ||
{stack && ( | ||
<RowStack baseline block gap={2}> | ||
<Fit> | ||
<h4 className={jsStyles.header()}>Client stack trace</h4> | ||
</Fit> | ||
<Fit> | ||
<Button icon={<CopyIcon16Regular />} onClick={this.handleCopyStack}> | ||
Скопировать | ||
</Button> | ||
</Fit> | ||
</RowStack> | ||
)} | ||
{stack && ( | ||
<div className={jsStyles.stackTraceContainer()}> | ||
<pre data-tid="ClientErrorStack" className={jsStyles.stackTrace(this.theme)}> | ||
{stack} | ||
</pre> | ||
</div> | ||
)} | ||
{serverStack && ( | ||
<RowStack baseline block gap={2}> | ||
<Fit> | ||
<h4 className={jsStyles.header()}>Server stack trace</h4> | ||
</Fit> | ||
<Fit> | ||
<Link icon={<CopyIcon16Regular />} onClick={this.handleCopyServerStack}> | ||
Скопировать | ||
</Link> | ||
</Fit> | ||
</RowStack> | ||
)} | ||
{serverStack && ( | ||
<div className={jsStyles.stackTraceContainer()}> | ||
<pre data-tid="ServerErrorStack" className={jsStyles.stackTrace(this.theme)}> | ||
{serverStack} | ||
</pre> | ||
</div> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
</Modal.Body> | ||
{canClose && ( | ||
<Modal.Footer panel> | ||
<Button onClick={onClose} data-tid="CloseButton"> | ||
Закрыть | ||
</Button> | ||
</Modal.Footer> | ||
)} | ||
</Modal> | ||
); | ||
} | ||
export const ErrorHandlingContainerModal = ({ | ||
onClose, | ||
...restProps | ||
}: ErrorHandlingContainerModalProps): React.JSX.Element => { | ||
const showStack = useDeveloperMode(); | ||
|
||
private copyData(stack: Nullable<string>) { | ||
if (stack != null) { | ||
CopyToClipboardToast.copyText(stack); | ||
} | ||
} | ||
} | ||
return showStack ? <ErrorModal {...restProps} onClose={onClose} /> : <ErrorMiniModal onClose={onClose} />; | ||
}; |
Oops, something went wrong.