Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data settings new layout - anchor navigation #8334

Merged
merged 36 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6ba2970
Implement object fields and settings new layout
gitstart-twenty Oct 25, 2024
5628299
update `if` block to fix eslint error
gitstart-twenty Oct 25, 2024
d7f7232
Merge branch 'main' of github.com:twentyhq/twenty into TWNTY-5491-new…
ijreilly Oct 28, 2024
4d9644a
Fix form saving
ijreilly Oct 28, 2024
3fb0300
Fix renaming applied to other workspaces
ijreilly Oct 29, 2024
3216337
Refactor
ijreilly Oct 29, 2024
0e93fa4
disable toggle for standard object
ijreilly Oct 29, 2024
29e04cd
fix object metadata renaming
Weiko Oct 29, 2024
8d81b38
Merge branch 'main' of github.com:twentyhq/twenty into TWNTY-5491-new…
ijreilly Oct 29, 2024
ef14dc0
Fix after merge and add workspaceId as arg
ijreilly Oct 29, 2024
039c4ed
fix missing workspaceId
Weiko Oct 29, 2024
a5eb182
some design fixes
ijreilly Oct 30, 2024
3c034a7
fix activeTabId
ijreilly Nov 4, 2024
ffc32c1
Merge branch 'main' of github.com:twentyhq/twenty into TWNTY-5491-new…
ijreilly Nov 4, 2024
c53cf5b
other design fixes
ijreilly Nov 4, 2024
c2f334c
wip - stories fix
ijreilly Nov 4, 2024
60e7d6e
write new storybook test
ijreilly Nov 4, 2024
8bdfd35
Merge branch 'main' of github.com:twentyhq/twenty into TWNTY-5491-new…
ijreilly Nov 4, 2024
ec78125
Fix design after merging main
ijreilly Nov 5, 2024
ec4095e
Navigation between tabs changes url
ijreilly Nov 5, 2024
dd7e2ed
Merge branch 'main' of github.com:twentyhq/twenty into new-layout-anc…
ijreilly Nov 7, 2024
a8fd2f0
finish merge
ijreilly Nov 7, 2024
aa02a45
Merge branch 'main' of github.com:twentyhq/twenty into new-layout-anc…
ijreilly Nov 8, 2024
35cd287
use Link in Tab to benefit from anchor navigation
ijreilly Nov 8, 2024
10856a1
move shared consts to a file in constants folder
ijreilly Nov 8, 2024
6fc2831
remove console
ijreilly Nov 8, 2024
1d3f119
Merge branch 'main' into new-layout-anchor-navigation
charlesBochet Nov 9, 2024
50d6630
Merge branch 'main' into new-layout-anchor-navigation
charlesBochet Nov 11, 2024
10ca2bf
Fix console.log
charlesBochet Nov 11, 2024
3f3de5b
Fix
charlesBochet Nov 11, 2024
856f85d
Fix
charlesBochet Nov 11, 2024
4bc1233
Fix
charlesBochet Nov 11, 2024
e478821
Fix
charlesBochet Nov 11, 2024
3ba8078
Fix
charlesBochet Nov 11, 2024
8738065
Fix
charlesBochet Nov 11, 2024
7f4c4ef
Fix CI
charlesBochet Nov 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export const SettingsAccountsCalendarChannelsContainer = () => {
{tabs.length > 1 && (
<StyledCalenderContainer>
<TabList
tabListId={SETTINGS_ACCOUNT_CALENDAR_CHANNELS_TAB_LIST_COMPONENT_ID}
tabListInstanceId={
SETTINGS_ACCOUNT_CALENDAR_CHANNELS_TAB_LIST_COMPONENT_ID
}
tabs={tabs}
/>
</StyledCalenderContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export const SettingsAccountsMessageChannelsContainer = () => {
{tabs.length > 1 && (
<StyledMessageContainer>
<TabList
tabListId={SETTINGS_ACCOUNT_MESSAGE_CHANNELS_TAB_LIST_COMPONENT_ID}
tabListInstanceId={
SETTINGS_ACCOUNT_MESSAGE_CHANNELS_TAB_LIST_COMPONENT_ID
}
tabs={tabs}
/>
</StyledMessageContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const SettingsServerlessFunctionCodeEditorTab = ({

const HeaderTabList = (
<StyledTabList
tabListId={SETTINGS_SERVERLESS_FUNCTION_TAB_LIST_COMPONENT_ID}
tabListInstanceId={SETTINGS_SERVERLESS_FUNCTION_TAB_LIST_COMPONENT_ID}
tabs={files
.filter((file) => file.path !== '.env')
.map((file) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const ShowPageSubContainer = ({
<StyledTabListContainer>
<TabList
loading={loading || isNewViewableRecordLoading}
tabListId={`${TAB_LIST_COMPONENT_ID}-${isInRightDrawer}`}
tabListInstanceId={`${TAB_LIST_COMPONENT_ID}-${isInRightDrawer}`}
tabs={tabs}
/>
</StyledTabListContainer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { ReactElement } from 'react';
import { Link } from 'react-router-dom';
import { IconComponent, Pill } from 'twenty-ui';

type TabProps = {
Expand All @@ -12,9 +13,10 @@ type TabProps = {
onClick?: () => void;
disabled?: boolean;
pill?: string | ReactElement;
to: string;
};

const StyledTab = styled.div<{ active?: boolean; disabled?: boolean }>`
const StyledTab = styled(Link)<{ active?: boolean; disabled?: boolean }>`
align-items: center;
border-bottom: 1px solid ${({ theme }) => theme.border.color.light};
border-color: ${({ theme, active }) =>
Expand All @@ -33,6 +35,7 @@ const StyledTab = styled.div<{ active?: boolean; disabled?: boolean }>`
margin-bottom: 0;
padding: ${({ theme }) => theme.spacing(2) + ' 0'};
pointer-events: ${({ disabled }) => (disabled ? 'none' : '')};
text-decoration: none;
`;

const StyledHover = styled.span`
Expand Down Expand Up @@ -61,6 +64,7 @@ export const Tab = ({
className,
disabled,
pill,
to,
}: TabProps) => {
const theme = useTheme();
return (
Expand All @@ -70,6 +74,7 @@ export const Tab = ({
className={className}
disabled={disabled}
data-testid={'tab-' + id}
to={to}
>
<StyledHover>
{Icon && <Icon size={theme.icon.size.md} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useTabList } from '@/ui/layout/tab/hooks/useTabList';
import { TabListScope } from '@/ui/layout/tab/scopes/TabListScope';
import { ScrollWrapper } from '@/ui/utilities/scroll/components/ScrollWrapper';

import { TabListFromUrlOptionalEffect } from '@/ui/layout/tab/components/TabListFromUrlOptionalEffect';
import { LayoutCard } from '@/ui/layout/tab/types/LayoutCard';
import { Tab } from './Tab';

Expand All @@ -21,7 +22,7 @@ export type SingleTabProps = {
};

type TabListProps = {
tabListId: string;
tabListInstanceId: string;
tabs: SingleTabProps[];
loading?: boolean;
className?: string;
Expand All @@ -38,13 +39,13 @@ const StyledContainer = styled.div`

export const TabList = ({
tabs,
tabListId,
tabListInstanceId,
loading,
className,
}: TabListProps) => {
const initialActiveTabId = tabs.find((tab) => !tab.hide)?.id || '';

const { activeTabIdState, setActiveTabId } = useTabList(tabListId);
const { activeTabIdState, setActiveTabId } = useTabList(tabListInstanceId);

const activeTabId = useRecoilValue(activeTabIdState);

Expand All @@ -53,7 +54,11 @@ export const TabList = ({
}, [initialActiveTabId, setActiveTabId]);

return (
<TabListScope tabListScopeId={tabListId}>
<TabListScope tabListScopeId={tabListInstanceId}>
<TabListFromUrlOptionalEffect
componentInstanceId={tabListInstanceId}
tabListIds={tabs.map((tab) => tab.id)}
/>
<ScrollWrapper enableYScroll={false} contextProviderName="tabList">
<StyledContainer className={className}>
{tabs
Expand All @@ -65,11 +70,9 @@ export const TabList = ({
title={tab.title}
Icon={tab.Icon}
active={tab.id === activeTabId}
onClick={() => {
setActiveTabId(tab.id);
}}
disabled={tab.disabled ?? loading}
pill={tab.pill}
to={`#${tab.id}`}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this changes the behaviour for all tabs but I think we may want that?

/>
))}
</StyledContainer>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useTabList } from '@/ui/layout/tab/hooks/useTabList';
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import { useRecoilValue } from 'recoil';

type TabListFromUrlOptionalEffectProps = {
componentInstanceId: string;
tabListIds: string[];
};

export const TabListFromUrlOptionalEffect = ({
componentInstanceId,
tabListIds,
}: TabListFromUrlOptionalEffectProps) => {
const location = useLocation();
const { activeTabIdState } = useTabList(componentInstanceId);
const { setActiveTabId } = useTabList(componentInstanceId);

const hash = location.hash.replace('#', '');
const activeTabId = useRecoilValue(activeTabIdState);

useEffect(() => {
if (hash === activeTabId) {
return;
}

if (tabListIds.includes(hash)) {
setActiveTabId(hash);
}
}, [hash, activeTabId, setActiveTabId, tabListIds]);

return <></>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const meta: Meta<typeof TabList> = {
title: 'UI/Layout/Tab/TabList',
component: TabList,
args: {
tabListId: 'tab-list-id',
tabListInstanceId: 'tab-list-id',
tabs: tabs,
},
decorators: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import {
IconPlus,
IconSettings,
IconTool,
isDefined,
MAIN_COLORS,
UndecoratedLink,
isDefined,
} from 'twenty-ui';
import { SETTINGS_OBJECT_DETAIL_TABS } from '~/pages/settings/data-model/constants/SettingsObjectDetailTabs';
import { updatedObjectSlugState } from '~/pages/settings/data-model/states/updatedObjectSlugState';

const StyledTabListContainer = styled.div`
Expand Down Expand Up @@ -63,11 +64,6 @@ const StyledTitleContainer = styled.div`
display: flex;
`;

const TAB_LIST_COMPONENT_ID = 'object-details-tab-list';
const FIELDS_TAB_ID = 'fields';
const SETTINGS_TAB_ID = 'settings';
const INDEXES_TAB_ID = 'indexes';

export const SettingsObjectDetailPage = () => {
const navigate = useNavigate();

Expand All @@ -82,7 +78,9 @@ export const SettingsObjectDetailPage = () => {
findActiveObjectMetadataItemBySlug(objectSlug) ??
findActiveObjectMetadataItemBySlug(updatedObjectSlug);

const { activeTabIdState } = useTabList(TAB_LIST_COMPONENT_ID);
const { activeTabIdState } = useTabList(
SETTINGS_OBJECT_DETAIL_TABS.COMPONENT_INSTANCE_ID,
);
const activeTabId = useRecoilValue(activeTabIdState);

const isAdvancedModeEnabled = useRecoilValue(isAdvancedModeEnabledState);
Expand All @@ -105,19 +103,19 @@ export const SettingsObjectDetailPage = () => {

const tabs = [
{
id: FIELDS_TAB_ID,
id: SETTINGS_OBJECT_DETAIL_TABS.TABS_IDS.FIELDS,
title: 'Fields',
Icon: IconListDetails,
hide: false,
},
{
id: SETTINGS_TAB_ID,
id: SETTINGS_OBJECT_DETAIL_TABS.TABS_IDS.SETTINGS,
title: 'Settings',
Icon: IconSettings,
hide: false,
},
{
id: INDEXES_TAB_ID,
id: SETTINGS_OBJECT_DETAIL_TABS.TABS_IDS.INDEXES,
title: 'Indexes',
Icon: IconCodeCircle,
hide: !isAdvancedModeEnabled || !isUniqueIndexesEnabled,
Expand All @@ -127,11 +125,11 @@ export const SettingsObjectDetailPage = () => {

const renderActiveTabContent = () => {
switch (activeTabId) {
case FIELDS_TAB_ID:
case SETTINGS_OBJECT_DETAIL_TABS.TABS_IDS.FIELDS:
return <ObjectFields objectMetadataItem={objectMetadataItem} />;
case SETTINGS_TAB_ID:
case SETTINGS_OBJECT_DETAIL_TABS.TABS_IDS.SETTINGS:
return <ObjectSettings objectMetadataItem={objectMetadataItem} />;
case INDEXES_TAB_ID:
case SETTINGS_OBJECT_DETAIL_TABS.TABS_IDS.INDEXES:
return <ObjectIndexes objectMetadataItem={objectMetadataItem} />;
default:
return <></>;
Expand All @@ -141,49 +139,51 @@ export const SettingsObjectDetailPage = () => {
const objectTypeLabel = getObjectTypeLabel(objectMetadataItem);

return (
<SubMenuTopBarContainer
title={
<StyledTitleContainer>
<H3Title title={objectMetadataItem.labelPlural} />
<StyledObjectTypeTag objectTypeLabel={objectTypeLabel} />
</StyledTitleContainer>
}
links={[
{
children: 'Workspace',
href: getSettingsPagePath(SettingsPath.Workspace),
},
{ children: 'Objects', href: '/settings/objects' },
{
children: objectMetadataItem.labelPlural,
},
]}
actionButton={
activeTabId === FIELDS_TAB_ID && (
<UndecoratedLink to={'./new-field/select'}>
<Button
title="New Field"
variant="primary"
size="small"
accent="blue"
Icon={IconPlus}
<>
<SubMenuTopBarContainer
links={[
{
children: 'Workspace',
href: getSettingsPagePath(SettingsPath.Workspace),
},
{ children: 'Objects', href: '/settings/objects' },
{
children: objectMetadataItem.labelPlural,
},
]}
actionButton={
activeTabId === SETTINGS_OBJECT_DETAIL_TABS.TABS_IDS.FIELDS && (
<UndecoratedLink to={'./new-field/select'}>
<Button
title="New Field"
variant="primary"
size="small"
accent="blue"
Icon={IconPlus}
/>
</UndecoratedLink>
)
}
>
<SettingsPageContainer>
<StyledTitleContainer>
<H3Title title={objectMetadataItem.labelPlural} />
<StyledObjectTypeTag objectTypeLabel={objectTypeLabel} />
</StyledTitleContainer>
<StyledTabListContainer>
<TabList
tabListInstanceId={
SETTINGS_OBJECT_DETAIL_TABS.COMPONENT_INSTANCE_ID
}
tabs={tabs}
className="tab-list"
/>
</UndecoratedLink>
)
}
>
<SettingsPageContainer>
<StyledTabListContainer>
<TabList
tabListId={TAB_LIST_COMPONENT_ID}
tabs={tabs}
className="tab-list"
/>
</StyledTabListContainer>
<StyledContentContainer>
{renderActiveTabContent()}
</StyledContentContainer>
</SettingsPageContainer>
</SubMenuTopBarContainer>
</StyledTabListContainer>
<StyledContentContainer>
{renderActiveTabContent()}
</StyledContentContainer>
</SettingsPageContainer>
</SubMenuTopBarContainer>
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const SETTINGS_OBJECT_DETAIL_TABS = {
COMPONENT_INSTANCE_ID: 'setting-object-details-tab-list',
TABS_IDS: {
FIELDS: 'fields',
SETTINGS: 'settings',
INDEXES: 'indexes',
},
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export const SettingsServerlessFunctionDetail = () => {
>
<SettingsPageContainer>
<Section>
<TabList tabListId={TAB_LIST_COMPONENT_ID} tabs={tabs} />
<TabList tabListInstanceId={TAB_LIST_COMPONENT_ID} tabs={tabs} />
</Section>
{renderActiveTabContent()}
</SettingsPageContainer>
Expand Down
Loading