common.ts


Overview

The common.ts file defines a set of TypeScript interfaces commonly used for managing UI state related to pagination and modal dialogs within an application. These interfaces provide standardized type contracts that help enforce consistent state handling and component behavior across different parts of the system.

This file primarily focuses on:

By centralizing these interfaces here, the file promotes reusability and maintainability of UI-related state management patterns.


Interfaces

1. Pagination

Represents the state of pagination controls typically used in paginated lists or tables.

export interface Pagination {
  current: number;
  pageSize: number;
  total: number;
}
const paginationState: Pagination = {
  current: 2,
  pageSize: 10,
  total: 45,
};

This interface is essential when implementing paginated data views, allowing components to track and update the current page, page size, and total item count.


2. BaseState

Defines a base UI state shape that combines pagination and search string filters.

export interface BaseState {
  pagination: Pagination;
  searchString: string;
}
const baseState: BaseState = {
  pagination: {
    current: 1,
    pageSize: 20,
    total: 100,
  },
  searchString: "example search",
};

This interface can be extended or used directly to manage UI state in list/filter views that feature both pagination and search capabilities.


3. IModalProps<T>

A generic interface defining properties and callbacks expected by modal dialog components.

export interface IModalProps<T> {
  showModal?(): void;
  hideModal?(): void;
  switchVisible?(visible: boolean): void;
  visible?: boolean;
  loading?: boolean;
  onOk?(payload?: T): Promise<any> | void;
}
interface FormData {
  username: string;
  password: string;
}

const modalProps: IModalProps<FormData> = {
  visible: true,
  loading: false,
  onOk: async (data) => {
    await submitUserCredentials(data);
  },
  hideModal: () => {
    console.log("Modal closed");
  },
};

This interface allows modal components to handle showing/hiding behavior, loading states during async operations, and processing user input in a type-safe manner.


Implementation Details


Interactions with Other System Components


Visual Diagram

flowchart TD
    Pagination["Pagination\n- current: number\n- pageSize: number\n- total: number"]
    BaseState["BaseState\n- pagination: Pagination\n- searchString: string"]
    IModalProps["IModalProps<T>\n- showModal?()\n- hideModal?()\n- switchVisible?(visible: boolean)\n- visible?: boolean\n- loading?: boolean\n- onOk?(payload?: T)"]

    BaseState --> Pagination

Diagram Explanation:


Summary

The common.ts file provides essential UI state interfaces:

These interfaces standardize UI state shape and modal behavior, enabling consistent and type-safe component implementations throughout the application.