refactor(web): remove legacy enableBilling consumers (#41913)

This commit is contained in:
yyh authored and GitHub committed 2026-09-07 07:56:01 +00:00
1 parent c7423ffb2d
commit fc0136647f
96 files changed
+1273 -1291

No files matched your search

@@ -1,4 +1,5 @@
import type { CloudPlan } from '@dify/contracts/api/console/features/types.gen'
import type { ReactElement } from 'react'
import type { Mock } from 'vite-plus/test'
import type { DocumentIndexingStatus, IndexingStatusResponse } from '@/models/datasets'
import type { InitialDocumentDetail } from '@/models/pipeline'
@@ -6,7 +7,7 @@ import { fireEvent, screen, waitFor } from '@testing-library/react'
import * as React from 'react'
import { IndexingType } from '@/app/components/datasets/create/step-two'
import { DatasourceType } from '@/models/pipeline'
import { renderWithConsoleQuery as render } from '@/test/console/query-data'
import { renderWithConsoleQuery } from '@/test/console/query-data'
import { RETRIEVE_METHOD } from '@/types/app'
import EmbeddingProcess from '../index'
@@ -29,14 +30,8 @@ vi.mock('@/next/link', () => ({
}))
// Mock provider context
let mockEnableBilling = false
let deploymentEdition: 'CLOUD' | 'COMMUNITY' = 'COMMUNITY'
let mockPlanType: CloudPlan = 'sandbox'
vi.mock('@/context/provider-context', () => ({
useProviderContext: () => ({
enableBilling: mockEnableBilling,
plan: { type: mockPlanType },
}),
}))
vi.mock('@/app/components/datasets/common/vector-space-admission-alert', () => ({
default: ({
@@ -142,6 +137,13 @@ const createDefaultProps = (
...overrides,
})
function render(ui: ReactElement) {
return renderWithConsoleQuery(ui, {
systemFeatures: { deployment_edition: deploymentEdition },
features: { billing: { subscription: { plan: mockPlanType } } },
})
}
describe('EmbeddingProcess', () => {
beforeEach(() => {
vi.clearAllMocks()
@@ -151,7 +153,7 @@ describe('EmbeddingProcess', () => {
documentIdCounter = 0
// Reset mock states
mockEnableBilling = false
deploymentEdition = 'COMMUNITY'
mockPlanType = 'sandbox'
mockIndexingStatusData = []
@@ -192,7 +194,7 @@ describe('EmbeddingProcess', () => {
describe('Billing and Upgrade Banner', () => {
// Tests for billing-related UI
it('should not show upgrade banner when billing is disabled', () => {
mockEnableBilling = false
deploymentEdition = 'COMMUNITY'
const props = createDefaultProps()
render(<EmbeddingProcess {...props} />)
@@ -203,7 +205,7 @@ describe('EmbeddingProcess', () => {
})
it('should show upgrade banner when billing is enabled and plan is not team', () => {
mockEnableBilling = true
deploymentEdition = 'CLOUD'
mockPlanType = 'sandbox'
const props = createDefaultProps()
@@ -215,7 +217,7 @@ describe('EmbeddingProcess', () => {
})
it('should not show upgrade banner when plan is team', () => {
mockEnableBilling = true
deploymentEdition = 'CLOUD'
mockPlanType = 'team'
const props = createDefaultProps()
@@ -227,7 +229,7 @@ describe('EmbeddingProcess', () => {
})
it('should show upgrade banner for professional plan', () => {
mockEnableBilling = true
deploymentEdition = 'CLOUD'
mockPlanType = 'professional'
const props = createDefaultProps()
@@ -379,7 +381,7 @@ describe('EmbeddingProcess', () => {
})
it('should not suggest an upgrade to team users', async () => {
mockEnableBilling = true
deploymentEdition = 'CLOUD'
mockPlanType = 'team'
const doc1 = createMockDocument({ id: 'doc-1' })
mockIndexingStatusData = [
@@ -1052,7 +1054,7 @@ describe('EmbeddingProcess', () => {
describe('Priority Label', () => {
// Tests for priority label display
it('should show priority label when billing is enabled', async () => {
mockEnableBilling = true
deploymentEdition = 'CLOUD'
mockPlanType = 'sandbox'
const doc1 = createMockDocument({ id: 'doc-1' })
mockIndexingStatusData = [
@@ -1071,7 +1073,7 @@ describe('EmbeddingProcess', () => {
})
it('should not show priority label when billing is disabled', async () => {
mockEnableBilling = false
deploymentEdition = 'COMMUNITY'
const doc1 = createMockDocument({ id: 'doc-1' })
mockIndexingStatusData = [
createMockIndexingStatus({ id: 'doc-1', indexing_status: 'indexing' }),
@@ -13,6 +13,8 @@ import {
RiLoader2Fill,
RiTerminalBoxLine,
} from '@remixicon/react'
import { useQuery } from '@tanstack/react-query'
import { useAtomValue } from 'jotai'
import * as React from 'react'
import { useEffect, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
@@ -22,10 +24,11 @@ import PriorityLabel from '@/app/components/billing/priority-label'
import UpgradeBtn from '@/app/components/billing/upgrade-btn'
import DocumentFileIcon from '@/app/components/datasets/common/document-file-icon'
import VectorSpaceAdmissionAlert from '@/app/components/datasets/common/vector-space-admission-alert'
import { useProviderContext } from '@/context/provider-context'
import { deploymentEditionAtom } from '@/features/system-features/state'
import { useDatasetApiAccessUrl } from '@/hooks/use-api-access-url'
import { DatasourceType } from '@/models/pipeline'
import Link from '@/next/link'
import { consoleQuery } from '@/service/client'
import { useIndexingStatusBatch, useProcessRule } from '@/service/knowledge/use-dataset'
import { useInvalidDocumentList } from '@/service/knowledge/use-document'
import RuleDetail from './rule-detail'
@@ -46,7 +49,13 @@ const EmbeddingProcess = ({
retrievalMethod,
}: EmbeddingProcessProps) => {
const { t } = useTranslation()
const { enableBilling, plan } = useProviderContext()
const deploymentEdition = useAtomValue(deploymentEditionAtom)
const { data: plan } = useQuery(
consoleQuery.features.get.queryOptions({
enabled: deploymentEdition === 'CLOUD',
select: (data) => data.billing.subscription.plan,
}),
)
const [indexingStatusBatchDetail, setIndexingStatusDetail] = useState<IndexingStatusResponse[]>(
[],
)
@@ -114,7 +123,8 @@ const EmbeddingProcess = ({
),
[indexingStatusBatchDetail],
)
const showUpgrade = enableBilling && (plan.type === 'sandbox' || plan.type === 'professional')
const showUpgrade =
deploymentEdition === 'CLOUD' && (plan === 'sandbox' || plan === 'professional')
const getSourceName = (id: string) => {
const doc = documents.find((document) => document.id === id)
@@ -166,7 +176,7 @@ const EmbeddingProcess = ({
planLimitMb={vectorSpaceAdmissionError.vector_space_limit_mb}
/>
)}
{enableBilling && plan.type !== 'team' && (
{deploymentEdition === 'CLOUD' && (plan === 'sandbox' || plan === 'professional') && (
<div className="flex h-13 items-center gap-x-2 rounded-xl border-[0.5px] border-components-panel-border-subtle bg-components-panel-on-panel-item-bg p-2.5 pl-3 shadow-xs shadow-shadow-shadow-3">
<div className="flex shrink-0 items-center justify-center rounded-lg border-[0.5px] border-divider-subtle bg-util-colors-blue-brand-blue-brand-500 shadow-md shadow-shadow-shadow-5">
<RiAedFill className="size-4 text-text-primary-on-surface" />
@@ -216,7 +226,7 @@ const EmbeddingProcess = ({
<div className="truncate system-xs-medium text-text-secondary">
{getSourceName(indexingStatusDetail.id)}
</div>
{enableBilling && <PriorityLabel className="ml-0" />}
<PriorityLabel className="ml-0" />
</div>
{isSourceEmbedding(indexingStatusDetail) && (
<div className="shrink-0 text-xs text-text-secondary">{`${getSourcePercent(indexingStatusDetail)}%`}</div>