This repository contains a comprehensive UI library built with Next.js, React, and TypeScript for managing master data and master settings. It provides a set of reusable components designed to build powerful and flexible administration interfaces. The library is structured as a package within a Next.js application, which also serves as a live demonstration environment.
The library is centered around four main components that provide the full CRUD (Create, Read, Update, Delete) functionality for master settings and their corresponding data.
This component renders a list of all available master setting definitions. It features searching and pagination capabilities to easily navigate through numerous settings. From here, users can select a setting to view its associated data or create a new setting definition.
This is the powerhouse for defining the structure of your master data. It provides a form to create or edit a "master setting." Key features include:
- Defining basic information like a unique
codeandname. - A dynamic Fields Table where you can add, remove, reorder, and edit the fields that will make up the master data records.
Once a master setting is selected, this component displays all the data records that conform to that setting's schema. It includes:
- A powerful data table with server-side pagination and sorting.
- Advanced search and filtering capabilities based on the fields defined in the master setting.
- Options to create new data records or navigate to edit existing ones.
This component renders a form that is dynamically generated based on the fields defined in the associated master setting. It allows users to create a new master data record or edit an existing one.
- Dynamic Form Generation: Forms in
EditMasterDataare created on-the-fly based on field definitions from aMasterSetting, ensuring data integrity and consistency. - Rich Field Types: Supports a wide variety of data types for master data fields, including:
string,number,boolean,datearray(for a list of strings)json(with a built-in JSON editor)text-area,text-html(rich text editor), andtext-markdownauto_numberfor automatically generating sequential codes.
- Advanced Data Table: The data tables for both settings and data come with robust features like server-side pagination, sorting, and filtering to handle large datasets efficiently.
- Role-Based UI: The root layout and URL structure are designed to support different user segments, such as
system_adminandtenant, allowing for tailored user experiences. - Bulk & Raw Data Handling: A
JSONEditorComponentis available for creating or editing both settings and data via raw JSON, which is ideal for bulk imports or complex data structures. - Asynchronous Task Monitoring: Uses AWS AppSync Subscriptions to provide real-time feedback for long-running operations like data deletion or copying data across tenants.
- Data Portability: Includes functionality for system administrators to copy master settings and their associated data to other tenants.
The included Next.js application serves as a demonstration of the UI library's capabilities.
Prerequisites:
- Node.js
- npm, yarn, or pnpm
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Install dependencies:
npm install
-
Configure Environment Variables: Create a
.envfile in the root of the project and add the necessary API endpoints.# Example NEXT_PUBLIC_MASTER_API_BASE=http://your-api-server.com NEXT_PUBLIC_MASTER_APPSYNC_URL=wss://your.appsync-api.us-east-1.amazonaws.com/graphql NEXT_PUBLIC_MASTER_APPSYNC_APIKEY=your-appsync-api-key NEXT_PUBLIC_MASTER_APPSYNC_REGION=us-east-1
-
Run the development server:
npm run dev
The application will be available at
http://localhost:8888. -
Access the Application: Upon visiting the application, you will be prompted to enter a Bearer Token and select a user Segment (
system_adminortenant). This is required to initialize the API clients and user context for the demo.
To use this library in other projects, you can build it into a distributable package.
- Run the build command:
npm run build
- Output:
The compiled and bundled library files will be located in the
dist/directory. This directory is ready to be published to a package registry like npm or consumed locally in another project.
The build process uses tsup and a custom postbuild.js script to ensure that all client-side components are correctly marked with the "use client" directive for compatibility with the Next.js App Router.
- Framework: Next.js (App Router)
- Language: TypeScript
- UI Library: React
- Styling: Tailwind CSS
- UI Components: shadcn/ui
- Form Management: React Hook Form & Zod
- Data Fetching: Axios (for REST APIs) & Apollo Client (for AWS AppSync GraphQL Subscriptions)
- State Management: React Context API
- Component Bundler: tsup