mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-23 16:24:06 +00:00
feat: integrate nightly survey system into app
Amp-Thread-ID: https://ampcode.com/threads/T-019c88b1-2d4d-717f-b08c-e2f71c4d80fe
This commit is contained in:
@@ -51,13 +51,22 @@
|
||||
</div>
|
||||
</div>
|
||||
<HelpCenterPopups :is-small="isSmall" />
|
||||
<component :is="NightlySurveyController" v-if="NightlySurveyController" />
|
||||
</nav>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useResizeObserver } from '@vueuse/core'
|
||||
import { debounce } from 'es-toolkit/compat'
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import {
|
||||
computed,
|
||||
defineAsyncComponent,
|
||||
nextTick,
|
||||
onBeforeUnmount,
|
||||
onMounted,
|
||||
ref,
|
||||
watch
|
||||
} from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
import HelpCenterPopups from '@/components/helpcenter/HelpCenterPopups.vue'
|
||||
@@ -67,7 +76,7 @@ import SidebarBottomPanelToggleButton from '@/components/sidebar/SidebarBottomPa
|
||||
import SidebarSettingsButton from '@/components/sidebar/SidebarSettingsButton.vue'
|
||||
import SidebarShortcutsToggleButton from '@/components/sidebar/SidebarShortcutsToggleButton.vue'
|
||||
import { useFeatureFlags } from '@/composables/useFeatureFlags'
|
||||
import { isCloud } from '@/platform/distribution/types'
|
||||
import { isCloud, isDesktop, isNightly } from '@/platform/distribution/types'
|
||||
import { useSettingStore } from '@/platform/settings/settingStore'
|
||||
import { useTelemetry } from '@/platform/telemetry'
|
||||
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
|
||||
@@ -84,6 +93,13 @@ import SidebarIcon from './SidebarIcon.vue'
|
||||
import SidebarLogoutIcon from './SidebarLogoutIcon.vue'
|
||||
import SidebarTemplatesButton from './SidebarTemplatesButton.vue'
|
||||
|
||||
const NightlySurveyController =
|
||||
isNightly && !isCloud && !isDesktop
|
||||
? defineAsyncComponent(
|
||||
() => import('@/platform/surveys/NightlySurveyController.vue')
|
||||
)
|
||||
: undefined
|
||||
|
||||
const { t } = useI18n()
|
||||
const workspaceStore = useWorkspaceStore()
|
||||
const settingStore = useSettingStore()
|
||||
|
||||
14
src/platform/surveys/NightlySurveyController.vue
Normal file
14
src/platform/surveys/NightlySurveyController.vue
Normal file
@@ -0,0 +1,14 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
|
||||
import NightlySurveyPopover from './NightlySurveyPopover.vue'
|
||||
import { getEnabledSurveys } from './surveyRegistry'
|
||||
|
||||
const enabledSurveys = computed(() => getEnabledSurveys())
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<template v-for="config in enabledSurveys" :key="config.featureId">
|
||||
<NightlySurveyPopover :config="config" />
|
||||
</template>
|
||||
</template>
|
||||
61
src/platform/surveys/useSurveyFeatureTracking.test.ts
Normal file
61
src/platform/surveys/useSurveyFeatureTracking.test.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const mockSurveyConfigs: Record<string, { enabled: boolean }> = {}
|
||||
|
||||
vi.mock('./surveyRegistry', () => ({
|
||||
getSurveyConfig: (featureId: string) => mockSurveyConfigs[featureId]
|
||||
}))
|
||||
|
||||
describe('useSurveyFeatureTracking', () => {
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
vi.resetModules()
|
||||
Object.keys(mockSurveyConfigs).forEach(
|
||||
(key) => delete mockSurveyConfigs[key]
|
||||
)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
localStorage.clear()
|
||||
})
|
||||
|
||||
it('tracks usage when config is enabled', async () => {
|
||||
mockSurveyConfigs['test-feature'] = { enabled: true }
|
||||
|
||||
const { useSurveyFeatureTracking } =
|
||||
await import('./useSurveyFeatureTracking')
|
||||
const { trackFeatureUsed, useCount } =
|
||||
useSurveyFeatureTracking('test-feature')
|
||||
|
||||
expect(useCount.value).toBe(0)
|
||||
|
||||
trackFeatureUsed()
|
||||
|
||||
expect(useCount.value).toBe(1)
|
||||
})
|
||||
|
||||
it('does not track when config is disabled', async () => {
|
||||
mockSurveyConfigs['disabled-feature'] = { enabled: false }
|
||||
|
||||
const { useSurveyFeatureTracking } =
|
||||
await import('./useSurveyFeatureTracking')
|
||||
const { trackFeatureUsed, useCount } =
|
||||
useSurveyFeatureTracking('disabled-feature')
|
||||
|
||||
trackFeatureUsed()
|
||||
|
||||
expect(useCount.value).toBe(0)
|
||||
})
|
||||
|
||||
it('does not track when config does not exist', async () => {
|
||||
const { useSurveyFeatureTracking } =
|
||||
await import('./useSurveyFeatureTracking')
|
||||
const { trackFeatureUsed, useCount } = useSurveyFeatureTracking(
|
||||
'nonexistent-feature'
|
||||
)
|
||||
|
||||
trackFeatureUsed()
|
||||
|
||||
expect(useCount.value).toBe(0)
|
||||
})
|
||||
})
|
||||
35
src/platform/surveys/useSurveyFeatureTracking.ts
Normal file
35
src/platform/surveys/useSurveyFeatureTracking.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { computed } from 'vue'
|
||||
|
||||
import { getSurveyConfig } from './surveyRegistry'
|
||||
import { useFeatureUsageTracker } from './useFeatureUsageTracker'
|
||||
|
||||
/**
|
||||
* Convenience composable for tracking feature usage for surveys.
|
||||
* Use this at the feature site to track when a feature is used.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* const { trackFeatureUsed } = useSurveyFeatureTracking('simple-mode')
|
||||
*
|
||||
* function onFeatureAction() {
|
||||
* trackFeatureUsed()
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export function useSurveyFeatureTracking(featureId: string) {
|
||||
const config = getSurveyConfig(featureId)
|
||||
|
||||
if (!config?.enabled) {
|
||||
return {
|
||||
trackFeatureUsed: () => {},
|
||||
useCount: computed(() => 0)
|
||||
}
|
||||
}
|
||||
|
||||
const { trackUsage, useCount } = useFeatureUsageTracker(featureId)
|
||||
|
||||
return {
|
||||
trackFeatureUsed: trackUsage,
|
||||
useCount
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user