Skip to content

Commit a80c880

Browse files
committed
fix for new store updates
1 parent 85945bd commit a80c880

File tree

18 files changed

+54
-41
lines changed

18 files changed

+54
-41
lines changed

packages/sap-systems-ext/src/commands/system/delete.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import type { StoredSystemViewNode, SystemCommandContext } from '../../types/system';
22
import type { PanelManager, SystemPanel } from '../../panel';
3-
import { BackendSystemKey, SystemService, type BackendSystem } from '@sap-ux/store';
3+
import { BackendSystemKey, type BackendSystem } from '@sap-ux/store';
44
import { window } from 'vscode';
5-
import { t, confirmPrompt, TelemetryHelper, geti18nOpts } from '../../utils';
5+
import { t, confirmPrompt, TelemetryHelper, geti18nOpts, getBackendSystemService } from '../../utils';
66
import { ConfirmationPromptType, SYSTEMS_EVENT, SystemAction, SystemActionStatus } from '../../utils/constants';
7-
import SystemsLogger from '../../utils/logger';
87

98
/**
109
* Returns a command handler function that deletes a specified system.
@@ -16,7 +15,7 @@ export const deleteSystemCommandHandler =
1615
(context: SystemCommandContext) =>
1716
async (system: StoredSystemViewNode): Promise<void> => {
1817
const backendSystemKey = new BackendSystemKey({ url: system.url, client: system.client });
19-
const systemService = new SystemService(SystemsLogger.logger);
18+
const systemService = await getBackendSystemService();
2019
const backendSystem = await systemService.read(backendSystemKey);
2120

2221
if (!backendSystem) {

packages/sap-systems-ext/src/commands/system/import.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { SystemConfig, SystemCommandContext, SystemConfigFile } from '../../types/system';
2-
import { BackendSystem, BackendSystemKey, SystemService, type SystemType } from '@sap-ux/store';
2+
import { BackendSystem, BackendSystemKey, type SystemType } from '@sap-ux/store';
33
import { window, workspace } from 'vscode';
44
import { platform } from 'node:os';
55
import { readFileSync } from 'node:fs';
6-
import { confirmPrompt, TelemetryHelper, t } from '../../utils';
6+
import { confirmPrompt, TelemetryHelper, t, getBackendSystemService } from '../../utils';
77
import {
88
ConfirmationPromptType,
99
SystemAction,
@@ -12,7 +12,6 @@ import {
1212
SYSTEMS_EVENT
1313
} from '../../utils/constants';
1414
import { SystemPanel } from '../../panel';
15-
import SystemsLogger from '../../utils/logger';
1615

1716
/**
1817
* Returns a command handler function that handles importing a system configuration from a file.
@@ -24,7 +23,7 @@ export const importSystemCommandHandler = (commandContext: SystemCommandContext)
2423
try {
2524
const systemConfig = await getImportSystemConfig();
2625
const backendSystemKey = new BackendSystemKey({ url: systemConfig.url, client: systemConfig.client });
27-
const systemService = new SystemService(SystemsLogger.logger);
26+
const systemService = await getBackendSystemService();
2827
const existingSystem = await systemService.read(backendSystemKey);
2928

3029
// if the system already exists, confirm if the user wants to overwrite

packages/sap-systems-ext/src/commands/system/launchAppGen.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type { StoredSystemViewNode, SystemCommandContext } from '../../types/system';
22
import { commands, window } from 'vscode';
3-
import { TelemetryHelper, t } from '../../utils';
3+
import { TelemetryHelper, getBackendSystemService, t } from '../../utils';
44
import {
55
fioriToolsAppModAppGenLaunchCmd,
66
launchAppGenCmdType,
77
SystemAction,
88
SystemActionStatus,
99
SYSTEMS_EVENT
1010
} from '../../utils/constants';
11-
import { BackendSystemKey, SystemService } from '@sap-ux/store';
11+
import { BackendSystemKey } from '@sap-ux/store';
1212
import SystemsLogger from '../../utils/logger';
1313

1414
/**
@@ -21,7 +21,7 @@ export const launchAppGenCommandHandler =
2121
(_context: SystemCommandContext) =>
2222
async (system: StoredSystemViewNode): Promise<void> => {
2323
if (system.url) {
24-
const systemService = new SystemService(SystemsLogger.logger);
24+
const systemService = await getBackendSystemService();
2525
const backendSystem = await systemService.read(
2626
new BackendSystemKey({ url: system.url, client: system.client })
2727
);

packages/sap-systems-ext/src/commands/system/show.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import type { StoredSystemViewNode, SystemCommandContext } from '../../types/system';
2-
import { BackendSystemKey, SystemService, type BackendSystem } from '@sap-ux/store';
2+
import { BackendSystemKey, type BackendSystem, type Service } from '@sap-ux/store';
33
import { window } from 'vscode';
44
import { SystemPanel } from '../../panel';
5-
import { TelemetryHelper, t } from '../../utils';
5+
import { TelemetryHelper, getBackendSystemService, t } from '../../utils';
66
import { SystemAction, LaunchViewStatus, SystemPanelViewType, SYSTEMS_EVENT } from '../../utils/constants';
7-
import SystemsLogger from '../../utils/logger';
87

98
/**
109
* Returns a command handler function that shows the details of a specified system.
@@ -16,7 +15,7 @@ export const showSystemsCommandHandler =
1615
(context: SystemCommandContext) =>
1716
async (system?: StoredSystemViewNode, statusMsg?: string): Promise<void> => {
1817
try {
19-
const systemService = new SystemService(SystemsLogger.logger);
18+
const systemService = await getBackendSystemService();
2019
const backendSystemKey = await getBackendSystemKey(systemService, system);
2120
const storedBackendSystem = await systemService.read(backendSystemKey);
2221
if (!storedBackendSystem) {
@@ -41,7 +40,7 @@ export const showSystemsCommandHandler =
4140
* @returns - the backend system key
4241
*/
4342
async function getBackendSystemKey(
44-
systemService: SystemService,
43+
systemService: Service<BackendSystem, BackendSystemKey>,
4544
system?: StoredSystemViewNode
4645
): Promise<BackendSystemKey> {
4746
if (system) {
@@ -57,7 +56,9 @@ async function getBackendSystemKey(
5756
* @param systemService - the system service for the store
5857
* @returns - the selected backend system key
5958
*/
60-
async function sapSystemDropdownPicker(systemService: SystemService): Promise<BackendSystemKey> {
59+
async function sapSystemDropdownPicker(
60+
systemService: Service<BackendSystem, BackendSystemKey>
61+
): Promise<BackendSystemKey> {
6162
const allBackendSystems = await systemService.getAll({ includeSensitiveData: false });
6263
const quickPickItems = allBackendSystems.map((system) => ({
6364
label: system.name,

packages/sap-systems-ext/src/panel/system/actions/updateSystem.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { UpdateSystem } from '@sap-ux/sap-systems-ext-types';
22
import type { PanelContext } from '../../../types/system';
3-
import { SystemService, type BackendSystem } from '@sap-ux/store';
3+
import type { BackendSystem } from '@sap-ux/store';
44
import { commands, window } from 'vscode';
5-
import { getBackendSystem, geti18nOpts, TelemetryHelper, t } from '../../../utils';
5+
import { getBackendSystem, geti18nOpts, TelemetryHelper, t, getBackendSystemService } from '../../../utils';
66
import { updateSystemStatus, validateSystemName } from '../utils';
77
import {
88
SystemAction,
@@ -11,7 +11,6 @@ import {
1111
SystemPanelViewType,
1212
SYSTEMS_EVENT
1313
} from '../../../utils/constants';
14-
import SystemsLogger from '../../../utils/logger';
1514

1615
/**
1716
* This action updates or creates a system based on the provided details.
@@ -87,7 +86,8 @@ async function updateHandler(
8786
// this requires us to delete the existing system, dispose of the panel, and create and load a new one
8887
if (panelViewType === SystemPanelViewType.View && !systemExistsInStore && context.backendSystem) {
8988
context.disposePanel();
90-
await new SystemService(SystemsLogger.logger).delete(context.backendSystem);
89+
const systemService = await getBackendSystemService();
90+
await systemService.delete(context.backendSystem);
9191
newPanelMsg = t('info.systemUpdated', { system: newSystem.name });
9292
}
9393

@@ -149,7 +149,8 @@ async function saveSystem(
149149
): Promise<void> {
150150
// ensure the user display name is set to the username
151151
const newBackendSystem = { ...backendSystem, userDisplayName: backendSystem.username };
152-
await new SystemService(SystemsLogger.logger).write(newBackendSystem, {
152+
const systemService = await getBackendSystemService();
153+
await systemService.write(newBackendSystem, {
153154
force: systemExistsInStore
154155
});
155156
const i18nKey = systemPanelViewType === SystemPanelViewType.Create ? 'info.systemSaved' : 'info.systemUpdated';

packages/sap-systems-ext/src/panel/system/utils/validate.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { SystemService, type BackendSystem } from '@sap-ux/store';
2-
import { t } from '../../../utils';
3-
import SystemsLogger from '../../../utils/logger';
1+
import type { BackendSystem } from '@sap-ux/store';
2+
import { getBackendSystemService, t } from '../../../utils';
43

54
/**
65
* Validates the provided system information.
@@ -25,7 +24,8 @@ export function validateSystemInfo(input: BackendSystem): boolean | string {
2524
* @throws error if the new name already exists in the store (and is not the current name)
2625
*/
2726
export async function validateSystemName(newName: string, currentName?: string): Promise<true> {
28-
const allSystems = await new SystemService(SystemsLogger.logger).getAll({ includeSensitiveData: false });
27+
const systemService = await getBackendSystemService();
28+
const allSystems = await systemService.getAll({ includeSensitiveData: false });
2929
const newSystemName = newName.trim();
3030

3131
const nameExists = allSystems.some(

packages/sap-systems-ext/src/providers/sapSystemsProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { TreeDataProvider, Command, ExtensionContext, Event } from 'vscode';
2-
import { SystemService, type BackendSystem } from '@sap-ux/store';
2+
import type { BackendSystem } from '@sap-ux/store';
33
import { commands, TreeItem, TreeItemCollapsibleState, Uri, EventEmitter } from 'vscode';
4-
import { t, getDisplayName } from '../utils';
4+
import { t, getDisplayName, getBackendSystemService } from '../utils';
55
import { SystemCommands } from '../utils/constants';
66
import SystemsLogger from '../utils/logger';
77

@@ -113,7 +113,7 @@ export class SapSystemsProvider implements TreeDataProvider<TreeItem> {
113113
let systems: BackendSystem[] = [];
114114
try {
115115
await commands.executeCommand('setContext', 'sap.ux.tools.sapSystems.treeLoading', true);
116-
const systemService = new SystemService(SystemsLogger.logger);
116+
const systemService = await getBackendSystemService();
117117
systems = await systemService.getAll({ includeSensitiveData: false });
118118
return systems;
119119
} catch (error) {

packages/sap-systems-ext/src/utils/store.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
import { BackendSystemKey, SystemService, type BackendSystem } from '@sap-ux/store';
1+
import { getService, BackendSystemKey, type BackendSystem, type Service } from '@sap-ux/store';
22
import SystemsLogger from './logger';
33

4+
/**
5+
* Get the backend system service instance.
6+
*
7+
* @returns the backend system service instance
8+
*/
9+
export async function getBackendSystemService(): Promise<Service<BackendSystem, BackendSystemKey>> {
10+
const backendService = await getService<BackendSystem, BackendSystemKey>({
11+
logger: SystemsLogger.logger,
12+
entityName: 'system'
13+
});
14+
return backendService;
15+
}
16+
417
/**
518
* Fetches a backend system based on the provided system details.
619
*
@@ -14,7 +27,7 @@ export async function getBackendSystem(system: { url: string; client?: string })
1427
url: system.url,
1528
client: system?.client
1629
});
17-
const systemService = new SystemService(SystemsLogger.logger);
30+
const systemService = await getBackendSystemService();
1831
const backendSystem = await systemService.read(backendSystemKey);
1932
return backendSystem;
2033
}

packages/sap-systems-ext/test/unit/commands/system/delete.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const systemServiceDeleteMock = jest.fn();
99

1010
jest.mock('@sap-ux/store', () => ({
1111
...jest.requireActual('@sap-ux/store'),
12-
SystemService: jest.fn().mockImplementation(() => ({
12+
getService: jest.fn().mockImplementation(() => ({
1313
read: systemServiceReadMock,
1414
delete: systemServiceDeleteMock
1515
}))

packages/sap-systems-ext/test/unit/commands/system/import.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const systemServiceReadMock = jest.fn();
99

1010
jest.mock('@sap-ux/store', () => ({
1111
...jest.requireActual('@sap-ux/store'),
12-
SystemService: jest.fn().mockImplementation(() => ({
12+
getService: jest.fn().mockImplementation(() => ({
1313
read: systemServiceReadMock
1414
}))
1515
}));

0 commit comments

Comments
 (0)