Skip to content

HynLcc/plugin-auto-rank

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Teable Ranking Plugin

A Teable plugin for automatic ranking of table records.

πŸ“Ί Demo

Demo GIF

✨ Features

  • πŸ† Multiple Ranking Methods - Standard and Dense ranking algorithms
  • 🎯 Field Mapping - Flexible source and target field selection
  • πŸ“Š Group-based Ranking - Calculate rankings within specific groups
  • πŸ”§ Advanced Configuration - Sort direction, zero value handling, and more
  • 🎨 Theme Support - Full light/dark mode compatibility with automatic theme detection
  • 🌍 Internationalization - Complete i18n support (English/Chinese)
  • πŸ“± Responsive Design - Optimized for all screen sizes
  • ⚑ Performance Optimized - Built with React Query for efficient data fetching
  • πŸ›‘οΈ Error Handling - Comprehensive error reporting and user feedback
  • πŸ”Œ Teable Integration - Seamless integration with Teable tables and fields

πŸ› οΈ Tech Stack

Core Framework

  • Next.js 14.2.14 - React full-stack framework with App Router
  • React 18.2.0 - UI library with modern React features
  • TypeScript 5 - Type-safe JavaScript superset (strict mode enabled)

Teable Ecosystem

  • @teable/sdk - Plugin bridge and UI configuration
  • @teable/openapi - API client and type definitions
  • @teable/core - Core type definitions and utilities
  • @teable/ui-lib - Teable official UI component library (shadcn/ui based)
  • @teable/next-themes - Theme switching support

UI & Styling

  • Tailwind CSS 3.4.1 - Atomic CSS framework with Teable UI configuration
  • Lucide React - Icon library for modern interfaces

State Management & Data

  • @tanstack/react-query 4.36.1 - Server state management, caching, and synchronization
  • react-i18next 14.1.0 - Internationalization framework
  • i18next 23.10.1 - Core internationalization library

πŸš€ Getting Started

Prerequisites

  • Node.js 18+
  • npm or yarn
  • Teable account with plugin access

1. Install Dependencies

npm install

2. Start Development Server

npm run dev -p 3001

Visit http://localhost:3001 to view the plugin.

3. Build for Production

npm run build

4. Start Production Server

npm start

5. Code Quality Checks

npm run lint          # Run ESLint

πŸ“ Project Structure

src/
β”œβ”€β”€ app/                          # Next.js App Router
β”‚   β”œβ”€β”€ page.tsx                 # Main app entry with i18n and theme setup
β”‚   β”œβ”€β”€ Main.tsx                 # Theme and QueryClient integration
β”‚   β”œβ”€β”€ layout.tsx               # Root layout component
β”‚   └── globals.css              # Global styles and CSS variables
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ RankingPages.tsx         # Main ranking interface component
β”‚   β”œβ”€β”€ ErrorBoundary.tsx        # Error boundary component
β”‚   β”œβ”€β”€ context/                 # React Context providers
β”‚   β”‚   β”œβ”€β”€ EnvProvider.tsx      # Environment variable injection
β”‚   β”‚   β”œβ”€β”€ I18nProvider.tsx     # Internationalization provider
β”‚   β”‚   β”œβ”€β”€ getQueryClient.ts    # QueryClient configuration
β”‚   β”‚   └── types.ts             # TypeScript type definitions
β”‚   β”œβ”€β”€ ranking/                 # Ranking-specific components
β”‚   β”‚   β”œβ”€β”€ FieldSelector.tsx    # Field selection component
β”‚   β”‚   β”œβ”€β”€ GroupFieldSelector.tsx # Group field selection
β”‚   β”‚   β”œβ”€β”€ ViewSelector.tsx     # View selection component
β”‚   β”‚   β”œβ”€β”€ RankingConfig.tsx    # Ranking configuration UI
β”‚   β”‚   β”œβ”€β”€ RankingExecutor.tsx  # Ranking execution engine
β”‚   β”‚   β”œβ”€β”€ RankingAlgorithms.ts # Ranking algorithm implementation
β”‚   β”‚   └── types.ts             # Ranking type definitions
β”‚   └── ui/                      # UI utility components
β”‚       └── Icons.tsx            # Icon components
β”œβ”€β”€ hooks/                       # Custom React hooks
β”‚   β”œβ”€β”€ useInitApi.ts           # API initialization
β”‚   β”œβ”€β”€ useFields.ts            # Field data fetching
β”‚   β”œβ”€β”€ useFieldMap.ts          # Field mapping utilities
β”‚   β”œβ”€β”€ useGlobalUrlParams.ts   # URL parameter management
β”‚   β”œβ”€β”€ useToast.ts             # Toast notifications
β”‚   β”œβ”€β”€ useViewId.ts            # View ID management
β”‚   └── useViews.ts             # View data fetching
β”œβ”€β”€ lib/                         # Business logic and utilities
β”‚   └── api.ts                  # API configuration and authentication
β”œβ”€β”€ types/                       # Global type definitions
β”‚   └── index.ts                # Type exports
β”œβ”€β”€ locales/                     # Internationalization files
β”‚   β”œβ”€β”€ en.json                 # English translations
β”‚   └── zh.json                 # Chinese translations
└── image/                       # Static image assets
    └── 20251120012132_rec_.gif # Feature demo GIF

πŸ”§ Configuration

Plugin Parameters

The plugin reads configuration from URL parameters via EnvProvider.tsx:

  • baseId - Teable base identifier
  • pluginId - Plugin identifier
  • pluginInstallId - Plugin installation ID
  • tableId - Target table for ranking operations
  • shareId, positionId, positionType - UI positioning
  • lang, theme - Localization and theme settings

Ranking Configuration

The plugin supports the following ranking configurations:

Ranking Methods

  • Standard Ranking: 1, 2, 2, 4 - Standard competition ranking
  • Dense Ranking: 1, 2, 2, 3 - Dense ranking with no gaps
  • European Ranking: 1, 2, 2, 3 - European competition ranking

Zero Value Handling

  • Skip Zero Values: Ignore zero values in ranking calculations
  • Include Zero Values: Include zero values in ranking

Grouping

  • No Grouping: Calculate rankings across all records
  • Group-based: Calculate rankings within specified groups

🎨 Styling & Theming

CSS Architecture

  • CSS Variables - Comprehensive theme system with HSL color values
  • Responsive Design - Mobile-first approach with breakpoints
  • Component Isolation - Scoped styles for custom components
  • Dark Mode Support - Automatic theme detection and switching

UI Components

  • Shadcn/ui Components - Modern, accessible UI components
  • Teable UI Integration - Consistent with Teable design system
  • Form Controls - Custom form elements for ranking configuration

🌍 Internationalization

Supported languages:

  • English (en)
  • Chinese (zh)

Adding New Languages

  1. Create translation file in src/locales/[lang].json
  2. Update I18nProvider.tsx resources configuration
  3. Add language-specific content to components

πŸ”Œ Teable Integration

Plugin Bridge Usage

import { usePluginBridge } from '@teable/sdk';

const bridge = usePluginBridge();

// Listen for configuration changes
bridge.on('syncUIConfig', handleConfigChange);

// Get temporary token for API calls
const token = await bridge.getSelfTempToken();

API Integration

The plugin uses Teable's OpenAPI with automatic authentication:

import { openApi } from '@teable/openapi';

// All API calls are automatically authenticated
const fields = await openApi.getFields(tableId);
const records = await openApi.getTableRecords(tableId, viewId);

πŸ† Ranking Algorithms

The plugin implements two ranking algorithms:

Standard Ranking

// Example: Values [10, 20, 20, 30] β†’ Ranks [1, 2, 2, 4]
// Standard competition ranking with gaps

Dense Ranking

// Example: Values [10, 20, 20, 30] β†’ Ranks [1, 2, 2, 3]
// Dense ranking without gaps

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A Teable plugin for automatic ranking of table records.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors