Skip to content

Commit f259d95

Browse files
committed
feat: discardAsPrimary option in ModalDialog
1 parent f14f212 commit f259d95

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

packages/webui/src/client/lib/ModalDialog.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ interface IModalDialogAttributes {
2727
warning?: boolean
2828
actions?: ModalAction[]
2929
className?: string
30+
discardAsPrimary?: boolean
3031
}
3132
interface ModalInput {
3233
type: EditAttributeType
@@ -56,6 +57,7 @@ export function ModalDialog({
5657
onDiscard,
5758
onSecondary,
5859
secondaryText,
60+
discardAsPrimary,
5961
}: React.PropsWithChildren<IModalDialogAttributes>): JSX.Element | null {
6062
const { t } = useTranslation()
6163
const inputResult = useRef<ModalInputResult>(
@@ -114,7 +116,7 @@ export function ModalDialog({
114116
e.stopPropagation()
115117

116118
if (isAcceptKey(e.code)) {
117-
handleAccept(e)
119+
discardAsPrimary ? handleDiscard(e) : handleAccept(e)
118120
} else if (isDismissKey(e.code)) {
119121
handleDiscard(e)
120122
}
@@ -213,7 +215,13 @@ export function ModalDialog({
213215
>
214216
{secondaryText && (
215217
<button
216-
className="btn btn-secondary cancel-btn"
218+
className={ClassNames(
219+
'btn',
220+
discardAsPrimary ? 'btn-primary' : 'btn-secondary',
221+
'discard-btn',
222+
{ 'btn-warn': discardAsPrimary && warning }
223+
)}
224+
autoFocus={discardAsPrimary}
217225
onClick={handleSecondary}
218226
onKeyDown={preventClickOnEnter}
219227
onKeyUp={emulateClick}
@@ -244,11 +252,11 @@ export function ModalDialog({
244252
})
245253
)}
246254
<button
247-
className={ClassNames('btn btn-primary', {
255+
className={ClassNames('btn', !discardAsPrimary ? 'btn-primary' : 'btn-secondary', {
248256
right: secondaryText !== undefined,
249-
'btn-warn': warning,
257+
'btn-warn': !discardAsPrimary && warning,
250258
})}
251-
autoFocus
259+
autoFocus={!discardAsPrimary}
252260
onClick={handleAccept}
253261
onKeyDown={preventClickOnEnter}
254262
onKeyUp={emulateClick}
@@ -288,6 +296,8 @@ export interface ModalDialogQueueItem {
288296
actions?: ModalAction[]
289297
/** Is a critical decition/information */
290298
warning?: boolean
299+
/** Discard as primary */
300+
discardAsPrimary?: boolean
291301
}
292302
interface IModalDialogGlobalContainerProps {}
293303
interface IModalDialogGlobalContainerState {
@@ -386,6 +396,7 @@ class ModalDialogGlobalContainer0 extends React.Component<
386396
actions={actions}
387397
show={true}
388398
warning={onQueue.warning}
399+
discardAsPrimary={onQueue.discardAsPrimary}
389400
>
390401
{_.isString(onQueue.message) ? this.renderString(onQueue.message) : onQueue.message}
391402
</ModalDialog>

packages/webui/src/client/styles/modalDialog.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
display: flex;
2424
justify-content: space-between;
2525

26-
.cancel-btn {
26+
.discard-btn {
2727
margin-right: 2rem;
2828
margin-left: 0px;
2929
}

packages/webui/src/client/ui/RundownView.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,10 @@ const RundownHeader = withTranslation()(
504504
warning: true,
505505
yes: t('Activate "On Air"'),
506506
no: t('Cancel'),
507+
discardAsPrimary: true,
508+
onDiscard: () => {
509+
// Do nothing
510+
},
507511
actions: [
508512
{
509513
label: t('Activate "Rehearsal"'),

0 commit comments

Comments
 (0)