The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Fixes on views (#16407)
Marie790a8d6f939d
diff --git a/packages/twenty-front/src/modules/object-record/object-options-dropdown/hooks/useSetViewTypeFromLayoutOptionsMenu.ts b/packages/twenty-front/src/modules/object-record/object-options-dropdown/hooks/useSetViewTypeFromLayoutOptionsMenu.tsindex d29ec98be8e..3e24902c344 100644--- a/packages/twenty-front/src/modules/object-record/object-options-dropdown/hooks/useSetViewTypeFromLayoutOptionsMenu.ts+++ b/packages/twenty-front/src/modules/object-record/object-options-dropdown/hooks/useSetViewTypeFromLayoutOptionsMenu.ts@@ -1,11 +1,9 @@import { MAIN_CONTEXT_STORE_INSTANCE_ID } from '@/context-store/constants/MainContextStoreInstanceId';import { contextStoreCurrentViewIdComponentState } from '@/context-store/states/contextStoreCurrentViewIdComponentState';-import { isSwitchingToKanbanViewTypeComponentState } from '@/object-record/record-board/states/isSwitchingToKanbanViewTypeComponentState';import { useRecordIndexContextOrThrow } from '@/object-record/record-index/contexts/RecordIndexContext';import { useLoadRecordIndexStates } from '@/object-record/record-index/hooks/useLoadRecordIndexStates';import { recordIndexViewTypeState } from '@/object-record/record-index/states/recordIndexViewTypeState';-import { useRecoilComponentCallbackState } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentCallbackState';import { useUpdateCurrentView } from '@/views/hooks/useUpdateCurrentView';import { coreViewsState } from '@/views/states/coreViewState';import { type GraphQLView } from '@/views/types/GraphQLView';@@ -21,8 +19,6 @@ import { ViewCalendarLayout } from '~/generated/graphql';export const useSetViewTypeFromLayoutOptionsMenu = () => {const { updateCurrentView } = useUpdateCurrentView();const setRecordIndexViewType = useSetRecoilState(recordIndexViewTypeState);- const isSwitchingToKanbanViewTypeCallbackState =- useRecoilComponentCallbackState(isSwitchingToKanbanViewTypeComponentState);const { availableFieldsForKanban } = useGetAvailableFieldsForKanban();const { objectMetadataItem } = useRecordIndexContextOrThrow();@@ -64,7 +60,6 @@ export const useSetViewTypeFromLayoutOptionsMenu = () => {switch (viewType) {case ViewType.Kanban: {- set(isSwitchingToKanbanViewTypeCallbackState, true);if (availableFieldsForKanban.length === 0) {throw new Error('No fields for kanban - should not happen');}@@ -159,7 +154,6 @@ export const useSetViewTypeFromLayoutOptionsMenu = () => {}},[- isSwitchingToKanbanViewTypeCallbackState,availableFieldsForKanban,setRecordIndexViewType,updateCurrentView,diff --git a/packages/twenty-front/src/modules/object-record/record-board/components/RecordBoardQueryEffect.tsx b/packages/twenty-front/src/modules/object-record/record-board/components/RecordBoardQueryEffect.tsxindex a9f99eb80ac..fb5ac2c5010 100644--- a/packages/twenty-front/src/modules/object-record/record-board/components/RecordBoardQueryEffect.tsx+++ b/packages/twenty-front/src/modules/object-record/record-board/components/RecordBoardQueryEffect.tsx@@ -1,10 +1,11 @@import { useTriggerRecordBoardFetchMore } from '@/object-record/record-board/hooks/useTriggerRecordBoardFetchMore';import { useTriggerRecordBoardInitialQuery } from '@/object-record/record-board/hooks/useTriggerRecordBoardInitialQuery';-import { isSwitchingToKanbanViewTypeComponentState } from '@/object-record/record-board/states/isSwitchingToKanbanViewTypeComponentState';import { lastRecordBoardQueryIdentifierComponentState } from '@/object-record/record-board/states/lastRecordBoardQueryIdentifierComponentState';+import { lastRecordGroupIdsComponentState } from '@/object-record/record-board/states/lastRecordGroupIdsComponentState';import { recordBoardCurrentGroupByQueryOffsetComponentState } from '@/object-record/record-board/states/recordBoardCurrentGroupByQueryOffsetComponentState';import { recordBoardIsFetchingMoreComponentState } from '@/object-record/record-board/states/recordBoardIsFetchingMoreComponentState';import { recordBoardShouldFetchMoreComponentState } from '@/object-record/record-board/states/recordBoardShouldFetchMoreComponentState';+import { recordGroupIdsComponentState } from '@/object-record/record-group/states/recordGroupIdsComponentState';import { useRecordIndexContextOrThrow } from '@/object-record/record-index/contexts/RecordIndexContext';import { useRecordIndexGroupCommonQueryVariables } from '@/object-record/record-index/hooks/useRecordIndexGroupCommonQueryVariables';@@ -16,6 +17,7 @@ import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hoimport { useSetRecoilComponentState } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentState';import { useEffect } from 'react';+import { isDeeplyEqual } from '~/utils/isDeeplyEqual';export const RecordBoardQueryEffect = () => {const { objectMetadataItem } = useRecordIndexContextOrThrow();@@ -23,10 +25,9 @@ export const RecordBoardQueryEffect = () => {const [lastRecordBoardQueryIdentifier, setLastRecordBoardQueryIdentifier] =useRecoilComponentState(lastRecordBoardQueryIdentifierComponentState);- const [- isSwitchingToKanbanViewTypeCallbackState,- setIsSwitchingToKanbanViewTypeComponentState,- ] = useRecoilComponentState(isSwitchingToKanbanViewTypeComponentState);+ const [lastRecordGroupIds, setLastRecordGroupIds] = useRecoilComponentState(+ lastRecordGroupIdsComponentState,+ );const [recordIndexRecordGroupsAreInInitialLoading] = useRecoilComponentState(recordIndexRecordGroupsAreInInitialLoadingComponentState,@@ -63,13 +64,19 @@ export const RecordBoardQueryEffect = () => {const { triggerRecordBoardInitialQuery } =useTriggerRecordBoardInitialQuery();+ const recordGroupdIds = useRecoilComponentValue(recordGroupIdsComponentState);+ const recordGroupIdsHaveChanged = !isDeeplyEqual(+ [...recordGroupdIds].sort(),+ [...lastRecordGroupIds].sort(),+ );+useEffect(() => {if (!recordIndexRecordGroupsAreInInitialLoading &&- (queryIdentifierHasChanged || isSwitchingToKanbanViewTypeCallbackState)+ (queryIdentifierHasChanged || recordGroupIdsHaveChanged)) {triggerRecordBoardInitialQuery();- setIsSwitchingToKanbanViewTypeComponentState(false);+ setLastRecordGroupIds(recordGroupdIds);} else if (!recordIndexRecordGroupsAreInInitialLoading &&shouldFetchMore &&@@ -89,8 +96,9 @@ export const RecordBoardQueryEffect = () => {shouldFetchMore,recordBoardIsFetchingMore,triggerRecordBoardFetchMore,- isSwitchingToKanbanViewTypeCallbackState,- setIsSwitchingToKanbanViewTypeComponentState,+ setLastRecordGroupIds,+ recordGroupdIds,+ recordGroupIdsHaveChanged,]);return null;diff --git a/packages/twenty-front/src/modules/object-record/record-board/states/isSwitchingToKanbanViewTypeComponentState.ts b/packages/twenty-front/src/modules/object-record/record-board/states/isSwitchingToKanbanViewTypeComponentState.tsdeleted file mode 100644index 74bdeb91f10..00000000000--- a/packages/twenty-front/src/modules/object-record/record-board/states/isSwitchingToKanbanViewTypeComponentState.ts+++ /dev/null@@ -1,9 +0,0 @@-import { ContextStoreComponentInstanceContext } from '@/context-store/states/contexts/ContextStoreComponentInstanceContext';-import { createComponentState } from '@/ui/utilities/state/component-state/utils/createComponentState';--export const isSwitchingToKanbanViewTypeComponentState =- createComponentState<boolean>({- key: 'isSwitchingToKanbanViewTypeComponentState',- componentInstanceContext: ContextStoreComponentInstanceContext,- defaultValue: false,- });diff --git a/packages/twenty-front/src/modules/object-record/record-board/states/lastRecordGroupIdsComponentState.ts b/packages/twenty-front/src/modules/object-record/record-board/states/lastRecordGroupIdsComponentState.tsnew file mode 100644index 00000000000..d9d23d6c876--- /dev/null+++ b/packages/twenty-front/src/modules/object-record/record-board/states/lastRecordGroupIdsComponentState.ts@@ -0,0 +1,8 @@+import { RecordBoardComponentInstanceContext } from '@/object-record/record-board/states/contexts/RecordBoardComponentInstanceContext';+import { createComponentState } from '@/ui/utilities/state/component-state/utils/createComponentState';++export const lastRecordGroupIdsComponentState = createComponentState<string[]>({+ key: 'lastRecordGroupIdsComponentState',+ componentInstanceContext: RecordBoardComponentInstanceContext,+ defaultValue: [],+});diff --git a/packages/twenty-front/src/modules/views/utils/mapViewGroupsToRecordGroupDefinitions.ts b/packages/twenty-front/src/modules/views/utils/mapViewGroupsToRecordGroupDefinitions.tsindex 8e6bca62ff1..4ab607a7609 100644--- a/packages/twenty-front/src/modules/views/utils/mapViewGroupsToRecordGroupDefinitions.ts+++ b/packages/twenty-front/src/modules/views/utils/mapViewGroupsToRecordGroupDefinitions.ts@@ -42,6 +42,14 @@ export const mapViewGroupsToRecordGroupDefinitions = ({(option) => option.value === viewGroup.fieldValue,);+ if (+ !selectedOption &&+ isDefined(viewGroup.fieldValue) &&+ viewGroup.fieldValue !== ''+ ) {+ return null;+ }+if (!selectedOption && selectFieldMetadataItem.isNullable === false) {return null;}