Change to using arrow functions (#1603)

* Change to using arrow functions

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Matheus <matheus_benini@hotmail.com>

* Add lint rule

---------

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Matheus <matheus_benini@hotmail.com>
Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
gitstart-twenty
2023-09-16 02:41:10 +01:00
committed by GitHub
parent 549335054a
commit 00a3c8ca2b
575 changed files with 2848 additions and 3063 deletions

View File

@ -3,13 +3,13 @@ import { useEditableCell } from '../editable-cell/hooks/useEditableCell';
import { useMoveSoftFocus } from './useMoveSoftFocus';
export function useCellInputEventHandlers<T>({
export const useCellInputEventHandlers = <T>({
onSubmit,
onCancel,
}: {
onSubmit?: (newValue: T) => void;
onCancel?: () => void;
}) {
}) => {
const { closeEditableCell } = useEditableCell();
const { isCurrentCellInEditMode } = useCurrentCellEditMode();
const { moveRight, moveLeft, moveDown } = useMoveSoftFocus();
@ -44,4 +44,4 @@ export function useCellInputEventHandlers<T>({
moveLeft();
},
};
}
};

View File

@ -3,8 +3,8 @@ import { useRecoilCallback } from 'recoil';
import { currentCellInEditModePositionState } from '../states/currentCellInEditModePositionState';
import { isCellInEditModeFamilyState } from '../states/isCellInEditModeFamilyState';
export function useCloseCurrentCellInEditMode() {
return useRecoilCallback(({ set, snapshot }) => {
export const useCloseCurrentCellInEditMode = () =>
useRecoilCallback(({ set, snapshot }) => {
return async () => {
const currentCellInEditModePosition = await snapshot.getPromise(
currentCellInEditModePositionState,
@ -13,4 +13,3 @@ export function useCloseCurrentCellInEditMode() {
set(isCellInEditModeFamilyState(currentCellInEditModePosition), false);
};
}, []);
}

View File

@ -2,8 +2,8 @@ import { useContext } from 'react';
import { RowIdContext } from '../contexts/RowIdContext';
export function useCurrentRowEntityId() {
export const useCurrentRowEntityId = () => {
const currentEntityId = useContext(RowIdContext);
return currentEntityId;
}
};

View File

@ -4,7 +4,7 @@ import { useRecoilCallback, useRecoilState } from 'recoil';
import { RowIdContext } from '../contexts/RowIdContext';
import { isRowSelectedFamilyState } from '../states/isRowSelectedFamilyState';
export function useCurrentRowSelected() {
export const useCurrentRowSelected = () => {
const currentRowId = useContext(RowIdContext);
const [isRowSelected] = useRecoilState(
@ -33,4 +33,4 @@ export function useCurrentRowSelected() {
currentRowSelected: isRowSelected,
setCurrentRowSelected,
};
}
};

View File

@ -4,8 +4,8 @@ import { isSoftFocusActiveState } from '../states/isSoftFocusActiveState';
import { isSoftFocusOnCellFamilyState } from '../states/isSoftFocusOnCellFamilyState';
import { softFocusPositionState } from '../states/softFocusPositionState';
export function useDisableSoftFocus() {
return useRecoilCallback(({ set, snapshot }) => {
export const useDisableSoftFocus = () =>
useRecoilCallback(({ set, snapshot }) => {
return () => {
const currentPosition = snapshot
.getLoadable(softFocusPositionState)
@ -16,4 +16,3 @@ export function useDisableSoftFocus() {
set(isSoftFocusOnCellFamilyState(currentPosition), false);
};
}, []);
}

View File

@ -8,7 +8,7 @@ import { TableHotkeyScope } from '../types/TableHotkeyScope';
import { useCloseCurrentCellInEditMode } from './useClearCellInEditMode';
import { useDisableSoftFocus } from './useDisableSoftFocus';
export function useLeaveTableFocus() {
export const useLeaveTableFocus = () => {
const disableSoftFocus = useDisableSoftFocus();
const closeCurrentCellInEditMode = useCloseCurrentCellInEditMode();
@ -36,4 +36,4 @@ export function useLeaveTableFocus() {
},
[closeCurrentCellInEditMode, disableSoftFocus],
);
}
};

View File

@ -8,7 +8,7 @@ import { TableHotkeyScope } from '../types/TableHotkeyScope';
import { useDisableSoftFocus } from './useDisableSoftFocus';
import { useMoveSoftFocus } from './useMoveSoftFocus';
export function useMapKeyboardToSoftFocus() {
export const useMapKeyboardToSoftFocus = () => {
const { moveDown, moveLeft, moveRight, moveUp } = useMoveSoftFocus();
const disableSoftFocus = useDisableSoftFocus();
@ -59,4 +59,4 @@ export function useMapKeyboardToSoftFocus() {
TableHotkeyScope.TableSoftFocus,
[disableSoftFocus],
);
}
};

View File

@ -4,8 +4,8 @@ import { currentCellInEditModePositionState } from '../states/currentCellInEditM
import { isCellInEditModeFamilyState } from '../states/isCellInEditModeFamilyState';
import { CellPosition } from '../types/CellPosition';
export function useMoveEditModeToCellPosition() {
return useRecoilCallback(({ set, snapshot }) => {
export const useMoveEditModeToCellPosition = () =>
useRecoilCallback(({ set, snapshot }) => {
return (newPosition: CellPosition) => {
const currentCellInEditModePosition = snapshot
.getLoadable(currentCellInEditModePositionState)
@ -18,4 +18,3 @@ export function useMoveEditModeToCellPosition() {
set(isCellInEditModeFamilyState(newPosition), true);
};
}, []);
}

View File

@ -10,7 +10,8 @@ import { softFocusPositionState } from '../states/softFocusPositionState';
import { useSetSoftFocusPosition } from './useSetSoftFocusPosition';
// TODO: stories
export function useMoveSoftFocus() {
export const useMoveSoftFocus = () => {
const tableScopeId = useRecoilScopeId(TableRecoilScopeContext);
const setSoftFocusPosition = useSetSoftFocusPosition();
@ -155,4 +156,4 @@ export function useMoveSoftFocus() {
moveRight,
moveUp,
};
}
};

View File

@ -3,8 +3,8 @@ import { useRecoilCallback } from 'recoil';
import { isRowSelectedFamilyState } from '../states/isRowSelectedFamilyState';
import { tableRowIdsState } from '../states/tableRowIdsState';
export function useResetTableRowSelection() {
return useRecoilCallback(
export const useResetTableRowSelection = () =>
useRecoilCallback(
({ snapshot, set }) =>
() => {
const tableRowIds = snapshot
@ -17,4 +17,3 @@ export function useResetTableRowSelection() {
},
[],
);
}

View File

@ -4,7 +4,7 @@ import { isRowSelectedFamilyState } from '../states/isRowSelectedFamilyState';
import { allRowsSelectedStatusSelector } from '../states/selectors/allRowsSelectedStatusSelector';
import { tableRowIdsState } from '../states/tableRowIdsState';
export function useSelectAllRows() {
export const useSelectAllRows = () => {
const allRowsSelectedStatus = useRecoilValue(allRowsSelectedStatusSelector);
const selectAllRows = useRecoilCallback(
@ -38,4 +38,4 @@ export function useSelectAllRows() {
allRowsSelectedStatus,
selectAllRows,
};
}
};

View File

@ -13,7 +13,7 @@ import { SortDefinition } from '@/ui/view-bar/types/SortDefinition';
import { isFetchingEntityTableDataState } from '../states/isFetchingEntityTableDataState';
import { numberOfTableRowsState } from '../states/numberOfTableRowsState';
export function useSetEntityTableData() {
export const useSetEntityTableData = () => {
const resetTableRowSelection = useResetTableRowSelection();
const tableContextScopeId = useRecoilScopeId(TableRecoilScopeContext);
@ -62,4 +62,4 @@ export function useSetEntityTableData() {
},
[resetTableRowSelection, tableContextScopeId],
);
}
};

View File

@ -2,8 +2,7 @@ import { useRecoilCallback } from 'recoil';
import { isRowSelectedFamilyState } from '../states/isRowSelectedFamilyState';
export function useSetRowSelectedState() {
return useRecoilCallback(({ set }) => (rowId: string, selected: boolean) => {
export const useSetRowSelectedState = () =>
useRecoilCallback(({ set }) => (rowId: string, selected: boolean) => {
set(isRowSelectedFamilyState(rowId), selected);
});
}

View File

@ -5,8 +5,8 @@ import { isSoftFocusOnCellFamilyState } from '../states/isSoftFocusOnCellFamilyS
import { softFocusPositionState } from '../states/softFocusPositionState';
import { CellPosition } from '../types/CellPosition';
export function useSetSoftFocusPosition() {
return useRecoilCallback(({ set, snapshot }) => {
export const useSetSoftFocusPosition = () =>
useRecoilCallback(({ set, snapshot }) => {
return (newPosition: CellPosition) => {
const currentPosition = snapshot
.getLoadable(softFocusPositionState)
@ -21,4 +21,3 @@ export function useSetSoftFocusPosition() {
set(isSoftFocusOnCellFamilyState(newPosition), true);
};
}, []);
}

View File

@ -49,10 +49,10 @@ import type {
import { EntityUpdateMutationContext } from '../contexts/EntityUpdateMutationHookContext';
import type { ColumnDefinition } from '../types/ColumnDefinition';
export function useUpdateEntityField() {
export const useUpdateEntityField = () => {
const updateEntity = useContext(EntityUpdateMutationContext);
return function updateEntityField<
const updateEntityField = <
MetadataType extends ViewFieldMetadata,
ValueType extends MetadataType extends ViewFieldDoubleTextMetadata
? ViewFieldDoubleTextValue
@ -77,7 +77,7 @@ export function useUpdateEntityField() {
currentEntityId: string,
columnDefinition: ColumnDefinition<MetadataType>,
newFieldValue: ValueType | null,
) {
) => {
// TODO: improve type guards organization, maybe with a common typeguard for all view fields
// taking an object of options as parameter ?
//
@ -174,4 +174,6 @@ export function useUpdateEntityField() {
});
}
};
}
return updateEntityField;
};

View File

@ -2,8 +2,8 @@ import { useRecoilCallback } from 'recoil';
import { tableEntitiesFamilyState } from '@/ui/table/states/tableEntitiesFamilyState';
export function useUpsertEntityTableItem() {
return useRecoilCallback(
export const useUpsertEntityTableItem = () =>
useRecoilCallback(
({ set, snapshot }) =>
<T extends { id: string }>(entity: T) => {
const currentEntity = snapshot
@ -16,4 +16,3 @@ export function useUpsertEntityTableItem() {
},
[],
);
}

View File

@ -2,8 +2,8 @@ import { useRecoilCallback } from 'recoil';
import { tableEntitiesFamilyState } from '@/ui/table/states/tableEntitiesFamilyState';
export function useUpsertEntityTableItems() {
return useRecoilCallback(
export const useUpsertEntityTableItems = () =>
useRecoilCallback(
({ set, snapshot }) =>
<T extends { id: string }>(entities: T[]) => {
// Create a map of new entities for quick lookup.
@ -31,4 +31,3 @@ export function useUpsertEntityTableItems() {
},
[],
);
}

View File

@ -2,8 +2,8 @@ import { useRecoilCallback } from 'recoil';
import { tableRowIdsState } from '../states/tableRowIdsState';
export function useUpsertTableRowId() {
return useRecoilCallback(
export const useUpsertTableRowId = () =>
useRecoilCallback(
({ set, snapshot }) =>
(rowId: string) => {
const currentRowIds = snapshot
@ -14,4 +14,3 @@ export function useUpsertTableRowId() {
},
[],
);
}

View File

@ -2,8 +2,8 @@ import { useRecoilCallback } from 'recoil';
import { tableRowIdsState } from '../states/tableRowIdsState';
export function useUpsertTableRowIds() {
return useRecoilCallback(
export const useUpsertTableRowIds = () =>
useRecoilCallback(
({ set, snapshot }) =>
(rowIds: string[]) => {
const currentRowIds = snapshot
@ -15,4 +15,3 @@ export function useUpsertTableRowIds() {
},
[],
);
}