Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix(nc-gui): update realtime actions info modal

Ramesh Mane2043bbdb8b0f
diff --git a/packages/nc-gui/components/nc/ModalConfirm.vue b/packages/nc-gui/components/nc/ModalConfirm.vue
index 2e0ffcf99e..e33136562d 100644
--- a/packages/nc-gui/components/nc/ModalConfirm.vue
+++ b/packages/nc-gui/components/nc/ModalConfirm.vue
@@ -58,6 +58,9 @@ export interface NcConfirmModalProps extends NcModalProps {
/** Additional class for the OK button */
okClass?: string
+ /** Whether to show the OK button */
+ showOkBtn?: boolean
+
okProps?: Partial<NcButtonProps>
/** Text for the Cancel button */
@@ -66,6 +69,9 @@ export interface NcConfirmModalProps extends NcModalProps {
/** Additional class for the Cancel button */
cancelClass?: string
+ /** Whether to show the Cancel button */
+ showCancelBtn?: boolean
+
cancelProps?: Partial<NcButtonProps>
/** Determines which button gets focus on open */
@@ -89,15 +95,18 @@ const props = withDefaults(defineProps<NcConfirmModalProps>(), {
okText: '',
okClass: '',
+ showOkBtn: true,
cancelText: '',
cancelClass: '',
+ showCancelBtn: true,
+
focusBtn: 'ok',
})
const emits = defineEmits<Emits>()
-const { visible: _visible, ...restProps } = props
+const { visible: _visible, showOkBtn: _showOkBtn, showCancelBtn: _showCancelBtn, ...restProps } = props
const initialFocus = ref<boolean>(false)
@@ -124,7 +133,7 @@ const vModel = computed({
},
})
-const { type } = toRefs(props)
+const { type, showCancelBtn, showOkBtn } = toRefs(props)
const iconName = computed<IconMapKey>(() => {
if (type.value === 'success') {
@@ -157,14 +166,14 @@ const onClickCancel = () => {
/** Watches for cancel button reference and sets focus if applicable */
watch(cancelBtnRef, () => {
- if (!cancelBtnRef.value?.$el || props.focusBtn !== 'cancel') return
+ if (!showCancelBtn.value || !cancelBtnRef.value?.$el || props.focusBtn !== 'cancel') return
;(cancelBtnRef.value?.$el as HTMLButtonElement)?.focus()
initialFocus.value = true
})
/** Watches for OK button reference and sets focus if applicable */
watch(okBtnRef, () => {
- if (!okBtnRef.value?.$el || props.focusBtn !== 'ok') return
+ if (!showOkBtn.value || !okBtnRef.value?.$el || props.focusBtn !== 'ok') return
;(okBtnRef.value?.$el as HTMLButtonElement)?.focus()
initialFocus.value = true
})
@@ -232,6 +241,7 @@ useSelectedCellKeydownListener(
<div class="flex flex-row w-full justify-end gap-2">
<NcButton
+ v-if="showCancelBtn"
ref="cancelBtnRef"
:type="cancelProps?.type ?? 'secondary'"
size="small"
@@ -243,6 +253,7 @@ useSelectedCellKeydownListener(
{{ cancelText || $t('general.cancel') }}
</NcButton>
<NcButton
+ v-if="showOkBtn"
ref="okBtnRef"
:type="okProps?.type ?? 'primary'"
size="small"
diff --git a/packages/nc-gui/composables/useNcConfirmModal.ts b/packages/nc-gui/composables/useNcConfirmModal.ts
new file mode 100644
index 0000000000..96d33cbf22
--- /dev/null
+++ b/packages/nc-gui/composables/useNcConfirmModal.ts
@@ -0,0 +1,62 @@
+import NcModalConfirm, { type NcConfirmModalProps } from '../components/nc/ModalConfirm.vue'
+
+export type NcShowConfirmModalProps = Pick<
+ NcConfirmModalProps,
+ 'type' | 'title' | 'content' | 'okText' | 'okClass' | 'showCancelBtn' | 'cancelText' | 'showIcon' | 'maskClosable' | 'keyboard'
+>
+
+const useNcConfirmModal = () => {
+ const showConfirmModal = ({
+ type,
+ title,
+ content,
+ okText,
+ okClass = '!px-4',
+ cancelText,
+ showIcon = false,
+ maskClosable = true,
+ keyboard = true,
+ showCancelBtn = false,
+ }: NcShowConfirmModalProps) => {
+ const isOpen = ref(true)
+
+ const { close } = useDialog(NcModalConfirm, {
+ 'visible': isOpen,
+ 'type': type,
+ 'title': title,
+ 'content': content,
+ 'okText': okText,
+ 'cancelText': cancelText,
+ 'onCancel': closeDialog,
+ 'onOk': closeDialog,
+ 'okClass': okClass,
+ 'update:visible': closeDialog,
+ 'showIcon': showIcon,
+ 'maskClosable': maskClosable,
+ 'keyboard': keyboard,
+ 'showCancelBtn': showCancelBtn,
+ })
+
+ function closeDialog() {
+ isOpen.value = false
+ close(1000)
+ }
+ }
+
+ return {
+ showInfoModal: (props: Omit<NcShowConfirmModalProps, 'type'>) => {
+ showConfirmModal({ ...props, type: 'info' })
+ },
+ showSuccessModal: (props: Omit<NcShowConfirmModalProps, 'type'>) => {
+ showConfirmModal({ ...props, type: 'success' })
+ },
+ showWarningModal: (props: Omit<NcShowConfirmModalProps, 'type'>) => {
+ showConfirmModal({ ...props, type: 'warning' })
+ },
+ showErrorModal: (props: Omit<NcShowConfirmModalProps, 'type'>) => {
+ showConfirmModal({ ...props, type: 'error' })
+ },
+ }
+}
+
+export default useNcConfirmModal