The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
feat: Improved Page and History names (#4908)
Zoltán Völcsey5477665e5db4
diff --git a/packages/twenty-front/src/modules/types/SettingsPath.ts b/packages/twenty-front/src/modules/types/SettingsPath.tsindex 656f57847b6..d0f45375710 100644--- a/packages/twenty-front/src/modules/types/SettingsPath.ts+++ b/packages/twenty-front/src/modules/types/SettingsPath.ts@@ -1,6 +1,6 @@export enum SettingsPath {ProfilePage = 'profile',- Appearance = 'profile/appearance',+ Appearance = 'appearance',Accounts = 'accounts',NewAccount = 'accounts/new',AccountsCalendars = 'accounts/calendars',diff --git a/packages/twenty-front/src/modules/views/components/ViewBar.tsx b/packages/twenty-front/src/modules/views/components/ViewBar.tsxindex ca9903c468f..1fa164e72cc 100644--- a/packages/twenty-front/src/modules/views/components/ViewBar.tsx+++ b/packages/twenty-front/src/modules/views/components/ViewBar.tsx@@ -5,14 +5,17 @@ import { ObjectFilterDropdownButton } from '@/object-record/object-filter-dropdoimport { FiltersHotkeyScope } from '@/object-record/object-filter-dropdown/types/FiltersHotkeyScope';import { ObjectSortDropdownButton } from '@/object-record/object-sort-dropdown/components/ObjectSortDropdownButton';import { TopBar } from '@/ui/layout/top-bar/TopBar';+import { PageTitle } from '@/ui/utilities/page-title/PageTitle';import { QueryParamsFiltersEffect } from '@/views/components/QueryParamsFiltersEffect';import { QueryParamsViewIdEffect } from '@/views/components/QueryParamsViewIdEffect';import { ViewBarEffect } from '@/views/components/ViewBarEffect';import { ViewBarFilterEffect } from '@/views/components/ViewBarFilterEffect';import { ViewBarSortEffect } from '@/views/components/ViewBarSortEffect';+import { useGetCurrentView } from '@/views/hooks/useGetCurrentView';import { ViewScope } from '@/views/scopes/ViewScope';import { GraphQLView } from '@/views/types/GraphQLView';import { ViewPickerDropdown } from '@/views/view-picker/components/ViewPickerDropdown';+import { capitalize } from '~/utils/string/capitalize';import { ViewsHotkeyScope } from '../types/ViewsHotkeyScope';@@ -34,6 +37,9 @@ export const ViewBar = ({}: ViewBarProps) => {const { objectNamePlural } = useParams();+ const { currentViewWithCombinedFiltersAndSorts: currentView } =+ useGetCurrentView(viewBarId);+const filterDropdownId = 'view-filter';const sortDropdownId = 'view-sort';@@ -41,6 +47,10 @@ export const ViewBar = ({return;}+ const pageTitle = currentView?.name+ ? `${currentView?.name} - ${capitalize(objectNamePlural)}`+ : capitalize(objectNamePlural);+return (<ViewScopeviewScopeId={viewBarId}@@ -52,6 +62,7 @@ export const ViewBar = ({<QueryParamsFiltersEffect /><QueryParamsViewIdEffect />+ <PageTitle title={pageTitle} /><TopBarclassName={className}leftComponent={diff --git a/packages/twenty-front/src/pages/not-found/NotFound.tsx b/packages/twenty-front/src/pages/not-found/NotFound.tsxindex d799fea0e10..d24a91ac3a9 100644--- a/packages/twenty-front/src/pages/not-found/NotFound.tsx+++ b/packages/twenty-front/src/pages/not-found/NotFound.tsx@@ -11,6 +11,7 @@ import {AnimatedPlaceholderErrorSubTitle,AnimatedPlaceholderErrorTitle,} from '@/ui/layout/animated-placeholder/components/ErrorPlaceholderStyled';+import { PageTitle } from '@/ui/utilities/page-title/PageTitle';const StyledBackDrop = styled.div`align-items: center;@@ -36,6 +37,7 @@ export const NotFound = () => {return (<>+ <PageTitle title="Page Not Found | Twenty" /><StyledBackDrop><AnimatedPlaceholderErrorContainer><AnimatedPlaceholder type="error404" />diff --git a/packages/twenty-front/src/pages/object-record/RecordIndexPage.tsx b/packages/twenty-front/src/pages/object-record/RecordIndexPage.tsxindex dbd2aacbad7..51ee50fce23 100644--- a/packages/twenty-front/src/pages/object-record/RecordIndexPage.tsx+++ b/packages/twenty-front/src/pages/object-record/RecordIndexPage.tsx@@ -9,7 +9,9 @@ import { useSelectedTableCellEditMode } from '@/object-record/record-table/recorimport { PageBody } from '@/ui/layout/page/PageBody';import { PageContainer } from '@/ui/layout/page/PageContainer';import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';+import { PageTitle } from '@/ui/utilities/page-title/PageTitle';import { RecordIndexPageHeader } from '~/pages/object-record/RecordIndexPageHeader';+import { capitalize } from '~/utils/string/capitalize';const StyledIndexContainer = styled.div`display: flex;@@ -40,6 +42,7 @@ export const RecordIndexPage = () => {return (<PageContainer>+ <PageTitle title={`${capitalize(objectNamePlural)}`} /><RecordIndexPageHeader createRecord={handleAddButtonClick} /><PageBody><StyledIndexContainer>diff --git a/packages/twenty-front/src/pages/object-record/RecordShowPage.tsx b/packages/twenty-front/src/pages/object-record/RecordShowPage.tsxindex 52c1d9f68a5..0a9dde69dda 100644--- a/packages/twenty-front/src/pages/object-record/RecordShowPage.tsx+++ b/packages/twenty-front/src/pages/object-record/RecordShowPage.tsx@@ -18,6 +18,7 @@ import { ShowPageMoreButton } from '@/ui/layout/show-page/components/ShowPageMorimport { PageTitle } from '@/ui/utilities/page-title/PageTitle';import { FieldMetadataType } from '~/generated-metadata/graphql';import { isDefined } from '~/utils/isDefined';+import { capitalize } from '~/utils/string/capitalize';export const RecordShowPage = () => {const { objectNameSingular, objectRecordId } = useParams<{@@ -80,13 +81,20 @@ export const RecordShowPage = () => {const labelIdentifierFieldValue =record?.[labelIdentifierFieldMetadataItem?.name ?? ''];+const pageName =labelIdentifierFieldMetadataItem?.type === FieldMetadataType.FullName? [labelIdentifierFieldValue?.firstName,labelIdentifierFieldValue?.lastName,].join(' ')- : `${labelIdentifierFieldValue}`;+ : isDefined(labelIdentifierFieldValue)+ ? `${labelIdentifierFieldValue}`+ : '';++ const pageTitle = pageName.trim()+ ? `${pageName} - ${capitalize(objectNameSingular)}`+ : capitalize(objectNameSingular);// Temporarily since we don't have relations for remote objects yetif (objectMetadataItem.isRemote) {@@ -95,7 +103,7 @@ export const RecordShowPage = () => {return (<PageContainer>- <PageTitle title={pageName} />+ <PageTitle title={pageTitle} /><PageHeadertitle={pageName ?? ''}hasBackButtondiff --git a/packages/twenty-front/src/utils/__tests__/title-utils.test.ts b/packages/twenty-front/src/utils/__tests__/title-utils.test.tsindex 1a4e53d3380..6fee91bf0a7 100644--- a/packages/twenty-front/src/utils/__tests__/title-utils.test.ts+++ b/packages/twenty-front/src/utils/__tests__/title-utils.test.ts@@ -1,4 +1,4 @@-import { getPageTitleFromPath } from '../title-utils';+import { getPageTitleFromPath, SettingsPageTitles } from '../title-utils';describe('title-utils', () => {it('should return the correct title for a given path', () => {@@ -13,14 +13,39 @@ describe('title-utils', () => {expect(getPageTitleFromPath('/objects/opportunities')).toBe('Opportunities',);- expect(getPageTitleFromPath('/settings/profile')).toBe('Profile');- expect(getPageTitleFromPath('/settings/profile/appearance')).toBe(- 'Appearance',+ expect(getPageTitleFromPath('/settings/objects/opportunities')).toBe(+ SettingsPageTitles.Objects,+ );+ expect(getPageTitleFromPath('/settings/profile')).toBe(+ SettingsPageTitles.Profile,+ );+ expect(getPageTitleFromPath('/settings/appearance')).toBe(+ SettingsPageTitles.Appearance,+ );+ expect(getPageTitleFromPath('/settings/accounts')).toBe(+ SettingsPageTitles.Accounts,+ );+ expect(getPageTitleFromPath('/settings/accounts/new')).toBe(+ SettingsPageTitles.Accounts,+ );+ expect(getPageTitleFromPath('/settings/accounts/calendars')).toBe(+ SettingsPageTitles.Accounts,+ );+ expect(+ getPageTitleFromPath('/settings/accounts/calendars/:accountUuid'),+ ).toBe(SettingsPageTitles.Accounts);+ expect(getPageTitleFromPath('/settings/accounts/emails')).toBe(+ SettingsPageTitles.Accounts,+ );+ expect(getPageTitleFromPath('/settings/accounts/emails/:accountUuid')).toBe(+ SettingsPageTitles.Accounts,);expect(getPageTitleFromPath('/settings/workspace-members')).toBe(- 'Workspace Members',+ SettingsPageTitles.Members,+ );+ expect(getPageTitleFromPath('/settings/workspace')).toBe(+ SettingsPageTitles.General,);- expect(getPageTitleFromPath('/settings/workspace')).toBe('Workspace');expect(getPageTitleFromPath('/')).toBe('Twenty');expect(getPageTitleFromPath('/random')).toBe('Twenty');});diff --git a/packages/twenty-front/src/utils/title-utils.ts b/packages/twenty-front/src/utils/title-utils.tsindex 8723e9aa51e..9d604c5eeb4 100644--- a/packages/twenty-front/src/utils/title-utils.ts+++ b/packages/twenty-front/src/utils/title-utils.ts@@ -2,8 +2,41 @@ import { AppBasePath } from '@/types/AppBasePath';import { AppPath } from '@/types/AppPath';import { SettingsPath } from '@/types/SettingsPath';+export enum SettingsPageTitles {+ Accounts = 'Account - Settings',+ Appearance = 'Appearance - Settings',+ Profile = 'Profile - Settings',+ Objects = 'Data model - Settings',+ Members = 'Members - Settings',+ Developers = 'Developers - Settings',+ Integration = 'Integrations - Settings',+ General = 'General - Settings',+ Default = 'Settings',+}++enum SettingsPathPrefixes {+ Accounts = `${AppBasePath.Settings}/${SettingsPath.Accounts}`,+ Appearance = `${AppBasePath.Settings}/${SettingsPath.Appearance}`,+ Profile = `${AppBasePath.Settings}/${SettingsPath.ProfilePage}`,+ Objects = `${AppBasePath.Settings}/${SettingsPath.Objects}`,+ Members = `${AppBasePath.Settings}/${SettingsPath.WorkspaceMembersPage}`,+ Developers = `${AppBasePath.Settings}/${SettingsPath.Developers}`,+ Integration = `${AppBasePath.Settings}/${SettingsPath.Integrations}`,+ General = `${AppBasePath.Settings}/${SettingsPath.Workspace}`,+}++const getPathnameOrPrefix = (pathname: string) => {+ for (const prefix of Object.values(SettingsPathPrefixes)) {+ if (pathname.startsWith(prefix)) {+ return prefix;+ }+ }+ return pathname;+};+export const getPageTitleFromPath = (pathname: string): string => {- switch (pathname) {+ const pathnameOrPrefix = getPathnameOrPrefix(pathname);+ switch (pathnameOrPrefix) {case AppPath.Verify:return 'Verify';case AppPath.SignInUp:@@ -18,14 +51,22 @@ export const getPageTitleFromPath = (pathname: string): string => {return 'Tasks';case AppPath.OpportunitiesPage:return 'Opportunities';- case `${AppBasePath.Settings}/${SettingsPath.ProfilePage}`:- return 'Profile';- case `${AppBasePath.Settings}/${SettingsPath.Appearance}`:- return 'Appearance';- case `${AppBasePath.Settings}/${SettingsPath.WorkspaceMembersPage}`:- return 'Workspace Members';- case `${AppBasePath.Settings}/${SettingsPath.Workspace}`:- return 'Workspace';+ case SettingsPathPrefixes.Appearance:+ return SettingsPageTitles.Appearance;+ case SettingsPathPrefixes.Accounts:+ return SettingsPageTitles.Accounts;+ case SettingsPathPrefixes.Profile:+ return SettingsPageTitles.Profile;+ case SettingsPathPrefixes.Members:+ return SettingsPageTitles.Members;+ case SettingsPathPrefixes.Objects:+ return SettingsPageTitles.Objects;+ case SettingsPathPrefixes.Developers:+ return SettingsPageTitles.Developers;+ case SettingsPathPrefixes.Integration:+ return SettingsPageTitles.Integration;+ case SettingsPathPrefixes.General:+ return SettingsPageTitles.General;default:return 'Twenty';}