Skip to content

Commit

Permalink
Data settings new layout - anchor navigation (#8334)
Browse files Browse the repository at this point in the history
Follow-up of #7979
Navigation between settings and fields tabs is now reflected in URL. 
<img width="1106" alt="Capture d’écran 2024-11-07 à 18 38 57"
src="https://github.com/user-attachments/assets/24b153ef-9e68-4aa2-8e3a-6bf70834c5ad">

---------

Co-authored-by: gitstart-twenty <[email protected]>
Co-authored-by: gitstart-twenty <[email protected]>
Co-authored-by: Weiko <[email protected]>
Co-authored-by: Charles Bochet <[email protected]>
  • Loading branch information
5 people authored Nov 11, 2024
1 parent 9d6a850 commit bec4da4
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-tinybird.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
ci:
timeout-minutes: 10
runs-on: ubuntu-latest
uses: tinybirdco/ci/.github/workflows/ci.yml@main
steps:
- name: Check for changed files
id: changed-files
Expand All @@ -28,7 +29,6 @@ jobs:
run: echo "No relevant changes. Skipping CI."

- name: Check twenty-tinybird package
uses: tinybirdco/ci/.github/workflows/ci.yml@main
with:
data_project_dir: packages/twenty-tinybird
tb_admin_token: ${{ secrets.TB_ADMIN_TOKEN }}
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ci-website.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: CI Website
timeout-minutes: 10
on:
push:
branches:
Expand Down
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 @@ -131,8 +131,9 @@ export const ShowPageSubContainer = ({
<StyledShowPageRightContainer isMobile={isMobile}>
<StyledTabListContainer>
<TabList
behaveAsLinks={!isInRightDrawer}
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,14 @@ type TabProps = {
onClick?: () => void;
disabled?: boolean;
pill?: string | ReactElement;
to?: string;
};

const StyledTab = styled.div<{ active?: boolean; disabled?: boolean }>`
const StyledTab = styled.button<{
active?: boolean;
disabled?: boolean;
to?: string;
}>`
align-items: center;
border-bottom: 1px solid ${({ theme }) => theme.border.color.light};
border-color: ${({ theme, active }) =>
Expand All @@ -26,13 +32,18 @@ const StyledTab = styled.div<{ active?: boolean; disabled?: boolean }>`
? theme.font.color.light
: theme.font.color.secondary};
cursor: pointer;
background-color: transparent;
border-left: none;
border-right: none;
border-top: none;
display: flex;
gap: ${({ theme }) => theme.spacing(1)};
justify-content: center;
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 +72,7 @@ export const Tab = ({
className,
disabled,
pill,
to,
}: TabProps) => {
const theme = useTheme();
return (
Expand All @@ -70,6 +82,8 @@ export const Tab = ({
className={className}
disabled={disabled}
data-testid={'tab-' + id}
as={to ? Link : 'button'}
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,10 +22,11 @@ export type SingleTabProps = {
};

type TabListProps = {
tabListId: string;
tabListInstanceId: string;
tabs: SingleTabProps[];
loading?: boolean;
className?: string;
behaveAsLinks?: boolean;
};

const StyledContainer = styled.div`
Expand All @@ -38,13 +40,14 @@ const StyledContainer = styled.div`

export const TabList = ({
tabs,
tabListId,
tabListInstanceId,
loading,
className,
behaveAsLinks = true,
}: 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 +56,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 +72,14 @@ 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={behaveAsLinks ? `#${tab.id}` : undefined}
onClick={() => {
if (!behaveAsLinks) {
setActiveTabId(tab.id);
}
}}
/>
))}
</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
@@ -1,6 +1,6 @@
import { Meta, StoryObj } from '@storybook/react';
import { expect, within } from '@storybook/test';
import { ComponentDecorator, IconCheckbox } from 'twenty-ui';
import { ComponentWithRouterDecorator, IconCheckbox } from 'twenty-ui';

import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';

Expand Down 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 All @@ -48,7 +48,7 @@ const meta: Meta<typeof TabList> = {
<Story />
</RecoilScope>
),
ComponentDecorator,
ComponentWithRouterDecorator,
],
};

Expand Down
Loading

0 comments on commit bec4da4

Please sign in to comment.