Skip to content

Commit

Permalink
feat: discardAsPrimary option in ModalDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon committed Jan 30, 2025
1 parent f14f212 commit f259d95
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
21 changes: 16 additions & 5 deletions packages/webui/src/client/lib/ModalDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface IModalDialogAttributes {
warning?: boolean
actions?: ModalAction[]
className?: string
discardAsPrimary?: boolean
}
interface ModalInput {
type: EditAttributeType
Expand Down Expand Up @@ -56,6 +57,7 @@ export function ModalDialog({
onDiscard,
onSecondary,
secondaryText,
discardAsPrimary,
}: React.PropsWithChildren<IModalDialogAttributes>): JSX.Element | null {
const { t } = useTranslation()
const inputResult = useRef<ModalInputResult>(
Expand Down Expand Up @@ -114,7 +116,7 @@ export function ModalDialog({
e.stopPropagation()

if (isAcceptKey(e.code)) {
handleAccept(e)
discardAsPrimary ? handleDiscard(e) : handleAccept(e)
} else if (isDismissKey(e.code)) {
handleDiscard(e)
}
Expand Down Expand Up @@ -213,7 +215,13 @@ export function ModalDialog({
>
{secondaryText && (
<button
className="btn btn-secondary cancel-btn"
className={ClassNames(
'btn',
discardAsPrimary ? 'btn-primary' : 'btn-secondary',
'discard-btn',
{ 'btn-warn': discardAsPrimary && warning }
)}
autoFocus={discardAsPrimary}
onClick={handleSecondary}
onKeyDown={preventClickOnEnter}
onKeyUp={emulateClick}
Expand Down Expand Up @@ -244,11 +252,11 @@ export function ModalDialog({
})
)}
<button
className={ClassNames('btn btn-primary', {
className={ClassNames('btn', !discardAsPrimary ? 'btn-primary' : 'btn-secondary', {
right: secondaryText !== undefined,
'btn-warn': warning,
'btn-warn': !discardAsPrimary && warning,
})}
autoFocus
autoFocus={!discardAsPrimary}
onClick={handleAccept}
onKeyDown={preventClickOnEnter}
onKeyUp={emulateClick}
Expand Down Expand Up @@ -288,6 +296,8 @@ export interface ModalDialogQueueItem {
actions?: ModalAction[]
/** Is a critical decition/information */
warning?: boolean
/** Discard as primary */
discardAsPrimary?: boolean
}
interface IModalDialogGlobalContainerProps {}
interface IModalDialogGlobalContainerState {
Expand Down Expand Up @@ -386,6 +396,7 @@ class ModalDialogGlobalContainer0 extends React.Component<
actions={actions}
show={true}
warning={onQueue.warning}
discardAsPrimary={onQueue.discardAsPrimary}
>
{_.isString(onQueue.message) ? this.renderString(onQueue.message) : onQueue.message}
</ModalDialog>
Expand Down
2 changes: 1 addition & 1 deletion packages/webui/src/client/styles/modalDialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
display: flex;
justify-content: space-between;

.cancel-btn {
.discard-btn {
margin-right: 2rem;
margin-left: 0px;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/webui/src/client/ui/RundownView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ const RundownHeader = withTranslation()(
warning: true,
yes: t('Activate "On Air"'),
no: t('Cancel'),
discardAsPrimary: true,
onDiscard: () => {
// Do nothing
},
actions: [
{
label: t('Activate "Rehearsal"'),
Expand Down

0 comments on commit f259d95

Please sign in to comment.