Browse Source

fix(gui): if copy failed show error message and print content in console

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5065/head
Pranav C 2 years ago
parent
commit
99a7bcbd5b
  1. 14
      packages/nc-gui/components/account/Token.vue
  2. 15
      packages/nc-gui/components/account/UserList.vue
  3. 12
      packages/nc-gui/components/account/UsersModal.vue
  4. 12
      packages/nc-gui/components/smartsheet/ApiSnippet.vue
  5. 23
      packages/nc-gui/components/smartsheet/toolbar/ShareView.vue
  6. 10
      packages/nc-gui/components/smartsheet/toolbar/SharedViewList.vue
  7. 19
      packages/nc-gui/components/tabs/auth/ApiTokenManagement.vue
  8. 13
      packages/nc-gui/components/tabs/auth/UserManagement.vue
  9. 25
      packages/nc-gui/components/tabs/auth/user-management/ShareBase.vue
  10. 12
      packages/nc-gui/components/tabs/auth/user-management/UsersModal.vue
  11. 16
      packages/nc-gui/components/template/Editor.vue
  12. 34
      packages/nc-gui/composables/useCopy.ts
  13. 10
      packages/nc-gui/pages/index/index/index.vue

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

@ -81,14 +81,18 @@ const generateToken = async () => {
$e('a:api-token:generate') $e('a:api-token:generate')
} }
const copyToken = (token: string | undefined) => { const copyToken = async (token: string | undefined) => {
if (!token) return if (!token) return
copy(token) try {
// Copied to clipboard await copy(token)
message.info(t('msg.info.copiedToClipboard')) // 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) => { 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') $e('a:org-user:resend-invite')
} }
const copyInviteUrl = (user: User) => { const copyInviteUrl = async (user: User) => {
if (!user.invite_token) return 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 } catch (e) {
message.success(t('msg.success.inviteURLCopied')) message.error(e.message)
}
$e('c:user:copy-url') $e('c:user:copy-url')
} }
@ -113,7 +116,7 @@ const copyPasswordResetUrl = async (user: User) => {
try { try {
const { reset_password_url } = await api.orgUsers.generatePasswordResetToken(user.id) const { reset_password_url } = await api.orgUsers.generatePasswordResetToken(user.id)
copy(reset_password_url) await copy(reset_password_url!)
// Invite URL copied to clipboard // Invite URL copied to clipboard
message.success(t('msg.success.passwordResetURLCopied')) 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 () => { const copyUrl = async () => {
if (!inviteUrl) return 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! } catch (e) {
message.success(t('msg.success.shareableURLCopied')) message.error(e.message)
}
$e('c:shared-base:copy-url') $e('c:shared-base:copy-url')
} }

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]), {}) return snippet.convert(activeLang?.name, selectedClient || (activeLang?.clients && activeLang?.clients[0]), {})
}) })
const onCopyToClipboard = () => { const onCopyToClipboard = async () => {
copy(code) try {
// Copied to clipboard await copy(code)
message.info(t('msg.info.copiedToClipboard')) // Copied to clipboard
message.info(t('msg.info.copiedToClipboard'))
} catch (e) {
message.error(e.message)
}
} }
const afterVisibleChange = (visible: boolean) => { const afterVisibleChange = (visible: boolean) => {

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

@ -186,10 +186,14 @@ function onChangeTheme(color: string) {
const copyLink = async () => { const copyLink = async () => {
if (sharedViewUrl.value) { if (sharedViewUrl.value) {
await copy(sharedViewUrl.value) try {
await copy(sharedViewUrl.value)
// Copied to clipboard // Copied to clipboard
message.success(t('msg.info.copiedToClipboard')) message.success(t('msg.info.copiedToClipboard'))
} catch (e) {
message.error(e.message)
}
} }
} }
@ -217,10 +221,14 @@ const iframeCode = computed(() => {
const copyIframeCode = async () => { const copyIframeCode = async () => {
if (iframeCode.value) { if (iframeCode.value) {
await copy(iframeCode.value) try {
await copy(iframeCode.value)
// Copied to clipboard // Copied to clipboard
message.success(t('msg.info.copiedToClipboard')) message.success(t('msg.info.copiedToClipboard'))
} catch (e) {
message.error(e.message)
}
} }
} }
</script> </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" class="flex gap-1 items-center pb-1 text-gray-500 cursor-pointer font-weight-medium mb-2 mt-4 pl-1"
@click="copyIframeCode" @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>
<div class="px-1 mt-2 flex flex-col gap-3"> <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) => { const copyLink = (view: SharedViewType) => {
copy(`${dashboardUrl?.value as string}#${sharedViewUrl(view)}`) try {
// Copied to clipboard copy(`${dashboardUrl?.value as string}#${sharedViewUrl(view)}`)
message.success(t('msg.info.copiedToClipboard')) // Copied to clipboard
message.success(t('msg.info.copiedToClipboard'))
} catch (e) {
message.error(e.message)
}
} }
const deleteLink = async (id: string) => { 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') $e('c:api-token:generate')
} }
const copyToken = (token: string | undefined) => { const copyToken = async (token: string | undefined) => {
if (!token) return if (!token) return
copy(token) try {
// Copied to clipboard await copy(token)
message.info(t('msg.info.copiedToClipboard')) // Copied to clipboard
message.info(t('msg.info.copiedToClipboard'))
} catch (e) {
message.error(e.message)
}
$e('c:api-token:copy') $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 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"> <div class="flex mt-6 justify-center space-x-2">
<a-button @click="showDeleteTokenModal = false"> {{ $t('general.cancel') }} </a-button> <a-button @click="showDeleteTokenModal = false"> {{ $t('general.cancel') }}</a-button>
<a-button type="primary" danger @click="deleteToken()"> {{ $t('general.confirm') }} </a-button> <a-button type="primary" danger @click="deleteToken()"> {{ $t('general.confirm') }}</a-button>
</div> </div>
</div> </div>
</a-modal> </a-modal>
@ -205,7 +208,7 @@ onMounted(() => {
</a-tooltip> </a-tooltip>
<a-tooltip placement="bottom"> <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)"> <a-button type="text" class="!rounded-md" @click="copyToken(item.token)">
<template #icon> <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') $e('a:user:resend-invite')
} }
const copyInviteUrl = (user: User) => { const copyInviteUrl = async (user: User) => {
if (!user.invite_token) return 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 } catch (e) {
message.success(t('msg.success.inviteURLCopied')) message.error(e.message)
}
$e('c:user:copy-url') $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 () => { const copyUrl = async () => {
if (!url) return 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! } catch (e) {
message.success(t('msg.success.shareableURLCopied')) message.error(e.message)
}
$e('c:shared-base:copy-url') $e('c:shared-base:copy-url')
} }
@ -111,10 +114,10 @@ const navigateToSharedBase = () => {
$e('c:shared-base:open-url') $e('c:shared-base:open-url')
} }
const generateEmbeddableIframe = () => { const generateEmbeddableIframe = async () => {
if (!url) return if (!url) return
try {
copy(`<iframe await copy(`<iframe
class="nc-embed" class="nc-embed"
src="${url}?embed" src="${url}?embed"
frameborder="0" frameborder="0"
@ -122,9 +125,11 @@ width="100%"
height="700" height="700"
style="background: transparent; border: 1px solid #ddd"></iframe>`) style="background: transparent; border: 1px solid #ddd"></iframe>`)
// Copied embeddable html code! // Copied embeddable html code!
message.success(t('msg.success.embeddableHTMLCodeCopied')) message.success(t('msg.success.embeddableHTMLCodeCopied'))
} catch (e) {
message.error(e.message)
}
$e('c:shared-base:copy-embed-frame') $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 () => { const copyUrl = async () => {
if (!inviteUrl) return 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! } catch (e) {
message.success(t('msg.success.shareableURLCopied')) message.error(e.message)
}
$e('c:shared-base:copy-url') $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( const createdTable = await $api.base.tableCreate(project.value?.id as string, (baseId || project.value?.bases?.[0].id)!, {
project.value?.id as string, table_name: table.table_name,
(baseId || project.value?.bases?.[0].id)!, // leave title empty to get a generated one based on table_name
{ title: '',
table_name: table.table_name, columns: table.columns || [],
// leave title empty to get a generated one based on table_name })
title: '',
columns: table.columns || [],
},
)
table.id = createdTable.id table.id = createdTable.id
table.title = createdTable.title table.title = createdTable.title

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

@ -2,14 +2,27 @@ import { useClipboard } from '#imports'
export const useCopy = () => { export const useCopy = () => {
/** fallback for copy if clipboard api is not supported */ /** fallback for copy if clipboard api is not supported */
const copyFallback = (text: string) => { const copyFallback = async (text: string, retryCount = 0): Promise<boolean> => {
const textAreaEl = document.createElement('textarea') try {
textAreaEl.innerHTML = text const textAreaEl = document.createElement('textarea')
document.body.appendChild(textAreaEl) textAreaEl.innerHTML = text
textAreaEl.select() document.body.appendChild(textAreaEl)
const result = document.execCommand('copy') textAreaEl.select()
document.body.removeChild(textAreaEl) const result = document.execCommand('copy')
return result document.body.removeChild(textAreaEl)
if (!result && retryCount < 3) {
// retry if copy failed
return new Promise((resolve) => setTimeout(() => resolve(copyFallback(text, retryCount + 1)), 100))
}
if (!result) {
throw new Error('failed')
}
return result
} catch (e) {
throw new Error('Clipboard copy failed, please copy it from console log')
console.log(text)
}
} }
const { copy: _copy, isSupported } = useClipboard() const { copy: _copy, isSupported } = useClipboard()
@ -18,11 +31,12 @@ export const useCopy = () => {
try { try {
if (isSupported.value) { if (isSupported.value) {
await _copy(text) await _copy(text)
return true
} else { } else {
copyFallback(text) return copyFallback(text)
} }
} catch (e) { } catch (e) {
copyFallback(text) return copyFallback(text)
} }
} }

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

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

Loading…
Cancel
Save