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. 8
      packages/nc-gui/components/account/Token.vue
  2. 11
      packages/nc-gui/components/account/UserList.vue
  3. 6
      packages/nc-gui/components/account/UsersModal.vue
  4. 8
      packages/nc-gui/components/smartsheet/ApiSnippet.vue
  5. 11
      packages/nc-gui/components/smartsheet/toolbar/ShareView.vue
  6. 4
      packages/nc-gui/components/smartsheet/toolbar/SharedViewList.vue
  7. 9
      packages/nc-gui/components/tabs/auth/ApiTokenManagement.vue
  8. 9
      packages/nc-gui/components/tabs/auth/UserManagement.vue
  9. 15
      packages/nc-gui/components/tabs/auth/user-management/ShareBase.vue
  10. 6
      packages/nc-gui/components/tabs/auth/user-management/UsersModal.vue
  11. 8
      packages/nc-gui/components/template/Editor.vue
  12. 20
      packages/nc-gui/composables/useCopy.ts
  13. 6
      packages/nc-gui/pages/index/index/index.vue

8
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)
try {
await copy(token)
// Copied to clipboard
message.info(t('msg.info.copiedToClipboard'))
$e('c:api-token:copy')
} catch (e) {
message.error(e.message)
}
}
const descriptionInput = (el) => {

11
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
copy(`${dashboardUrl}#/signup/${user.invite_token}`)
try {
await copy(`${dashboardUrl}#/signup/${user.invite_token}`)
// 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'))

6
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)
// Copied shareable base url to clipboard!
message.success(t('msg.success.shareableURLCopied'))
} catch (e) {
message.error(e.message)
}
$e('c:shared-base:copy-url')
}

8
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)
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) => {

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

@ -186,10 +186,14 @@ function onChangeTheme(color: string) {
const copyLink = async () => {
if (sharedViewUrl.value) {
try {
await copy(sharedViewUrl.value)
// 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) {
try {
await copy(iframeCode.value)
// 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">

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

@ -75,9 +75,13 @@ const renderAllowCSVDownload = (view: SharedViewType) => {
}
const copyLink = (view: SharedViewType) => {
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) => {

9
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)
try {
await copy(token)
// Copied to clipboard
message.info(t('msg.info.copiedToClipboard'))
} catch (e) {
message.error(e.message)
}
$e('c:api-token:copy')
}

9
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
copy(`${dashboardUrl}#/signup/${user.invite_token}`)
try {
await copy(`${dashboardUrl}#/signup/${user.invite_token}`)
// Invite URL copied to clipboard
message.success(t('msg.success.inviteURLCopied'))
} catch (e) {
message.error(e.message)
}
$e('c:user:copy-url')
}

15
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)
// 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"
@ -124,7 +127,9 @@ style="background: transparent; border: 1px solid #ddd"></iframe>`)
// Copied embeddable html code!
message.success(t('msg.success.embeddableHTMLCodeCopied'))
} catch (e) {
message.error(e.message)
}
$e('c:shared-base:copy-embed-frame')
}

6
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)
// Copied shareable base url to clipboard!
message.success(t('msg.success.shareableURLCopied'))
} catch (e) {
message.error(e.message)
}
$e('c:shared-base:copy-url')
}

8
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)!,
{
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

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

@ -2,14 +2,27 @@ import { useClipboard } from '#imports'
export const useCopy = () => {
/** fallback for copy if clipboard api is not supported */
const copyFallback = (text: string) => {
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) => 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()
@ -18,11 +31,12 @@ export const useCopy = () => {
try {
if (isSupported.value) {
await _copy(text)
return true
} else {
copyFallback(text)
return copyFallback(text)
}
} catch (e) {
copyFallback(text)
return copyFallback(text)
}
}

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

@ -132,9 +132,13 @@ onBeforeMount(loadProjects)
const { copy } = useCopy()
const copyProjectMeta = async () => {
try {
const aggregatedMetaInfo = await $api.utils.aggregatedMetaInfo()
copy(JSON.stringify(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