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

check if in popup before triggering shortcut #2789

Merged
merged 3 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion packages/altair-api/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (process.env.NODE_ENV === 'production') {
if (process.env.NEW_RELIC_APP_NAME && process.env.NODE_ENV === 'production') {
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('newrelic');
}
Expand Down
25 changes: 12 additions & 13 deletions packages/altair-api/src/newrelic/newrelic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import type {
recordMetric,
incrementMetric,
} from 'newrelic';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const newrelic = require('newrelic');

export interface Agent {
startWebTransaction: typeof startWebTransaction;
Expand All @@ -14,18 +12,19 @@ export interface Agent {
incrementMetric: typeof incrementMetric;
}

const prodAgent: Agent = {
startWebTransaction: (...args: unknown[]) => newrelic.startWebTransaction(...args),
getTransaction: (...args: unknown[]) => newrelic.getTransaction(...args),
recordMetric: (name: string, ...rest: unknown[]) =>
newrelic.recordMetric(name.split('.').join('/'), ...rest),
incrementMetric: (name: string, ...rest: unknown[]) =>
newrelic.incrementMetric(name.split('.').join('/'), ...rest),
};

export const getAgent = (): Agent | undefined => {
if (process.env.NEW_RELIC_APP_NAME) {
return prodAgent;
if (process.env.NEW_RELIC_APP_NAME && process.env.NODE_ENV === 'production') {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const newrelic = require('newrelic');
return {
startWebTransaction: (...args: unknown[]) =>
newrelic.startWebTransaction(...args),
getTransaction: (...args: unknown[]) => newrelic.getTransaction(...args),
recordMetric: (name: string, ...rest: unknown[]) =>
newrelic.recordMetric(name.split('.').join('/'), ...rest),
incrementMetric: (name: string, ...rest: unknown[]) =>
newrelic.incrementMetric(name.split('.').join('/'), ...rest),
};
}
return;
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
</ng-template>

<ng-template #modalContent>
<ng-content></ng-content>
<form (ngSubmit)="onSubmit($event)">
<ng-content></ng-content>
<button type="submit" style="display: none"></button>
</form>
Comment on lines +19 to +22

Choose a reason for hiding this comment

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

medium

Wrapping the content in a <form> element might interfere with existing form elements within the dialog content. Consider if this is the best approach, or if there's a way to prevent potential conflicts. For example, could you add a class to the form and target that class in your CSS to avoid style conflicts?

Suggested change
<form (ngSubmit)="onSubmit($event)">
<ng-content></ng-content>
<button type="submit" style="display: none"></button>
</form>
<div class="dialog-form">
<ng-content></ng-content>
<button type="submit" style="display: none"></button>
</div>

</ng-template>

<ng-template #modalFooter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ export class DialogComponent {
@Output() saveChange = new EventEmitter();
constructor() {}

onClickSave(e: MouseEvent) {
onClickSave(e: Event) {
this.toggleDialog.emit(!this.showDialog);
this.saveChange.emit(e);
}

onSubmit(e: Event) {
this.toggleDialog.emit(!this.showDialog);
this.saveChange.emit(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export class KeybinderService {
this.store.dispatch(
new dialogsActions.ToggleVariableDialogAction(this.activeWindowId)
),
'Toggle Variable Pane'
'Toggle Variable Pane',
true
);

this.bindShortcut(
Expand All @@ -60,16 +61,15 @@ export class KeybinderService {
this.store.dispatch(
new dialogsActions.ToggleHeaderDialogAction(this.activeWindowId)
),
'Toggle Header Pane'
'Toggle Header Pane',
true
);

this.bindShortcut(
['Ctrl+Shift+R'],
() =>
this.store.dispatch(
new queryActions.SendIntrospectionQueryRequestAction(
this.activeWindowId
)
new queryActions.SendIntrospectionQueryRequestAction(this.activeWindowId)
),
'Reload Docs'
);
Expand All @@ -87,9 +87,7 @@ export class KeybinderService {
['Ctrl+Shift+P'],
() => {
if (
document.activeElement?.closest(
VARIABLE_EDITOR_COMPONENT_ELEMENT_NAME
)
document.activeElement?.closest(VARIABLE_EDITOR_COMPONENT_ELEMENT_NAME)
) {
this.store.dispatch(
new variablesActions.PrettifyVariablesAction(this.activeWindowId)
Expand Down Expand Up @@ -156,7 +154,8 @@ export class KeybinderService {
bindShortcut(
keys: string[],
callback: (...args: unknown[]) => unknown,
description = 'TODO - Add description'
description: string,
allowInPopups = false
Comment on lines +157 to +158

Choose a reason for hiding this comment

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

medium

The description parameter is now required. Consider providing a default value that indicates the description is missing, rather than forcing every call site to provide one. Also, the TODO comment is now gone, but it would be good to have a description for each shortcut.

Suggested change
description: string,
allowInPopups = false
description: string = 'No description provided',

) {
this.shortcuts.push({
keys,
Expand All @@ -166,6 +165,9 @@ export class KeybinderService {
return (mousetrap as any).bindGlobal(
keys.map((key) => key.toLowerCase()),
() => {
if (!allowInPopups && this.isInPopup()) {
return;
}
this.zone.run(callback);
return false;
}
Expand Down Expand Up @@ -209,4 +211,9 @@ export class KeybinderService {

return categories;
}

private isInPopup() {
const activeElement = document.activeElement as HTMLElement | null;
return !!activeElement?.closest('nz-modal-container');

Choose a reason for hiding this comment

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

medium

This function relies on the presence of nz-modal-container. If a different modal implementation is used, this check will fail. Consider making this more generic or configurable, perhaps by allowing a custom selector to be passed in.

Suggested change
return !!activeElement?.closest('nz-modal-container');
return !!activeElement?.closest('nz-modal-container, .custom-modal-container');

}
}
Loading