mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-18 09:02:11 +03:00
refactoring editableFieldContext to match with table implementation (#1164)
This commit is contained in:
parent
a12b6c4bda
commit
4288cef096
@ -7,7 +7,9 @@ import { selectedBoardCardIdsState } from '@/ui/board/states/selectedBoardCardId
|
|||||||
import { viewFieldsDefinitionsState } from '@/ui/board/states/viewFieldsDefinitionsState';
|
import { viewFieldsDefinitionsState } from '@/ui/board/states/viewFieldsDefinitionsState';
|
||||||
import { EntityChipVariant } from '@/ui/chip/components/EntityChip';
|
import { EntityChipVariant } from '@/ui/chip/components/EntityChip';
|
||||||
import { GenericEditableField } from '@/ui/editable-field/components/GenericEditableField';
|
import { GenericEditableField } from '@/ui/editable-field/components/GenericEditableField';
|
||||||
import { EditableFieldContext } from '@/ui/editable-field/states/EditableFieldContext';
|
import { EditableFieldDefinitionContext } from '@/ui/editable-field/states/EditableFieldDefinitionContext';
|
||||||
|
import { EditableFieldEntityIdContext } from '@/ui/editable-field/states/EditableFieldEntityIdContext';
|
||||||
|
import { EditableFieldMutationContext } from '@/ui/editable-field/states/EditableFieldMutationContext';
|
||||||
import {
|
import {
|
||||||
Checkbox,
|
Checkbox,
|
||||||
CheckboxVariant,
|
CheckboxVariant,
|
||||||
@ -167,27 +169,29 @@ export function CompanyBoardCard() {
|
|||||||
</StyledCheckboxContainer>
|
</StyledCheckboxContainer>
|
||||||
</StyledBoardCardHeader>
|
</StyledBoardCardHeader>
|
||||||
<StyledBoardCardBody>
|
<StyledBoardCardBody>
|
||||||
|
<EditableFieldMutationContext.Provider
|
||||||
|
value={useUpdateOnePipelineProgressMutation}
|
||||||
|
>
|
||||||
|
<EditableFieldEntityIdContext.Provider value={boardCardId}>
|
||||||
{viewFieldsDefinitions.map((viewField) => {
|
{viewFieldsDefinitions.map((viewField) => {
|
||||||
return (
|
return (
|
||||||
<PreventSelectOnClickContainer key={viewField.id}>
|
<PreventSelectOnClickContainer key={viewField.id}>
|
||||||
<EditableFieldContext.Provider
|
<EditableFieldDefinitionContext.Provider
|
||||||
value={{
|
value={{
|
||||||
entityId: boardCardId,
|
|
||||||
mutation: useUpdateOnePipelineProgressMutation,
|
|
||||||
fieldDefinition: {
|
|
||||||
id: viewField.id,
|
id: viewField.id,
|
||||||
label: viewField.columnLabel,
|
label: viewField.columnLabel,
|
||||||
icon: viewField.columnIcon,
|
icon: viewField.columnIcon,
|
||||||
type: viewField.metadata.type,
|
type: viewField.metadata.type,
|
||||||
metadata: viewField.metadata,
|
metadata: viewField.metadata,
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<GenericEditableField />
|
<GenericEditableField />
|
||||||
</EditableFieldContext.Provider>
|
</EditableFieldDefinitionContext.Provider>
|
||||||
</PreventSelectOnClickContainer>
|
</PreventSelectOnClickContainer>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</EditableFieldEntityIdContext.Provider>
|
||||||
|
</EditableFieldMutationContext.Provider>
|
||||||
</StyledBoardCardBody>
|
</StyledBoardCardBody>
|
||||||
</StyledBoardCard>
|
</StyledBoardCard>
|
||||||
</StyledBoardCardWrapper>
|
</StyledBoardCardWrapper>
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
import { DateInputDisplay } from '@/ui/input/date/components/DateInputDisplay';
|
|
||||||
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
|
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
|
||||||
import { parseDate } from '~/utils/date-utils';
|
|
||||||
|
|
||||||
import { EditableFieldContext } from '../states/EditableFieldContext';
|
import { EditableFieldDefinitionContext } from '../states/EditableFieldDefinitionContext';
|
||||||
|
import { EditableFieldEntityIdContext } from '../states/EditableFieldEntityIdContext';
|
||||||
import { FieldContext } from '../states/FieldContext';
|
import { FieldContext } from '../states/FieldContext';
|
||||||
import { genericEntityFieldFamilySelector } from '../states/genericEntityFieldFamilySelector';
|
import { genericEntityFieldFamilySelector } from '../states/genericEntityFieldFamilySelector';
|
||||||
import { FieldDefinition } from '../types/FieldDefinition';
|
import { FieldDefinition } from '../types/FieldDefinition';
|
||||||
import { FieldDateMetadata } from '../types/FieldMetadata';
|
import { FieldDateMetadata } from '../types/FieldMetadata';
|
||||||
|
|
||||||
import { EditableField } from './EditableField';
|
import { EditableField } from './EditableField';
|
||||||
|
import { GenericEditableDateFieldDisplayMode } from './GenericEditableDateFieldDisplayMode';
|
||||||
import { GenericEditableDateFieldEditMode } from './GenericEditableDateFieldEditMode';
|
import { GenericEditableDateFieldEditMode } from './GenericEditableDateFieldEditMode';
|
||||||
|
|
||||||
export function GenericEditableDateField() {
|
export function GenericEditableDateField() {
|
||||||
const currentEditableField = useContext(EditableFieldContext);
|
const currentEditableFieldEntityId = useContext(EditableFieldEntityIdContext);
|
||||||
const currentEditableFieldEntityId = currentEditableField.entityId;
|
const currentEditableFieldDefinition = useContext(
|
||||||
const currentEditableFieldDefinition =
|
EditableFieldDefinitionContext,
|
||||||
currentEditableField.fieldDefinition as FieldDefinition<FieldDateMetadata>;
|
) as FieldDefinition<FieldDateMetadata>;
|
||||||
|
|
||||||
const fieldValue = useRecoilValue<string>(
|
const fieldValue = useRecoilValue<string>(
|
||||||
genericEntityFieldFamilySelector({
|
genericEntityFieldFamilySelector({
|
||||||
@ -29,16 +29,12 @@ export function GenericEditableDateField() {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
const internalDateValue = fieldValue
|
|
||||||
? parseDate(fieldValue).toJSDate()
|
|
||||||
: null;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RecoilScope SpecificContext={FieldContext}>
|
<RecoilScope SpecificContext={FieldContext}>
|
||||||
<EditableField
|
<EditableField
|
||||||
iconLabel={currentEditableFieldDefinition.icon}
|
iconLabel={currentEditableFieldDefinition.icon}
|
||||||
editModeContent={<GenericEditableDateFieldEditMode />}
|
editModeContent={<GenericEditableDateFieldEditMode />}
|
||||||
displayModeContent={<DateInputDisplay value={internalDateValue} />}
|
displayModeContent={<GenericEditableDateFieldDisplayMode />}
|
||||||
isDisplayModeContentEmpty={!fieldValue}
|
isDisplayModeContentEmpty={!fieldValue}
|
||||||
/>
|
/>
|
||||||
</RecoilScope>
|
</RecoilScope>
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
import { useContext } from 'react';
|
||||||
|
import { useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
|
import { DateInputDisplay } from '@/ui/input/date/components/DateInputDisplay';
|
||||||
|
import { parseDate } from '~/utils/date-utils';
|
||||||
|
|
||||||
|
import { EditableFieldDefinitionContext } from '../states/EditableFieldDefinitionContext';
|
||||||
|
import { EditableFieldEntityIdContext } from '../states/EditableFieldEntityIdContext';
|
||||||
|
import { genericEntityFieldFamilySelector } from '../states/genericEntityFieldFamilySelector';
|
||||||
|
import { FieldDefinition } from '../types/FieldDefinition';
|
||||||
|
import { FieldDateMetadata } from '../types/FieldMetadata';
|
||||||
|
|
||||||
|
export function GenericEditableDateFieldDisplayMode() {
|
||||||
|
const currentEditableFieldEntityId = useContext(EditableFieldEntityIdContext);
|
||||||
|
const currentEditableFieldDefinition = useContext(
|
||||||
|
EditableFieldDefinitionContext,
|
||||||
|
) as FieldDefinition<FieldDateMetadata>;
|
||||||
|
|
||||||
|
const fieldValue = useRecoilValue<string>(
|
||||||
|
genericEntityFieldFamilySelector({
|
||||||
|
entityId: currentEditableFieldEntityId ?? '',
|
||||||
|
fieldName: currentEditableFieldDefinition
|
||||||
|
? currentEditableFieldDefinition.metadata.fieldName
|
||||||
|
: '',
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
const internalDateValue = fieldValue
|
||||||
|
? parseDate(fieldValue).toJSDate()
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return <DateInputDisplay value={internalDateValue} />;
|
||||||
|
}
|
@ -2,17 +2,18 @@ import { useContext } from 'react';
|
|||||||
import { useRecoilState } from 'recoil';
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
import { useUpdateGenericEntityField } from '../hooks/useUpdateGenericEntityField';
|
import { useUpdateGenericEntityField } from '../hooks/useUpdateGenericEntityField';
|
||||||
import { EditableFieldContext } from '../states/EditableFieldContext';
|
import { EditableFieldDefinitionContext } from '../states/EditableFieldDefinitionContext';
|
||||||
|
import { EditableFieldEntityIdContext } from '../states/EditableFieldEntityIdContext';
|
||||||
import { genericEntityFieldFamilySelector } from '../states/genericEntityFieldFamilySelector';
|
import { genericEntityFieldFamilySelector } from '../states/genericEntityFieldFamilySelector';
|
||||||
import { FieldDefinition } from '../types/FieldDefinition';
|
import { FieldDefinition } from '../types/FieldDefinition';
|
||||||
import { FieldDateMetadata } from '../types/FieldMetadata';
|
import { FieldDateMetadata } from '../types/FieldMetadata';
|
||||||
import { EditableFieldEditModeDate } from '../variants/components/EditableFieldEditModeDate';
|
import { EditableFieldEditModeDate } from '../variants/components/EditableFieldEditModeDate';
|
||||||
|
|
||||||
export function GenericEditableDateFieldEditMode() {
|
export function GenericEditableDateFieldEditMode() {
|
||||||
const currentEditableField = useContext(EditableFieldContext);
|
const currentEditableFieldEntityId = useContext(EditableFieldEntityIdContext);
|
||||||
const currentEditableFieldEntityId = currentEditableField.entityId;
|
const currentEditableFieldDefinition = useContext(
|
||||||
const currentEditableFieldDefinition =
|
EditableFieldDefinitionContext,
|
||||||
currentEditableField.fieldDefinition as FieldDefinition<FieldDateMetadata>;
|
) as FieldDefinition<FieldDateMetadata>;
|
||||||
|
|
||||||
// TODO: we could use a hook that would return the field value with the right type
|
// TODO: we could use a hook that would return the field value with the right type
|
||||||
const [fieldValue, setFieldValue] = useRecoilState<string>(
|
const [fieldValue, setFieldValue] = useRecoilState<string>(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
|
|
||||||
import { EditableFieldContext } from '../states/EditableFieldContext';
|
import { EditableFieldDefinitionContext } from '../states/EditableFieldDefinitionContext';
|
||||||
import { isFieldDate } from '../types/guards/isFieldDate';
|
import { isFieldDate } from '../types/guards/isFieldDate';
|
||||||
import { isFieldNumber } from '../types/guards/isFieldNumber';
|
import { isFieldNumber } from '../types/guards/isFieldNumber';
|
||||||
import { isFieldProbability } from '../types/guards/isFieldProbability';
|
import { isFieldProbability } from '../types/guards/isFieldProbability';
|
||||||
@ -12,8 +12,7 @@ import { GenericEditableRelationField } from './GenericEditableRelationField';
|
|||||||
import { ProbabilityEditableField } from './ProbabilityEditableField';
|
import { ProbabilityEditableField } from './ProbabilityEditableField';
|
||||||
|
|
||||||
export function GenericEditableField() {
|
export function GenericEditableField() {
|
||||||
const currentEditableField = useContext(EditableFieldContext);
|
const fieldDefinition = useContext(EditableFieldDefinitionContext);
|
||||||
const fieldDefinition = currentEditableField.fieldDefinition;
|
|
||||||
|
|
||||||
if (isFieldRelation(fieldDefinition)) {
|
if (isFieldRelation(fieldDefinition)) {
|
||||||
return <GenericEditableRelationField />;
|
return <GenericEditableRelationField />;
|
||||||
|
@ -3,7 +3,8 @@ import { useRecoilValue } from 'recoil';
|
|||||||
|
|
||||||
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
|
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
|
||||||
|
|
||||||
import { EditableFieldContext } from '../states/EditableFieldContext';
|
import { EditableFieldDefinitionContext } from '../states/EditableFieldDefinitionContext';
|
||||||
|
import { EditableFieldEntityIdContext } from '../states/EditableFieldEntityIdContext';
|
||||||
import { FieldContext } from '../states/FieldContext';
|
import { FieldContext } from '../states/FieldContext';
|
||||||
import { genericEntityFieldFamilySelector } from '../states/genericEntityFieldFamilySelector';
|
import { genericEntityFieldFamilySelector } from '../states/genericEntityFieldFamilySelector';
|
||||||
import { FieldDefinition } from '../types/FieldDefinition';
|
import { FieldDefinition } from '../types/FieldDefinition';
|
||||||
@ -13,10 +14,10 @@ import { EditableField } from './EditableField';
|
|||||||
import { GenericEditableNumberFieldEditMode } from './GenericEditableNumberFieldEditMode';
|
import { GenericEditableNumberFieldEditMode } from './GenericEditableNumberFieldEditMode';
|
||||||
|
|
||||||
export function GenericEditableNumberField() {
|
export function GenericEditableNumberField() {
|
||||||
const currentEditableField = useContext(EditableFieldContext);
|
const currentEditableFieldEntityId = useContext(EditableFieldEntityIdContext);
|
||||||
const currentEditableFieldEntityId = currentEditableField.entityId;
|
const currentEditableFieldDefinition = useContext(
|
||||||
const currentEditableFieldDefinition =
|
EditableFieldDefinitionContext,
|
||||||
currentEditableField.fieldDefinition as FieldDefinition<FieldNumberMetadata>;
|
) as FieldDefinition<FieldNumberMetadata>;
|
||||||
|
|
||||||
const fieldValue = useRecoilValue<string>(
|
const fieldValue = useRecoilValue<string>(
|
||||||
genericEntityFieldFamilySelector({
|
genericEntityFieldFamilySelector({
|
||||||
|
@ -9,16 +9,17 @@ import {
|
|||||||
|
|
||||||
import { useRegisterCloseFieldHandlers } from '../hooks/useRegisterCloseFieldHandlers';
|
import { useRegisterCloseFieldHandlers } from '../hooks/useRegisterCloseFieldHandlers';
|
||||||
import { useUpdateGenericEntityField } from '../hooks/useUpdateGenericEntityField';
|
import { useUpdateGenericEntityField } from '../hooks/useUpdateGenericEntityField';
|
||||||
import { EditableFieldContext } from '../states/EditableFieldContext';
|
import { EditableFieldDefinitionContext } from '../states/EditableFieldDefinitionContext';
|
||||||
|
import { EditableFieldEntityIdContext } from '../states/EditableFieldEntityIdContext';
|
||||||
import { genericEntityFieldFamilySelector } from '../states/genericEntityFieldFamilySelector';
|
import { genericEntityFieldFamilySelector } from '../states/genericEntityFieldFamilySelector';
|
||||||
import { FieldDefinition } from '../types/FieldDefinition';
|
import { FieldDefinition } from '../types/FieldDefinition';
|
||||||
import { FieldNumberMetadata } from '../types/FieldMetadata';
|
import { FieldNumberMetadata } from '../types/FieldMetadata';
|
||||||
|
|
||||||
export function GenericEditableNumberFieldEditMode() {
|
export function GenericEditableNumberFieldEditMode() {
|
||||||
const currentEditableField = useContext(EditableFieldContext);
|
const currentEditableFieldEntityId = useContext(EditableFieldEntityIdContext);
|
||||||
const currentEditableFieldEntityId = currentEditableField.entityId;
|
const currentEditableFieldDefinition = useContext(
|
||||||
const currentEditableFieldDefinition =
|
EditableFieldDefinitionContext,
|
||||||
currentEditableField.fieldDefinition as FieldDefinition<FieldNumberMetadata>;
|
) as FieldDefinition<FieldNumberMetadata>;
|
||||||
|
|
||||||
// TODO: we could use a hook that would return the field value with the right type
|
// TODO: we could use a hook that would return the field value with the right type
|
||||||
const [fieldValue, setFieldValue] = useRecoilState<number | null>(
|
const [fieldValue, setFieldValue] = useRecoilState<number | null>(
|
||||||
|
@ -1,51 +1,25 @@
|
|||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
import { PersonChip } from '@/people/components/PersonChip';
|
|
||||||
import { ViewFieldRelationMetadata } from '@/ui/editable-field/types/ViewField';
|
|
||||||
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
|
||||||
import { RelationPickerHotkeyScope } from '@/ui/input/relation-picker/types/RelationPickerHotkeyScope';
|
import { RelationPickerHotkeyScope } from '@/ui/input/relation-picker/types/RelationPickerHotkeyScope';
|
||||||
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
|
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
|
||||||
|
|
||||||
import { EditableFieldContext } from '../states/EditableFieldContext';
|
import { EditableFieldDefinitionContext } from '../states/EditableFieldDefinitionContext';
|
||||||
|
import { EditableFieldEntityIdContext } from '../states/EditableFieldEntityIdContext';
|
||||||
import { FieldContext } from '../states/FieldContext';
|
import { FieldContext } from '../states/FieldContext';
|
||||||
import { genericEntityFieldFamilySelector } from '../states/genericEntityFieldFamilySelector';
|
import { genericEntityFieldFamilySelector } from '../states/genericEntityFieldFamilySelector';
|
||||||
import { FieldDefinition } from '../types/FieldDefinition';
|
import { FieldDefinition } from '../types/FieldDefinition';
|
||||||
import { FieldRelationMetadata } from '../types/FieldMetadata';
|
import { FieldRelationMetadata } from '../types/FieldMetadata';
|
||||||
|
|
||||||
import { EditableField } from './EditableField';
|
import { EditableField } from './EditableField';
|
||||||
|
import { GenericEditableRelationFieldDisplayMode } from './GenericEditableRelationFieldDisplayMode';
|
||||||
import { GenericEditableRelationFieldEditMode } from './GenericEditableRelationFieldEditMode';
|
import { GenericEditableRelationFieldEditMode } from './GenericEditableRelationFieldEditMode';
|
||||||
|
|
||||||
function RelationChip({
|
|
||||||
fieldDefinition,
|
|
||||||
fieldValue,
|
|
||||||
}: {
|
|
||||||
fieldDefinition: FieldDefinition<FieldRelationMetadata>;
|
|
||||||
fieldValue: any | null;
|
|
||||||
}) {
|
|
||||||
switch (fieldDefinition.metadata.relationType) {
|
|
||||||
case Entity.Person: {
|
|
||||||
return (
|
|
||||||
<PersonChip
|
|
||||||
id={fieldValue?.id ?? ''}
|
|
||||||
name={fieldValue?.displayName ?? ''}
|
|
||||||
pictureUrl={fieldValue?.avatarUrl ?? ''}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
console.warn(
|
|
||||||
`Unknown relation type: "${fieldDefinition.metadata.relationType}" in GenericEditableRelationField`,
|
|
||||||
);
|
|
||||||
return <> </>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function GenericEditableRelationField() {
|
export function GenericEditableRelationField() {
|
||||||
const currentEditableField = useContext(EditableFieldContext);
|
const currentEditableFieldEntityId = useContext(EditableFieldEntityIdContext);
|
||||||
const currentEditableFieldEntityId = currentEditableField.entityId;
|
const currentEditableFieldDefinition = useContext(
|
||||||
const currentEditableFieldDefinition =
|
EditableFieldDefinitionContext,
|
||||||
currentEditableField.fieldDefinition as FieldDefinition<ViewFieldRelationMetadata>;
|
) as FieldDefinition<FieldRelationMetadata>;
|
||||||
|
|
||||||
const fieldValue = useRecoilValue<any | null>(
|
const fieldValue = useRecoilValue<any | null>(
|
||||||
genericEntityFieldFamilySelector({
|
genericEntityFieldFamilySelector({
|
||||||
@ -66,12 +40,7 @@ export function GenericEditableRelationField() {
|
|||||||
}}
|
}}
|
||||||
iconLabel={currentEditableFieldDefinition.icon}
|
iconLabel={currentEditableFieldDefinition.icon}
|
||||||
editModeContent={<GenericEditableRelationFieldEditMode />}
|
editModeContent={<GenericEditableRelationFieldEditMode />}
|
||||||
displayModeContent={
|
displayModeContent={<GenericEditableRelationFieldDisplayMode />}
|
||||||
<RelationChip
|
|
||||||
fieldDefinition={currentEditableFieldDefinition}
|
|
||||||
fieldValue={fieldValue}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
isDisplayModeContentEmpty={!fieldValue}
|
isDisplayModeContentEmpty={!fieldValue}
|
||||||
isDisplayModeFixHeight
|
isDisplayModeFixHeight
|
||||||
/>
|
/>
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
import { useContext } from 'react';
|
||||||
|
import { useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
|
import { PersonChip } from '@/people/components/PersonChip';
|
||||||
|
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
||||||
|
|
||||||
|
import { EditableFieldDefinitionContext } from '../states/EditableFieldDefinitionContext';
|
||||||
|
import { EditableFieldEntityIdContext } from '../states/EditableFieldEntityIdContext';
|
||||||
|
import { genericEntityFieldFamilySelector } from '../states/genericEntityFieldFamilySelector';
|
||||||
|
import { FieldDefinition } from '../types/FieldDefinition';
|
||||||
|
import { FieldRelationMetadata } from '../types/FieldMetadata';
|
||||||
|
|
||||||
|
export function GenericEditableRelationFieldDisplayMode() {
|
||||||
|
const currentEditableFieldEntityId = useContext(EditableFieldEntityIdContext);
|
||||||
|
const currentEditableFieldDefinition = useContext(
|
||||||
|
EditableFieldDefinitionContext,
|
||||||
|
) as FieldDefinition<FieldRelationMetadata>;
|
||||||
|
|
||||||
|
const fieldValue = useRecoilValue<any | null>(
|
||||||
|
genericEntityFieldFamilySelector({
|
||||||
|
entityId: currentEditableFieldEntityId ?? '',
|
||||||
|
fieldName: currentEditableFieldDefinition
|
||||||
|
? currentEditableFieldDefinition.metadata.fieldName
|
||||||
|
: '',
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
switch (currentEditableFieldDefinition.metadata.relationType) {
|
||||||
|
case Entity.Person: {
|
||||||
|
return (
|
||||||
|
<PersonChip
|
||||||
|
id={fieldValue?.id ?? ''}
|
||||||
|
name={fieldValue?.displayName ?? ''}
|
||||||
|
pictureUrl={fieldValue?.avatarUrl ?? ''}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
console.warn(
|
||||||
|
`Unknown relation type: "${currentEditableFieldDefinition.metadata.relationType}"
|
||||||
|
in GenericEditableRelationField`,
|
||||||
|
);
|
||||||
|
return <> </>;
|
||||||
|
}
|
||||||
|
}
|
@ -3,16 +3,14 @@ import styled from '@emotion/styled';
|
|||||||
import { useRecoilState } from 'recoil';
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
import { PeoplePicker } from '@/people/components/PeoplePicker';
|
import { PeoplePicker } from '@/people/components/PeoplePicker';
|
||||||
import {
|
import { ViewFieldRelationValue } from '@/ui/editable-field/types/ViewField';
|
||||||
ViewFieldRelationMetadata,
|
|
||||||
ViewFieldRelationValue,
|
|
||||||
} from '@/ui/editable-field/types/ViewField';
|
|
||||||
import { EntityForSelect } from '@/ui/input/relation-picker/types/EntityForSelect';
|
import { EntityForSelect } from '@/ui/input/relation-picker/types/EntityForSelect';
|
||||||
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
||||||
|
|
||||||
import { useEditableField } from '../hooks/useEditableField';
|
import { useEditableField } from '../hooks/useEditableField';
|
||||||
import { useUpdateGenericEntityField } from '../hooks/useUpdateGenericEntityField';
|
import { useUpdateGenericEntityField } from '../hooks/useUpdateGenericEntityField';
|
||||||
import { EditableFieldContext } from '../states/EditableFieldContext';
|
import { EditableFieldDefinitionContext } from '../states/EditableFieldDefinitionContext';
|
||||||
|
import { EditableFieldEntityIdContext } from '../states/EditableFieldEntityIdContext';
|
||||||
import { genericEntityFieldFamilySelector } from '../states/genericEntityFieldFamilySelector';
|
import { genericEntityFieldFamilySelector } from '../states/genericEntityFieldFamilySelector';
|
||||||
import { FieldDefinition } from '../types/FieldDefinition';
|
import { FieldDefinition } from '../types/FieldDefinition';
|
||||||
import { FieldRelationMetadata } from '../types/FieldMetadata';
|
import { FieldRelationMetadata } from '../types/FieldMetadata';
|
||||||
@ -53,10 +51,10 @@ function RelationPicker({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function GenericEditableRelationFieldEditMode() {
|
export function GenericEditableRelationFieldEditMode() {
|
||||||
const currentEditableField = useContext(EditableFieldContext);
|
const currentEditableFieldEntityId = useContext(EditableFieldEntityIdContext);
|
||||||
const currentEditableFieldEntityId = currentEditableField.entityId;
|
const currentEditableFieldDefinition = useContext(
|
||||||
const currentEditableFieldDefinition =
|
EditableFieldDefinitionContext,
|
||||||
currentEditableField.fieldDefinition as FieldDefinition<ViewFieldRelationMetadata>;
|
) as FieldDefinition<FieldRelationMetadata>;
|
||||||
|
|
||||||
// TODO: we could use a hook that would return the field value with the right type
|
// TODO: we could use a hook that would return the field value with the right type
|
||||||
const [fieldValue, setFieldValue] = useRecoilState<any | null>(
|
const [fieldValue, setFieldValue] = useRecoilState<any | null>(
|
||||||
|
@ -4,13 +4,16 @@ import { EditableField } from '@/ui/editable-field/components/EditableField';
|
|||||||
import { FieldContext } from '@/ui/editable-field/states/FieldContext';
|
import { FieldContext } from '@/ui/editable-field/states/FieldContext';
|
||||||
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
|
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
|
||||||
|
|
||||||
import { EditableFieldContext } from '../states/EditableFieldContext';
|
import { EditableFieldDefinitionContext } from '../states/EditableFieldDefinitionContext';
|
||||||
|
import { FieldDefinition } from '../types/FieldDefinition';
|
||||||
|
import { FieldProbabilityMetadata } from '../types/FieldMetadata';
|
||||||
|
|
||||||
import { ProbabilityEditableFieldEditMode } from './ProbabilityEditableFieldEditMode';
|
import { ProbabilityEditableFieldEditMode } from './ProbabilityEditableFieldEditMode';
|
||||||
|
|
||||||
export function ProbabilityEditableField() {
|
export function ProbabilityEditableField() {
|
||||||
const currentEditableField = useContext(EditableFieldContext);
|
const currentEditableFieldDefinition = useContext(
|
||||||
const currentEditableFieldDefinition = currentEditableField.fieldDefinition;
|
EditableFieldDefinitionContext,
|
||||||
|
) as FieldDefinition<FieldProbabilityMetadata>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RecoilScope SpecificContext={FieldContext}>
|
<RecoilScope SpecificContext={FieldContext}>
|
||||||
|
@ -5,7 +5,8 @@ import { useRecoilState } from 'recoil';
|
|||||||
import { useEditableField } from '@/ui/editable-field/hooks/useEditableField';
|
import { useEditableField } from '@/ui/editable-field/hooks/useEditableField';
|
||||||
|
|
||||||
import { useUpdateGenericEntityField } from '../hooks/useUpdateGenericEntityField';
|
import { useUpdateGenericEntityField } from '../hooks/useUpdateGenericEntityField';
|
||||||
import { EditableFieldContext } from '../states/EditableFieldContext';
|
import { EditableFieldDefinitionContext } from '../states/EditableFieldDefinitionContext';
|
||||||
|
import { EditableFieldEntityIdContext } from '../states/EditableFieldEntityIdContext';
|
||||||
import { genericEntityFieldFamilySelector } from '../states/genericEntityFieldFamilySelector';
|
import { genericEntityFieldFamilySelector } from '../states/genericEntityFieldFamilySelector';
|
||||||
import { FieldDefinition } from '../types/FieldDefinition';
|
import { FieldDefinition } from '../types/FieldDefinition';
|
||||||
import { FieldProbabilityMetadata } from '../types/FieldMetadata';
|
import { FieldProbabilityMetadata } from '../types/FieldMetadata';
|
||||||
@ -70,10 +71,10 @@ export function ProbabilityEditableFieldEditMode() {
|
|||||||
const [nextProbabilityIndex, setNextProbabilityIndex] = useState<
|
const [nextProbabilityIndex, setNextProbabilityIndex] = useState<
|
||||||
number | null
|
number | null
|
||||||
>(null);
|
>(null);
|
||||||
const currentEditableField = useContext(EditableFieldContext);
|
const currentEditableFieldEntityId = useContext(EditableFieldEntityIdContext);
|
||||||
const currentEditableFieldEntityId = currentEditableField.entityId;
|
const currentEditableFieldDefinition = useContext(
|
||||||
const currentEditableFieldDefinition =
|
EditableFieldDefinitionContext,
|
||||||
currentEditableField.fieldDefinition as FieldDefinition<FieldProbabilityMetadata>;
|
) as FieldDefinition<FieldProbabilityMetadata>;
|
||||||
|
|
||||||
const [fieldValue, setFieldValue] = useRecoilState<number>(
|
const [fieldValue, setFieldValue] = useRecoilState<number>(
|
||||||
genericEntityFieldFamilySelector({
|
genericEntityFieldFamilySelector({
|
||||||
|
@ -2,7 +2,7 @@ import { useContext } from 'react';
|
|||||||
|
|
||||||
import { isFieldChip } from '@/ui/editable-field/types/guards/isFieldChip';
|
import { isFieldChip } from '@/ui/editable-field/types/guards/isFieldChip';
|
||||||
|
|
||||||
import { EditableFieldContext } from '../states/EditableFieldContext';
|
import { EditableFieldMutationContext } from '../states/EditableFieldMutationContext';
|
||||||
import { FieldDefinition } from '../types/FieldDefinition';
|
import { FieldDefinition } from '../types/FieldDefinition';
|
||||||
import {
|
import {
|
||||||
FieldChipMetadata,
|
FieldChipMetadata,
|
||||||
@ -48,8 +48,7 @@ import { isFieldURL } from '../types/guards/isFieldURL';
|
|||||||
import { isFieldURLValue } from '../types/guards/isFieldURLValue';
|
import { isFieldURLValue } from '../types/guards/isFieldURLValue';
|
||||||
|
|
||||||
export function useUpdateGenericEntityField() {
|
export function useUpdateGenericEntityField() {
|
||||||
const currentEditableField = useContext(EditableFieldContext);
|
const useUpdateEntityMutation = useContext(EditableFieldMutationContext);
|
||||||
const useUpdateEntityMutation = currentEditableField?.mutation;
|
|
||||||
|
|
||||||
const [updateEntity] = useUpdateEntityMutation();
|
const [updateEntity] = useUpdateEntityMutation();
|
||||||
|
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
import { createContext } from 'react';
|
|
||||||
|
|
||||||
import { FieldDefinition } from '../types/FieldDefinition';
|
|
||||||
import { ViewFieldMetadata } from '../types/ViewField';
|
|
||||||
|
|
||||||
type EditableFieldContextValue = {
|
|
||||||
entityId: string;
|
|
||||||
fieldDefinition: FieldDefinition<ViewFieldMetadata>;
|
|
||||||
mutation: any;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const EditableFieldContext = createContext<EditableFieldContextValue>({
|
|
||||||
entityId: '',
|
|
||||||
fieldDefinition: {} as FieldDefinition<ViewFieldMetadata>,
|
|
||||||
mutation: undefined,
|
|
||||||
});
|
|
@ -0,0 +1,8 @@
|
|||||||
|
import { createContext } from 'react';
|
||||||
|
|
||||||
|
import { FieldDefinition } from '../types/FieldDefinition';
|
||||||
|
import { ViewFieldMetadata } from '../types/ViewField';
|
||||||
|
|
||||||
|
export const EditableFieldDefinitionContext = createContext<
|
||||||
|
FieldDefinition<ViewFieldMetadata>
|
||||||
|
>({} as FieldDefinition<ViewFieldMetadata>);
|
@ -1,3 +1,3 @@
|
|||||||
import { createContext } from 'react';
|
import { createContext } from 'react';
|
||||||
|
|
||||||
export const EditableFieldEntityIdContext = createContext<string | null>(null);
|
export const EditableFieldEntityIdContext = createContext<string>('');
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
import { createContext } from 'react';
|
||||||
|
|
||||||
|
export const EditableFieldMutationContext = createContext<any>(undefined);
|
Loading…
Reference in New Issue
Block a user