mirror of
https://github.com/podman-desktop/podman-desktop
synced 2026-05-24 10:18:53 +00:00
feat: add navigateTo resources and edit container connection (#6733)
* feat: add navigateTo resources and edit container connection Signed-off-by: lstocchi <lstocchi@redhat.com>
This commit is contained in:
parent
37782bbce2
commit
54cdb5cd43
9 changed files with 105 additions and 1 deletions
|
|
@ -4175,6 +4175,15 @@ declare module '@podman-desktop/api' {
|
|||
* Navigate to Authentication settings page
|
||||
*/
|
||||
export function navigateToAuthentication(): Promise<void>;
|
||||
|
||||
/**
|
||||
* Navigate to Resources page
|
||||
*/
|
||||
export function navigateToResources(): Promise<void>;
|
||||
/**
|
||||
* Navigate to the Edit Provider Container Connection page
|
||||
*/
|
||||
export function navigateToEditProviderContainerConnection(connection: ProviderContainerConnection): Promise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -212,6 +212,7 @@ const navigationManager: NavigationManager = new NavigationManager(
|
|||
apiSender,
|
||||
containerProviderRegistry,
|
||||
contributionManager,
|
||||
providerRegistry,
|
||||
webviewRegistry,
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -1224,6 +1224,14 @@ export class ExtensionLoader {
|
|||
navigateToAuthentication: async (): Promise<void> => {
|
||||
await this.navigationManager.navigateToAuthentication();
|
||||
},
|
||||
navigateToResources: async (): Promise<void> => {
|
||||
await this.navigationManager.navigateToResources();
|
||||
},
|
||||
navigateToEditProviderContainerConnection: async (
|
||||
connection: containerDesktopAPI.ProviderContainerConnection,
|
||||
): Promise<void> => {
|
||||
await this.navigationManager.navigateToEditProviderContainerConnection(connection);
|
||||
},
|
||||
};
|
||||
|
||||
const version = app.getVersion();
|
||||
|
|
|
|||
|
|
@ -584,6 +584,7 @@ export class PluginSystem {
|
|||
apiSender,
|
||||
containerProviderRegistry,
|
||||
contributionManager,
|
||||
providerRegistry,
|
||||
webviewRegistry,
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,12 +16,14 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
***********************************************************************/
|
||||
|
||||
import type { ProviderContainerConnection } from '@podman-desktop/api';
|
||||
import { beforeEach, expect, test, vi } from 'vitest';
|
||||
|
||||
import type { ApiSenderType } from '../api.js';
|
||||
import type { WebviewInfo } from '../api/webview-info.js';
|
||||
import type { ContainerProviderRegistry } from '../container-registry.js';
|
||||
import type { ContributionManager } from '../contribution-manager.js';
|
||||
import type { ProviderRegistry } from '../provider-registry.js';
|
||||
import type { WebviewRegistry } from '../webview/webview-registry.js';
|
||||
import { NavigationManager } from './navigation-manager.js';
|
||||
import { NavigationPage } from './navigation-page.js';
|
||||
|
|
@ -48,13 +50,23 @@ const contributionManager = {
|
|||
listContributions: vi.fn(),
|
||||
} as unknown as ContributionManager;
|
||||
|
||||
const providerRegistry = {
|
||||
getMatchingProviderInternalId: vi.fn(),
|
||||
} as unknown as ProviderRegistry;
|
||||
|
||||
const webviewRegistry = {
|
||||
listWebviews: vi.fn(),
|
||||
} as unknown as WebviewRegistry;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
navigationManager = new TestNavigationManager(apiSender, containerRegistry, contributionManager, webviewRegistry);
|
||||
navigationManager = new TestNavigationManager(
|
||||
apiSender,
|
||||
containerRegistry,
|
||||
contributionManager,
|
||||
providerRegistry,
|
||||
webviewRegistry,
|
||||
);
|
||||
});
|
||||
|
||||
test('check contribution does not exist', async () => {
|
||||
|
|
@ -89,3 +101,35 @@ test('check navigateToWebview', async () => {
|
|||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('check navigateToResources', async () => {
|
||||
await navigationManager.navigateToResources();
|
||||
|
||||
expect(apiSender.send).toHaveBeenCalledWith('navigate', {
|
||||
page: NavigationPage.RESOURCES,
|
||||
});
|
||||
});
|
||||
|
||||
test('check navigateToEditProviderContainerConnection', async () => {
|
||||
vi.mocked(providerRegistry.getMatchingProviderInternalId).mockReturnValue('id');
|
||||
const connection: ProviderContainerConnection = {
|
||||
providerId: 'internal',
|
||||
connection: {
|
||||
name: 'connection',
|
||||
type: 'docker',
|
||||
endpoint: {
|
||||
socketPath: '/endpoint1.sock',
|
||||
},
|
||||
status: () => 'stopped',
|
||||
},
|
||||
};
|
||||
await navigationManager.navigateToEditProviderContainerConnection(connection);
|
||||
|
||||
expect(apiSender.send).toHaveBeenCalledWith('navigate', {
|
||||
page: NavigationPage.EDIT_CONTAINER_CONNECTION,
|
||||
parameters: {
|
||||
provider: 'id',
|
||||
name: Buffer.from(connection.connection.name).toString('base64'),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -16,12 +16,15 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
***********************************************************************/
|
||||
|
||||
import type { ProviderContainerConnection } from '@podman-desktop/api';
|
||||
|
||||
import type { ApiSenderType } from '/@/plugin/api.js';
|
||||
import type { ContainerProviderRegistry } from '/@/plugin/container-registry.js';
|
||||
import type { ContributionManager } from '/@/plugin/contribution-manager.js';
|
||||
import { NavigationPage } from '/@/plugin/navigation/navigation-page.js';
|
||||
import type { NavigationRequest } from '/@/plugin/navigation/navigation-request.js';
|
||||
|
||||
import type { ProviderRegistry } from '../provider-registry.js';
|
||||
import type { WebviewRegistry } from '../webview/webview-registry.js';
|
||||
|
||||
export class NavigationManager {
|
||||
|
|
@ -29,6 +32,7 @@ export class NavigationManager {
|
|||
private apiSender: ApiSenderType,
|
||||
private containerRegistry: ContainerProviderRegistry,
|
||||
private contributionManager: ContributionManager,
|
||||
private providerRegistry: ProviderRegistry,
|
||||
private webviewRegistry: WebviewRegistry,
|
||||
) {}
|
||||
|
||||
|
|
@ -213,4 +217,21 @@ export class NavigationManager {
|
|||
page: NavigationPage.AUTHENTICATION,
|
||||
});
|
||||
}
|
||||
|
||||
async navigateToResources(): Promise<void> {
|
||||
this.navigateTo({
|
||||
page: NavigationPage.RESOURCES,
|
||||
});
|
||||
}
|
||||
|
||||
async navigateToEditProviderContainerConnection(connection: ProviderContainerConnection): Promise<void> {
|
||||
const internalId = this.providerRegistry.getMatchingProviderInternalId(connection.providerId);
|
||||
this.navigateTo({
|
||||
page: NavigationPage.EDIT_CONTAINER_CONNECTION,
|
||||
parameters: {
|
||||
provider: internalId,
|
||||
name: Buffer.from(connection.connection.name).toString('base64'),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,4 +33,6 @@ export enum NavigationPage {
|
|||
HELP = 'help',
|
||||
WEBVIEW = 'webview',
|
||||
AUTHENTICATION = 'authentication',
|
||||
RESOURCES = 'resources',
|
||||
EDIT_CONTAINER_CONNECTION = 'edit-container-connection',
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,3 +42,15 @@ test('Test navigationHandle to a specific webview', () => {
|
|||
|
||||
expect(vi.mocked(router.goto)).toHaveBeenCalledWith('/webviews/123');
|
||||
});
|
||||
|
||||
test('Test navigationHandle to resources page', () => {
|
||||
handleNavigation(NavigationPage.RESOURCES);
|
||||
|
||||
expect(vi.mocked(router.goto)).toHaveBeenCalledWith('/preferences/resources');
|
||||
});
|
||||
|
||||
test('Test navigationHandle to a specific edit page', () => {
|
||||
handleNavigation(NavigationPage.EDIT_CONTAINER_CONNECTION, { provider: '123', name: 'test' });
|
||||
|
||||
expect(vi.mocked(router.goto)).toHaveBeenCalledWith('/preferences/container-connection/edit/123/test');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -82,5 +82,11 @@ export const handleNavigation = (page: NavigationPage, parameters?: { [key: stri
|
|||
case NavigationPage.AUTHENTICATION:
|
||||
router.goto('/preferences/authentication-providers');
|
||||
break;
|
||||
case NavigationPage.RESOURCES:
|
||||
router.goto('/preferences/resources');
|
||||
break;
|
||||
case NavigationPage.EDIT_CONTAINER_CONNECTION:
|
||||
router.goto(`/preferences/container-connection/edit/${parameters?.['provider']}/${parameters?.['name']}`);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue