Browse Source

Merge branch 'develop' into enhancement/filters

pull/5106/head
Wing-Kam Wong 2 years ago
parent
commit
8153a8eb2a
  1. 7
      packages/nc-gui/assets/style.scss
  2. 14
      packages/nc-gui/components/account/Token.vue
  3. 15
      packages/nc-gui/components/account/UserList.vue
  4. 12
      packages/nc-gui/components/account/UsersModal.vue
  5. 5
      packages/nc-gui/components/cell/attachment/Modal.vue
  6. 12
      packages/nc-gui/components/smartsheet/ApiSnippet.vue
  7. 23
      packages/nc-gui/components/smartsheet/toolbar/ShareView.vue
  8. 10
      packages/nc-gui/components/smartsheet/toolbar/SharedViewList.vue
  9. 19
      packages/nc-gui/components/tabs/auth/ApiTokenManagement.vue
  10. 13
      packages/nc-gui/components/tabs/auth/UserManagement.vue
  11. 25
      packages/nc-gui/components/tabs/auth/user-management/ShareBase.vue
  12. 12
      packages/nc-gui/components/tabs/auth/user-management/UsersModal.vue
  13. 16
      packages/nc-gui/components/template/Editor.vue
  14. 53
      packages/nc-gui/components/virtual-cell/Lookup.vue
  15. 60
      packages/nc-gui/composables/useCopy.ts
  16. 29
      packages/nc-gui/pages/[projectType]/[projectId]/index.vue
  17. 10
      packages/nc-gui/pages/index/index/index.vue

7
packages/nc-gui/assets/style.scss

@ -311,3 +311,10 @@ a {
@apply block bg-red-500
}
}
.nc-copy-failed-modal .ant-modal-confirm-content{
@apply pt-4 overflow-auto;
white-space: pre;
user-select: auto;
}

14
packages/nc-gui/components/account/Token.vue

