mirror of
https://github.com/twentyhq/twenty.git
synced 2024-11-30 03:43:02 +03:00
parent
be20a690b3
commit
3ae89d15de
@ -27,6 +27,7 @@ export const StyledSelectableItem = styled(SelectableItem)`
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
`;
|
||||
|
||||
export const MultiRecordSelect = ({
|
||||
onChange,
|
||||
onSubmit,
|
||||
|
@ -10,7 +10,7 @@ import { FieldContext } from '@/object-record/record-field/contexts/FieldContext
|
||||
import { BooleanFieldInput } from '@/object-record/record-field/meta-types/input/components/BooleanFieldInput';
|
||||
import { RatingFieldInput } from '@/object-record/record-field/meta-types/input/components/RatingFieldInput';
|
||||
import { SettingsDataModelSetFieldValueEffect } from '@/settings/data-model/fields/preview/components/SettingsDataModelSetFieldValueEffect';
|
||||
import { SettingsDataModelSetRecordEffect } from '@/settings/data-model/fields/preview/components/SettingsDataModelSetRecordEffect';
|
||||
import { SettingsDataModelSetPreviewRecordEffect } from '@/settings/data-model/fields/preview/components/SettingsDataModelSetRecordEffect';
|
||||
import { useFieldPreviewValue } from '@/settings/data-model/fields/preview/hooks/useFieldPreviewValue';
|
||||
import { usePreviewRecord } from '@/settings/data-model/fields/preview/hooks/usePreviewRecord';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
@ -96,7 +96,7 @@ export const SettingsDataModelFieldPreview = ({
|
||||
return (
|
||||
<>
|
||||
{previewRecord ? (
|
||||
<SettingsDataModelSetRecordEffect
|
||||
<SettingsDataModelSetPreviewRecordEffect
|
||||
fieldName={fieldName}
|
||||
record={previewRecord}
|
||||
/>
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { useSetRecordFieldValue } from '@/object-record/record-store/contexts/RecordFieldValueSelectorContext';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { recordStoreFamilySelector } from '@/object-record/record-store/states/selectors/recordStoreFamilySelector';
|
||||
import { previewRecordIdState } from '@/settings/data-model/fields/preview/states/previewRecordIdState';
|
||||
import { settingsPreviewRecordIdState } from '@/settings/data-model/fields/preview/states/settingsPreviewRecordIdState';
|
||||
import { useEffect } from 'react';
|
||||
import { useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
@ -17,10 +17,10 @@ export const SettingsDataModelSetFieldValueEffect = ({
|
||||
fieldName,
|
||||
value,
|
||||
}: SettingsDataModelSetFieldValueEffectProps) => {
|
||||
const previewRecordId = useRecoilValue(previewRecordIdState);
|
||||
const settingsPreviewRecordId = useRecoilValue(settingsPreviewRecordIdState);
|
||||
|
||||
const upsertedPreviewRecord = useRecoilValue(
|
||||
recordStoreFamilyState(previewRecordId ?? ''),
|
||||
recordStoreFamilyState(settingsPreviewRecordId ?? ''),
|
||||
);
|
||||
|
||||
const setFieldValue = useSetRecoilState(
|
||||
|
@ -1,34 +1,36 @@
|
||||
import { useSetRecordFieldValue } from '@/object-record/record-store/contexts/RecordFieldValueSelectorContext';
|
||||
import { useUpsertRecordsInStore } from '@/object-record/record-store/hooks/useUpsertRecordsInStore';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { previewRecordIdState } from '@/settings/data-model/fields/preview/states/previewRecordIdState';
|
||||
import { settingsPreviewRecordIdState } from '@/settings/data-model/fields/preview/states/settingsPreviewRecordIdState';
|
||||
import { useEffect } from 'react';
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
|
||||
type SettingsDataModelSetRecordEffectProps = {
|
||||
type SettingsDataModelSetPreviewRecordEffectProps = {
|
||||
record: ObjectRecord;
|
||||
fieldName: string;
|
||||
};
|
||||
|
||||
export const SettingsDataModelSetRecordEffect = ({
|
||||
export const SettingsDataModelSetPreviewRecordEffect = ({
|
||||
record,
|
||||
fieldName,
|
||||
}: SettingsDataModelSetRecordEffectProps) => {
|
||||
}: SettingsDataModelSetPreviewRecordEffectProps) => {
|
||||
const { upsertRecords: upsertRecordsInStore } = useUpsertRecordsInStore();
|
||||
const setRecordFieldValue = useSetRecordFieldValue();
|
||||
|
||||
const setPreviewRecordId = useSetRecoilState(previewRecordIdState);
|
||||
const setSettingsPreviewRecordId = useSetRecoilState(
|
||||
settingsPreviewRecordIdState,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
upsertRecordsInStore([record]);
|
||||
setRecordFieldValue(record.id, fieldName, record[fieldName]);
|
||||
setPreviewRecordId(record.id);
|
||||
setSettingsPreviewRecordId(record.id);
|
||||
}, [
|
||||
record,
|
||||
upsertRecordsInStore,
|
||||
setRecordFieldValue,
|
||||
fieldName,
|
||||
setPreviewRecordId,
|
||||
setSettingsPreviewRecordId,
|
||||
]);
|
||||
|
||||
return null;
|
||||
|
@ -1,6 +0,0 @@
|
||||
import { createState } from 'twenty-ui';
|
||||
|
||||
export const previewRecordIdState = createState<string | null>({
|
||||
key: 'previewRecordId',
|
||||
defaultValue: null,
|
||||
});
|
@ -0,0 +1,6 @@
|
||||
import { createState } from 'twenty-ui';
|
||||
|
||||
export const settingsPreviewRecordIdState = createState<string | null>({
|
||||
key: 'settingsPreviewRecordIdState',
|
||||
defaultValue: null,
|
||||
});
|
Loading…
Reference in New Issue
Block a user