Browse Source

chore(extensions): fix on extension (#9972)

pull/9976/head
Aman Desai 7 days ago committed by GitHub
parent
commit
3ea811bd7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      packages/nc-gui/components/extensions/Extension/Header.vue
  2. 2
      packages/nc-gui/components/extensions/Market.vue
  3. 14
      packages/nc-gui/components/extensions/Market/ExtensionsTab.vue
  4. 1
      packages/nc-gui/components/extensions/Pane.vue
  5. 28
      packages/nc-gui/composables/useExtensions.ts
  6. 9
      packages/nc-gui/extensions/data-exporter/index.vue

10
packages/nc-gui/components/extensions/Extension/Header.vue

@ -14,9 +14,12 @@ withDefaults(defineProps<Props>(), {
isFullscreen: true, isFullscreen: true,
}) })
const { $e } = useNuxtApp()
const { eventBus, getExtensionAssetsUrl, duplicateExtension, showExtensionDetails } = useExtensions() const { eventBus, getExtensionAssetsUrl, duplicateExtension, showExtensionDetails } = useExtensions()
const { fullscreen, collapsed, extension, extensionManifest, activeError, showExpandBtn } = useExtensionHelperOrThrow() const { fullscreen, collapsed, extension, extensionManifest, activeError, showExpandBtn } = useExtensionHelperOrThrow()
const EXTENSION_ID = extension.value.extensionId;
const titleInput = ref<HTMLInputElement | null>(null) const titleInput = ref<HTMLInputElement | null>(null)
@ -65,6 +68,11 @@ const handleDuplicateExtension = async (id: string, open: boolean = false) => {
}) })
} }
} }
const toggleFullScreen = () => {
fullscreen.value = true
$e(`c:extensions:${EXTENSION_ID}:full-screen`)
}
</script> </script>
<template> <template>
@ -150,7 +158,7 @@ const handleDuplicateExtension = async (id: string, open: boolean = false) => {
size="xs" size="xs"
type="text" type="text"
class="nc-extension-expand-btn !px-1" class="nc-extension-expand-btn !px-1"
@click.stop="fullscreen = true" @click.stop="toggleFullScreen"
> >
<GeneralIcon icon="ncMaximize2" class="h-3.5 w-3.5" /> <GeneralIcon icon="ncMaximize2" class="h-3.5 w-3.5" />
</NcButton> </NcButton>

2
packages/nc-gui/components/extensions/Market.vue

@ -14,6 +14,8 @@ interface TabItem {
const props = defineProps<Prop>() const props = defineProps<Prop>()
const { $e } = useNuxtApp()
const emit = defineEmits(['update:modelValue']) const emit = defineEmits(['update:modelValue'])
const tabs = [ const tabs = [

14
packages/nc-gui/components/extensions/Market/ExtensionsTab.vue

@ -4,6 +4,8 @@ interface Props {
isOpen: boolean isOpen: boolean
} }
const { $e } = useNuxtApp()
const props = withDefaults(defineProps<Props>(), {}) const props = withDefaults(defineProps<Props>(), {})
const emits = defineEmits(['update:searchQuery', 'update:isOpen']) const emits = defineEmits(['update:searchQuery', 'update:isOpen'])
@ -12,6 +14,16 @@ const searchQuery = useVModel(props, 'searchQuery', emits)
const isOpen = useVModel(props, 'isOpen', emits) const isOpen = useVModel(props, 'isOpen', emits)
watchDebounced(
searchQuery,
() => {
if (searchQuery.value) {
$e('c:extensions:marketplace:search')
}
},
{ debounce: 3000 },
)
const { availableExtensions, addExtension, getExtensionAssetsUrl, showExtensionDetails } = useExtensions() const { availableExtensions, addExtension, getExtensionAssetsUrl, showExtensionDetails } = useExtensions()
const filteredAvailableExtensions = computed(() => const filteredAvailableExtensions = computed(() =>
@ -23,7 +35,7 @@ const filteredAvailableExtensions = computed(() =>
) )
const onExtensionClick = (extensionId: string) => { const onExtensionClick = (extensionId: string) => {
showExtensionDetails(extensionId) showExtensionDetails(extensionId, 'market')
isOpen.value = false isOpen.value = false
} }

1
packages/nc-gui/components/extensions/Pane.vue

@ -59,6 +59,7 @@ const filteredExtensionList = computed(() =>
) )
const toggleMarket = () => { const toggleMarket = () => {
$e('c:extensions:marketplace:open')
isMarketVisible.value = !isMarketVisible.value isMarketVisible.value = !isMarketVisible.value
} }

28
packages/nc-gui/composables/useExtensions.ts

@ -75,7 +75,7 @@ export { ExtensionType }
export const useExtensions = createSharedComposable(() => { export const useExtensions = createSharedComposable(() => {
const { baseExtensions } = extensionsState() const { baseExtensions } = extensionsState()
const { $api } = useNuxtApp() const { $api, $e } = useNuxtApp()
const { base } = storeToRefs(useBase()) const { base } = storeToRefs(useBase())
@ -159,6 +159,7 @@ export const useExtensions = createSharedComposable(() => {
nextTick(() => { nextTick(() => {
eventBus.emit(ExtensionsEvents.ADD, newExtension?.id) eventBus.emit(ExtensionsEvents.ADD, newExtension?.id)
$e('a:extension:add', { extensionId: extensionReq.extension_id })
}) })
} }
@ -205,9 +206,13 @@ export const useExtensions = createSharedComposable(() => {
await $api.extensions.delete(extensionId) await $api.extensions.delete(extensionId)
const extensionToDelete = baseExtensions.value[base.value.id].extensions.find((e: any) => e.id === extensionId);
baseExtensions.value[base.value.id].extensions = baseExtensions.value[base.value.id].extensions.filter( baseExtensions.value[base.value.id].extensions = baseExtensions.value[base.value.id].extensions.filter(
(ext: any) => ext.id !== extensionId, (ext: any) => ext.id !== extensionId,
) )
$e('a:extension:delete', { extensionId: extensionToDelete.extensionId })
} }
const duplicateExtension = async (extensionId: string) => { const duplicateExtension = async (extensionId: string) => {
@ -229,7 +234,11 @@ export const useExtensions = createSharedComposable(() => {
}) })
if (newExtension) { if (newExtension) {
baseExtensions.value[base.value.id].extensions.push(new Extension(newExtension)) const duplicatedExtension = new Extension(newExtension);
baseExtensions.value[base.value.id].extensions.push(duplicatedExtension)
eventBus.emit(ExtensionsEvents.DUPLICATE, duplicatedExtension.id)
$e('a:extension:duplicate', { extensionId: extension.extensionId })
} }
return newExtension return newExtension
@ -291,25 +300,25 @@ export const useExtensions = createSharedComposable(() => {
} }
} }
class KvStore<T = any> implements IKvStore<T> { class KvStore<T extends Record<string, any> = any> implements IKvStore<T> {
private _id: string private _id: string
private data: Record<string, T> private data: T
constructor(id: string, data: Record<string, T>) { constructor(id: string, data: T) {
this._id = id this._id = id
this.data = data || {} this.data = data || {}
} }
get(key: string) { get<K extends keyof T = any>(key: K) {
return this.data[key] || null return this.data[key] || null
} }
set(key: string, value: any) { set<K extends keyof T = any>(key: K, value: any) {
this.data[key] = value this.data[key] = value
return updateExtension(this._id, { kv_store: this.data }) return updateExtension(this._id, { kv_store: this.data })
} }
async delete(key: string) { async delete<K extends keyof T = any>(key: K) {
delete this.data[key] delete this.data[key]
await updateExtension(this._id, { kv_store: this.data }) await updateExtension(this._id, { kv_store: this.data })
} }
@ -412,6 +421,7 @@ export const useExtensions = createSharedComposable(() => {
nextTick(() => { nextTick(() => {
eventBus.emit(ExtensionsEvents.CLEARDATA, this.id) eventBus.emit(ExtensionsEvents.CLEARDATA, this.id)
$e('c:extension:clear-data', { extensionId: this._extensionId })
}) })
}) })
} }
@ -514,6 +524,8 @@ export const useExtensions = createSharedComposable(() => {
detailsExtensionId.value = extensionId detailsExtensionId.value = extensionId
isDetailsVisible.value = true isDetailsVisible.value = true
detailsFrom.value = from || 'market' detailsFrom.value = from || 'market'
$e('c:extension:details', { source: from, extensionId })
} }
// Extension market modal // Extension market modal

9
packages/nc-gui/extensions/data-exporter/index.vue

@ -7,7 +7,7 @@ const jobStatusTooltip = {
[JobStatus.FAILED]: 'Export failed', [JobStatus.FAILED]: 'Export failed',
} as Record<string, string> } as Record<string, string>
const { $api, $poller } = useNuxtApp() const { $api, $poller, $e } = useNuxtApp()
const { appInfo } = useGlobal() const { appInfo } = useGlobal()
@ -23,6 +23,7 @@ const activeViewTitleOrId = computed(() => {
const { eventBus } = useExtensions() const { eventBus } = useExtensions()
const { extension, tables, fullscreen, getViewsForTable } = useExtensionHelperOrThrow() const { extension, tables, fullscreen, getViewsForTable } = useExtensionHelperOrThrow()
const EXTENSION_ID = extension.value.extensionId
const { jobList, loadJobsForBase } = useJobs() const { jobList, loadJobsForBase } = useJobs()
@ -164,6 +165,7 @@ async function exportDataAsync() {
} }
isExporting.value = false isExporting.value = false
$e(`a:extension:${EXTENSION_ID}:export:completed`)
} else if (data.status === JobStatus.FAILED) { } else if (data.status === JobStatus.FAILED) {
message.error('Failed to export data!') message.error('Failed to export data!')
@ -182,12 +184,15 @@ async function exportDataAsync() {
} }
isExporting.value = false isExporting.value = false
$e(`a:extension:${EXTENSION_ID}:export:failed`)
} }
} }
}, },
) )
} catch (e: any) { } catch (e: any) {
message.error(await extractSdkResponseErrorMsg(e)) message.error(await extractSdkResponseErrorMsg(e))
} finally {
$e(`a:extension:${EXTENSION_ID}:export`)
} }
} }
@ -216,6 +221,8 @@ const handleDownload = async (url: string) => {
document.body.appendChild(link) document.body.appendChild(link)
link.click() link.click()
document.body.removeChild(link) document.body.removeChild(link)
$e(`a:extension:${EXTENSION_ID}:export:download`)
} }
function titleHelper() { function titleHelper() {

Loading…
Cancel
Save