Skip to content

Commit a68cec5

Browse files
committed
Add a non_dismissable option to the AutoClosingModal component and enable it for checkpoint restoration success messages
- when showing 'auto closing modal' from checkpoint restoration, make it non-dismissable (on_close is not provided) - when showing 'auto closing modal' from checkpoint restoration, make it non-dismissable (on_close is not provided) - rename 'disable_close' to 'non-dismissable' - on `packages/ui/src/components/editor/panel/modals/AutoClosingModal/AutoClosingModal.tsx`make on_close required, add optinal prop "non_dismissable". When true, remove footer button and on background click. Just close as the duration finishes.
1 parent 028ffd7 commit a68cec5

5 files changed

Lines changed: 22 additions & 13 deletions

File tree

‎apps/editor/src/commands/checkpoints-command/actions/restore-checkpoint.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,8 @@ export const restore_checkpoint = async (params: {
549549
params.panel_provider.send_message({
550550
command: 'SHOW_AUTO_CLOSING_MODAL',
551551
title: message.slice(0, -1),
552-
type: 'success'
552+
type: 'success',
553+
non_dismissable: true
553554
})
554555
} else if (temp_checkpoint) {
555556
const action = await vscode.window.showInformationMessage(

‎apps/editor/src/views/panel/frontend/Panel.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,9 +866,8 @@ export const Panel = () => {
866866
title={auto_closing_modal_data.title}
867867
type={auto_closing_modal_data.type}
868868
duration={3000}
869-
on_close={() => {
870-
set_auto_closing_modal_data(undefined)
871-
}}
869+
on_close={() => set_auto_closing_modal_data(undefined)}
870+
non_dismissable={auto_closing_modal_data.non_dismissable}
872871
/>
873872
</div>
874873
)}

‎apps/editor/src/views/panel/frontend/hooks/use-modal-manager.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ export const use_modal_manager = () => {
2727
>({})
2828

2929
const [auto_closing_modal_data, set_auto_closing_modal_data] = useState<
30-
| { title: string; type: 'success' | 'warning' | 'error' | 'info' }
30+
| {
31+
title: string
32+
type: 'success' | 'warning' | 'error' | 'info'
33+
non_dismissable?: boolean
34+
}
3135
| undefined
3236
>()
3337

@@ -77,7 +81,8 @@ export const use_modal_manager = () => {
7781
} else if (message.command == 'SHOW_AUTO_CLOSING_MODAL') {
7882
set_auto_closing_modal_data({
7983
title: message.title,
80-
type: message.type
84+
type: message.type,
85+
non_dismissable: message.non_dismissable
8186
})
8287
} else if (message.command == 'SHOW_PREVIEW_ONGOING_MODAL') {
8388
set_is_preview_ongoing_modal_visible(true)

‎apps/editor/src/views/panel/types/messages.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,8 @@ export interface HideApiManagerProgressMessage extends BaseMessage {
878878
export interface ShowAutoClosingModalMessage extends BaseMessage {
879879
command: 'SHOW_AUTO_CLOSING_MODAL'
880880
title: string
881-
type: 'success' | 'warning' | 'error'
881+
type: 'success' | 'warning' | 'error' | 'info'
882+
non_dismissable?: boolean
882883
}
883884

884885
export interface UpdateFileInPreviewMessage extends BaseMessage {

‎packages/ui/src/components/editor/panel/modals/AutoClosingModal/AutoClosingModal.tsx‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ type Props = {
77
title: string
88
duration: number
99
type: ModalIconType
10-
on_close?: () => void
10+
on_close: () => void
11+
non_dismissable?: boolean
1112
}
1213

1314
export const AutoClosingModal: React.FC<Props> = (props) => {
@@ -16,7 +17,7 @@ export const AutoClosingModal: React.FC<Props> = (props) => {
1617
useEffect(() => {
1718
set_is_filling(true)
1819
const timeout = setTimeout(() => {
19-
props.on_close?.()
20+
props.on_close()
2021
}, props.duration)
2122

2223
return () => {
@@ -27,9 +28,9 @@ export const AutoClosingModal: React.FC<Props> = (props) => {
2728
return (
2829
<div
2930
onKeyDown={(e) => {
30-
if (e.key == 'Escape') {
31+
if (e.key == 'Escape' && !props.non_dismissable) {
3132
e.stopPropagation()
32-
props.on_close?.()
33+
props.on_close()
3334
}
3435
}}
3536
>
@@ -47,9 +48,11 @@ export const AutoClosingModal: React.FC<Props> = (props) => {
4748
/>
4849
</div>
4950
}
50-
on_background_click={props.on_close}
51+
on_background_click={
52+
!props.non_dismissable ? props.on_close : undefined
53+
}
5154
footer_slot={
52-
props.on_close ? (
55+
!props.non_dismissable ? (
5356
<Button on_click={props.on_close} is_focused={true}>
5457
Close
5558
</Button>

0 commit comments

Comments
 (0)