Overview
Schema-driven approach to building UI components with integrated CRUD functionality
View Package
The @repo/view
package provides a schema-driven approach to building UI components with integrated CRUD functionality, internationalization support, and error handling. It enables developers to define complex UI components using JSON schemas, with full type safety and validation.
Features
- Schema-Driven Views: Define your UI components using JSON schemas
- Type Safety: Enhanced type definitions for different view types
- Validation: Zod-based schema validation to ensure compatibility with CRUD components
- Internationalization: Built-in support for multiple languages
- Error Handling: Comprehensive error handling with custom error boundaries
- Persistence: Storage providers for both client and server-side persistence
- Extensible: Plugin system for custom field types and renderers
Installation
This package is part of the zopio
monorepo and is available to all applications in the workspace.
Package Structure
The View package is organized into several subpackages:
- Engine: Core view rendering functionality
- Hooks: React hooks for view operations
- Service: Storage and persistence for view schemas
- i18n: Internationalization support
- Schema: Schema definitions and validation
- Types: TypeScript type definitions
Dependencies
The View package depends on the following packages:
- @repo/crud: For CRUD operations and UI components
- @repo/design-system: For UI components
- next-intl: Internationalization support
- zod: Schema validation
Basic Usage
Rendering a View
Using View Hooks
Persisting View Schemas
View Types
The package supports the following view types:
- Form: For creating and editing data
- Table: For displaying tabular data
- Detail: For displaying detailed information about a record
- Audit Log: For displaying audit logs
- Import: For importing data
- Export: For exporting data
- Dashboard: For displaying multiple views in a dashboard layout
- Wizard: For multi-step forms and processes
Internationalization
The View package supports internationalization using next-intl:
Supported Locales
- English (en)
- Turkish (tr)
- Spanish (es)
- German (de)
Error Handling
The package includes a comprehensive error handling system:
Integration with View Builder
The View package is designed to work seamlessly with the View Builder package, which provides a visual interface for creating and editing view schemas:
Detailed Documentation
For more detailed information on using the View package, see the following pages:
- Engine - Core view rendering functionality
- Hooks - React hooks for view operations
- Service - Storage and persistence for view schemas
- Internationalization - Internationalization support
Core Concepts
View Schema
The View Schema is the core concept of the package, defining the structure and behavior of UI components:
View Engine
The View Engine is responsible for rendering views based on schemas and handling interactions:
View Designer
The View Designer provides a visual interface for creating and editing view schemas:
API Reference
Components
renderView(schema, options)
: Renders a view based on the provided schemaViewErrorBoundary
: Error boundary component for catching and displaying view rendering errorsViewDesigner
: Component for visually designing view schemasViewDesignerForm
: Form component for editing view schemas
Hooks
useViewTranslations(namespace)
: Hook for accessing translationsuseViewSchema(id)
: Hook for fetching a view schema by ID
Functions
validateViewSchema(schema)
: Validates a view schemasafeValidateViewSchema(schema)
: Safely validates a view schema (doesn’t throw errors)initViewService(options)
: Initializes the view service with storage optionssaveView(id, schema)
: Saves a view schemagetView(id)
: Gets a view schema by IDlistViews()
: Lists all available view schemasdeleteView(id)
: Deletes a view schema