Skip to content

Commit

Permalink
Add check for underscore in table name before auto-launch
Browse files Browse the repository at this point in the history
  • Loading branch information
georgecwan committed Nov 24, 2023
1 parent 6083173 commit 23f998d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
15 changes: 10 additions & 5 deletions packages/console/src/Console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ interface ConsoleProps {
statusBarChildren: ReactNode;
settings: Partial<Settings>;
focusCommandHistory: () => void;
openObject: (object: VariableDefinition) => void;
openObject: (object: VariableDefinition, autoLaunch?: boolean) => void;
closeObject: (object: VariableDefinition) => void;
session: IdeSession;
language: string;
Expand Down Expand Up @@ -471,15 +471,20 @@ export class Console extends PureComponent<ConsoleProps, ConsoleState> {
}, Console.LOG_THROTTLE);

openUpdatedItems(changes: VariableChanges): void {
log.log('openUpdatedItems', changes);
const { isAutoLaunchPanelsEnabled } = this.state;
if (changes == null || !isAutoLaunchPanelsEnabled) {
if (changes == null) {
return;
}

const { openObject } = this.props;
[...changes.created, ...changes.updated].forEach(object =>
openObject(object)
);
[...changes.created, ...changes.updated].forEach(object => {
openObject(
object,
isAutoLaunchPanelsEnabled &&
(object.title === undefined || !object.title.startsWith('_'))
);
});
}

closeRemovedItems(changes: VariableChanges): void {
Expand Down
36 changes: 32 additions & 4 deletions packages/dashboard-core-plugins/src/panels/ConsolePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export class ConsolePanel extends PureComponent<
// as they may have been saved with the dashboard
this.closeDisconnectedPanels();
glEventHub.on(PanelEvent.MOUNT, this.handlePanelMount);
glEventHub.on(PanelEvent.CLOSED, this.handleItemClosed);
this.subscribeToFieldUpdates();
}

Expand All @@ -143,6 +144,7 @@ export class ConsolePanel extends PureComponent<
const { glEventHub } = this.props;
this.savePanelState.flush();
glEventHub.off(PanelEvent.MOUNT, this.handlePanelMount);
glEventHub.off(PanelEvent.CLOSED, this.handleItemClosed);
this.objectSubscriptionCleanup?.();
}

Expand Down Expand Up @@ -222,6 +224,22 @@ export class ConsolePanel extends PureComponent<
}
}

handleItemClosed(panelId: string | string[] | null | undefined): void {
if (panelId == null) {
return;
}
const removeId = Array.isArray(panelId) ? panelId[0] : panelId;
this.setState(({ itemIds }) => {
const newItemIds = new Map(itemIds);
newItemIds.forEach(([key, value]) => {
if (value === removeId) {
newItemIds.delete(key);
}
});
return { itemIds: newItemIds };
});
}

handleFocusCommandHistory(): void {
const { glEventHub } = this.props;
glEventHub.emit(ConsoleEvent.FOCUS_HISTORY);
Expand All @@ -235,18 +253,28 @@ export class ConsolePanel extends PureComponent<
this.updateDimensions();
}

handleOpenObject(object: VariableDefinition): void {
handleOpenObject(object: VariableDefinition, autoLaunch = true): void {
const { sessionWrapper } = this.props;
const { itemIds } = this.state;
const { session } = sessionWrapper;
this.openWidget(object, session);
// Title should always be non-null
if (
autoLaunch ||
(object.title !== undefined && itemIds.has(object.title))
) {
log.log('handleOpenObject', autoLaunch, object, itemIds);
this.openWidget(object, session);
}
}

handleCloseObject(object: VariableDefinition): void {
const { title } = object;
if (title !== undefined) {
const id = this.getItemId(title, false);
const { glEventHub } = this.props;
glEventHub.emit(PanelEvent.CLOSE, id);
if (id != null) {
const { glEventHub } = this.props;
glEventHub.emit(PanelEvent.CLOSE, id);
}
}
}

Expand Down

0 comments on commit 23f998d

Please sign in to comment.