Skip to content

The open alternative to Salesforce, designed for AI.

Improve editable field performances (#1182)

Weikobf09a4d6a296
diff --git a/front/src/modules/ui/editable-field/components/EditableField.tsx b/front/src/modules/ui/editable-field/components/EditableField.tsx
index e7e4bc4b6a2..538aabc74a3 100644
--- a/front/src/modules/ui/editable-field/components/EditableField.tsx
+++ b/front/src/modules/ui/editable-field/components/EditableField.tsx
@@ -4,7 +4,6 @@ import { motion } from 'framer-motion';
import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';
-import { useBindFieldHotkeyScope } from '../hooks/useBindFieldHotkeyScope';
import { useEditableField } from '../hooks/useEditableField';
import { EditableFieldDisplayMode } from './EditableFieldDisplayMode';
@@ -74,7 +73,6 @@ type OwnProps = {
displayModeContentOnly?: boolean;
disableHoverEffect?: boolean;
displayModeContent: React.ReactNode;
- parentHotkeyScope?: HotkeyScope;
customEditHotkeyScope?: HotkeyScope;
isDisplayModeContentEmpty?: boolean;
isDisplayModeFixHeight?: boolean;
@@ -89,7 +87,6 @@ export function EditableField({
useEditButton,
editModeContent,
displayModeContent,
- parentHotkeyScope,
customEditHotkeyScope,
disableHoverEffect,
isDisplayModeContentEmpty,
@@ -100,11 +97,6 @@ export function EditableField({
}: OwnProps) {
const [isHovered, setIsHovered] = useState(false);
- useBindFieldHotkeyScope({
- customEditHotkeyScope,
- parentHotkeyScope,
- });
-
function handleContainerMouseEnter() {
setIsHovered(true);
}
@@ -116,7 +108,7 @@ export function EditableField({
const { isFieldInEditMode, openEditableField } = useEditableField();
function handleDisplayModeClick() {
- openEditableField();
+ openEditableField(customEditHotkeyScope);
}
const showEditButton = !isFieldInEditMode && isHovered && useEditButton;
diff --git a/front/src/modules/ui/editable-field/hooks/useBindFieldHotkeyScope.ts b/front/src/modules/ui/editable-field/hooks/useBindFieldHotkeyScope.ts
deleted file mode 100644
index 2552fa7ba32..00000000000
--- a/front/src/modules/ui/editable-field/hooks/useBindFieldHotkeyScope.ts
+++ /dev/null
@@ -1,75 +0,0 @@
-import { useEffect } from 'react';
-import { useRecoilCallback } from 'recoil';
-
-import { currentHotkeyScopeState } from '@/ui/utilities/hotkey/states/internal/currentHotkeyScopeState';
-import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';
-import { isSameHotkeyScope } from '@/ui/utilities/hotkey/utils/isSameHotkeyScope';
-import { useContextScopeId } from '@/ui/utilities/recoil-scope/hooks/useContextScopeId';
-import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
-import { getSnapshotScopedState } from '@/ui/utilities/recoil-scope/utils/getSnapshotScopedState';
-import { getSnapshotState } from '@/ui/utilities/recoil-scope/utils/getSnapshotState';
-
-import { customEditHotkeyScopeForFieldScopedState } from '../states/customEditHotkeyScopeForFieldScopedState';
-import { FieldContext } from '../states/FieldContext';
-import { parentHotkeyScopeForFieldScopedState } from '../states/parentHotkeyScopeForFieldScopedState';
-
-export function useBindFieldHotkeyScope({
- customEditHotkeyScope,
- parentHotkeyScope,
-}: {
- customEditHotkeyScope?: HotkeyScope;
- parentHotkeyScope?: HotkeyScope;
-}) {
- const [customEditHotkeyScopeForField, setCustomEditHotkeyScopeForField] =
- useRecoilScopedState(
- customEditHotkeyScopeForFieldScopedState,
- FieldContext,
- );
-
- const fieldContextScopeId = useContextScopeId(FieldContext);
-
- useEffect(() => {
- if (
- customEditHotkeyScope &&
- !isSameHotkeyScope(customEditHotkeyScope, customEditHotkeyScopeForField)
- ) {
- setCustomEditHotkeyScopeForField(customEditHotkeyScope);
- }
- }, [
- customEditHotkeyScope,
- customEditHotkeyScopeForField,
- setCustomEditHotkeyScopeForField,
- ]);
-
- const setParentHotkeyScopeForField = useRecoilCallback(
- ({ snapshot, set }) =>
- (parentHotkeyScopeToSet: HotkeyScope | null | undefined) => {
- const currentHotkeyScope = getSnapshotState({
- snapshot,
- state: currentHotkeyScopeState,
- });
-
- const parentHotkeyScopeForField = getSnapshotScopedState({
- snapshot,
- state: parentHotkeyScopeForFieldScopedState,
- contextScopeId: fieldContextScopeId,
- });
-
- if (!parentHotkeyScopeToSet) {
- set(
- parentHotkeyScopeForFieldScopedState(fieldContextScopeId),
- currentHotkeyScope,
- );
- } else if (
- !isSameHotkeyScope(parentHotkeyScopeToSet, parentHotkeyScopeForField)
- ) {
- setParentHotkeyScopeForField(parentHotkeyScopeToSet);
- }
- },
- [fieldContextScopeId],
- );
-
- useEffect(() => {
- setParentHotkeyScopeForField(parentHotkeyScope);
- }, [parentHotkeyScope, setParentHotkeyScopeForField]);
-}
diff --git a/front/src/modules/ui/editable-field/hooks/useEditableField.ts b/front/src/modules/ui/editable-field/hooks/useEditableField.ts
index b676c1b43e8..4db05c69600 100644
--- a/front/src/modules/ui/editable-field/hooks/useEditableField.ts
+++ b/front/src/modules/ui/editable-field/hooks/useEditableField.ts
@@ -1,10 +1,9 @@
-import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
+import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousHotkeyScope';
+import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
-import { customEditHotkeyScopeForFieldScopedState } from '../states/customEditHotkeyScopeForFieldScopedState';
import { FieldContext } from '../states/FieldContext';
import { isFieldInEditModeScopedState } from '../states/isFieldInEditModeScopedState';
-import { parentHotkeyScopeForFieldScopedState } from '../states/parentHotkeyScopeForFieldScopedState';
import { EditableFieldHotkeyScope } from '../types/EditableFieldHotkeyScope';
export function useEditableField() {
@@ -13,39 +12,29 @@ export function useEditableField() {
FieldContext,
);
- const [customEditHotkeyScopeForField] = useRecoilScopedState(
- customEditHotkeyScopeForFieldScopedState,
- FieldContext,
- );
-
- const [parentHotkeyScopeForField] = useRecoilScopedState(
- parentHotkeyScopeForFieldScopedState,
- FieldContext,
- );
-
- const setHotkeyScope = useSetHotkeyScope();
+ const {
+ setHotkeyScopeAndMemorizePreviousScope,
+ goBackToPreviousHotkeyScope,
+ } = usePreviousHotkeyScope();
function closeEditableField() {
setIsFieldInEditMode(false);
- if (parentHotkeyScopeForField) {
- setHotkeyScope(
- parentHotkeyScopeForField.scope,
- parentHotkeyScopeForField.customScopes,
- );
- }
+ goBackToPreviousHotkeyScope();
}
- function openEditableField() {
+ function openEditableField(customEditHotkeyScopeForField?: HotkeyScope) {
setIsFieldInEditMode(true);
if (customEditHotkeyScopeForField) {
- setHotkeyScope(
+ setHotkeyScopeAndMemorizePreviousScope(
customEditHotkeyScopeForField.scope,
customEditHotkeyScopeForField.customScopes,
);
} else {
- setHotkeyScope(EditableFieldHotkeyScope.EditableField);
+ setHotkeyScopeAndMemorizePreviousScope(
+ EditableFieldHotkeyScope.EditableField,
+ );
}
}