2024-02-13 08:22:04 +00:00
|
|
|
import React from "react";
|
2023-05-19 18:37:06 +00:00
|
|
|
import type { CollapsibleTabProps } from "design-system-old";
|
2021-10-07 06:53:58 +00:00
|
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
|
|
|
|
import { DEBUGGER_TAB_KEYS } from "./Debugger/helpers";
|
2023-05-19 18:37:06 +00:00
|
|
|
import { Tab, TabPanel, Tabs, TabsList } from "design-system";
|
|
|
|
|
import styled from "styled-components";
|
2024-04-09 08:37:54 +00:00
|
|
|
import { LIST_HEADER_HEIGHT, FOOTER_MARGIN } from "./Debugger/DebuggerLogs";
|
2023-05-19 18:37:06 +00:00
|
|
|
|
|
|
|
|
const TabPanelWrapper = styled(TabPanel)`
|
|
|
|
|
margin-top: 0;
|
|
|
|
|
height: calc(100% - ${LIST_HEADER_HEIGHT});
|
|
|
|
|
&.ads-v2-tabs__panel {
|
|
|
|
|
overflow: auto;
|
|
|
|
|
}
|
2024-04-09 08:37:54 +00:00
|
|
|
& .t--code-editor-wrapper.codeWrapper {
|
|
|
|
|
height: calc(100% - ${FOOTER_MARGIN});
|
|
|
|
|
& .CodeMirror-scroll {
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-19 18:37:06 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const TabsListWrapper = styled(TabsList)`
|
|
|
|
|
padding: calc(var(--ads-v2-spaces-1) + 2px) var(--ads-v2-spaces-7)
|
|
|
|
|
var(--ads-v2-spaces-1);
|
|
|
|
|
`;
|
2021-10-07 06:53:58 +00:00
|
|
|
|
2024-01-31 05:07:40 +00:00
|
|
|
export interface BottomTab {
|
|
|
|
|
key: string;
|
|
|
|
|
title: string;
|
|
|
|
|
count?: number;
|
|
|
|
|
panelComponent: React.ReactNode;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 07:35:24 +00:00
|
|
|
interface EntityBottomTabsProps {
|
2023-05-19 18:37:06 +00:00
|
|
|
className?: string;
|
2024-01-31 05:07:40 +00:00
|
|
|
tabs: Array<BottomTab>;
|
|
|
|
|
onSelect?: (tab: string) => void;
|
2022-10-17 15:16:38 +00:00
|
|
|
selectedTabKey: string;
|
2023-10-11 07:35:24 +00:00
|
|
|
}
|
2022-04-28 16:51:02 +00:00
|
|
|
|
|
|
|
|
type CollapsibleEntityBottomTabsProps = EntityBottomTabsProps &
|
|
|
|
|
CollapsibleTabProps;
|
|
|
|
|
|
2021-10-07 06:53:58 +00:00
|
|
|
// Using this if there are debugger related tabs
|
2022-04-28 16:51:02 +00:00
|
|
|
function EntityBottomTabs(
|
|
|
|
|
props: EntityBottomTabsProps | CollapsibleEntityBottomTabsProps,
|
|
|
|
|
) {
|
2023-05-19 18:37:06 +00:00
|
|
|
const onTabSelect = (key: string) => {
|
2024-01-31 05:07:40 +00:00
|
|
|
const tab = props.tabs.find((tab) => tab.key === key);
|
|
|
|
|
if (tab) {
|
|
|
|
|
props.onSelect && props.onSelect(tab.key);
|
2021-10-07 06:53:58 +00:00
|
|
|
|
2024-01-31 05:07:40 +00:00
|
|
|
if (Object.values<string>(DEBUGGER_TAB_KEYS).includes(tab.key)) {
|
|
|
|
|
AnalyticsUtil.logEvent("DEBUGGER_TAB_SWITCH", {
|
|
|
|
|
tabName: tab.key,
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-10-07 06:53:58 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2023-05-19 18:37:06 +00:00
|
|
|
<Tabs
|
|
|
|
|
className="h-full"
|
|
|
|
|
defaultValue={props.selectedTabKey}
|
|
|
|
|
onValueChange={onTabSelect}
|
|
|
|
|
value={props.selectedTabKey}
|
|
|
|
|
>
|
|
|
|
|
<TabsListWrapper>
|
2024-01-31 05:07:40 +00:00
|
|
|
{props.tabs.map((tab) => {
|
2023-05-19 18:37:06 +00:00
|
|
|
return (
|
|
|
|
|
<Tab
|
|
|
|
|
data-testid={"t--tab-" + tab.key}
|
2024-02-08 07:55:23 +00:00
|
|
|
id={`debugger-tab-${tab.key}`}
|
2023-05-19 18:37:06 +00:00
|
|
|
key={tab.key}
|
|
|
|
|
notificationCount={tab.count}
|
|
|
|
|
value={tab.key}
|
|
|
|
|
>
|
|
|
|
|
{tab.title}
|
|
|
|
|
</Tab>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</TabsListWrapper>
|
2024-01-31 05:07:40 +00:00
|
|
|
{props.tabs.map((tab) => (
|
2023-05-19 18:37:06 +00:00
|
|
|
<TabPanelWrapper key={tab.key} value={tab.key}>
|
|
|
|
|
{tab.panelComponent}
|
|
|
|
|
</TabPanelWrapper>
|
|
|
|
|
))}
|
|
|
|
|
</Tabs>
|
2021-10-07 06:53:58 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default EntityBottomTabs;
|