发布

  • [OPIK-3213] [FE] Address PR review comments and optimize dashboard widgets (#4315)

    frostbyte_neo 发布于 2025-12-02 14:26:44 +00:00

    Code Quality Improvements:

    • Remove unnecessary object spread in useDashboardCreateMutation
    • Simplify onClick handler in AddSectionButton (remove arrow wrapper)
    • Make widget categories dynamic using Object.values()
    • Refactor TextMarkdownEditor with separate handlers (handleTitleChange, handleSubtitleChange, handleContentChange)

    Performance Optimizations:

    • Optimize widget selectors with conditional subscription pattern
    • Only subscribe to previewWidget when in preview mode
    • Prevents unnecessary re-renders when preview updates
    • Apply to all three widgets (ProjectMetrics, ProjectStatsCard, TextMarkdown)

    Form Management:

    • Replace complex form.reset useEffect with key prop pattern
    • Add key={widgetData.type} to force remount on type change
    • Remove useEffect with extensive dependency arrays
    • Simpler and more predictable form behavior

    Files changed:

    • useDashboardCreateMutation.ts
    • AddSectionButton.tsx
    • WidgetConfigDialogAddStep.tsx
    • WidgetConfigForm.tsx
    • ProjectMetricsEditor.tsx, ProjectMetricsWidget.tsx
    • ProjectStatsCardEditor.tsx, ProjectStatsCardWidget.tsx
    • TextMarkdownEditor.tsx, TextMarkdownWidget.tsx
    下载附件