Commit 00a4585c authored by ioedeveloper's avatar ioedeveloper

Expand props

parent f8be36a5
...@@ -18,7 +18,7 @@ export const ModalDialog = (props: ModalDialogProps) => { ...@@ -18,7 +18,7 @@ export const ModalDialog = (props: ModalDialogProps) => {
const modalKeyEvent = (keyCode) => { const modalKeyEvent = (keyCode) => {
if (keyCode === 27) { // Esc if (keyCode === 27) { // Esc
if (props.cancel && props.cancel.fn) props.cancel.fn() if (props.cancelFn) props.cancelFn()
handleHide() handleHide()
} else if (keyCode === 13) { // Enter } else if (keyCode === 13) { // Enter
enterHandler() enterHandler()
...@@ -33,9 +33,9 @@ export const ModalDialog = (props: ModalDialogProps) => { ...@@ -33,9 +33,9 @@ export const ModalDialog = (props: ModalDialogProps) => {
const enterHandler = () => { const enterHandler = () => {
if (state.toggleBtn) { if (state.toggleBtn) {
if (props.ok && props.ok.fn) props.ok.fn() if (props.okFn) props.okFn()
} else { } else {
if (props.cancel && props.cancel.fn) props.cancel.fn() if (props.cancelFn) props.cancelFn()
} }
handleHide() handleHide()
} }
...@@ -79,29 +79,29 @@ export const ModalDialog = (props: ModalDialogProps) => { ...@@ -79,29 +79,29 @@ export const ModalDialog = (props: ModalDialogProps) => {
</div> </div>
<div className="modal-footer" data-id={`${props.id}ModalDialogModalFooter-react`}> <div className="modal-footer" data-id={`${props.id}ModalDialogModalFooter-react`}>
{/* todo add autofocus ^^ */} {/* todo add autofocus ^^ */}
{ props.ok && { props.okLabel &&
<span <span
data-id={`${props.id}-modal-footer-ok-react`} data-id={`${props.id}-modal-footer-ok-react`}
className={'modal-ok btn btn-sm ' + (state.toggleBtn ? 'btn-dark' : 'btn-light')} className={'modal-ok btn btn-sm ' + (state.toggleBtn ? 'btn-dark' : 'btn-light')}
onClick={() => { onClick={() => {
if (props.ok.fn) props.ok.fn() if (props.okFn) props.okFn()
handleHide() handleHide()
}} }}
> >
{ props.ok.label ? props.ok.label : 'OK' } { props.okLabel ? props.okLabel : 'OK' }
</span> </span>
} }
{ props.cancel && { props.cancelLabel &&
<span <span
data-id={`${props.id}-modal-footer-cancel-react`} data-id={`${props.id}-modal-footer-cancel-react`}
className={'modal-cancel btn btn-sm ' + (state.toggleBtn ? 'btn-light' : 'btn-dark')} className={'modal-cancel btn btn-sm ' + (state.toggleBtn ? 'btn-light' : 'btn-dark')}
data-dismiss="modal" data-dismiss="modal"
onClick={() => { onClick={() => {
if (props.cancel.fn) props.cancel.fn() if (props.cancelFn) props.cancelFn()
handleHide() handleHide()
}} }}
> >
{ props.cancel.label ? props.cancel.label : 'Cancel' } { props.cancelLabel ? props.cancelLabel : 'Cancel' }
</span> </span>
} }
</div> </div>
......
...@@ -2,8 +2,10 @@ export interface ModalDialogProps { ...@@ -2,8 +2,10 @@ export interface ModalDialogProps {
id?: string id?: string
title?: string, title?: string,
message?: string, message?: string,
ok?: { label: string, fn: () => void }, okLabel?: string,
cancel: { label: string, fn: () => void }, okFn?: () => void,
cancelLabel?: string,
cancelFn?: () => void,
modalClass?: string, modalClass?: string,
showCancelIcon?: boolean, showCancelIcon?: boolean,
hide: boolean, hide: boolean,
......
...@@ -91,10 +91,8 @@ export const Toaster = (props: ToasterProps) => { ...@@ -91,10 +91,8 @@ export const Toaster = (props: ToasterProps) => {
<> <>
<ModalDialog <ModalDialog
message={props.message} message={props.message}
cancel={{ cancelLabel='Close'
label: 'Close', cancelFn={() => {}}
fn: () => {}
}}
hide={!state.showModal} hide={!state.showModal}
handleHide={hideFullMessage} handleHide={hideFullMessage}
/> />
......
...@@ -145,14 +145,10 @@ export const Workspace = (props: WorkspaceProps) => { ...@@ -145,14 +145,10 @@ export const Workspace = (props: WorkspaceProps) => {
hide: true, hide: true,
title: '', title: '',
message: null, message: null,
ok: { okLabel: '',
label: '', okFn: () => {},
fn: () => {} cancelLabel: '',
}, cancelFn: () => {},
cancel: {
label: '',
fn: () => {}
},
handleHide: null handleHide: null
}, },
loadingLocalhost: false, loadingLocalhost: false,
...@@ -168,41 +164,20 @@ export const Workspace = (props: WorkspaceProps) => { ...@@ -168,41 +164,20 @@ export const Workspace = (props: WorkspaceProps) => {
/* workspace creation, renaming and deletion */ /* workspace creation, renaming and deletion */
const renameCurrentWorkspace = () => { const renameCurrentWorkspace = () => {
modal('Rename Current Workspace', renameModalMessage(), { modal('Rename Current Workspace', renameModalMessage(), 'OK', onFinishRenameWorkspace, '', () => {})
label: 'OK',
fn: onFinishRenameWorkspace
}, {
label: '',
fn: () => {}
})
} }
const createWorkspace = () => { const createWorkspace = () => {
modal('Create Workspace', createModalMessage(), { modal('Create Workspace', createModalMessage(), 'OK', onFinishCreateWorkspace, '', () => {})
label: 'OK',
fn: onFinishCreateWorkspace
}, {
label: '',
fn: () => {}
})
} }
const deleteCurrentWorkspace = () => { const deleteCurrentWorkspace = () => {
modal('Delete Current Workspace', 'Are you sure to delete the current workspace?', { modal('Delete Current Workspace', 'Are you sure to delete the current workspace?', 'OK', onFinishDeleteWorkspace, '', () => {})
label: 'OK',
fn: onFinishDeleteWorkspace
}, {
label: '',
fn: () => {}
})
} }
const modalMessage = (title: string, body: string) => { const modalMessage = (title: string, body: string) => {
setTimeout(() => { // wait for any previous modal a chance to close setTimeout(() => { // wait for any previous modal a chance to close
modal(title, body, { modal(title, body, 'OK', () => {}, '', null)
label: 'OK',
fn: () => {}
}, null)
}, 200) }, 200)
} }
...@@ -297,7 +272,7 @@ export const Workspace = (props: WorkspaceProps) => { ...@@ -297,7 +272,7 @@ export const Workspace = (props: WorkspaceProps) => {
}) })
} }
const modal = async (title: string, message: string | JSX.Element, ok: { label: string, fn: () => void }, cancel: { label: string, fn: () => void }) => { const modal = async (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel: string, cancelFn: () => void) => {
await setState(prevState => { await setState(prevState => {
return { return {
...prevState, ...prevState,
...@@ -306,8 +281,10 @@ export const Workspace = (props: WorkspaceProps) => { ...@@ -306,8 +281,10 @@ export const Workspace = (props: WorkspaceProps) => {
hide: false, hide: false,
message, message,
title, title,
ok, okLabel,
cancel, okFn,
cancelLabel,
cancelFn,
handleHide: handleHideModal handleHide: handleHideModal
} }
} }
...@@ -339,8 +316,10 @@ export const Workspace = (props: WorkspaceProps) => { ...@@ -339,8 +316,10 @@ export const Workspace = (props: WorkspaceProps) => {
title={ state.modal.title } title={ state.modal.title }
message={ state.modal.message } message={ state.modal.message }
hide={ state.modal.hide } hide={ state.modal.hide }
ok={ state.modal.ok } okLabel={ state.modal.okLabel }
cancel={ state.modal.cancel } okFn={ state.modal.okFn }
cancelLabel={ state.modal.cancelLabel }
cancelFn={ state.modal.cancelFn }
handleHide={ handleHideModal }> handleHide={ handleHideModal }>
{ (typeof state.modal.message !== 'string') && state.modal.message } { (typeof state.modal.message !== 'string') && state.modal.message }
</ModalDialog> </ModalDialog>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment