浏览代码

fix(dashboard): Fix dashboard bulk action hook imports (#3640)

Michael Bromley 6 月之前
父节点
当前提交
969e1a1819
共有 17 个文件被更改,包括 144 次插入24 次删除
  1. 4 0
      .github/workflows/build_test_dashboard.yml
  2. 108 9
      packages/dashboard/scripts/check-lib-imports.js
  3. 2 1
      packages/dashboard/src/app/common/delete-bulk-action.tsx
  4. 1 1
      packages/dashboard/src/app/common/duplicate-bulk-action.tsx
  5. 4 1
      packages/dashboard/src/app/routes/_authenticated/_collections/components/collection-bulk-actions.tsx
  6. 2 1
      packages/dashboard/src/app/routes/_authenticated/_facets/components/facet-bulk-actions.tsx
  7. 2 1
      packages/dashboard/src/app/routes/_authenticated/_payment-methods/components/payment-method-bulk-actions.tsx
  8. 3 1
      packages/dashboard/src/app/routes/_authenticated/_product-variants/components/product-variant-bulk-actions.tsx
  9. 3 1
      packages/dashboard/src/app/routes/_authenticated/_products/components/product-bulk-actions.tsx
  10. 1 1
      packages/dashboard/src/app/routes/_authenticated/_products/components/product-variants-table.tsx
  11. 2 1
      packages/dashboard/src/app/routes/_authenticated/_promotions/components/promotion-bulk-actions.tsx
  12. 2 1
      packages/dashboard/src/app/routes/_authenticated/_shipping-methods/components/shipping-method-bulk-actions.tsx
  13. 2 1
      packages/dashboard/src/app/routes/_authenticated/_stock-locations/components/stock-location-bulk-actions.tsx
  14. 2 1
      packages/dashboard/src/lib/components/shared/assign-to-channel-bulk-action.tsx
  15. 2 1
      packages/dashboard/src/lib/components/shared/remove-from-channel-bulk-action.tsx
  16. 2 1
      packages/dashboard/src/lib/framework/dashboard-widget/latest-orders-widget/index.tsx
  17. 2 1
      packages/dashboard/src/lib/framework/dashboard-widget/orders-summary/index.tsx

+ 4 - 0
.github/workflows/build_test_dashboard.yml

@@ -70,6 +70,10 @@ jobs:
           npm install
         env:
           CI: true
+      - name: Check for banned imports
+        run: |
+          cd $GITHUB_WORKSPACE/packages/dashboard
+          node scripts/check-lib-imports.js
       - name: Build & publish dashboard
         run: |
           nohup verdaccio --config $HOME/.config/verdaccio/config.yaml &

+ 108 - 9
packages/dashboard/scripts/check-lib-imports.js

@@ -14,9 +14,14 @@ const isDashboardDir = currentDir.endsWith('packages/dashboard');
 const HOOKS_DIR = isDashboardDir
     ? path.join(__dirname, '../src/lib/hooks')
     : path.join(currentDir, 'packages/dashboard/src/lib/hooks');
+const DASHBOARD_SRC_DIR = isDashboardDir
+    ? path.join(__dirname, '../src')
+    : path.join(currentDir, 'packages/dashboard/src');
 
 // Required prefix for imports in hook files
 const REQUIRED_PREFIX = '@/vdb';
+// Banned import pattern
+const BANNED_IMPORT = '@/vdb/index.js';
 
 function findHookFiles(dir) {
     const files = [];
@@ -37,6 +42,31 @@ function findHookFiles(dir) {
     return files;
 }
 
+function findDashboardFiles(dir) {
+    const files = [];
+
+    function scanDirectory(currentDir) {
+        const items = fs.readdirSync(currentDir);
+
+        for (const item of items) {
+            const fullPath = path.join(currentDir, item);
+            const stat = fs.statSync(fullPath);
+
+            if (stat.isDirectory()) {
+                // Skip node_modules and other common directories to avoid
+                if (!['node_modules', '.git', 'dist', 'build', '.next'].includes(item)) {
+                    scanDirectory(fullPath);
+                }
+            } else if (stat.isFile() && (item.endsWith('.ts') || item.endsWith('.tsx'))) {
+                files.push(fullPath);
+            }
+        }
+    }
+
+    scanDirectory(dir);
+    return files;
+}
+
 function checkFileForBadImports(filePath) {
     const content = fs.readFileSync(filePath, 'utf8');
     const lines = content.split('\n');
@@ -71,11 +101,34 @@ function checkFileForBadImports(filePath) {
     return badImports;
 }
 
+function checkFileForBannedImports(filePath) {
+    const content = fs.readFileSync(filePath, 'utf8');
+    const lines = content.split('\n');
+    const badImports = [];
+
+    for (let i = 0; i < lines.length; i++) {
+        const line = lines[i];
+        const trimmedLine = line.trim();
+
+        // Check for import statements
+        if (trimmedLine.startsWith('import') && trimmedLine.includes(BANNED_IMPORT)) {
+            badImports.push({
+                line: i + 1,
+                content: trimmedLine,
+                reason: `Import from '${BANNED_IMPORT}' is not allowed anywhere in the dashboard app`,
+            });
+        }
+    }
+
+    return badImports;
+}
+
 function main() {
-    console.log(
-        '🔍 Checking for import patterns in hook files (use-*.ts/tsx) in src/lib/hooks directory...\n',
-    );
-    console.log('✅ Requirements:');
+    console.log('🔍 Checking for import patterns in the dashboard app...\n');
+
+    // Check hook files
+    console.log('📁 Checking hook files (use-*.ts/tsx) in src/lib/hooks directory...');
+    console.log('✅ Hook file requirements:');
     console.log(`   - All imports must start with ${REQUIRED_PREFIX}`);
     console.log('   - Relative imports going up directories (../) are not allowed');
     console.log('   - Relative imports in same directory (./) are allowed');
@@ -86,11 +139,11 @@ function main() {
         process.exit(1);
     }
 
-    const files = findHookFiles(HOOKS_DIR);
+    const hookFiles = findHookFiles(HOOKS_DIR);
     let hasBadImports = false;
     let totalBadImports = 0;
 
-    for (const file of files) {
+    for (const file of hookFiles) {
         const relativePath = path.relative(process.cwd(), file);
         const badImports = checkFileForBadImports(file);
 
@@ -108,15 +161,61 @@ function main() {
     }
 
     if (hasBadImports) {
-        console.log(`❌ Found ${totalBadImports} bad import(s) in ${files.length} hook file(s)`);
+        console.log(`❌ Found ${totalBadImports} bad import(s) in ${hookFiles.length} hook file(s)`);
         console.log(
             `💡 All imports in hook files must start with ${REQUIRED_PREFIX} and must not use relative paths going up directories`,
         );
-        process.exit(1);
     } else {
-        console.log(`✅ No bad imports found in ${files.length} hook file(s)`);
+        console.log(`✅ No bad imports found in ${hookFiles.length} hook file(s)`);
         console.log(`🎉 All imports in hook files are using ${REQUIRED_PREFIX} prefix`);
     }
+
+    // Check all dashboard files for banned imports
+    console.log('\n📁 Checking all dashboard files for banned imports...');
+    console.log('✅ Dashboard-wide requirements:');
+    console.log(`   - Import from '${BANNED_IMPORT}' is not allowed anywhere`);
+    console.log('');
+
+    if (!fs.existsSync(DASHBOARD_SRC_DIR)) {
+        console.error('❌ src directory not found!');
+        process.exit(1);
+    }
+
+    const dashboardFiles = findDashboardFiles(DASHBOARD_SRC_DIR);
+    let hasBannedImports = false;
+    let totalBannedImports = 0;
+
+    for (const file of dashboardFiles) {
+        const relativePath = path.relative(process.cwd(), file);
+        const bannedImports = checkFileForBannedImports(file);
+
+        if (bannedImports.length > 0) {
+            hasBannedImports = true;
+            totalBannedImports += bannedImports.length;
+
+            console.log(`❌ ${relativePath}:`);
+            for (const bannedImport of bannedImports) {
+                console.log(`   Line ${bannedImport.line}: ${bannedImport.content}`);
+                console.log(`      Reason: ${bannedImport.reason}`);
+            }
+            console.log('');
+        }
+    }
+
+    if (hasBannedImports) {
+        console.log(
+            `❌ Found ${totalBannedImports} banned import(s) in ${dashboardFiles.length} dashboard file(s)`,
+        );
+        console.log(`💡 Import from '${BANNED_IMPORT}' is not allowed anywhere in the dashboard app`);
+    } else {
+        console.log(`✅ No banned imports found in ${dashboardFiles.length} dashboard file(s)`);
+        console.log(`🎉 All dashboard files are free of banned imports`);
+    }
+
+    // Exit with error if any issues found
+    if (hasBadImports || hasBannedImports) {
+        process.exit(1);
+    }
 }
 
 main();

+ 2 - 1
packages/dashboard/src/app/common/delete-bulk-action.tsx

@@ -3,8 +3,9 @@ import { TrashIcon } from 'lucide-react';
 import { toast } from 'sonner';
 
 import { DataTableBulkActionItem } from '@/vdb/components/data-table/data-table-bulk-action-item.js';
+import { usePaginatedList } from '@/vdb/components/shared/paginated-list-data-table.js';
+import { getMutationName } from '@/vdb/framework/document-introspection/get-document-structure.js';
 import { api } from '@/vdb/graphql/api.js';
-import { getMutationName, usePaginatedList } from '@/vdb/index.js';
 import { Trans, useLingui } from '@/vdb/lib/trans.js';
 
 interface DeleteBulkActionProps {

+ 1 - 1
packages/dashboard/src/app/common/duplicate-bulk-action.tsx

@@ -4,9 +4,9 @@ import { useState } from 'react';
 import { toast } from 'sonner';
 
 import { DataTableBulkActionItem } from '@/vdb/components/data-table/data-table-bulk-action-item.js';
+import { usePaginatedList } from '@/vdb/components/shared/paginated-list-data-table.js';
 import { api } from '@/vdb/graphql/api.js';
 import { duplicateEntityDocument } from '@/vdb/graphql/common-operations.js';
-import { usePaginatedList } from '@/vdb/index.js';
 import { Trans, useLingui } from '@/vdb/lib/trans.js';
 
 interface DuplicateBulkActionProps {

+ 4 - 1
packages/dashboard/src/app/routes/_authenticated/_collections/components/collection-bulk-actions.tsx

@@ -6,7 +6,10 @@ import { Trans } from '@/vdb/lib/trans.js';
 import { AssignToChannelBulkAction } from '@/vdb/components/shared/assign-to-channel-bulk-action.js';
 import { RemoveFromChannelBulkAction } from '@/vdb/components/shared/remove-from-channel-bulk-action.js';
 import { api } from '@/vdb/graphql/api.js';
-import { BulkActionComponent, useChannel, DataTableBulkActionItem, usePaginatedList } from '@/vdb/index.js';
+import { BulkActionComponent } from '@/vdb/framework/extension-api/types/data-table.js';
+import { useChannel } from '@/vdb/hooks/use-channel.js';
+import { DataTableBulkActionItem } from '@/vdb/components/data-table/data-table-bulk-action-item.js';
+import { usePaginatedList } from '@/vdb/components/shared/paginated-list-data-table.js';
 import { DeleteBulkAction } from '../../../../common/delete-bulk-action.js';
 import { DuplicateBulkAction } from '../../../../common/duplicate-bulk-action.js';
 import {

+ 2 - 1
packages/dashboard/src/app/routes/_authenticated/_facets/components/facet-bulk-actions.tsx

@@ -4,7 +4,8 @@ import { AssignToChannelBulkAction } from '@/vdb/components/shared/assign-to-cha
 import { RemoveFromChannelBulkAction } from '@/vdb/components/shared/remove-from-channel-bulk-action.js';
 import { api } from '@/vdb/graphql/api.js';
 import { ResultOf } from '@/vdb/graphql/graphql.js';
-import { BulkActionComponent, useChannel } from '@/vdb/index.js';
+import { BulkActionComponent } from '@/vdb/framework/extension-api/types/data-table.js';
+import { useChannel } from '@/vdb/hooks/use-channel.js';
 import { useLingui } from '@/vdb/lib/trans.js';
 import { DeleteBulkAction } from '../../../../common/delete-bulk-action.js';
 import { DuplicateBulkAction } from '../../../../common/duplicate-bulk-action.js';

+ 2 - 1
packages/dashboard/src/app/routes/_authenticated/_payment-methods/components/payment-method-bulk-actions.tsx

@@ -1,7 +1,8 @@
 import { AssignToChannelBulkAction } from '@/vdb/components/shared/assign-to-channel-bulk-action.js';
 import { RemoveFromChannelBulkAction } from '@/vdb/components/shared/remove-from-channel-bulk-action.js';
+import { BulkActionComponent } from '@/vdb/framework/extension-api/types/data-table.js';
 import { api } from '@/vdb/graphql/api.js';
-import { BulkActionComponent, useChannel } from '@/vdb/index.js';
+import { useChannel } from '@/vdb/hooks/use-channel.js';
 import { DeleteBulkAction } from '../../../../common/delete-bulk-action.js';
 
 import {

+ 3 - 1
packages/dashboard/src/app/routes/_authenticated/_product-variants/components/product-variant-bulk-actions.tsx

@@ -6,7 +6,9 @@ import { AssignToChannelBulkAction } from '@/vdb/components/shared/assign-to-cha
 import { usePriceFactor } from '@/vdb/components/shared/assign-to-channel-dialog.js';
 import { RemoveFromChannelBulkAction } from '@/vdb/components/shared/remove-from-channel-bulk-action.js';
 import { api } from '@/vdb/graphql/api.js';
-import { BulkActionComponent, useChannel, usePaginatedList } from '@/vdb/index.js';
+import { BulkActionComponent } from '@/vdb/framework/extension-api/types/data-table.js';
+import { useChannel } from '@/vdb/hooks/use-channel.js';
+import { usePaginatedList } from '@/vdb/components/shared/paginated-list-data-table.js';
 import { Trans } from '@/vdb/lib/trans.js';
 import { DeleteBulkAction } from '../../../../common/delete-bulk-action.js';
 

+ 3 - 1
packages/dashboard/src/app/routes/_authenticated/_products/components/product-bulk-actions.tsx

@@ -4,9 +4,11 @@ import { useState } from 'react';
 import { DataTableBulkActionItem } from '@/vdb/components/data-table/data-table-bulk-action-item.js';
 import { AssignToChannelBulkAction } from '@/vdb/components/shared/assign-to-channel-bulk-action.js';
 import { usePriceFactor } from '@/vdb/components/shared/assign-to-channel-dialog.js';
+import { usePaginatedList } from '@/vdb/components/shared/paginated-list-data-table.js';
 import { RemoveFromChannelBulkAction } from '@/vdb/components/shared/remove-from-channel-bulk-action.js';
+import { BulkActionComponent } from '@/vdb/framework/extension-api/types/data-table.js';
 import { api } from '@/vdb/graphql/api.js';
-import { BulkActionComponent, useChannel, usePaginatedList } from '@/vdb/index.js';
+import { useChannel } from '@/vdb/hooks/use-channel.js';
 import { Trans } from '@/vdb/lib/trans.js';
 import { DeleteBulkAction } from '../../../../common/delete-bulk-action.js';
 import { DuplicateBulkAction } from '../../../../common/duplicate-bulk-action.js';

+ 1 - 1
packages/dashboard/src/app/routes/_authenticated/_products/components/product-variants-table.tsx

@@ -1,4 +1,5 @@
 import { Money } from '@/vdb/components/data-display/money.js';
+import { DetailPageButton } from '@/vdb/components/shared/detail-page-button.js';
 import {
     PaginatedListDataTable,
     PaginatedListRefresherRegisterFn,
@@ -6,7 +7,6 @@ import {
 import { StockLevelLabel } from '@/vdb/components/shared/stock-level-label.js';
 import { graphql } from '@/vdb/graphql/graphql.js';
 import { useLocalFormat } from '@/vdb/hooks/use-local-format.js';
-import { DetailPageButton } from '@/vdb/index.js';
 import { ColumnFiltersState, SortingState } from '@tanstack/react-table';
 import { useState } from 'react';
 import { productVariantListDocument } from '../products.graphql.js';

+ 2 - 1
packages/dashboard/src/app/routes/_authenticated/_promotions/components/promotion-bulk-actions.tsx

@@ -1,7 +1,8 @@
 import { AssignToChannelBulkAction } from '@/vdb/components/shared/assign-to-channel-bulk-action.js';
 import { RemoveFromChannelBulkAction } from '@/vdb/components/shared/remove-from-channel-bulk-action.js';
+import { BulkActionComponent } from '@/vdb/framework/extension-api/types/data-table.js';
 import { api } from '@/vdb/graphql/api.js';
-import { BulkActionComponent, useChannel } from '@/vdb/index.js';
+import { useChannel } from '@/vdb/hooks/use-channel.js';
 import { DeleteBulkAction } from '../../../../common/delete-bulk-action.js';
 import { DuplicateBulkAction } from '../../../../common/duplicate-bulk-action.js';
 

+ 2 - 1
packages/dashboard/src/app/routes/_authenticated/_shipping-methods/components/shipping-method-bulk-actions.tsx

@@ -1,7 +1,8 @@
 import { AssignToChannelBulkAction } from '@/vdb/components/shared/assign-to-channel-bulk-action.js';
 import { RemoveFromChannelBulkAction } from '@/vdb/components/shared/remove-from-channel-bulk-action.js';
+import { BulkActionComponent } from '@/vdb/framework/extension-api/types/data-table.js';
 import { api } from '@/vdb/graphql/api.js';
-import { BulkActionComponent, useChannel } from '@/vdb/index.js';
+import { useChannel } from '@/vdb/hooks/use-channel.js';
 import { DeleteBulkAction } from '../../../../common/delete-bulk-action.js';
 
 import {

+ 2 - 1
packages/dashboard/src/app/routes/_authenticated/_stock-locations/components/stock-location-bulk-actions.tsx

@@ -1,7 +1,8 @@
 import { AssignToChannelBulkAction } from '@/vdb/components/shared/assign-to-channel-bulk-action.js';
 import { RemoveFromChannelBulkAction } from '@/vdb/components/shared/remove-from-channel-bulk-action.js';
 import { api } from '@/vdb/graphql/api.js';
-import { BulkActionComponent, useChannel } from '@/vdb/index.js';
+import { BulkActionComponent } from '@/vdb/framework/extension-api/types/data-table.js';
+import { useChannel } from '@/vdb/hooks/use-channel.js';
 import { DeleteBulkAction } from '../../../../common/delete-bulk-action.js';
 
 import {

+ 2 - 1
packages/dashboard/src/lib/components/shared/assign-to-channel-bulk-action.tsx

@@ -3,7 +3,8 @@ import { useState } from 'react';
 
 import { DataTableBulkActionItem } from '@/vdb/components/data-table/data-table-bulk-action-item.js';
 import { AssignToChannelDialog } from '@/vdb/components/shared/assign-to-channel-dialog.js';
-import { useChannel, usePaginatedList } from '@/vdb/index.js';
+import { usePaginatedList } from '@/vdb/components/shared/paginated-list-data-table.js';
+import { useChannel } from '@/vdb/hooks/use-channel.js';
 import { Trans } from '@/vdb/lib/trans.js';
 
 interface AssignToChannelBulkActionProps {

+ 2 - 1
packages/dashboard/src/lib/components/shared/remove-from-channel-bulk-action.tsx

@@ -3,8 +3,9 @@ import { LayersIcon } from 'lucide-react';
 import { toast } from 'sonner';
 
 import { DataTableBulkActionItem } from '@/vdb/components/data-table/data-table-bulk-action-item.js';
+import { usePaginatedList } from '@/vdb/components/shared/paginated-list-data-table.js';
 import { ResultOf } from '@/vdb/graphql/graphql.js';
-import { useChannel, usePaginatedList } from '@/vdb/index.js';
+import { useChannel } from '@/vdb/hooks/use-channel.js';
 import { Trans, useLingui } from '@/vdb/lib/trans.js';
 
 interface RemoveFromChannelBulkActionProps {

+ 2 - 1
packages/dashboard/src/lib/framework/dashboard-widget/latest-orders-widget/index.tsx

@@ -1,5 +1,6 @@
+import { PaginatedListDataTable } from '@/vdb/components/shared/paginated-list-data-table.js';
 import { Button } from '@/vdb/components/ui/button.js';
-import { PaginatedListDataTable, useLocalFormat } from '@/vdb/index.js';
+import { useLocalFormat } from '@/vdb/hooks/use-local-format.js';
 import { Link } from '@tanstack/react-router';
 import { ColumnFiltersState, SortingState } from '@tanstack/react-table';
 import { formatRelative } from 'date-fns';

+ 2 - 1
packages/dashboard/src/lib/framework/dashboard-widget/orders-summary/index.tsx

@@ -1,7 +1,8 @@
 import { AnimatedCurrency, AnimatedNumber } from '@/vdb/components/shared/animated-number.js';
 import { Tabs, TabsList, TabsTrigger } from '@/vdb/components/ui/tabs.js';
 import { api } from '@/vdb/graphql/api.js';
-import { useChannel, useLocalFormat } from '@/vdb/index.js';
+import { useChannel } from '@/vdb/hooks/use-channel.js';
+import { useLocalFormat } from '@/vdb/hooks/use-local-format.js';
 import { useQuery } from '@tanstack/react-query';
 import { endOfDay, endOfMonth, startOfDay, startOfMonth, subDays, subMonths } from 'date-fns';
 import { useMemo, useState } from 'react';