* Removed view field duplicate types * wip * wip 2 * wip 3 * Unified state for fields * Renaming * Wip * Post merge * Post post merge * wip * Delete unused file * Boolean and Probability * Finished InlineCell * Renamed EditableCell to TableCell * Finished double texts * Finished MoneyField * Fixed bug inline cell click outside * Fixed hotkey scope * Final fixes * Phone * Fix url and number input validation * Fix * Fix position * wip refactor activity editor * Fixed activity editor --------- Co-authored-by: Charles Bochet <charles@twenty.com>
73 lines
2.4 KiB
TypeScript
73 lines
2.4 KiB
TypeScript
import { RecoilScopeContext } from '@/types/RecoilScopeContext';
|
|
import { useBoardColumns } from '@/ui/board/hooks/useBoardColumns';
|
|
import { boardCardFieldsScopedState } from '@/ui/board/states/boardCardFieldsScopedState';
|
|
import { BoardFieldDefinition } from '@/ui/board/types/BoardFieldDefinition';
|
|
import { FieldMetadata } from '@/ui/field/types/FieldMetadata';
|
|
import { useRecoilScopedValue } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedValue';
|
|
import { filtersScopedState } from '@/ui/view-bar/states/filtersScopedState';
|
|
import { sortsScopedState } from '@/ui/view-bar/states/sortsScopedState';
|
|
import { ViewType } from '~/generated/graphql';
|
|
|
|
import { useBoardViewFields } from './useBoardViewFields';
|
|
import { useViewFilters } from './useViewFilters';
|
|
import { useViews } from './useViews';
|
|
import { useViewSorts } from './useViewSorts';
|
|
|
|
export const useBoardViews = ({
|
|
fieldDefinitions,
|
|
objectId,
|
|
RecoilScopeContext,
|
|
}: {
|
|
fieldDefinitions: BoardFieldDefinition<FieldMetadata>[];
|
|
objectId: 'company';
|
|
RecoilScopeContext: RecoilScopeContext;
|
|
}) => {
|
|
const boardCardFields = useRecoilScopedValue(
|
|
boardCardFieldsScopedState,
|
|
RecoilScopeContext,
|
|
);
|
|
const filters = useRecoilScopedValue(filtersScopedState, RecoilScopeContext);
|
|
const sorts = useRecoilScopedValue(sortsScopedState, RecoilScopeContext);
|
|
|
|
const handleViewCreate = async (viewId: string) => {
|
|
await createViewFields(boardCardFields, viewId);
|
|
await createViewFilters(filters, viewId);
|
|
await createViewSorts(sorts, viewId);
|
|
};
|
|
|
|
const { createView, deleteView, isFetchingViews, updateView } = useViews({
|
|
objectId,
|
|
onViewCreate: handleViewCreate,
|
|
type: ViewType.Pipeline,
|
|
RecoilScopeContext,
|
|
});
|
|
|
|
const { createViewFields, persistCardFields } = useBoardViewFields({
|
|
objectId,
|
|
viewFieldDefinition: fieldDefinitions,
|
|
skipFetch: isFetchingViews,
|
|
RecoilScopeContext,
|
|
});
|
|
|
|
const { persistBoardColumns } = useBoardColumns();
|
|
|
|
const { createViewFilters, persistFilters } = useViewFilters({
|
|
skipFetch: isFetchingViews,
|
|
RecoilScopeContext,
|
|
});
|
|
|
|
const { createViewSorts, persistSorts } = useViewSorts({
|
|
skipFetch: isFetchingViews,
|
|
RecoilScopeContext,
|
|
});
|
|
|
|
const submitCurrentView = async () => {
|
|
await persistCardFields();
|
|
await persistBoardColumns();
|
|
await persistFilters();
|
|
await persistSorts();
|
|
};
|
|
|
|
return { createView, deleteView, submitCurrentView, updateView };
|
|
};
|