@ -81,14 +81,18 @@ const generateToken = async () => {
$e('a:api-token:generate')
}
const copyToken = (token: string | undefined) => {
const copyToken = async (token: string | undefined) => {
if (!token) return
copy(token)
// Copied to clipboard
message.info(t('msg.info.copiedToClipboard'))
try {
await copy(token)
// Copied to clipboard
message.info(t('msg.info.copiedToClipboard'))
$e('c:api-token:copy')
$e('c:api-token:copy')
} catch (e) {
message.error(e.message)
}
}
const descriptionInput = (el) => {

15
packages/nc-gui/components/account/UserList.vue

@ -99,13 +99,16 @@ const resendInvite = async (user: User) => {
$e('a:org-user:resend-invite')
}
const copyInviteUrl = (user: User) => {
const copyInviteUrl = async (user: User) => {
if (!user.invite_token) return
try {
await copy(`${dashboardUrl}#/signup/${user.invite_token}`)
copy(`${dashboardUrl}#/signup/${user.invite_token}`)
// Invite URL copied to clipboard
message.success(t('msg.success.inviteURLCopied'))
// Invite URL copied to clipboard
message.success(t('msg.success.inviteURLCopied'))
} catch (e) {
message.error(e.message)
}
$e('c:user:copy-url')
}
@ -113,7 +116,7 @@ const copyPasswordResetUrl = async (user: User) => {
try {
const { reset_password_url } = await api.orgUsers.generatePasswordResetToken(user.id)
copy(reset_password_url)
await copy(reset_password_url!)
// Invite URL copied to clipboard
message.success(t('msg.success.passwordResetURLCopied'))

12
packages/nc-gui/components/account/UsersModal.vue

@ -93,12 +93,14 @@ const inviteUrl = $computed(() => (usersData.invitationToken ? `${dashboardUrl}#
const copyUrl = async () => {
if (!inviteUrl) return
try {
await copy(inviteUrl)
await copy(inviteUrl)
// Copied shareable base url to clipboard!
message.success(t('msg.success.shareableURLCopied'))
// Copied shareable base url to clipboard!
message.success(t('msg.success.shareableURLCopied'))
} catch (e) {
message.error(e.message)
}
$e('c:shared-base:copy-url')
}

5
packages/nc-gui/components/cell/attachment/Modal.vue

@ -146,7 +146,10 @@ function onRemoveFileClick(title: any, i: number) {
</div>
</a-tooltip>
<a-tooltip placement="bottom">
<a-tooltip
v-if="isSharedForm || (!readOnly && isUIAllowed('tableAttachment') && !isPublic && !isLocked)"
placement="bottom"
>
<template #title> Rename File </template>
<div class="nc-attachment-download group-hover:(opacity-100) mr-[35px]">

12
packages/nc-gui/components/smartsheet/ApiSnippet.vue

@ -126,10 +126,14 @@ api.dbViewRow.list(
return snippet.convert(activeLang?.name, selectedClient || (activeLang?.clients && activeLang?.clients[0]), {})
})
const onCopyToClipboard = () => {
copy(code)
// Copied to clipboard
message.info(t('msg.info.copiedToClipboard'))
const onCopyToClipboard = async () => {
try {
await copy(code)
// Copied to clipboard
message.info(t('msg.info.copiedToClipboard'))
} catch (e) {
message.error(e.message)
}
}
const afterVisibleChange = (visible: boolean) => {

23
packages/nc-gui/components/smartsheet/toolbar/ShareView.vue

@ -186,10 +186,14 @@ function onChangeTheme(color: string) {
const copyLink = async () => {
if (sharedViewUrl.value) {
await copy(sharedViewUrl.value)
try {
await copy(sharedViewUrl.value)
// Copied to clipboard
message.success(t('msg.info.copiedToClipboard'))
// Copied to clipboard
message.success(t('msg.info.copiedToClipboard'))
} catch (e) {
message.error(e.message)
}
}
}
@ -217,10 +221,14 @@ const iframeCode = computed(() => {
const copyIframeCode = async () => {
if (iframeCode.value) {
await copy(iframeCode.value)
try {
await copy(iframeCode.value)
// Copied to clipboard
message.success(t('msg.info.copiedToClipboard'))
// Copied to clipboard
message.success(t('msg.info.copiedToClipboard'))
} catch (e) {
message.error(e.message)
}
}
}
</script>
@ -268,7 +276,8 @@ const copyIframeCode = async () => {
class="flex gap-1 items-center pb-1 text-gray-500 cursor-pointer font-weight-medium mb-2 mt-4 pl-1"
@click="copyIframeCode"
>
<MdiCodeTags class="text-gray-500" /> Embed this view in your site
<MdiCodeTags class="text-gray-500" />
Embed this view in your site
</div>
<div class="px-1 mt-2 flex flex-col gap-3">

10
packages/nc-gui/components/smartsheet/toolbar/SharedViewList.vue

@ -75,9 +75,13 @@ const renderAllowCSVDownload = (view: SharedViewType) => {
}
const copyLink = (view: SharedViewType) => {
copy(`${dashboardUrl?.value as string}#${sharedViewUrl(view)}`)
// Copied to clipboard
message.success(t('msg.info.copiedToClipboard'))
try {
copy(`${dashboardUrl?.value as string}#${sharedViewUrl(view)}`)
// Copied to clipboard
message.success(t('msg.info.copiedToClipboard'))
} catch (e) {
message.error(e.message)
}
}
const deleteLink = async (id: string) => {

19
packages/nc-gui/components/tabs/auth/ApiTokenManagement.vue

@ -33,13 +33,16 @@ const openNewTokenModal = () => {
$e('c:api-token:generate')
}
const copyToken = (token: string | undefined) => {
const copyToken = async (token: string | undefined) => {
if (!token) return
copy(token)
// Copied to clipboard
message.info(t('msg.info.copiedToClipboard'))
try {
await copy(token)
// Copied to clipboard
message.info(t('msg.info.copiedToClipboard'))
} catch (e) {
message.error(e.message)
}
$e('c:api-token:copy')
}
@ -145,8 +148,8 @@ onMounted(() => {
<div class="flex flex-row justify-center mt-2 text-center w-full text-base">This action will remove this API Token</div>
<div class="flex mt-6 justify-center space-x-2">
<a-button @click="showDeleteTokenModal = false"> {{ $t('general.cancel') }} </a-button>
<a-button type="primary" danger @click="deleteToken()"> {{ $t('general.confirm') }} </a-button>
<a-button @click="showDeleteTokenModal = false"> {{ $t('general.cancel') }}</a-button>
<a-button type="primary" danger @click="deleteToken()"> {{ $t('general.confirm') }}</a-button>
</div>
</div>
</a-modal>
@ -205,7 +208,7 @@ onMounted(() => {
</a-tooltip>
<a-tooltip placement="bottom">
<template #title> {{ $t('general.copy') }} </template>
<template #title> {{ $t('general.copy') }}</template>
<a-button type="text" class="!rounded-md" @click="copyToken(item.token)">
<template #icon>

13
packages/nc-gui/components/tabs/auth/UserManagement.vue

@ -140,13 +140,16 @@ const resendInvite = async (user: User) => {
$e('a:user:resend-invite')
}
const copyInviteUrl = (user: User) => {
const copyInviteUrl = async (user: User) => {
if (!user.invite_token) return
try {
await copy(`${dashboardUrl}#/signup/${user.invite_token}`)
copy(`${dashboardUrl}#/signup/${user.invite_token}`)
// Invite URL copied to clipboard
message.success(t('msg.success.inviteURLCopied'))
// Invite URL copied to clipboard
message.success(t('msg.success.inviteURLCopied'))
} catch (e) {
message.error(e.message)
}
$e('c:user:copy-url')
}

25
packages/nc-gui/components/tabs/auth/user-management/ShareBase.vue

@ -94,11 +94,14 @@ const recreate = async () => {
const copyUrl = async () => {
if (!url) return
try {
await copy(url)
await copy(url)
// Copied shareable base url to clipboard!
message.success(t('msg.success.shareableURLCopied'))
// Copied shareable base url to clipboard!
message.success(t('msg.success.shareableURLCopied'))
} catch (e) {
message.error(e.message)
}
$e('c:shared-base:copy-url')
}
@ -111,10 +114,10 @@ const navigateToSharedBase = () => {
$e('c:shared-base:open-url')
}
const generateEmbeddableIframe = () => {
const generateEmbeddableIframe = async () => {
if (!url) return
copy(`<iframe
try {
await copy(`<iframe
class="nc-embed"
src="${url}?embed"
frameborder="0"
@ -122,9 +125,11 @@ width="100%"
height="700"
style="background: transparent; border: 1px solid #ddd"></iframe>`)
// Copied embeddable html code!
message.success(t('msg.success.embeddableHTMLCodeCopied'))
// Copied embeddable html code!
message.success(t('msg.success.embeddableHTMLCodeCopied'))
} catch (e) {
message.error(e.message)
}
$e('c:shared-base:copy-embed-frame')
}

12
packages/nc-gui/components/tabs/auth/user-management/UsersModal.vue

@ -125,12 +125,14 @@ const inviteUrl = $computed(() => (usersData.invitationToken ? `${dashboardUrl}#
const copyUrl = async () => {
if (!inviteUrl) return
try {
await copy(inviteUrl)
await copy(inviteUrl)
// Copied shareable base url to clipboard!
message.success(t('msg.success.shareableURLCopied'))
// Copied shareable base url to clipboard!
message.success(t('msg.success.shareableURLCopied'))
} catch (e) {
message.error(e.message)
}
$e('c:shared-base:copy-url')
}

16
packages/nc-gui/components/template/Editor.vue

@ -501,16 +501,12 @@ async function importTemplate() {
}
}
}
const createdTable = await $api.base.tableCreate(
project.value?.id as string,
(baseId || project.value?.bases?.[0].id)!,
{
table_name: table.table_name,
// leave title empty to get a generated one based on table_name
title: '',
columns: table.columns || [],
},
)
const createdTable = await $api.base.tableCreate(project.value?.id as string, (baseId || project.value?.bases?.[0].id)!, {
table_name: table.table_name,
// leave title empty to get a generated one based on table_name
title: '',
columns: table.columns || [],
})
table.id = createdTable.id
table.title = createdTable.title

53
packages/nc-gui/components/virtual-cell/Lookup.vue

@ -6,7 +6,6 @@ import {
CellValueInj,
ColumnInj,
MetaInj,
ReadonlyInj,
computed,
inject,
isAttachment,
@ -19,8 +18,6 @@ import {
const { metas, getMeta } = useMetas()
provide(ReadonlyInj, ref(true))
const column = inject(ColumnInj, ref())
const meta = inject(MetaInj, ref())
@ -29,7 +26,7 @@ const cellValue = inject(CellValueInj, ref())
const relationColumn = computed(
() =>
meta.value?.columns?.find((c) => c.id === (column.value?.colOptions as LookupType)?.fk_relation_column_id) as
meta.value?.columns?.find((c: ColumnType) => c.id === (column.value?.colOptions as LookupType)?.fk_relation_column_id) as
| (ColumnType & {
colOptions: LinkToAnotherRecordType | undefined
})
@ -38,7 +35,7 @@ const relationColumn = computed(
watch(
relationColumn,
async (relationCol) => {
async (relationCol: { colOptions: LinkToAnotherRecordType }) => {
if (relationCol && relationCol.colOptions) await getMeta(relationCol.colOptions.fk_related_model_id!)
},
{ immediate: true },
@ -94,28 +91,46 @@ const { showEditNonEditableFieldWarning, showClearNonEditableFieldWarning, activ
:edit-enabled="false"
:model-value="v"
:column="lookupColumn"
:read-only="true"
/>
</template>
<LazySmartsheetVirtualCell v-else :edit-enabled="false" :model-value="arrValue" :column="lookupColumn" />
<LazySmartsheetVirtualCell
v-else
:edit-enabled="false"
:read-only="true"
:model-value="arrValue"
:column="lookupColumn"
/>
</div>
<!-- Render normal cell -->
<template v-else>
<!-- For attachment cell avoid adding chip style -->
<div
v-for="(v, i) of arrValue"
:key="i"
class="min-w-max"
:class="{
'bg-gray-100 px-1 rounded-full flex-1': !isAttachment(lookupColumn),
' border-gray-200 rounded border-1': ![UITypes.Attachment, UITypes.MultiSelect, UITypes.SingleSelect].includes(
lookupColumn.uidt,
),
}"
>
<LazySmartsheetCell :model-value="v" :column="lookupColumn" :edit-enabled="false" :virtual="true" />
<div v-if="isAttachment(lookupColumn) && arrValue[0] && !Array.isArray(arrValue[0]) && typeof arrValue[0] === 'object'">
<LazySmartsheetCell :model-value="arrValue" :column="lookupColumn" :edit-enabled="false" :read-only="true" />
</div>
<!-- For attachment cell avoid adding chip style -->
<template v-else>
<div
v-for="(v, i) of arrValue"
:key="i"
class="min-w-max"
:class="{
'bg-gray-100 px-1 rounded-full flex-1': !isAttachment(lookupColumn),
'border-gray-200 rounded border-1': ![UITypes.Attachment, UITypes.MultiSelect, UITypes.SingleSelect].includes(
lookupColumn.uidt,
),
}"
>
<LazySmartsheetCell
:model-value="v"
:column="lookupColumn"
:edit-enabled="false"
:virtual="true"
:read-only="true"
/>
</div>
</template>
</template>
</template>
</div>

60
packages/nc-gui/composables/useCopy.ts

@ -1,15 +1,46 @@
import { useClipboard } from '#imports'
import { Modal } from 'ant-design-vue'
import { useClipboard, useI18n } from '#imports'
export const useCopy = (showDialogIfFailed = false) => {
const { t } = useI18n()
export const useCopy = () => {
/** fallback for copy if clipboard api is not supported */
const copyFallback = (text: string) => {
const textAreaEl = document.createElement('textarea')
textAreaEl.innerHTML = text
document.body.appendChild(textAreaEl)
textAreaEl.select()
const result = document.execCommand('copy')
document.body.removeChild(textAreaEl)
return result
const copyFallback = async (text: string, retryCount = 0): Promise<boolean> => {
try {
const textAreaEl = document.createElement('textarea')
textAreaEl.innerHTML = text
document.body.appendChild(textAreaEl)
textAreaEl.select()
const result = document.execCommand('copy')
document.body.removeChild(textAreaEl)
if (!result && retryCount < 3) {
// retry if copy failed
return new Promise((resolve, reject) =>
setTimeout(
() =>
copyFallback(text, retryCount + 1)
.then(resolve)
.catch(reject),
100,
),
)
}
if (!result) {
throw new Error('failed')
}
return result
} catch (e) {
if (!showDialogIfFailed) throw new Error(t('msg.error.copyToClipboardError'))
Modal.info({
title: 'Copy failed, please manually copy it from here',
content: text,
class: 'nc-copy-failed-modal',
width: '550px',
})
return false
}
}
const { copy: _copy, isSupported } = useClipboard()
@ -18,12 +49,11 @@ export const useCopy = () => {
try {
if (isSupported.value) {
await _copy(text)
} else {
copyFallback(text)
return true
}
} catch (e) {
copyFallback(text)
}
} catch {}
return copyFallback(text)
}
return { copy }

29
packages/nc-gui/pages/[projectType]/[projectId]/index.vue

@ -52,7 +52,7 @@ const { clearTabs, addTab } = useTabs()
const { isUIAllowed } = useUIPermission()
const { copy } = useCopy()
const { copy } = useCopy(true)
// create a new sidebar state
const { isOpen, toggle, toggleHasSidebar } = useSidebar('nc-left-sidebar', { hasSidebar: false, isOpen: false })
@ -128,15 +128,17 @@ const copyProjectInfo = async () => {
try {
await loadProjectMetaInfo()
await copy(
Object.entries(projectMetaInfo.value!)
.map(([k, v]) => `${k}: **${v}**`)
.join('\n'),
)
// Copied to clipboard
message.info(t('msg.info.copiedToClipboard'))
} catch (e: any) {
if (
await copy(
Object.entries(projectMetaInfo.value!)
.map(([k, v]) => `${k}: **${v}**`)
.join('\n'),
)
) {
// Copied to clipboard
message.info(t('msg.info.copiedToClipboard'))
}
} catch (e) {
console.error(e)
message.error(e.message)
}
@ -144,9 +146,10 @@ const copyProjectInfo = async () => {
const copyAuthToken = async () => {
try {
await copy(token.value!)
// Copied to clipboard
message.info(t('msg.info.copiedToClipboard'))
if (await copy(token.value!)) {
// Copied to clipboard
message.info(t('msg.info.copiedToClipboard'))
}
} catch (e: any) {
console.error(e)
message.error(e.message)

10
packages/nc-gui/pages/index/index/index.vue

@ -132,9 +132,13 @@ onBeforeMount(loadProjects)
const { copy } = useCopy()
const copyProjectMeta = async () => {
const aggregatedMetaInfo = await $api.utils.aggregatedMetaInfo()
copy(JSON.stringify(aggregatedMetaInfo))
message.info('Copied aggregated project meta to clipboard')
try {
const aggregatedMetaInfo = await $api.utils.aggregatedMetaInfo()
await copy(JSON.stringify(aggregatedMetaInfo))
message.info('Copied aggregated project meta to clipboard')
} catch (e) {
message.error(await extractSdkResponseErrorMsg(e))
}
}
</script>

Loading…
Cancel
Save