mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-26 19:09:52 +00:00
feat: integrate nightly survey system into app
This commit is contained in:
@@ -50,6 +50,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<HelpCenterPopups :is-small="isSmall" />
|
||||
<NightlySurveyController />
|
||||
</nav>
|
||||
</template>
|
||||
|
||||
@@ -66,6 +67,7 @@ import SidebarSettingsButton from '@/components/sidebar/SidebarSettingsButton.vu
|
||||
import SidebarShortcutsToggleButton from '@/components/sidebar/SidebarShortcutsToggleButton.vue'
|
||||
import { useFeatureFlags } from '@/composables/useFeatureFlags'
|
||||
import { useSettingStore } from '@/platform/settings/settingStore'
|
||||
import NightlySurveyController from '@/platform/surveys/NightlySurveyController.vue'
|
||||
import { useTelemetry } from '@/platform/telemetry'
|
||||
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
|
||||
import { useCommandStore } from '@/stores/commandStore'
|
||||
|
||||
21
src/platform/surveys/NightlySurveyController.vue
Normal file
21
src/platform/surveys/NightlySurveyController.vue
Normal file
@@ -0,0 +1,21 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
|
||||
import { isCloud, isDesktop, isNightly } from '@/platform/distribution/types'
|
||||
|
||||
import NightlySurveyPopover from './NightlySurveyPopover.vue'
|
||||
import { getEnabledSurveys } from './surveyRegistry'
|
||||
|
||||
const isNightlyLocalhost = computed(() => isNightly && !isCloud && !isDesktop)
|
||||
|
||||
const enabledSurveys = computed(() => {
|
||||
if (!isNightlyLocalhost.value) return []
|
||||
return 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)
|
||||
})
|
||||
})
|
||||
30
src/platform/surveys/useSurveyFeatureTracking.ts
Normal file
30
src/platform/surveys/useSurveyFeatureTracking.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
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)
|
||||
const { trackUsage, useCount } = useFeatureUsageTracker(featureId)
|
||||
|
||||
function trackFeatureUsed() {
|
||||
if (!config?.enabled) return
|
||||
trackUsage()
|
||||
}
|
||||
|
||||
return {
|
||||
trackFeatureUsed,
|
||||
useCount
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user