Skip to content

Commit

Permalink
fix: use fsPath
Browse files Browse the repository at this point in the history
  • Loading branch information
alenakhineika committed Dec 9, 2024
1 parent 34fb8a2 commit 36a86bb
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 66 deletions.
10 changes: 5 additions & 5 deletions src/test/suite/views/webviewController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ suite('Webview Test Suite', () => {
const extensionPath = mdbTestExtension.extensionContextStub.extensionPath;
const htmlString = getWebviewContent({
extensionPath,
telemetryUserId: 'MOCK_ANONYMOU_ID',
telemetryUserId: 'MOCK_ANONYMOUS_ID',
webview: {
asWebviewUri: (jsUri) => {
return jsUri;
Expand All @@ -133,7 +133,7 @@ suite('Webview Test Suite', () => {
});

expect(htmlString).to.include(
">window['VSCODE_EXTENSION_SEGMENT_ANONYMOUS_ID'] = 'MOCK_ANONYMOU_ID';"
">window['VSCODE_EXTENSION_SEGMENT_ANONYMOUS_ID'] = 'MOCK_ANONYMOUS_ID';"
);
});

Expand All @@ -143,7 +143,7 @@ suite('Webview Test Suite', () => {
extensionPath,
telemetryUserId: 'test',
webview: {
asWebviewUri: (jsUri) => {
asWebviewUri: (jsUri: vscode.Uri) => {
return jsUri;
},
} as unknown as vscode.Webview,
Expand Down Expand Up @@ -177,7 +177,7 @@ suite('Webview Test Suite', () => {
extensionPath,
telemetryUserId: 'test',
webview: {
asWebviewUri: (jsUri) => {
asWebviewUri: (jsUri: vscode.Uri) => {
return jsUri;
},
} as unknown as vscode.Webview,
Expand Down Expand Up @@ -368,7 +368,7 @@ suite('Webview Test Suite', () => {
onDidReceiveMessage: (callback): void => {
messageReceived = callback;
},
asWebviewUri: () => '',
asWebviewUri: (): string => '',
};
const fakeVSCodeExecuteCommand = sandbox
.stub(vscode.commands, 'executeCommand')
Expand Down
2 changes: 1 addition & 1 deletion src/views/webview-app/connection-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const ConnectionForm: React.FunctionComponent<
// Warning: This property may be removed in future
// modal releases.
contentClassName={modalContentStyles}
setOpen={() => onClose()}
setOpen={(): void => onClose()}
open={open}
size="large"
>
Expand Down
23 changes: 15 additions & 8 deletions src/views/webview-app/overview-page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useCallback, useLayoutEffect, useState } from 'react';
import type { ElectronShowFileDialogProvider } from '@mongodb-js/compass-components';
import {
HorizontalRule,
css,
Expand All @@ -8,6 +9,7 @@ import {
createElectronFileInputBackend,
type ElectronFileDialogOptions,
} from '@mongodb-js/compass-components';
import type { ConnectionOptions } from 'mongodb-data-service';

import OverviewHeader from './overview-header';
import ConnectionStatus from './connection-status';
Expand Down Expand Up @@ -69,8 +71,10 @@ const OverviewPage: React.FC = () => {
): Promise<T> {
const requestId = handleOpenFileChooser(options);
return new Promise((resolve) => {
const messageHandler = (event) => {
const message: MessageFromExtensionToWebview = event.data;
const messageHandler = (
event: MessageEvent<MessageFromExtensionToWebview>
): void => {
const message = event.data;
if (
message.command === MESSAGE_TYPES.OPEN_FILE_CHOOSER_RESULT &&
message.requestId === requestId
Expand All @@ -89,7 +93,7 @@ const OverviewPage: React.FC = () => {
// To work around this, we use a custom dialog provider that uses webview APIs
// to send a message to the extension process to open the electron file dialog
// and listen for the response to get the file path and send them to the electron file input backend.
const dialogProvider = {
const dialogProvider: ElectronShowFileDialogProvider<void> = {
getCurrentWindow(): void {},
dialog: {
async showSaveDialog(
Expand Down Expand Up @@ -128,11 +132,14 @@ const OverviewPage: React.FC = () => {
<ConnectionForm
isConnecting={isConnecting}
initialConnectionInfo={initialConnectionInfo}
onSaveAndConnectClicked={({ id, connectionOptions }) => {
void handleSaveConnectionClicked({
id,
connectionOptions,
});
onSaveAndConnectClicked={({
id,
connectionOptions,
}: {
id: string;
connectionOptions: ConnectionOptions;
}): void => {
void handleSaveConnectionClicked();
handleConnectClicked({
id,
connectionOptions,
Expand Down
18 changes: 7 additions & 11 deletions src/views/webview-app/use-connection-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export default function useConnectionForm() {
}
};
window.addEventListener('message', handleConnectResultResponse);
return () => {
return (): void => {
window.removeEventListener('message', handleConnectResultResponse);
};
}, []);
Expand All @@ -189,38 +189,34 @@ export default function useConnectionForm() {
isConnecting,
initialConnectionInfo,
connectionErrorMessage,
openConnectionForm: () => {
openConnectionForm: (): void => {
dispatch({
type: 'open-connection-form',
});
sendFormOpenedToExtension();
},
closeConnectionForm: () => {
closeConnectionForm: (): void => {
dispatch({
type: 'close-connection-form',
});
},
handleOpenFileChooser: (options: FileChooserOptions) => {
handleOpenFileChooser: (options: FileChooserOptions): string => {
const requestId = uuidv4();
sendOpenFileChooserToExtension(options, requestId);
return requestId;
},
handleCancelConnectClicked: () => {
handleCancelConnectClicked: (): void => {
sendCancelConnectToExtension();
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
handleSaveConnectionClicked: (connectionAttempt: {
id: string;
connectionOptions: ConnectionOptions;
}) => {
handleSaveConnectionClicked: (): Promise<void> => {
// no-op, this cannot be called as don't set the `showFavoriteActions` setting.

return Promise.resolve();
},
handleConnectClicked: (connectionAttempt: {
id: string;
connectionOptions: ConnectionOptions;
}) => {
}): void => {
dispatch({
type: 'attempt-connect',
});
Expand Down
7 changes: 5 additions & 2 deletions src/views/webview-app/use-connection-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import vscode from './vscode-api';

const CONNECTION_STATUS_POLLING_FREQ_MS = 1000;

const useConnectionStatus = () => {
const useConnectionStatus = (): {
connectionStatus: CONNECTION_STATUS;
connectionName: string;
} => {
const [connectionStatus, setConnectionStatus] = useState<CONNECTION_STATUS>(
CONNECTION_STATUS.LOADING
);
Expand All @@ -23,7 +26,7 @@ const useConnectionStatus = () => {
};
window.addEventListener('message', handleConnectionStatusResponse);

const requestConnectionStatus = () =>
const requestConnectionStatus = (): void =>
vscode.postMessage({
command: MESSAGE_TYPES.GET_CONNECTION_STATUS,
});
Expand Down
4 changes: 2 additions & 2 deletions src/views/webview-app/use-detect-vscode-dark-mode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
MESSAGE_TYPES,
} from './extension-app-message-constants';

export const useDetectVsCodeDarkMode = () => {
export const useDetectVsCodeDarkMode = (): boolean => {
const [darkModeDetected, setDarkModeDetected] = useState(
globalThis.document.body.classList.contains('vscode-dark') ||
globalThis.document.body.classList.contains('vscode-high-contrast')
Expand All @@ -17,7 +17,7 @@ export const useDetectVsCodeDarkMode = () => {
}
};
window.addEventListener('message', onThemeChanged);
return () => window.removeEventListener('message', onThemeChanged);
return (): void => window.removeEventListener('message', onThemeChanged);
}, []);

return darkModeDetected;
Expand Down
23 changes: 13 additions & 10 deletions src/views/webview-app/vscode-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const vscode = acquireVsCodeApi();

export const sendEditConnectionToExtension = (
connectionInfo: ConnectMessage['connectionInfo']
) => {
): void => {
vscode.postMessage({
command: MESSAGE_TYPES.EDIT_CONNECTION_AND_CONNECT,
connectionInfo,
Expand All @@ -23,7 +23,7 @@ export const sendEditConnectionToExtension = (

export const sendConnectToExtension = (
connectionInfo: ConnectMessage['connectionInfo']
) => {
): void => {
vscode.postMessage({
command: MESSAGE_TYPES.CONNECT,
connectionInfo,
Expand All @@ -33,55 +33,58 @@ export const sendConnectToExtension = (
export const sendOpenFileChooserToExtension = (
fileChooserOptions: FileChooserOptions,
requestId: string
) => {
): void => {
vscode.postMessage({
command: MESSAGE_TYPES.OPEN_FILE_CHOOSER,
fileChooserOptions,
requestId,
});
};

export const sendCancelConnectToExtension = () => {
export const sendCancelConnectToExtension = (): void => {
vscode.postMessage({
command: MESSAGE_TYPES.CANCEL_CONNECT,
});
};

// When the form is opened we want to close the connection string
// input if it's open, so we message the extension.
export const sendFormOpenedToExtension = () => {
export const sendFormOpenedToExtension = (): void => {
vscode.postMessage({
command: MESSAGE_TYPES.CONNECTION_FORM_OPENED,
});
};

export const renameActiveConnection = () => {
export const renameActiveConnection = (): void => {
vscode.postMessage({
command: MESSAGE_TYPES.RENAME_ACTIVE_CONNECTION,
});
};

export const createNewPlayground = () => {
export const createNewPlayground = (): void => {
vscode.postMessage({
command: MESSAGE_TYPES.CREATE_NEW_PLAYGROUND,
});
};

export const connectWithConnectionString = () => {
export const connectWithConnectionString = (): void => {
vscode.postMessage({
command: MESSAGE_TYPES.OPEN_CONNECTION_STRING_INPUT,
});
};

export const trackExtensionLinkClicked = (screen: string, linkId: string) => {
export const trackExtensionLinkClicked = (
screen: string,
linkId: string
): void => {
vscode.postMessage({
command: MESSAGE_TYPES.EXTENSION_LINK_CLICKED,
screen,
linkId,
});
};

export const openTrustedLink = (linkTo: string) => {
export const openTrustedLink = (linkTo: string): void => {
vscode.postMessage({
command: MESSAGE_TYPES.OPEN_TRUSTED_LINK,
linkTo,
Expand Down
Loading

0 comments on commit 36a86bb

Please sign in to comment.