Skip to content

Commit 86ebf61

Browse files
committed
Keep track of tab selection in modal
1 parent 749fe8e commit 86ebf61

File tree

1 file changed

+31
-21
lines changed
  • packages/app/src/app/pages/Dashboard/Content/CreateNewSandbox/NewSandboxModal

1 file changed

+31
-21
lines changed

packages/app/src/app/pages/Dashboard/Content/CreateNewSandbox/NewSandboxModal/NewSandboxModal.tsx

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,26 @@ export const NewSandboxModal = inject('store', 'signals')(
3434
}: INewSandboxModalProps) => {
3535
const [selectedTab, setSelectedTab] = useState(0);
3636

37+
const tabs = [
38+
'Overview',
39+
user && 'My Templates',
40+
'Client Templates',
41+
'Container Templates',
42+
'Import',
43+
]
44+
.map((buttonName, index) => ({
45+
name: buttonName,
46+
tabIndex: index,
47+
}))
48+
.filter(({ name }) => Boolean(name));
49+
50+
const selectTab = (tabIndex: number) => {
51+
const tab = tabs[tabIndex];
52+
setSelectedTab(tabIndex);
53+
54+
track('New Sandbox Modal - Open Tab', { tabName: tab.name });
55+
};
56+
3757
const selectTemplate = template => {
3858
track('New Sandbox Modal - Select Template', { template });
3959
createSandbox(template);
@@ -42,27 +62,17 @@ export const NewSandboxModal = inject('store', 'signals')(
4262
return (
4363
<Container closing={closing} forking={forking}>
4464
<TabContainer forking={forking} closing={closing}>
45-
{[
46-
'Overview',
47-
user && 'My Templates',
48-
'Client Templates',
49-
'Container Templates',
50-
'Import',
51-
]
52-
.map((buttonName, index) => ({
53-
name: buttonName,
54-
tabIndex: index,
55-
}))
56-
.filter(({ name }) => Boolean(name))
57-
.map(({ name, tabIndex }) => (
58-
<Button
59-
key={name}
60-
onClick={() => setSelectedTab(tabIndex)}
61-
selected={selectedTab === tabIndex}
62-
>
63-
{name}
64-
</Button>
65-
))}
65+
{tabs.map(({ name, tabIndex }) => (
66+
<Button
67+
key={name}
68+
onClick={() => {
69+
selectTab(tabIndex);
70+
}}
71+
selected={selectedTab === tabIndex}
72+
>
73+
{name}
74+
</Button>
75+
))}
6676
</TabContainer>
6777

6878
<InnerContainer forking={forking} closing={closing}>

0 commit comments

Comments
 (0)