feat: add RowActions component for enhanced row-level actions in data grids
- Introduced RowActions component to manage row-level actions with tooltips and dropdown menus. - Created types for row actions and page actions to standardize action properties. - Implemented utility function to map action intents to Mantine theme colors. - Updated CoreAppShell component to support optional slots for better flexibility. - Added enterprise module structure with context hooks for managing module state and actions. - Implemented draft management for forms to enhance user experience during data entry. - Established context providers for detail, form, and index pages to streamline data handling. - Updated dependencies to ensure compatibility with the latest versions.
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
import { createContext, useContext } from 'react';
|
||||
import type { BaseEntity, BaseRemoteDataServices } from '@repo/core-api/data-services';
|
||||
import type {
|
||||
ConfigSlice,
|
||||
DataServiceSlice,
|
||||
SelectionSlice,
|
||||
NavigationSlice,
|
||||
ModalSlice,
|
||||
TranslationSlice,
|
||||
} from '../entities/entity';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Context Definitions
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export const EnterpriseConfigContext = createContext<ConfigSlice<any> | null>(null);
|
||||
export const EnterpriseDataServiceContext = createContext<DataServiceSlice<any, any> | null>(null);
|
||||
export const EnterpriseSelectionContext = createContext<SelectionSlice<any> | null>(null);
|
||||
export const EnterpriseNavigationContext = createContext<NavigationSlice | null>(null);
|
||||
export const EnterpriseModalContext = createContext<ModalSlice | null>(null);
|
||||
export const EnterpriseTranslationContext = createContext<TranslationSlice | null>(null);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Granular Hooks
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export function useEnterpriseModuleConfigContext<E extends BaseEntity = BaseEntity>(): ConfigSlice<E> {
|
||||
const context = useContext(EnterpriseConfigContext);
|
||||
if (!context) {
|
||||
throw new Error('useEnterpriseModuleConfigContext must be used within an EnterpriseModuleProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
export function useEnterpriseModuleDataServiceContext<
|
||||
E extends BaseEntity = BaseEntity,
|
||||
S extends BaseRemoteDataServices<E> = BaseRemoteDataServices<E>,
|
||||
>(): DataServiceSlice<E, S> {
|
||||
const context = useContext(EnterpriseDataServiceContext);
|
||||
if (!context) {
|
||||
throw new Error('useEnterpriseModuleDataServiceContext must be used within an EnterpriseModuleProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
export function useEnterpriseModuleSelectionContext<E extends BaseEntity = BaseEntity>(): SelectionSlice<E> {
|
||||
const context = useContext(EnterpriseSelectionContext);
|
||||
if (!context) {
|
||||
throw new Error('useEnterpriseModuleSelectionContext must be used within an EnterpriseModuleProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
export function useEnterpriseModuleNavigationContext(): NavigationSlice {
|
||||
const context = useContext(EnterpriseNavigationContext);
|
||||
if (!context) {
|
||||
throw new Error('useEnterpriseModuleNavigationContext must be used within an EnterpriseModuleProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
export function useEnterpriseModuleModalContext(): ModalSlice {
|
||||
const context = useContext(EnterpriseModalContext);
|
||||
if (!context) {
|
||||
throw new Error('useEnterpriseModuleModalContext must be used within an EnterpriseModuleProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
export function useEnterpriseModuleTranslationContext(): TranslationSlice {
|
||||
const context = useContext(EnterpriseTranslationContext);
|
||||
if (!context) {
|
||||
throw new Error('useEnterpriseModuleTranslationContext must be used within an EnterpriseModuleProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Composed Hook (Use Sparingly)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export function useEnterpriseModuleContext<E extends BaseEntity = BaseEntity>() {
|
||||
return {
|
||||
...useEnterpriseModuleConfigContext<E>(),
|
||||
...useEnterpriseModuleDataServiceContext<E>(),
|
||||
...useEnterpriseModuleSelectionContext<E>(),
|
||||
...useEnterpriseModuleNavigationContext(),
|
||||
...useEnterpriseModuleModalContext(),
|
||||
...useEnterpriseModuleTranslationContext(),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user