Remove unused components (#1180)
* Remove unused components * Fix company not being created issue * Fix company not being created issue * Fix company not being created issue * Optimize rendering * Optimize rendering
This commit is contained in:
@ -1,23 +0,0 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
|
||||
import { numberOfTableRowsState } from '../states/numberOfTableRowsState';
|
||||
import { tableRowIdsState } from '../states/tableRowIdsState';
|
||||
|
||||
import { useResetTableRowSelection } from './useResetTableRowSelection';
|
||||
|
||||
export function useInitializeEntityTable() {
|
||||
const resetTableRowSelection = useResetTableRowSelection();
|
||||
|
||||
const tableRowIds = useRecoilValue(tableRowIdsState);
|
||||
|
||||
useEffect(() => {
|
||||
resetTableRowSelection();
|
||||
}, [resetTableRowSelection]);
|
||||
|
||||
const setNumberOfTableRows = useSetRecoilState(numberOfTableRowsState);
|
||||
|
||||
useEffect(() => {
|
||||
setNumberOfTableRows(tableRowIds?.length);
|
||||
}, [tableRowIds, setNumberOfTableRows]);
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { availableFiltersScopedState } from '@/ui/filter-n-sort/states/availableFiltersScopedState';
|
||||
import { FilterDefinition } from '@/ui/filter-n-sort/types/FilterDefinition';
|
||||
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
||||
|
||||
import { TableContext } from '../states/TableContext';
|
||||
|
||||
export function useInitializeEntityTableFilters({
|
||||
availableFilters,
|
||||
}: {
|
||||
availableFilters: FilterDefinition[];
|
||||
}) {
|
||||
const [, setAvailableFilters] = useRecoilScopedState(
|
||||
availableFiltersScopedState,
|
||||
TableContext,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
setAvailableFilters(availableFilters);
|
||||
}, [setAvailableFilters, availableFilters]);
|
||||
}
|
||||
19
front/src/modules/ui/table/hooks/useSetTableRowIds.ts
Normal file
19
front/src/modules/ui/table/hooks/useSetTableRowIds.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { useRecoilCallback } from 'recoil';
|
||||
|
||||
import { tableRowIdsState } from '../states/tableRowIdsState';
|
||||
|
||||
export function useSetTableRowIds() {
|
||||
return useRecoilCallback(
|
||||
({ set, snapshot }) =>
|
||||
(rowIds: string[]) => {
|
||||
const currentRowIds = snapshot
|
||||
.getLoadable(tableRowIdsState)
|
||||
.valueOrThrow();
|
||||
|
||||
if (JSON.stringify(rowIds) !== JSON.stringify(currentRowIds)) {
|
||||
set(tableRowIdsState, rowIds);
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
}
|
||||
@ -17,7 +17,6 @@ import { isViewFieldText } from '@/ui/editable-field/types/guards/isViewFieldTex
|
||||
import { isViewFieldTextValue } from '@/ui/editable-field/types/guards/isViewFieldTextValue';
|
||||
import { isViewFieldURL } from '@/ui/editable-field/types/guards/isViewFieldURL';
|
||||
import { isViewFieldURLValue } from '@/ui/editable-field/types/guards/isViewFieldURLValue';
|
||||
import { EntityUpdateMutationHookContext } from '@/ui/table/states/EntityUpdateMutationHookContext';
|
||||
|
||||
import { isViewFieldChipValue } from '../../editable-field/types/guards/isViewFieldChipValue';
|
||||
import {
|
||||
@ -42,11 +41,10 @@ import {
|
||||
ViewFieldURLMetadata,
|
||||
ViewFieldURLValue,
|
||||
} from '../../editable-field/types/ViewField';
|
||||
import { EntityUpdateMutationContext } from '../states/EntityUpdateMutationHookContext';
|
||||
|
||||
export function useUpdateEntityField() {
|
||||
const useUpdateEntityMutation = useContext(EntityUpdateMutationHookContext);
|
||||
|
||||
const [updateEntity] = useUpdateEntityMutation();
|
||||
const updateEntity = useContext(EntityUpdateMutationContext);
|
||||
|
||||
return function updatePeopleField<
|
||||
MetadataType extends ViewFieldMetadata,
|
||||
|
||||
19
front/src/modules/ui/table/hooks/useUpsertEntityTableItem.ts
Normal file
19
front/src/modules/ui/table/hooks/useUpsertEntityTableItem.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { useRecoilCallback } from 'recoil';
|
||||
|
||||
import { tableEntitiesFamilyState } from '@/ui/table/states/tableEntitiesFamilyState';
|
||||
|
||||
export function useUpsertEntityTableItem() {
|
||||
return useRecoilCallback(
|
||||
({ set, snapshot }) =>
|
||||
<T extends { id: string }>(entity: T) => {
|
||||
const currentEntity = snapshot
|
||||
.getLoadable(tableEntitiesFamilyState(entity.id))
|
||||
.valueOrThrow();
|
||||
|
||||
if (JSON.stringify(currentEntity) !== JSON.stringify(entity)) {
|
||||
set(tableEntitiesFamilyState(entity.id), entity);
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
}
|
||||
17
front/src/modules/ui/table/hooks/useUpsertTableRowId.ts
Normal file
17
front/src/modules/ui/table/hooks/useUpsertTableRowId.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { useRecoilCallback } from 'recoil';
|
||||
|
||||
import { tableRowIdsState } from '../states/tableRowIdsState';
|
||||
|
||||
export function useUpsertTableRowId() {
|
||||
return useRecoilCallback(
|
||||
({ set, snapshot }) =>
|
||||
(rowId: string) => {
|
||||
const currentRowIds = snapshot
|
||||
.getLoadable(tableRowIdsState)
|
||||
.valueOrThrow();
|
||||
|
||||
set(tableRowIdsState, Array.from(new Set([...currentRowIds, rowId])));
|
||||
},
|
||||
[],
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user