Skip to content

Commit db2c200

Browse files
ui: Added an option to disable sandwich view (#5715)
* Added an option to disable sandwich view * [pre-commit.ci lite] apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 7c56882 commit db2c200

File tree

6 files changed

+48
-24
lines changed

6 files changed

+48
-24
lines changed

ui/packages/app/web/src/pages/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const Profiles = () => {
5757
queryServiceClient: queryClient,
5858
navigateTo,
5959
isDarkMode,
60+
enableSandwichView: true,
6061
}}
6162
>
6263
<div className="bg-white dark:bg-gray-900 p-3">

ui/packages/shared/components/src/ParcaContext/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ interface Props {
5454
queryServiceClient: QueryServiceClient;
5555
navigateTo: NavigateFunction;
5656
enableSourcesView?: boolean;
57+
enableSandwichView?: boolean;
5758
enableIciclechartView?: boolean;
5859
authenticationErrorMessage?: string;
5960
isDarkMode: boolean;
@@ -95,6 +96,7 @@ export const defaultValue: Props = {
9596
queryServiceClient: {} as unknown as QueryServiceClient,
9697
navigateTo: () => {},
9798
enableSourcesView: false,
99+
enableSandwichView: false,
98100
isDarkMode: false,
99101
preferencesModal: false,
100102
};

ui/packages/shared/profile/src/ProfileIcicleGraph/IcicleGraphArrow/ContextMenu.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const ContextMenu = ({
5555
isSandwich = false,
5656
}: ContextMenuProps): JSX.Element => {
5757
const {isDarkMode} = useParcaContext();
58-
const {enableSourcesView, checkDebuginfoStatusHandler} = useParcaContext();
58+
const {enableSourcesView, enableSandwichView, checkDebuginfoStatusHandler} = useParcaContext();
5959
const [isGraphTooltipDocked, setIsDocked] = useUserPreference<boolean>(
6060
USER_PREFERENCES.GRAPH_METAINFO_DOCKED.key
6161
);
@@ -177,18 +177,20 @@ const ContextMenu = ({
177177
<div>Show in table</div>
178178
</div>
179179
</Item>
180-
<Item
181-
id="show-in-sandwich"
182-
onClick={() => {
183-
setSandwichFunctionName(functionName);
184-
setDashboardItems(['sandwich']);
185-
}}
186-
>
187-
<div className="flex w-full items-center gap-2">
188-
<Icon icon="tdesign:sandwich-filled" />
189-
<div>Show in sandwich</div>
190-
</div>
191-
</Item>
180+
{enableSandwichView === true && (
181+
<Item
182+
id="show-in-sandwich"
183+
onClick={() => {
184+
setSandwichFunctionName(functionName);
185+
setDashboardItems(['sandwich']);
186+
}}
187+
>
188+
<div className="flex w-full items-center gap-2">
189+
<Icon icon="tdesign:sandwich-filled" />
190+
<div>Show in sandwich</div>
191+
</div>
192+
</Item>
193+
)}
192194
<Item id="reset-view" onClick={handleResetView}>
193195
<div className="flex w-full items-center gap-2">
194196
<Icon icon="system-uicons:reset" />

ui/packages/shared/profile/src/ProfileView/components/ViewSelector/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const ViewSelector = ({profileSource}: Props): JSX.Element => {
3030
alwaysReturnArray: true,
3131
}
3232
);
33-
const {enableSourcesView} = useParcaContext();
33+
const {enableSourcesView, enableSandwichView} = useParcaContext();
3434

3535
const [enableicicleCharts] = useUserPreference<boolean>(USER_PREFERENCES.ENABLE_ICICLECHARTS.key);
3636

@@ -43,8 +43,15 @@ const ViewSelector = ({profileSource}: Props): JSX.Element => {
4343
}> = [
4444
{key: 'table', label: 'Table', canBeSelected: !dashboardItems.includes('table')},
4545
{key: 'icicle', label: 'icicle', canBeSelected: !dashboardItems.includes('icicle')},
46-
{key: 'sandwich', label: 'sandwich', canBeSelected: !dashboardItems.includes('sandwich')},
4746
];
47+
48+
if (enableSandwichView === true) {
49+
allItems.push({
50+
key: 'sandwich',
51+
label: 'sandwich',
52+
canBeSelected: !dashboardItems.includes('sandwich'),
53+
});
54+
}
4855
if (enableicicleCharts) {
4956
allItems.push({
5057
key: 'iciclechart',

ui/packages/shared/profile/src/Table/MoreDropdown.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,33 @@
1414
import {Menu} from '@headlessui/react';
1515
import {Icon} from '@iconify/react';
1616

17-
import {useURLState} from '@parca/components';
17+
import {useParcaContext, useURLState} from '@parca/components';
1818

19-
const MoreDropdown = ({functionName}: {functionName: string}): React.JSX.Element => {
19+
const MoreDropdown = ({functionName}: {functionName: string}): React.JSX.Element | null => {
2020
const [_, setSandwichFunctionName] = useURLState<string | undefined>('sandwich_function_name');
2121
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2222
const [dashboardItems, setDashboardItems] = useURLState<string[]>('dashboard_items', {
2323
alwaysReturnArray: true,
2424
});
25+
const {enableSandwichView} = useParcaContext();
2526

2627
const onSandwichViewSelect = (): void => {
2728
setSandwichFunctionName(functionName.trim());
2829
setDashboardItems(['sandwich']);
2930
};
3031

31-
const menuItems = [
32-
{
32+
const menuItems: Array<{label: string; action: () => void}> = [];
33+
34+
if (enableSandwichView === true) {
35+
menuItems.push({
3336
label: 'Show in Sandwich view',
3437
action: () => onSandwichViewSelect(),
35-
},
36-
];
38+
});
39+
}
40+
41+
if (menuItems.length === 0) {
42+
return null;
43+
}
3744

3845
return (
3946
<div className="relative">

ui/packages/shared/profile/src/Table/hooks/useTableConfiguration.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {useEffect, useMemo, useState} from 'react';
1515

1616
import {createColumnHelper, type ColumnDef} from '@tanstack/table-core';
1717

18-
import {useURLState} from '@parca/components';
18+
import {useParcaContext, useURLState} from '@parca/components';
1919
import {valueFormatter} from '@parca/utilities';
2020

2121
import {type Row} from '..';
@@ -50,6 +50,7 @@ export function useTableConfiguration({
5050
const [dashboardItems] = useURLState<string[]>('dashboard_items', {
5151
alwaysReturnArray: true,
5252
});
53+
const {enableSandwichView} = useParcaContext();
5354

5455
const [columnVisibility, setColumnVisibility] = useState(() => {
5556
return {
@@ -203,7 +204,11 @@ export function useTableConfiguration({
203204
}),
204205
];
205206

206-
if (dashboardItems.length === 1 && dashboardItems[0] === 'table') {
207+
if (
208+
dashboardItems.length === 1 &&
209+
dashboardItems[0] === 'table' &&
210+
enableSandwichView === true
211+
) {
207212
baseColumns.unshift(
208213
columnHelper.accessor('moreActions', {
209214
id: 'moreActions',
@@ -218,7 +223,7 @@ export function useTableConfiguration({
218223
}
219224

220225
return baseColumns;
221-
}, [unit, total, filtered, columnHelper, dashboardItems]);
226+
}, [unit, total, filtered, columnHelper, dashboardItems, enableSandwichView]);
222227

223228
const initialSorting = useMemo(() => {
224229
return [

0 commit comments

Comments
 (0)