The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(workflow): polish the core workflows index and its command menu (#27066)
Thomas Trompette19eda409519e
diff --git a/packages/twenty-front/src/modules/command-menu-item/display/components/SidePanelCommandMenuItemDisplayPage.tsx b/packages/twenty-front/src/modules/command-menu-item/display/components/SidePanelCommandMenuItemDisplayPage.tsxindex 540480cbc45..499b8df4eea 100644--- a/packages/twenty-front/src/modules/command-menu-item/display/components/SidePanelCommandMenuItemDisplayPage.tsx+++ b/packages/twenty-front/src/modules/command-menu-item/display/components/SidePanelCommandMenuItemDisplayPage.tsx@@ -64,8 +64,11 @@ export const SidePanelCommandMenuItemDisplayPage = () => {const { commandMenuItems, commandMenuContextApi } =useContext(CommandMenuContext);- const { coreViewCommandIds, coreSelectionCommandIds } =- useCoreObjectsCommands();+ const {+ coreObjectCommandIds,+ coreSelectionCommandIds,+ coreSelectionSectionContext,+ } = useCoreObjectsCommands();const selectionSectionContext = useCommandMenuItemSelectionSectionContext();const currentViewSectionContext =@@ -141,7 +144,7 @@ export const SidePanelCommandMenuItemDisplayPage = () => {const getSectionContext = (section: CommandMenuItemSection) => {switch (section) {case 'SELECTION':- return selectionSectionContext;+ return coreSelectionSectionContext ?? selectionSectionContext;case 'CURRENT_VIEW':return currentViewSectionContext;case 'THIS_OBJECT':@@ -157,8 +160,11 @@ export const SidePanelCommandMenuItemDisplayPage = () => {appActions.filter((item) => item.section === section);const getSectionExtraItemIds = (section: CommandMenuItemSection) => {- if (section === 'CURRENT_VIEW') {- return coreViewCommandIds;+ if (section === 'THIS_OBJECT') {+ return [+ ...coreObjectCommandIds,+ ...getSectionAppActions(section).map((item) => item.id),+ ];}if (section === 'SELECTION') {@@ -171,7 +177,7 @@ export const SidePanelCommandMenuItemDisplayPage = () => {const hasNoMatchingItems =!matchingItems.length &&appActions.length === 0 &&- coreViewCommandIds.length === 0 &&+ coreObjectCommandIds.length === 0 &&coreSelectionCommandIds.length === 0;const shouldDisplayAskAiFallbackItem = isSearchActive && hasAiPermission;@@ -221,7 +227,7 @@ export const SidePanelCommandMenuItemDisplayPage = () => {{sectionCommandMenuItems.map((item) => (<CommandMenuItemRenderer item={item} key={item.id} />))}- {(section === 'CURRENT_VIEW' || section === 'SELECTION') && (+ {(section === 'THIS_OBJECT' || section === 'SELECTION') && (<CoreObjectsCommands section={section} />)}{getSectionAppActions(section).map((item) => {diff --git a/packages/twenty-front/src/modules/command-menu-item/display/hooks/useCommandMenuItemSelectionSectionContext.tsx b/packages/twenty-front/src/modules/command-menu-item/display/hooks/useCommandMenuItemSelectionSectionContext.tsxindex 53a8df40b3c..f168fa3ff5e 100644--- a/packages/twenty-front/src/modules/command-menu-item/display/hooks/useCommandMenuItemSelectionSectionContext.tsx+++ b/packages/twenty-front/src/modules/command-menu-item/display/hooks/useCommandMenuItemSelectionSectionContext.tsx@@ -3,13 +3,13 @@ import {isDefined,isNonEmptyArray,isNonEmptyString,- resolveObjectMetadataLabel,} from 'twenty-shared/utils';import { allowRequestsToTwentyIconsState } from '@/client-config/states/allowRequestsToTwentyIcons';import { CommandMenuContext } from '@/command-menu-item/contexts/CommandMenuContext';import { CommandMenuItemSelectionRecordStack } from '@/command-menu-item/display/components/CommandMenuItemSelectionRecordStack';import { type CommandMenuItemSectionContext } from '@/command-menu-item/types/CommandMenuItemSectionContext';+import { getSelectedRecordsCountLabel } from '@/command-menu-item/utils/getSelectedRecordsCountLabel';import { useContextStoreObjectMetadataItem } from '@/context-store/hooks/useContextStoreObjectMetadataItem';import { PreComputedChipGeneratorsContext } from '@/object-metadata/contexts/PreComputedChipGeneratorsContext';import { contextStoreRecordIdsInSelectionOrderComponentState } from '@/context-store/states/contextStoreRecordIdsInSelectionOrderComponentState';@@ -83,10 +83,10 @@ export const useCommandMenuItemSelectionSectionContext = ():const label = isNonEmptyString(singleRecordName)? singleRecordName- : `${numberOfSelectedRecords} ${resolveObjectMetadataLabel({+ : getSelectedRecordsCountLabel({objectMetadataItem,numberOfSelectedRecords,- })}`;+ });// Record avatars come from the object's identifier chip, which objects// without a label identifier field do not have.diff --git a/packages/twenty-front/src/modules/command-menu-item/utils/getSelectedRecordsCountLabel.ts b/packages/twenty-front/src/modules/command-menu-item/utils/getSelectedRecordsCountLabel.tsnew file mode 100644index 00000000000..debdb2bdf76--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/utils/getSelectedRecordsCountLabel.ts@@ -0,0 +1,13 @@+import { resolveObjectMetadataLabel } from 'twenty-shared/utils';++export const getSelectedRecordsCountLabel = ({+ objectMetadataItem,+ numberOfSelectedRecords,+}: {+ objectMetadataItem: { labelSingular: string; labelPlural: string };+ numberOfSelectedRecords: number;+}) =>+ `${numberOfSelectedRecords} ${resolveObjectMetadataLabel({+ objectMetadataItem,+ numberOfSelectedRecords,+ })}`;diff --git a/packages/twenty-front/src/modules/object-core/commands/components/CoreObjectsCommands.tsx b/packages/twenty-front/src/modules/object-core/commands/components/CoreObjectsCommands.tsxindex 23fd22bee21..ce263b1f39b 100644--- a/packages/twenty-front/src/modules/object-core/commands/components/CoreObjectsCommands.tsx+++ b/packages/twenty-front/src/modules/object-core/commands/components/CoreObjectsCommands.tsx@@ -10,7 +10,7 @@ import { useSidePanelMenu } from '@/side-panel/hooks/useSidePanelMenu';import { SelectableListItem } from '@/ui/layout/selectable-list/components/SelectableListItem';type CoreObjectsCommandsProps = {- section: 'CURRENT_VIEW' | 'SELECTION';+ section: 'THIS_OBJECT' | 'SELECTION';};export const CoreObjectsCommands = ({ section }: CoreObjectsCommandsProps) => {@@ -35,20 +35,19 @@ export const CoreObjectsCommands = ({ section }: CoreObjectsCommandsProps) => {return (<>- {section === 'CURRENT_VIEW' &&- shouldDisplayCoreWorkflowFiltersCommand && (- <SelectableListItem- itemId={CORE_WORKFLOW_FILTERS_COMMAND_ID}- onEnter={openCoreWorkflowFiltersSidePanel}- >- <CommandMenuItem- id={CORE_WORKFLOW_FILTERS_COMMAND_ID}- label={coreWorkflowFiltersCommandLabel}- Icon={IconFilter}- onClick={openCoreWorkflowFiltersSidePanel}- />- </SelectableListItem>- )}+ {section === 'THIS_OBJECT' && shouldDisplayCoreWorkflowFiltersCommand && (+ <SelectableListItem+ itemId={CORE_WORKFLOW_FILTERS_COMMAND_ID}+ onEnter={openCoreWorkflowFiltersSidePanel}+ >+ <CommandMenuItem+ id={CORE_WORKFLOW_FILTERS_COMMAND_ID}+ label={coreWorkflowFiltersCommandLabel}+ Icon={IconFilter}+ onClick={openCoreWorkflowFiltersSidePanel}+ />+ </SelectableListItem>+ )}{section === 'SELECTION' && shouldDisplayCoreWorkflowsDeleteCommand && (<SelectableListItemitemId={CORE_WORKFLOWS_DELETE_COMMAND_ID}diff --git a/packages/twenty-front/src/modules/object-core/commands/hooks/__tests__/useCoreObjectsCommands.test.tsx b/packages/twenty-front/src/modules/object-core/commands/hooks/__tests__/useCoreObjectsCommands.test.tsxindex 4b058ec737b..f3dedbd405f 100644--- a/packages/twenty-front/src/modules/object-core/commands/hooks/__tests__/useCoreObjectsCommands.test.tsx+++ b/packages/twenty-front/src/modules/object-core/commands/hooks/__tests__/useCoreObjectsCommands.test.tsx@@ -32,6 +32,8 @@ jest.mock('@/object-metadata/hooks/useObjectMetadataItem', () => ({useObjectMetadataItem: () => ({objectMetadataItem: {id: '20202020-9e2b-4f2b-8f47-61b41565859a',+ labelSingular: 'Workflow',+ labelPlural: 'Workflows',},}),}));@@ -91,6 +93,13 @@ describe('useCoreObjectsCommands', () => {expect(result.current.shouldDisplayCoreWorkflowFiltersCommand).toBe(true);});+ it('labels the selection section with the selected workflow count', () => {+ const { result } = renderCommands();+ expect(result.current.coreSelectionSectionContext).toEqual({+ label: '1 Workflow',+ });+ });+it('does not expose core deletion without the workflow permission', () => {mockHasPermission.mockReturnValue(false);const { result } = renderCommands();@@ -106,7 +115,8 @@ describe('useCoreObjectsCommands', () => {it('keeps core commands hidden with the flag off', () => {mockIsCoreEnabled.mockReturnValue(false);const { result } = renderCommands();- expect(result.current.coreViewCommandIds).toEqual([]);+ expect(result.current.coreObjectCommandIds).toEqual([]);expect(result.current.coreSelectionCommandIds).toEqual([]);+ expect(result.current.coreSelectionSectionContext).toBeUndefined();});});diff --git a/packages/twenty-front/src/modules/object-core/commands/hooks/useCoreObjectsCommands.ts b/packages/twenty-front/src/modules/object-core/commands/hooks/useCoreObjectsCommands.tsindex b4638ccaa18..6c7e9baa327 100644--- a/packages/twenty-front/src/modules/object-core/commands/hooks/useCoreObjectsCommands.ts+++ b/packages/twenty-front/src/modules/object-core/commands/hooks/useCoreObjectsCommands.ts@@ -8,6 +8,7 @@ import {import { isNonEmptyArray } from 'twenty-shared/utils';import { CommandMenuContext } from '@/command-menu-item/contexts/CommandMenuContext';+import { getSelectedRecordsCountLabel } from '@/command-menu-item/utils/getSelectedRecordsCountLabel';import { CORE_WORKFLOWS_DELETE_COMMAND_ID } from '@/object-core/commands/constants/CoreWorkflowsDeleteCommandId';import { CORE_WORKFLOW_FILTERS_COMMAND_ID } from '@/object-core/commands/constants/CoreWorkflowFiltersCommandId';import { coreWorkflowsFilterSettingsState } from '@/object-core/workflows/states/coreWorkflowsFilterSettingsState';@@ -82,7 +83,7 @@ export const useCoreObjectsCommands = () => {workflowObjectPermissions.canSoftDeleteObjectRecords &&matchesSidePanelSearch(coreWorkflowsDeleteCommandLabel);- const coreViewCommandIds = shouldDisplayCoreWorkflowFiltersCommand+ const coreObjectCommandIds = shouldDisplayCoreWorkflowFiltersCommand? [CORE_WORKFLOW_FILTERS_COMMAND_ID]: [];@@ -90,9 +91,20 @@ export const useCoreObjectsCommands = () => {? [CORE_WORKFLOWS_DELETE_COMMAND_ID]: [];+ const coreSelectionSectionContext =+ isOnCoreWorkflowsIndex && isNonEmptyArray(selectedCoreWorkflowIds)+ ? {+ label: getSelectedRecordsCountLabel({+ objectMetadataItem: workflowObjectMetadataItem,+ numberOfSelectedRecords: selectedCoreWorkflowIds.length,+ }),+ }+ : undefined;+return {- coreViewCommandIds,+ coreObjectCommandIds,coreSelectionCommandIds,+ coreSelectionSectionContext,coreWorkflowFiltersCommandLabel,shouldDisplayCoreWorkflowFiltersCommand,coreWorkflowsDeleteCommandLabel,diff --git a/packages/twenty-front/src/modules/object-core/components/CoreObjectTableAddNewRow.tsx b/packages/twenty-front/src/modules/object-core/components/CoreObjectTableAddNewRow.tsxindex a549276f863..50a6a461629 100644--- a/packages/twenty-front/src/modules/object-core/components/CoreObjectTableAddNewRow.tsx+++ b/packages/twenty-front/src/modules/object-core/components/CoreObjectTableAddNewRow.tsx@@ -2,6 +2,8 @@ import { styled } from '@linaria/react';import { IconPlus } from 'twenty-ui/icon';import { themeCssVariables } from 'twenty-ui/theme';+import { CORE_OBJECT_TABLE_CHECKBOX_COLUMN_GRID_TRACK } from '@/object-core/constants/CoreObjectTableCheckboxColumnGridTrack';+const StyledAddNewRow = styled.button`align-items: center;background: transparent;@@ -14,6 +16,10 @@ const StyledAddNewRow = styled.button`gap: ${themeCssVariables.spacing[1]};height: ${themeCssVariables.spacing[8]};padding: 0 ${themeCssVariables.spacing[2]};+ padding-inline-start: calc(+ ${CORE_OBJECT_TABLE_CHECKBOX_COLUMN_GRID_TRACK} ++ ${themeCssVariables.spacing[2]}+ );width: 100%;&:not(:disabled) {diff --git a/packages/twenty-front/src/modules/object-core/components/cells/CoreObjectNameCell.tsx b/packages/twenty-front/src/modules/object-core/components/cells/CoreObjectNameCell.tsxindex 65f54857a75..4fc17254a1c 100644--- a/packages/twenty-front/src/modules/object-core/components/cells/CoreObjectNameCell.tsx+++ b/packages/twenty-front/src/modules/object-core/components/cells/CoreObjectNameCell.tsx@@ -1,21 +1,20 @@import { styled } from '@linaria/react';import { useLingui } from '@lingui/react/macro';import { isNonEmptyString } from '@sniptt/guards';-import { TintedIconTile } from 'twenty-ui/components';+import { Avatar, type AvatarShape } from 'twenty-ui/primitives/data-display';import { OverflowingTextWithTooltip } from 'twenty-ui/primitives/typography';-import { type IconComponent } from 'twenty-ui/icon';-import { type ThemeColor, themeCssVariables } from 'twenty-ui/theme';+import { themeCssVariables } from 'twenty-ui/theme';const StyledContainer = styled.div`align-items: center;color: ${themeCssVariables.font.color.primary};display: flex;- gap: ${themeCssVariables.spacing[2]};+ gap: ${themeCssVariables.spacing[1]};min-width: 0;overflow: hidden;`;-const StyledIconContainer = styled.span`+const StyledAvatarContainer = styled.span`align-items: center;display: flex;flex-shrink: 0;@@ -23,22 +22,27 @@ const StyledIconContainer = styled.span`type CoreObjectNameCellProps = {name: string | null | undefined;- Icon: IconComponent;- iconColor?: ThemeColor;+ avatarColorSeed: string;+ avatarShape: AvatarShape;};export const CoreObjectNameCell = ({name,- Icon,- iconColor,+ avatarColorSeed,+ avatarShape,}: CoreObjectNameCellProps) => {const { t } = useLingui();return (<StyledContainer>- <StyledIconContainer>- <TintedIconTile Icon={Icon} color={iconColor} size={16} />- </StyledIconContainer>+ <StyledAvatarContainer>+ <Avatar+ name={name ?? undefined}+ colorSeed={avatarColorSeed}+ size="sm"+ shape={avatarShape}+ />+ </StyledAvatarContainer><OverflowingTextWithTooltiptext={isNonEmptyString(name) ? name : t`Untitled`}/>diff --git a/packages/twenty-front/src/modules/object-core/workflows/components/CoreWorkflowNameCell.tsx b/packages/twenty-front/src/modules/object-core/workflows/components/CoreWorkflowNameCell.tsxindex addbb8e7f27..387f0b0329e 100644--- a/packages/twenty-front/src/modules/object-core/workflows/components/CoreWorkflowNameCell.tsx+++ b/packages/twenty-front/src/modules/object-core/workflows/components/CoreWorkflowNameCell.tsx@@ -1,9 +1,8 @@import { CoreObjectNameSingular } from 'twenty-shared/types';-import { useIcons } from 'twenty-ui/icon';-import { stringToThemeColor } from 'twenty-ui/utilities';import { CoreObjectNameCell } from '@/object-core/components/cells/CoreObjectNameCell';import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';+import { getAvatarShape } from '@/object-metadata/utils/getAvatarShape';type CoreWorkflowNameCellProps = {name: string | null | undefined;@@ -17,13 +16,12 @@ export const CoreWorkflowNameCell = ({const { objectMetadataItem } = useObjectMetadataItem({objectNameSingular: CoreObjectNameSingular.Workflow,});- const { getIcon } = useIcons();return (<CoreObjectNameCellname={name}- Icon={getIcon(objectMetadataItem.icon)}- iconColor={stringToThemeColor(workflowId)}+ avatarColorSeed={workflowId}+ avatarShape={getAvatarShape(objectMetadataItem)}/>);};diff --git a/packages/twenty-front/src/modules/object-core/workflows/components/CoreWorkflowVisibilityCell.tsx b/packages/twenty-front/src/modules/object-core/workflows/components/CoreWorkflowVisibilityCell.tsxindex 79edcebac7b..12ad61d4c2a 100644--- a/packages/twenty-front/src/modules/object-core/workflows/components/CoreWorkflowVisibilityCell.tsx+++ b/packages/twenty-front/src/modules/object-core/workflows/components/CoreWorkflowVisibilityCell.tsx@@ -1,6 +1,6 @@import { t } from '@lingui/core/macro';import { isDefined } from 'twenty-shared/utils';-import { OverflowingTextWithTooltip } from 'twenty-ui/primitives/typography';+import { Tag } from 'twenty-ui/primitives/data-display';import { type WorkflowVisibility } from '~/generated/graphql';import { CORE_WORKFLOW_VISIBILITY_OPTIONS } from '@/object-core/workflows/constants/CoreWorkflowVisibilityOptions';@@ -20,5 +20,13 @@ export const CoreWorkflowVisibilityCell = ({return null;}- return <OverflowingTextWithTooltip text={t(visibilityOption.label)} />;+ return (+ <Tag+ color="transparent"+ startIcon={<visibilityOption.Icon />}+ preventPadding+ >+ {t(visibilityOption.label)}+ </Tag>+ );};