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

Hide console tab list #6555

Merged
merged 4 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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 @@ -39,6 +39,7 @@ const kPaddingRight = 8;
*/
interface ActionBarProps {
readonly reactComponentContainer: IReactComponentContainer;
readonly showDeleteButton?: boolean;
}

/**
Expand All @@ -60,6 +61,7 @@ const positronClearConsole = localize('positronClearConsole', "Clear console");
const positronRestartConsole = localize('positronRestartConsole', "Restart console");
const positronShutdownConsole = localize('positronShutdownConsole', "Shutdown console");
const positronStartConsole = localize('positronStartConsole', "Start console");
const positronDeleteConsole = localize('positronDeleteConsole', "Delete console");
const positronCurrentWorkingDirectory = localize('positronCurrentWorkingDirectory', "Current Working Directory");

/**
Expand Down Expand Up @@ -326,6 +328,14 @@ export const ActionBar = (props: ActionBarProps) => {
'User-requested restart from console action bar');
};

const deleteSessionHandler = async () => {
if (!positronConsoleContext.activePositronConsoleInstance) {
return;
}

await positronConsoleContext.runtimeSessionService.deleteSession(positronConsoleContext.activePositronConsoleInstance.session.sessionId);
};

/**
* CurrentWorkingDirectoryProps interface.
*/
Expand Down Expand Up @@ -439,6 +449,16 @@ export const ActionBar = (props: ActionBarProps) => {
tooltip={positronRestartConsole}
onPressed={restartConsoleHandler}
/>
{props.showDeleteButton &&
<ActionBarButton
align='right'
ariaLabel={positronDeleteConsole}
disabled={!(canShutdown || canStart)}
iconId='trash'
tooltip={positronDeleteConsole}
onPressed={deleteSessionHandler}
/>
}
{multiSessionsEnabled && <ConsoleInstanceInfoButton />}
<ActionBarSeparator />
{showDeveloperUI &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export const ConsoleCore = (props: ConsoleCoreProps) => {
// The maximum tab list width is 1/5 of the total available width
const MAXIMUM_CONSOLE_TAB_LIST_WIDTH = Math.trunc(props.width / 5);

if (positronConsoleContext.consoleSessionListCollapsed) {
setConsolePaneWidth(props.width);
return;
}

// Initialize the width for the console pane and console tab list if it hasn't been
if (consoleWidth === 0) {
setConsoleTabListWidth(MAXIMUM_CONSOLE_TAB_LIST_WIDTH)
Expand All @@ -88,7 +93,7 @@ export const ConsoleCore = (props: ConsoleCoreProps) => {

// Track the console width to accurately resize in future
setConsoleWidth(props.width)
}, [consolePaneWidth, consoleTabListWidth, consoleWidth, props.width])
}, [consolePaneWidth, consoleTabListWidth, consoleWidth, props.width, positronConsoleContext.consoleSessionListCollapsed])

/**
* onBeginResize handler.
Expand Down Expand Up @@ -130,7 +135,7 @@ export const ConsoleCore = (props: ConsoleCoreProps) => {
<div
style={{ height: props.height, width: consolePaneWidth }}
>
<ActionBar {...props} />
<ActionBar {...props} showDeleteButton={positronConsoleContext.consoleSessionListCollapsed} />
<div className='console-instances-container'>
{positronConsoleContext.positronConsoleInstances.map(positronConsoleInstance =>
<ConsoleInstance
Expand All @@ -149,7 +154,7 @@ export const ConsoleCore = (props: ConsoleCoreProps) => {
onBeginResize={handleBeginResize}
onResize={handleResize}
/>
<ConsoleTabList height={props.height} width={consoleTabListWidth} />
{!positronConsoleContext.consoleSessionListCollapsed && <ConsoleTabList height={props.height} width={consoleTabListWidth} />}
</>
: <>
<ActionBar {...props} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export interface PositronConsoleServices extends PositronActionBarServices {
export interface PositronConsoleState extends PositronConsoleServices {
readonly positronConsoleInstances: IPositronConsoleInstance[];
readonly activePositronConsoleInstance?: IPositronConsoleInstance;

readonly consoleSessionListCollapsed: boolean;
}

/**
Expand All @@ -71,6 +73,7 @@ export const usePositronConsoleState = (services: PositronConsoleServices): Posi
const [activePositronConsoleInstance, setActivePositronConsoleInstance] = useState<IPositronConsoleInstance | undefined>(
services.positronConsoleService.activePositronConsoleInstance
);
const [consoleSessionListCollapsed, setConsoleSessionListCollapsed] = useState<boolean>(positronConsoleInstances.length <= 1);

// Add event handlers.
useEffect(() => {
Expand Down Expand Up @@ -104,10 +107,16 @@ export const usePositronConsoleState = (services: PositronConsoleServices): Posi
return () => disposableStore.dispose();
}, [services.positronConsoleService, services.runtimeSessionService, setActivePositronConsoleInstance]);

useEffect(() => {
setConsoleSessionListCollapsed(positronConsoleInstances.length <= 1);
}, [positronConsoleInstances]);


// Return the Positron console state.
return {
...services,
consoleSessionListCollapsed,
positronConsoleInstances,
activePositronConsoleInstance: activePositronConsoleInstance
activePositronConsoleInstance: activePositronConsoleInstance,
Copy link
Contributor

Choose a reason for hiding this comment

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

This can just be activePositronConsoleInstance.

Copy link
Contributor

Choose a reason for hiding this comment

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

@softwarenerd We should add a linting rule for trailing commas if we don't want to use them in our repo. I think we just set this rule: https://eslint.style/rules/js/comma-dangle

};
};
Loading