Introduce main identifier to power RelationFieldDisplay (#2577)
* Introduce main identifier to power RelationFieldDisplay, FilterDrodown, TableFirstColumn * Apply to RelationPicker
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
import { useContext } from 'react';
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import { useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
|
||||
import { RelationPickerHotkeyScope } from '@/ui/input/relation-picker/types/RelationPickerHotkeyScope';
|
||||
import { contextMenuIsOpenState } from '@/ui/navigation/context-menu/states/contextMenuIsOpenState';
|
||||
import { contextMenuPositionState } from '@/ui/navigation/context-menu/states/contextMenuPositionState';
|
||||
import { useRecordTableScopedStates } from '@/ui/object/record-table/hooks/internal/useRecordTableScopedStates';
|
||||
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
|
||||
|
||||
import { FieldContext } from '../../field/contexts/FieldContext';
|
||||
@ -20,6 +21,9 @@ export const RecordTableCell = ({ cellIndex }: { cellIndex: number }) => {
|
||||
const setContextMenuPosition = useSetRecoilState(contextMenuPositionState);
|
||||
const setContextMenuOpenState = useSetRecoilState(contextMenuIsOpenState);
|
||||
const currentRowId = useContext(RowIdContext);
|
||||
const { objectMetadataConfigState } = useRecordTableScopedStates();
|
||||
|
||||
const objectMetadataConfig = useRecoilValue(objectMetadataConfigState);
|
||||
|
||||
const { setCurrentRowSelected } = useCurrentRowSelected();
|
||||
|
||||
@ -56,6 +60,10 @@ export const RecordTableCell = ({ cellIndex }: { cellIndex: number }) => {
|
||||
fieldDefinition: columnDefinition,
|
||||
useUpdateEntityMutation: () => [updateEntityMutation, {}],
|
||||
hotkeyScope: customHotkeyScope,
|
||||
isMainIdentifier:
|
||||
columnDefinition.fieldMetadataId ===
|
||||
objectMetadataConfig?.mainIdentifierFieldMetadataId,
|
||||
mainIdentifierMapper: objectMetadataConfig?.mainIdentifierMapper,
|
||||
}}
|
||||
>
|
||||
<TableCell customHotkeyScope={{ scope: customHotkeyScope }} />
|
||||
|
||||
@ -18,6 +18,7 @@ export const useRecordTableScopedStates = (args?: {
|
||||
tableFiltersState,
|
||||
tableSortsState,
|
||||
tableColumnsState,
|
||||
objectMetadataConfigState,
|
||||
tableColumnsByKeySelector,
|
||||
hiddenTableColumnsSelector,
|
||||
visibleTableColumnsSelector,
|
||||
@ -33,6 +34,7 @@ export const useRecordTableScopedStates = (args?: {
|
||||
tableFiltersState,
|
||||
tableSortsState,
|
||||
tableColumnsState,
|
||||
objectMetadataConfigState,
|
||||
tableColumnsByKeySelector,
|
||||
hiddenTableColumnsSelector,
|
||||
visibleTableColumnsSelector,
|
||||
|
||||
@ -43,6 +43,7 @@ export const useRecordTable = (props?: useRecordTableProps) => {
|
||||
tableFiltersState,
|
||||
tableSortsState,
|
||||
tableColumnsState,
|
||||
objectMetadataConfigState,
|
||||
onEntityCountChangeState,
|
||||
} = useRecordTableScopedStates({
|
||||
customRecordTableScopeId: scopeId,
|
||||
@ -54,6 +55,7 @@ export const useRecordTable = (props?: useRecordTableProps) => {
|
||||
|
||||
const setOnEntityCountChange = useSetRecoilState(onEntityCountChangeState);
|
||||
const setTableFilters = useSetRecoilState(tableFiltersState);
|
||||
const setObjectMetadataConfig = useSetRecoilState(objectMetadataConfigState);
|
||||
|
||||
const setTableSorts = useSetRecoilState(tableSortsState);
|
||||
|
||||
@ -301,6 +303,7 @@ export const useRecordTable = (props?: useRecordTableProps) => {
|
||||
setAvailableTableColumns,
|
||||
setTableFilters,
|
||||
setTableSorts,
|
||||
setObjectMetadataConfig,
|
||||
setOnEntityCountChange,
|
||||
setRecordTableData,
|
||||
setTableColumns,
|
||||
|
||||
@ -37,7 +37,8 @@ export const useTableCell = () => {
|
||||
|
||||
const isEmpty = useIsFieldEmpty();
|
||||
|
||||
const { entityId, fieldDefinition } = useContext(FieldContext);
|
||||
const { entityId, fieldDefinition, basePathToShowPage } =
|
||||
useContext(FieldContext);
|
||||
|
||||
const [, setFieldInitialValue] = useRecoilState(
|
||||
entityFieldInitialValueFamilyState({
|
||||
@ -47,8 +48,8 @@ export const useTableCell = () => {
|
||||
);
|
||||
|
||||
const openTableCell = (options?: { initialValue?: FieldInitialValue }) => {
|
||||
if (isFirstColumnCell && !isEmpty && fieldDefinition.basePathToShowPage) {
|
||||
navigate(`${fieldDefinition.basePathToShowPage}${entityId}`);
|
||||
if (isFirstColumnCell && !isEmpty && basePathToShowPage) {
|
||||
navigate(`${basePathToShowPage}${entityId}`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
import { ObjectMetadataConfig } from '@/ui/object/record-table/types/ObjectMetadataConfig';
|
||||
import { createScopedState } from '@/ui/utilities/recoil-scope/utils/createScopedState';
|
||||
|
||||
export const objectMetadataConfigScopedState =
|
||||
createScopedState<ObjectMetadataConfig | null>({
|
||||
key: 'objectMetadataConfigScopedState',
|
||||
defaultValue: null,
|
||||
});
|
||||
@ -0,0 +1,11 @@
|
||||
import { AvatarType } from '@/users/components/Avatar';
|
||||
|
||||
export type ObjectMetadataConfig = {
|
||||
mainIdentifierFieldMetadataId: string;
|
||||
mainIdentifierMapper: (record: any) => {
|
||||
name: string;
|
||||
avatarUrl?: string;
|
||||
avatarType: AvatarType;
|
||||
};
|
||||
basePathToShowPage: string;
|
||||
};
|
||||
@ -1,3 +1,4 @@
|
||||
import { objectMetadataConfigScopedState } from '@/ui/object/record-table/states/objectMetadataConfigScopedState';
|
||||
import { getScopedState } from '@/ui/utilities/recoil-scope/utils/getScopedState';
|
||||
|
||||
import { availableTableColumnsScopedState } from '../states/availableTableColumnsScopedState';
|
||||
@ -36,6 +37,11 @@ export const getRecordTableScopedStates = ({
|
||||
recordTableScopeId,
|
||||
);
|
||||
|
||||
const objectMetadataConfigState = getScopedState(
|
||||
objectMetadataConfigScopedState,
|
||||
recordTableScopeId,
|
||||
);
|
||||
|
||||
const tableColumnsByKeySelector =
|
||||
tableColumnsByKeyScopedSelector(recordTableScopeId);
|
||||
|
||||
@ -60,6 +66,7 @@ export const getRecordTableScopedStates = ({
|
||||
tableFiltersState,
|
||||
tableSortsState,
|
||||
tableColumnsState,
|
||||
objectMetadataConfigState,
|
||||
tableColumnsByKeySelector,
|
||||
hiddenTableColumnsSelector,
|
||||
visibleTableColumnsSelector,
|
||||
|
||||
Reference in New Issue
Block a user