feat: add new ACTOR field type and createdBy standard fields (#6324)
This pull request introduces a new `FieldMetadataType` called `ACTOR`.
The primary objective of this new type is to add an extra column to the
following objects: `person`, `company`, `opportunity`, `note`, `task`,
and all custom objects.
This composite type contains three properties:
- `source`
```typescript
export enum FieldActorSource {
EMAIL = 'EMAIL',
CALENDAR = 'CALENDAR',
API = 'API',
IMPORT = 'IMPORT',
MANUAL = 'MANUAL',
}
```
- `workspaceMemberId`
- This property can be `undefined` in some cases and refers to the
member who created the record.
- `name`
- Serves as a fallback if the `workspaceMember` is deleted and is used
for other source types like `API`.
### Functionality
The pre-hook system has been updated to allow real-time argument
updates. When a record is created, a pre-hook can now compute and update
the arguments accordingly. This enhancement enables the `createdBy`
field to be populated with the correct values based on the
`authContext`.
The `authContext` now includes:
- An optional User entity
- An optional ApiKey entity
- The workspace entity
This provides access to the necessary data for the `createdBy` field.
In the GraphQL API, only the `source` can be specified in the
`createdBy` input. This allows the front-end to specify the source when
creating records from a CSV file.
### Front-End Handling
On the front-end, `orderBy` and `filter` are only applied to the name
property of the `ACTOR` composite type. Currently, we are unable to
apply these operations to the workspace member relation. This means that
if a workspace member changes their first name or last name, there may
be a mismatch because the name will differ from the new one. The name
displayed on the screen is based on the workspace member entity when
available.
### Missing Components
Currently, this PR does not include a `createdBy` value for the `MAIL`
and `CALENDAR` sources. These records are created in a job, and at
present, we only have access to the workspaceId within the job. To
address this, we should use a function similar to
`loadServiceWithContext`, which was recently removed from `TwentyORM`.
This function would allow us to pass the `authContext` to the jobs
without disrupting existing jobs.
Another PR will be created to handle these cases.
### Related Issues
Fixes issue #5155.
### Additional Notes
This PR doesn't include the migrations of the current records and views.
Everything works properly when the database is reset but this part is
still missing for now. We'll add that in another PR.
- There is a minor issue: front-end tests are broken since this commit:
[80c0fc7ff1).
---------
Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -90,6 +90,10 @@ export type LinksFilter = {
|
||||
primaryLinkLabel?: StringFilter;
|
||||
};
|
||||
|
||||
export type ActorFilter = {
|
||||
name?: StringFilter;
|
||||
};
|
||||
|
||||
export type LeafFilter =
|
||||
| UUIDFilter
|
||||
| StringFilter
|
||||
@ -101,6 +105,7 @@ export type LeafFilter =
|
||||
| BooleanFilter
|
||||
| AddressFilter
|
||||
| LinksFilter
|
||||
| ActorFilter
|
||||
| undefined;
|
||||
|
||||
export type AndObjectRecordFilter = {
|
||||
|
||||
@ -65,6 +65,7 @@ export const MultipleFiltersDropdownContent = ({
|
||||
'LINK',
|
||||
'LINKS',
|
||||
'ADDRESS',
|
||||
'ACTOR',
|
||||
].includes(filterDefinitionUsedInDropdown.type) && (
|
||||
<ObjectFilterDropdownTextSearchInput />
|
||||
)}
|
||||
|
||||
@ -13,4 +13,5 @@ export type FilterType =
|
||||
| 'ADDRESS'
|
||||
| 'SELECT'
|
||||
| 'RATING'
|
||||
| 'MULTI_SELECT';
|
||||
| 'MULTI_SELECT'
|
||||
| 'ACTOR';
|
||||
|
||||
@ -28,6 +28,7 @@ describe('getOperandsForFilterType', () => {
|
||||
['ADDRESS', [...containsOperands, ...emptyOperands]],
|
||||
['LINK', [...containsOperands, ...emptyOperands]],
|
||||
['LINKS', [...containsOperands, ...emptyOperands]],
|
||||
['ACTOR', [...containsOperands, ...emptyOperands]],
|
||||
['CURRENCY', [...numberOperands, ...emptyOperands]],
|
||||
['NUMBER', [...numberOperands, ...emptyOperands]],
|
||||
['DATE_TIME', [...numberOperands, ...emptyOperands]],
|
||||
|
||||
@ -20,6 +20,7 @@ export const getOperandsForFilterType = (
|
||||
case 'PHONE':
|
||||
case 'LINK':
|
||||
case 'LINKS':
|
||||
case 'ACTOR':
|
||||
return [
|
||||
ViewFilterOperand.Contains,
|
||||
ViewFilterOperand.DoesNotContain,
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
import { formatFieldMetadataItemAsFieldDefinition } from '@/object-metadata/utils/formatFieldMetadataItemAsFieldDefinition';
|
||||
import { FieldDefinition } from '@/object-record/record-field/types/FieldDefinition';
|
||||
import {
|
||||
FieldActorMetadata,
|
||||
FieldFullNameMetadata,
|
||||
FieldLinkMetadata,
|
||||
FieldRatingMetadata,
|
||||
FieldSelectMetadata,
|
||||
FieldTextMetadata,
|
||||
FieldTextMetadata
|
||||
} from '@/object-record/record-field/types/FieldMetadata';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
import {
|
||||
@ -79,7 +80,7 @@ export const phoneFieldDefinition = formatFieldMetadataItemAsFieldDefinition({
|
||||
objectMetadataItem: mockedPersonObjectMetadataItem,
|
||||
});
|
||||
|
||||
export const ratingfieldDefinition: FieldDefinition<FieldRatingMetadata> = {
|
||||
export const ratingFieldDefinition: FieldDefinition<FieldRatingMetadata> = {
|
||||
fieldMetadataId,
|
||||
label: 'Rating',
|
||||
iconName: 'iconName',
|
||||
@ -97,3 +98,14 @@ export const booleanFieldDefinition = formatFieldMetadataItemAsFieldDefinition({
|
||||
field: booleanFieldMetadataItem!,
|
||||
objectMetadataItem: mockedCompanyObjectMetadataItem,
|
||||
});
|
||||
|
||||
export const actorFieldDefinition: FieldDefinition<FieldActorMetadata> = {
|
||||
fieldMetadataId,
|
||||
label: 'Created By',
|
||||
iconName: 'restart',
|
||||
type: FieldMetadataType.Actor,
|
||||
defaultValue: { source: 'MANUAL', name: '' },
|
||||
metadata: {
|
||||
fieldName: 'actor',
|
||||
},
|
||||
};
|
||||
@ -1,11 +1,13 @@
|
||||
import { useContext } from 'react';
|
||||
|
||||
import { ActorFieldDisplay } from '@/object-record/record-field/meta-types/display/components/ActorFieldDisplay';
|
||||
import { BooleanFieldDisplay } from '@/object-record/record-field/meta-types/display/components/BooleanFieldDisplay';
|
||||
import { LinksFieldDisplay } from '@/object-record/record-field/meta-types/display/components/LinksFieldDisplay';
|
||||
import { RatingFieldDisplay } from '@/object-record/record-field/meta-types/display/components/RatingFieldDisplay';
|
||||
import { RelationFromManyFieldDisplay } from '@/object-record/record-field/meta-types/display/components/RelationFromManyFieldDisplay';
|
||||
import { RichTextFieldDisplay } from '@/object-record/record-field/meta-types/display/components/RichTextFieldDisplay';
|
||||
import { isFieldIdentifierDisplay } from '@/object-record/record-field/meta-types/display/utils/isFieldIdentifierDisplay';
|
||||
import { isFieldActor } from '@/object-record/record-field/types/guards/isFieldActor';
|
||||
import { isFieldBoolean } from '@/object-record/record-field/types/guards/isFieldBoolean';
|
||||
import { isFieldDisplayedAsPhone } from '@/object-record/record-field/types/guards/isFieldDisplayedAsPhone';
|
||||
import { isFieldLinks } from '@/object-record/record-field/types/guards/isFieldLinks';
|
||||
@ -96,5 +98,7 @@ export const FieldDisplay = () => {
|
||||
<RatingFieldDisplay />
|
||||
) : isFieldRichText(fieldDefinition) ? (
|
||||
<RichTextFieldDisplay />
|
||||
) : isFieldActor(fieldDefinition) ? (
|
||||
<ActorFieldDisplay />
|
||||
) : null;
|
||||
};
|
||||
|
||||
@ -0,0 +1,50 @@
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { ReactNode } from 'react';
|
||||
import { RecoilRoot } from 'recoil';
|
||||
|
||||
import {
|
||||
actorFieldDefinition,
|
||||
phoneFieldDefinition,
|
||||
} from '@/object-record/record-field/__mocks__/fieldDefinitions';
|
||||
import { FieldContext } from '@/object-record/record-field/contexts/FieldContext';
|
||||
import { useIsFieldReadOnly } from '@/object-record/record-field/hooks/useIsFieldReadOnly';
|
||||
import { FieldDefinition } from '@/object-record/record-field/types/FieldDefinition';
|
||||
import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';
|
||||
|
||||
const entityId = 'entityId';
|
||||
|
||||
const getWrapper =
|
||||
(fieldDefinition: FieldDefinition<FieldMetadata>) =>
|
||||
({ children }: { children: ReactNode }) => (
|
||||
<FieldContext.Provider
|
||||
value={{
|
||||
fieldDefinition,
|
||||
entityId,
|
||||
hotkeyScope: 'hotkeyScope',
|
||||
isLabelIdentifier: false,
|
||||
}}
|
||||
>
|
||||
<RecoilRoot>{children}</RecoilRoot>
|
||||
</FieldContext.Provider>
|
||||
);
|
||||
|
||||
const ActorWrapper = getWrapper(actorFieldDefinition);
|
||||
const PhoneWrapper = getWrapper(phoneFieldDefinition);
|
||||
|
||||
describe('useIsFieldReadOnly', () => {
|
||||
it('should return true', () => {
|
||||
const { result } = renderHook(() => useIsFieldReadOnly(), {
|
||||
wrapper: ActorWrapper,
|
||||
});
|
||||
|
||||
expect(result.current).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false', () => {
|
||||
const { result } = renderHook(() => useIsFieldReadOnly(), {
|
||||
wrapper: PhoneWrapper,
|
||||
});
|
||||
|
||||
expect(result.current).toBe(false);
|
||||
});
|
||||
});
|
||||
@ -1,14 +1,16 @@
|
||||
import { useContext } from 'react';
|
||||
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
import { isFieldActor } from '@/object-record/record-field/types/guards/isFieldActor';
|
||||
import { isFieldRichText } from '@/object-record/record-field/types/guards/isFieldRichText';
|
||||
import { FieldContext } from '../contexts/FieldContext';
|
||||
|
||||
export const useIsFieldReadOnly = () => {
|
||||
const { fieldDefinition } = useContext(FieldContext);
|
||||
|
||||
return (
|
||||
fieldDefinition.type === FieldMetadataType.RichText ||
|
||||
fieldDefinition.metadata.fieldName === 'noteTargets' ||
|
||||
fieldDefinition.metadata.fieldName === 'taskTargets' // TODO: do something cleaner
|
||||
fieldDefinition.metadata.fieldName === 'taskTargets' ||
|
||||
isFieldActor(fieldDefinition) ||
|
||||
isFieldRichText(fieldDefinition)
|
||||
);
|
||||
};
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
import { useActorFieldDisplay } from '@/object-record/record-field/meta-types/hooks/useActorFieldDisplay';
|
||||
import { ActorDisplay } from '@/ui/field/display/components/ActorDisplay';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
|
||||
export const ActorFieldDisplay = () => {
|
||||
const { fieldValue } = useActorFieldDisplay();
|
||||
|
||||
const name = !fieldValue.workspaceMemberId
|
||||
? fieldValue.name
|
||||
: [
|
||||
fieldValue.workspaceMember?.name.firstName,
|
||||
fieldValue.workspaceMember?.name.lastName,
|
||||
]
|
||||
.filter(isNonEmptyString)
|
||||
.join(' ');
|
||||
|
||||
return (
|
||||
<ActorDisplay
|
||||
name={name}
|
||||
source={fieldValue.source}
|
||||
avatarUrl={fieldValue.workspaceMember?.avatarUrl}
|
||||
workspaceMemberId={fieldValue.workspaceMemberId}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@ -0,0 +1,41 @@
|
||||
import { ActorFieldDisplay } from '@/object-record/record-field/meta-types/display/components/ActorFieldDisplay';
|
||||
import { FieldActorValue } from '@/object-record/record-field/types/FieldMetadata';
|
||||
import { Meta, StoryObj } from '@storybook/react';
|
||||
import { ComponentDecorator } from 'twenty-ui';
|
||||
|
||||
import { ChipGeneratorsDecorator } from '~/testing/decorators/ChipGeneratorsDecorator';
|
||||
import { getFieldDecorator } from '~/testing/decorators/getFieldDecorator';
|
||||
import { MemoryRouterDecorator } from '~/testing/decorators/MemoryRouterDecorator';
|
||||
import { getProfilingStory } from '~/testing/profiling/utils/getProfilingStory';
|
||||
|
||||
const meta: Meta = {
|
||||
title: 'UI/Data/Field/Display/ActorFieldDisplay',
|
||||
decorators: [
|
||||
MemoryRouterDecorator,
|
||||
ChipGeneratorsDecorator,
|
||||
getFieldDecorator('person', 'actor', {
|
||||
name: 'John Doe',
|
||||
source: 'API',
|
||||
workspaceMemberId: undefined,
|
||||
} satisfies FieldActorValue),
|
||||
ComponentDecorator,
|
||||
],
|
||||
component: ActorFieldDisplay,
|
||||
args: {},
|
||||
parameters: {
|
||||
chromatic: { disableSnapshot: true },
|
||||
},
|
||||
};
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof ActorFieldDisplay>;
|
||||
|
||||
export const Default: Story = {};
|
||||
|
||||
export const Performance = getProfilingStory({
|
||||
componentName: 'ActorFieldDisplay',
|
||||
averageThresholdInMs: 0.2,
|
||||
numberOfRuns: 20,
|
||||
numberOfTestsPerRun: 100,
|
||||
});
|
||||
@ -0,0 +1,30 @@
|
||||
import { useContext } from 'react';
|
||||
|
||||
import { FieldActorValue } from '@/object-record/record-field/types/FieldMetadata';
|
||||
import { useRecordFieldValue } from '@/object-record/record-store/contexts/RecordFieldValueSelectorContext';
|
||||
|
||||
import { AuthContext } from '@/auth/contexts/AuthContext';
|
||||
import { FieldContext } from '../../contexts/FieldContext';
|
||||
|
||||
export const useActorFieldDisplay = () => {
|
||||
const { entityId, fieldDefinition } = useContext(FieldContext);
|
||||
|
||||
const { currentWorkspaceMembers } = useContext(AuthContext);
|
||||
|
||||
const fieldName = fieldDefinition.metadata.fieldName;
|
||||
|
||||
const fieldValue = useRecordFieldValue<FieldActorValue | undefined>(
|
||||
entityId,
|
||||
fieldName,
|
||||
);
|
||||
|
||||
return {
|
||||
fieldDefinition,
|
||||
fieldValue: {
|
||||
...fieldValue,
|
||||
workspaceMember: currentWorkspaceMembers?.find(
|
||||
(member) => member.id === fieldValue?.workspaceMemberId,
|
||||
),
|
||||
},
|
||||
};
|
||||
};
|
||||
@ -8,6 +8,7 @@ import { isFieldText } from '@/object-record/record-field/types/guards/isFieldTe
|
||||
import { useRecordValue } from '@/object-record/record-store/contexts/RecordFieldValueSelectorContext';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
import { isFieldActor } from '@/object-record/record-field/types/guards/isFieldActor';
|
||||
import { FieldContext } from '../../contexts/FieldContext';
|
||||
|
||||
export const useChipFieldDisplay = () => {
|
||||
@ -25,7 +26,8 @@ export const useChipFieldDisplay = () => {
|
||||
const objectNameSingular =
|
||||
isFieldText(fieldDefinition) ||
|
||||
isFieldFullName(fieldDefinition) ||
|
||||
isFieldNumber(fieldDefinition)
|
||||
isFieldNumber(fieldDefinition) ||
|
||||
isFieldActor(fieldDefinition)
|
||||
? fieldDefinition.metadata.objectMetadataNameSingular
|
||||
: undefined;
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { CurrencyCode } from '@/object-record/record-field/types/CurrencyCode';
|
||||
import {
|
||||
FieldActorValue,
|
||||
FieldAddressValue,
|
||||
FieldBooleanValue,
|
||||
FieldCurrencyValue,
|
||||
@ -51,6 +52,11 @@ export type FieldAddressDraftValue = {
|
||||
addressLng: number | null;
|
||||
};
|
||||
export type FieldJsonDraftValue = string;
|
||||
export type FieldActorDraftValue = {
|
||||
source: string;
|
||||
workspaceMemberId?: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type FieldInputDraftValue<FieldValue> = FieldValue extends FieldTextValue
|
||||
? FieldTextDraftValue
|
||||
@ -88,4 +94,6 @@ export type FieldInputDraftValue<FieldValue> = FieldValue extends FieldTextValue
|
||||
? FieldAddressDraftValue
|
||||
: FieldValue extends FieldJsonValue
|
||||
? FieldJsonDraftValue
|
||||
: never;
|
||||
: FieldValue extends FieldActorValue
|
||||
? FieldActorDraftValue
|
||||
: never;
|
||||
|
||||
@ -142,6 +142,11 @@ export type FieldMultiSelectMetadata = {
|
||||
options: { label: string; color: ThemeColor; value: string }[];
|
||||
};
|
||||
|
||||
export type FieldActorMetadata = {
|
||||
objectMetadataNameSingular?: string;
|
||||
fieldName: string;
|
||||
};
|
||||
|
||||
export type FieldMetadata =
|
||||
| FieldBooleanMetadata
|
||||
| FieldCurrencyMetadata
|
||||
@ -158,7 +163,8 @@ export type FieldMetadata =
|
||||
| FieldMultiSelectMetadata
|
||||
| FieldTextMetadata
|
||||
| FieldUuidMetadata
|
||||
| FieldAddressMetadata;
|
||||
| FieldAddressMetadata
|
||||
| FieldActorMetadata;
|
||||
|
||||
export type FieldTextValue = string;
|
||||
export type FieldUUidValue = string;
|
||||
@ -204,3 +210,9 @@ export type FieldRelationValue<
|
||||
|
||||
export type Json = ZodHelperLiteral | { [key: string]: Json } | Json[];
|
||||
export type FieldJsonValue = Record<string, Json> | Json[] | null;
|
||||
|
||||
export type FieldActorValue = {
|
||||
source: string;
|
||||
workspaceMemberId?: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
@ -2,6 +2,7 @@ import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
|
||||
import { FieldDefinition } from '../FieldDefinition';
|
||||
import {
|
||||
FieldActorMetadata,
|
||||
FieldAddressMetadata,
|
||||
FieldBooleanMetadata,
|
||||
FieldCurrencyMetadata,
|
||||
@ -63,7 +64,9 @@ type AssertFieldMetadataFunction = <
|
||||
? FieldRawJsonMetadata
|
||||
: E extends 'RICH_TEXT'
|
||||
? FieldTextMetadata
|
||||
: never,
|
||||
: E extends 'ACTOR'
|
||||
? FieldActorMetadata
|
||||
: never,
|
||||
>(
|
||||
fieldType: E,
|
||||
fieldTypeGuard: (
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
|
||||
import { FieldDefinition } from '../FieldDefinition';
|
||||
import { FieldActorMetadata, FieldMetadata } from '../FieldMetadata';
|
||||
|
||||
export const isFieldActor = (
|
||||
field: Pick<FieldDefinition<FieldMetadata>, 'type'>,
|
||||
): field is FieldDefinition<FieldActorMetadata> =>
|
||||
field.type === FieldMetadataType.Actor;
|
||||
@ -0,0 +1,13 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { FieldActorValue } from '../FieldMetadata';
|
||||
|
||||
const actorSchema = z.object({
|
||||
source: z.string(),
|
||||
workspaceMemberId: z.optional(z.string().nullable()),
|
||||
name: z.string(),
|
||||
});
|
||||
|
||||
export const isFieldActorValue = (
|
||||
fieldValue: unknown,
|
||||
): fieldValue is FieldActorValue => actorSchema.safeParse(fieldValue).success;
|
||||
@ -2,7 +2,7 @@ import { z } from 'zod';
|
||||
|
||||
import { FieldFullNameValue } from '../FieldMetadata';
|
||||
|
||||
const currencySchema = z.object({
|
||||
const fullnameSchema = z.object({
|
||||
firstName: z.string(),
|
||||
lastName: z.string(),
|
||||
});
|
||||
@ -10,4 +10,4 @@ const currencySchema = z.object({
|
||||
export const isFieldFullNameValue = (
|
||||
fieldValue: unknown,
|
||||
): fieldValue is FieldFullNameValue =>
|
||||
currencySchema.safeParse(fieldValue).success;
|
||||
fullnameSchema.safeParse(fieldValue).success;
|
||||
|
||||
@ -2,6 +2,8 @@ import { isString } from '@sniptt/guards';
|
||||
|
||||
import { FieldDefinition } from '@/object-record/record-field/types/FieldDefinition';
|
||||
import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';
|
||||
import { isFieldActor } from '@/object-record/record-field/types/guards/isFieldActor';
|
||||
import { isFieldActorValue } from '@/object-record/record-field/types/guards/isFieldActorValue';
|
||||
import { isFieldAddress } from '@/object-record/record-field/types/guards/isFieldAddress';
|
||||
import { isFieldAddressValue } from '@/object-record/record-field/types/guards/isFieldAddressValue';
|
||||
import { isFieldBoolean } from '@/object-record/record-field/types/guards/isFieldBoolean';
|
||||
@ -13,9 +15,9 @@ import { isFieldEmail } from '@/object-record/record-field/types/guards/isFieldE
|
||||
import { isFieldFullName } from '@/object-record/record-field/types/guards/isFieldFullName';
|
||||
import { isFieldFullNameValue } from '@/object-record/record-field/types/guards/isFieldFullNameValue';
|
||||
import { isFieldLink } from '@/object-record/record-field/types/guards/isFieldLink';
|
||||
import { isFieldLinkValue } from '@/object-record/record-field/types/guards/isFieldLinkValue';
|
||||
import { isFieldLinks } from '@/object-record/record-field/types/guards/isFieldLinks';
|
||||
import { isFieldLinksValue } from '@/object-record/record-field/types/guards/isFieldLinksValue';
|
||||
import { isFieldLinkValue } from '@/object-record/record-field/types/guards/isFieldLinkValue';
|
||||
import { isFieldMultiSelect } from '@/object-record/record-field/types/guards/isFieldMultiSelect';
|
||||
import { isFieldMultiSelectValue } from '@/object-record/record-field/types/guards/isFieldMultiSelectValue';
|
||||
import { isFieldNumber } from '@/object-record/record-field/types/guards/isFieldNumber';
|
||||
@ -112,6 +114,10 @@ export const isFieldValueEmpty = ({
|
||||
);
|
||||
}
|
||||
|
||||
if (isFieldActor(fieldDefinition)) {
|
||||
return !isFieldActorValue(fieldValue) || isValueEmpty(fieldValue.name);
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Entity field type not supported in isFieldValueEmpty : ${fieldDefinition.type}}`,
|
||||
);
|
||||
|
||||
@ -2,6 +2,7 @@ import { isObject } from '@sniptt/guards';
|
||||
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import {
|
||||
ActorFilter,
|
||||
AddressFilter,
|
||||
AndObjectRecordFilter,
|
||||
BooleanFilter,
|
||||
@ -256,6 +257,17 @@ export const isRecordMatchingFilter = ({
|
||||
value: record[filterKey].amountMicros,
|
||||
});
|
||||
}
|
||||
case FieldMetadataType.Actor: {
|
||||
const actorFilter = filterValue as ActorFilter;
|
||||
|
||||
return (
|
||||
actorFilter.name === undefined ||
|
||||
isMatchingStringFilter({
|
||||
stringFilter: actorFilter.name,
|
||||
value: record[filterKey].name,
|
||||
})
|
||||
);
|
||||
}
|
||||
case FieldMetadataType.Relation: {
|
||||
throw new Error(
|
||||
`Not implemented yet, use UUID filter instead on the corredponding "${filterKey}Id" field`,
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
|
||||
import {
|
||||
ActorFilter,
|
||||
AddressFilter,
|
||||
CurrencyFilter,
|
||||
DateFilter,
|
||||
@ -212,6 +213,22 @@ const applyEmptyFilters = (
|
||||
[correspondingField.name + 'Id']: { is: 'NULL' } as RelationFilter,
|
||||
};
|
||||
break;
|
||||
case 'ACTOR':
|
||||
emptyRecordFilter = {
|
||||
or: [
|
||||
{
|
||||
[correspondingField.name]: {
|
||||
name: { ilike: '' },
|
||||
} as ActorFilter,
|
||||
},
|
||||
{
|
||||
[correspondingField.name]: {
|
||||
name: { is: 'NULL' },
|
||||
} as ActorFilter,
|
||||
},
|
||||
],
|
||||
};
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported empty filter type ${filterType}`);
|
||||
}
|
||||
@ -744,6 +761,51 @@ export const turnObjectDropdownFilterIntoQueryFilter = (
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'ACTOR':
|
||||
switch (rawUIFilter.operand) {
|
||||
case ViewFilterOperand.Contains:
|
||||
objectRecordFilters.push({
|
||||
or: [
|
||||
{
|
||||
[correspondingField.name]: {
|
||||
name: {
|
||||
ilike: `%${rawUIFilter.value}%`,
|
||||
},
|
||||
} as ActorFilter,
|
||||
},
|
||||
],
|
||||
});
|
||||
break;
|
||||
case ViewFilterOperand.DoesNotContain:
|
||||
objectRecordFilters.push({
|
||||
and: [
|
||||
{
|
||||
not: {
|
||||
[correspondingField.name]: {
|
||||
name: {
|
||||
ilike: `%${rawUIFilter.value}%`,
|
||||
},
|
||||
} as ActorFilter,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
break;
|
||||
case ViewFilterOperand.IsEmpty:
|
||||
case ViewFilterOperand.IsNotEmpty:
|
||||
applyEmptyFilters(
|
||||
rawUIFilter.operand,
|
||||
correspondingField,
|
||||
objectRecordFilters,
|
||||
rawUIFilter.definition.type,
|
||||
);
|
||||
break;
|
||||
default:
|
||||
throw new Error(
|
||||
`Unknown operand ${rawUIFilter.operand} for ${rawUIFilter.definition.type} filter`,
|
||||
);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown filter type');
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ import { RelationPickerHotkeyScope } from '@/object-record/relation-picker/types
|
||||
import { useInlineCell } from '../hooks/useInlineCell';
|
||||
|
||||
import { RecordInlineCellContainer } from './RecordInlineCellContainer';
|
||||
import { useIsFieldReadOnly } from '@/object-record/record-field/hooks/useIsFieldReadOnly';
|
||||
|
||||
type RecordInlineCellProps = {
|
||||
readonly?: boolean;
|
||||
@ -32,8 +33,12 @@ export const RecordInlineCell = ({
|
||||
|
||||
const isFieldInputOnly = useIsFieldInputOnly();
|
||||
|
||||
const isFieldReadOnly = useIsFieldReadOnly();
|
||||
|
||||
const { closeInlineCell } = useInlineCell();
|
||||
|
||||
const cellIsReadOnly = readonly || isFieldReadOnly;
|
||||
|
||||
const handleEnter: FieldInputEvent = (persistField) => {
|
||||
persistField();
|
||||
closeInlineCell();
|
||||
@ -72,7 +77,7 @@ export const RecordInlineCell = ({
|
||||
return (
|
||||
<FieldFocusContextProvider>
|
||||
<RecordInlineCellContainer
|
||||
readonly={readonly}
|
||||
readonly={cellIsReadOnly}
|
||||
buttonIcon={buttonIcon}
|
||||
customEditHotkeyScope={
|
||||
isFieldRelation(fieldDefinition)
|
||||
@ -100,7 +105,7 @@ export const RecordInlineCell = ({
|
||||
onTab={handleTab}
|
||||
onShiftTab={handleShiftTab}
|
||||
onClickOutside={handleClickOutside}
|
||||
isReadOnly={readonly}
|
||||
isReadOnly={cellIsReadOnly}
|
||||
/>
|
||||
}
|
||||
displayModeContent={<FieldDisplay />}
|
||||
|
||||
@ -78,7 +78,11 @@ export const RecordTableCellSoftFocusMode = ({
|
||||
useScopedHotkeys(
|
||||
Key.Enter,
|
||||
() => {
|
||||
if (!isFieldInputOnly && !isCellReadOnly) {
|
||||
if (isCellReadOnly) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isFieldInputOnly) {
|
||||
openTableCell();
|
||||
} else {
|
||||
toggleEditOnlyInput();
|
||||
@ -91,6 +95,10 @@ export const RecordTableCellSoftFocusMode = ({
|
||||
useScopedHotkeys(
|
||||
'*',
|
||||
(keyboardEvent) => {
|
||||
if (isCellReadOnly) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isFieldInputOnly) {
|
||||
const isWritingText =
|
||||
!isNonTextWritingKey(keyboardEvent.key) &&
|
||||
@ -150,6 +158,8 @@ export const RecordTableCellSoftFocusMode = ({
|
||||
(!isFirstColumn || !isEmpty) &&
|
||||
!isCellReadOnly;
|
||||
|
||||
const dontShowContent = isEmpty && isCellReadOnly;
|
||||
|
||||
return (
|
||||
<>
|
||||
<RecordTableCellDisplayContainer
|
||||
@ -157,7 +167,13 @@ export const RecordTableCellSoftFocusMode = ({
|
||||
scrollRef={scrollRef}
|
||||
softFocus
|
||||
>
|
||||
{editModeContentOnly ? editModeContent : nonEditModeContent}
|
||||
{dontShowContent ? (
|
||||
<></>
|
||||
) : editModeContentOnly ? (
|
||||
editModeContent
|
||||
) : (
|
||||
nonEditModeContent
|
||||
)}
|
||||
</RecordTableCellDisplayContainer>
|
||||
{showButton && (
|
||||
<RecordTableCellButton onClick={handleButtonClick} Icon={buttonIcon} />
|
||||
|
||||
@ -30,4 +30,7 @@ export const COMPOSITE_FIELD_IMPORT_LABELS = {
|
||||
primaryLinkUrlLabel: 'Link URL',
|
||||
primaryLinkLabelLabel: 'Link Label',
|
||||
} satisfies Partial<CompositeFieldLabels<FieldLinksValue>>,
|
||||
[FieldMetadataType.Actor]: {
|
||||
sourceLabel: 'Source',
|
||||
},
|
||||
};
|
||||
|
||||
@ -160,6 +160,11 @@ export const buildRecordFromImportedStructuredRow = (
|
||||
};
|
||||
}
|
||||
break;
|
||||
case FieldMetadataType.Actor:
|
||||
recordToBuild[field.name] = {
|
||||
source: 'IMPORT',
|
||||
};
|
||||
break;
|
||||
default:
|
||||
recordToBuild[field.name] = importedFieldValue;
|
||||
break;
|
||||
|
||||
@ -87,6 +87,12 @@ export const generateEmptyFieldValue = (
|
||||
case FieldMetadataType.RichText: {
|
||||
return null;
|
||||
}
|
||||
case FieldMetadataType.Actor: {
|
||||
return {
|
||||
source: 'MANUAL',
|
||||
name: '',
|
||||
};
|
||||
}
|
||||
default: {
|
||||
throw new Error('Unhandled FieldMetadataType');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user