Skip to content

Commit 15ed538

Browse files
author
Priti Sambandam
committed
fix(templates): Adding a reload handler when a resource changes and services to reload
1 parent f30e568 commit 15ed538

File tree

11 files changed

+269
-129
lines changed

11 files changed

+269
-129
lines changed

apps/Standalone/src/templates/app/LocalTemplates.tsx

+52-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useMemo, useState } from 'react';
22
import { TemplatesDataProvider, TemplatesView } from '@microsoft/logic-apps-designer';
33
import type { RootState } from '../state/Store';
4-
import { TemplatesDesigner, TemplatesDesignerProvider } from '@microsoft/logic-apps-designer';
4+
import { TemplatesDesigner, TemplatesDesignerProvider, templateStore, resetStateOnResourceChange } from '@microsoft/logic-apps-designer';
55
import { useSelector } from 'react-redux';
66
import {
77
BaseGatewayService,
@@ -20,10 +20,6 @@ import {
2020
} from '@microsoft/logic-apps-shared';
2121
import { HttpClient } from '../../designer/app/AzureLogicAppsDesigner/Services/HttpClient';
2222

23-
const subscriptionId = 'one';
24-
const resourceGroup = 'SecondRG';
25-
const location = 'eastus';
26-
2723
const loadLocalTemplateFromResourcePath = async (resourcePath: string, artifactType = 'manifest') => {
2824
const paths = resourcePath.split('/');
2925

@@ -33,6 +29,9 @@ const loadLocalTemplateFromResourcePath = async (resourcePath: string, artifactT
3329
};
3430

3531
const localTemplateManifestPaths = ['BasicWorkflowOnly', 'SimpleConnectionParameter', 'SimpleAccelerator', 'SimpleParametersOnly'];
32+
const defaultSubscriptionId = 'one';
33+
const defaultResourceGroup = 'SecondRG';
34+
const defaultLocation = 'eastus';
3635

3736
export const LocalTemplates = () => {
3837
const { theme, templatesView } = useSelector((state: RootState) => ({
@@ -55,19 +54,23 @@ export const LocalTemplates = () => {
5554
}, [useEndpoint]);
5655

5756
const services = useMemo(
58-
() => getServices(isConsumption, !!useEndpoint),
57+
() => getServices(defaultSubscriptionId, defaultResourceGroup, defaultLocation, isConsumption, !!useEndpoint),
5958
// eslint-disable-next-line react-hooks/exhaustive-deps
6059
[isConsumption, useEndpoint]
6160
);
61+
const onReloadServices = () => {
62+
const { subscriptionId, resourceGroup, location } = templateStore.getState().workflow;
63+
templateStore.dispatch(resetStateOnResourceChange(getResourceBasedServices(subscriptionId, resourceGroup, location, isConsumption)));
64+
};
6265
const isSingleTemplateView = useMemo(() => templatesView !== 'gallery', [templatesView]);
6366

6467
return (
6568
<TemplatesDesignerProvider locale="en-US" theme={theme}>
6669
<TemplatesDataProvider
6770
resourceDetails={{
68-
subscriptionId,
69-
resourceGroup,
70-
location,
71+
subscriptionId: defaultSubscriptionId,
72+
resourceGroup: defaultResourceGroup,
73+
location: defaultLocation,
7174
workflowAppName: 'app1',
7275
}}
7376
reload={reload}
@@ -76,6 +79,7 @@ export const LocalTemplates = () => {
7679
isConsumption={isConsumption}
7780
isCreateView={!isConsumption || !!isCreateView}
7881
enableResourceSelection={enableResourceSelection}
82+
onResourceChange={onReloadServices}
7983
existingWorkflowName={undefined}
8084
viewTemplate={
8185
isSingleTemplateView
@@ -167,7 +171,13 @@ export const LocalTemplates = () => {
167171

168172
const httpClient = new HttpClient();
169173

170-
const getServices = (isConsumption: boolean, useEndpoint: boolean): any => {
174+
const getServices = (
175+
subscriptionId: string,
176+
resourceGroup: string,
177+
location: string,
178+
isConsumption: boolean,
179+
useEndpoint: boolean
180+
): any => {
171181
const connectionService = isConsumption
172182
? new ConsumptionConnectionService({
173183
apiVersion: '2018-07-01-preview',
@@ -276,6 +286,38 @@ const getServices = (isConsumption: boolean, useEndpoint: boolean): any => {
276286
};
277287
};
278288

289+
const getResourceBasedServices = (subscriptionId: string, resourceGroup: string, location: string, isConsumption: boolean) => {
290+
const connectionService = isConsumption
291+
? new ConsumptionConnectionService({
292+
apiVersion: '2018-07-01-preview',
293+
baseUrl: '/baseUrl',
294+
subscriptionId,
295+
resourceGroup,
296+
location,
297+
httpClient,
298+
})
299+
: new StandardConnectionService({
300+
baseUrl: '/url',
301+
apiVersion: '2018-11-01',
302+
httpClient,
303+
apiHubServiceDetails: {
304+
apiVersion: '2018-07-01-preview',
305+
baseUrl: '/baseUrl',
306+
subscriptionId,
307+
resourceGroup,
308+
location,
309+
httpClient,
310+
},
311+
workflowAppDetails: {
312+
appName: 'app',
313+
identity: { type: ResourceIdentityType.SYSTEM_ASSIGNED },
314+
},
315+
readConnections: () => Promise.resolve({}),
316+
});
317+
318+
return { connectionService };
319+
};
320+
279321
class LocalTemplateService extends StandardTemplateService {
280322
constructor(private readonly _options: any) {
281323
super(_options);

apps/Standalone/src/templates/app/TemplatesConsumption.tsx

+90-42
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
type WorkflowParameter,
99
} from '@microsoft/logic-apps-designer';
1010
import type { RootState } from '../state/Store';
11-
import { TemplatesView, TemplatesDesignerProvider } from '@microsoft/logic-apps-designer';
11+
import { TemplatesView, TemplatesDesignerProvider, templateStore, resetStateOnResourceChange } from '@microsoft/logic-apps-designer';
1212
import { useSelector } from 'react-redux';
1313
import {
1414
BaseGatewayService,
@@ -157,6 +157,24 @@ export const TemplatesConsumption = () => {
157157

158158
const resourceDetails = new ArmParser(workflowId ?? '');
159159

160+
const onReloadServices = () => {
161+
const { subscriptionId, resourceGroup, location } = templateStore.getState().workflow;
162+
templateStore.dispatch(
163+
resetStateOnResourceChange(
164+
getResourceBasedServices(
165+
subscriptionId,
166+
resourceGroup,
167+
tenantId,
168+
objectId,
169+
WorkflowUtility.convertToCanonicalFormat(location ?? 'westus'),
170+
language,
171+
queryClient,
172+
workflowId
173+
)
174+
)
175+
);
176+
};
177+
160178
if (!workflowData) {
161179
return null;
162180
}
@@ -175,6 +193,7 @@ export const TemplatesConsumption = () => {
175193
enableResourceSelection={enableResourceSelection}
176194
viewTemplate={isSingleTemplateView ? { id: templatesView } : undefined}
177195
reload={reload}
196+
onResourceChange={onReloadServices}
178197
>
179198
<div
180199
style={{
@@ -249,6 +268,75 @@ const getServices = (
249268

250269
const defaultServiceParams = { baseUrl, httpClient, apiVersion };
251270

271+
const gatewayService = new BaseGatewayService({
272+
baseUrl,
273+
httpClient,
274+
apiVersions: {
275+
subscription: apiVersion,
276+
gateway: '2016-06-01',
277+
},
278+
});
279+
const tenantService = new BaseTenantService({
280+
...defaultServiceParams,
281+
apiVersion: '2017-08-01',
282+
});
283+
const workflowService = {
284+
getCallbackUrl: (triggerName: string) => listCallbackUrl(workflowId, triggerName, true),
285+
getAppIdentity: () => workflow?.identity,
286+
isExplicitAuthRequiredForManagedIdentity: () => false,
287+
getDefinitionSchema: (operationInfos: { type: string; kind?: string }[]) => {
288+
return operationInfos.some((info) => startsWith(info.type, 'openapiconnection'))
289+
? 'https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2023-01-31-preview/workflowdefinition.json#'
290+
: undefined;
291+
},
292+
};
293+
const templateService = new ConsumptionTemplateService({
294+
...defaultServiceParams,
295+
endpoint: 'https://priti-cxf4h5cpcteue4az.b02.azurefd.net',
296+
useEndpointForTemplates: !!useEndpoint,
297+
openBladeAfterCreate: (_workflowName: string | undefined) => {
298+
window.alert('Open blade after create, consumption creation is complete');
299+
},
300+
onAddBlankWorkflow: onBlankWorkflowClick,
301+
});
302+
const resourceService = new BaseResourceService(defaultServiceParams);
303+
const { connectionService, oAuthService, operationManifestService, connectorService } = getResourceBasedServices(
304+
subscriptionId,
305+
resourceGroup,
306+
tenantId,
307+
objectId,
308+
location,
309+
locale,
310+
queryClient,
311+
workflowId
312+
);
313+
314+
return {
315+
connectionService,
316+
gatewayService,
317+
tenantService,
318+
oAuthService,
319+
operationManifestService,
320+
templateService,
321+
workflowService,
322+
connectorService,
323+
resourceService,
324+
};
325+
};
326+
327+
const getResourceBasedServices = (
328+
subscriptionId: string,
329+
resourceGroup: string,
330+
tenantId: string | undefined,
331+
objectId: string | undefined,
332+
location: string,
333+
locale: string | undefined,
334+
queryClient?: any,
335+
workflowId?: string
336+
): any => {
337+
const baseUrl = 'https://management.azure.com';
338+
const defaultServiceParams = { baseUrl, httpClient, apiVersion };
339+
252340
const connectionService = new ConsumptionConnectionService({
253341
apiVersion: '2018-07-01-preview',
254342
baseUrl,
@@ -319,20 +407,7 @@ const getServices = (
319407
},
320408
},
321409
apiVersion: '2018-07-01-preview',
322-
workflowReferenceId: workflowId,
323-
});
324-
325-
const gatewayService = new BaseGatewayService({
326-
baseUrl,
327-
httpClient,
328-
apiVersions: {
329-
subscription: apiVersion,
330-
gateway: '2016-06-01',
331-
},
332-
});
333-
const tenantService = new BaseTenantService({
334-
...defaultServiceParams,
335-
apiVersion: '2017-08-01',
410+
workflowReferenceId: workflowId ?? 'default',
336411
});
337412
const oAuthService = new StandaloneOAuthService({
338413
...defaultServiceParams,
@@ -349,39 +424,12 @@ const getServices = (
349424
subscriptionId,
350425
location: location || 'location',
351426
});
352-
const workflowService = {
353-
getCallbackUrl: (triggerName: string) => listCallbackUrl(workflowId, triggerName, true),
354-
getAppIdentity: () => workflow?.identity,
355-
isExplicitAuthRequiredForManagedIdentity: () => false,
356-
getDefinitionSchema: (operationInfos: { type: string; kind?: string }[]) => {
357-
return operationInfos.some((info) => startsWith(info.type, 'openapiconnection'))
358-
? 'https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2023-01-31-preview/workflowdefinition.json#'
359-
: undefined;
360-
},
361-
};
362-
363-
const templateService = new ConsumptionTemplateService({
364-
...defaultServiceParams,
365-
endpoint: 'https://priti-cxf4h5cpcteue4az.b02.azurefd.net',
366-
useEndpointForTemplates: !!useEndpoint,
367-
openBladeAfterCreate: (_workflowName: string | undefined) => {
368-
window.alert('Open blade after create, consumption creation is complete');
369-
},
370-
onAddBlankWorkflow: onBlankWorkflowClick,
371-
});
372-
373-
const resourceService = new BaseResourceService(defaultServiceParams);
374427

375428
return {
376429
connectionService,
377-
gatewayService,
378-
tenantService,
379430
oAuthService,
380431
operationManifestService,
381-
templateService,
382-
workflowService,
383432
connectorService,
384-
resourceService,
385433
};
386434
};
387435

0 commit comments

Comments
 (0)