Skip to content

Commit 0d5fb04

Browse files
author
Priti Sambandam
committed
Adding CITs and also updated standard app template standalone
1 parent 15ed538 commit 0d5fb04

File tree

9 files changed

+407
-131
lines changed

9 files changed

+407
-131
lines changed

apps/Standalone/src/designer/app/AzureLogicAppsDesigner/Services/WorkflowAndArtifacts.tsx

+79-81
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { CustomCodeService, LogEntryLevel, LoggerService, equals, getAppFileForF
88
import type { LogicAppsV2, VFSObject } from '@microsoft/logic-apps-shared';
99
import axios from 'axios';
1010
import jwt_decode from 'jwt-decode';
11-
import { useQuery } from '@tanstack/react-query';
11+
import { type QueryClient, useQuery } from '@tanstack/react-query';
1212
import { isSuccessResponse } from './HttpClient';
1313
import { fetchFileData, fetchFilesFromFolder } from './vfsService';
1414
import type { CustomCodeFileNameMapping } from '@microsoft/logic-apps-designer';
@@ -22,33 +22,31 @@ const hybridApiVersion = '2024-02-02-preview';
2222
const consumptionApiVersion = '2019-05-01';
2323

2424
export const useConnectionsData = (appId?: string) => {
25-
return useQuery(
26-
['getConnectionsData', appId],
27-
async () => {
28-
const uri = `${baseUrl}/${appId}/workflowsconfiguration/connections?api-version=2018-11-01`;
29-
try {
30-
const response = await axios.get(uri, {
31-
headers: {
32-
Authorization: `Bearer ${environment.armToken}`,
33-
},
34-
});
35-
const { files, health } = response.data.properties;
36-
if (equals(health.state, 'healthy')) {
37-
return files['connections.json'];
38-
}
39-
const { error } = health;
40-
throw new Error(error.message);
41-
} catch {
42-
return {};
43-
}
44-
},
45-
{
46-
enabled: !!appId,
47-
refetchOnMount: false,
48-
refetchOnReconnect: false,
49-
refetchOnWindowFocus: false,
25+
return useQuery(['getConnectionsData', appId], async () => getConnectionsData(appId as string), {
26+
enabled: !!appId,
27+
refetchOnMount: false,
28+
refetchOnReconnect: false,
29+
refetchOnWindowFocus: false,
30+
});
31+
};
32+
33+
export const getConnectionsData = async (appId: string): Promise<ConnectionsData> => {
34+
const uri = `${baseUrl}/${appId}/workflowsconfiguration/connections?api-version=2018-11-01`;
35+
try {
36+
const response = await axios.get(uri, {
37+
headers: {
38+
Authorization: `Bearer ${environment.armToken}`,
39+
},
40+
});
41+
const { files, health } = response.data.properties;
42+
if (equals(health.state, 'healthy')) {
43+
return files['connections.json'];
5044
}
51-
);
45+
const { error } = health;
46+
throw new Error(error.message);
47+
} catch {
48+
return {};
49+
}
5250
};
5351

5452
export const useWorkflowAndArtifactsStandard = (workflowId: string) => {
@@ -293,66 +291,66 @@ export const listCallbackUrl = async (
293291
};
294292

295293
export const useWorkflowApp = (siteResourceId: string, hostingPlan: HostingPlanTypes) => {
296-
return useQuery(
297-
['workflowApp', siteResourceId],
298-
async () => {
299-
const apiVersions = {
300-
consumption: '2016-10-01',
301-
standard: '2018-11-01',
302-
hybrid: '2023-11-02-preview',
303-
};
304-
const uri = `${baseUrl}${siteResourceId}?api-version=${apiVersions[hostingPlan] || '2018-11-01'}`;
305-
const response = await axios.get(uri, {
306-
headers: {
307-
Authorization: `Bearer ${environment.armToken}`,
308-
},
309-
});
294+
return useQuery(['workflowApp', siteResourceId], async () => getWorkflowApp(siteResourceId, hostingPlan), {
295+
refetchOnMount: false,
296+
refetchOnReconnect: false,
297+
refetchOnWindowFocus: false,
298+
});
299+
};
310300

311-
return response.data;
301+
export const getWorkflowAppFromCache = async (siteResourceId: string, hostingPlan: HostingPlanTypes, queryClient: QueryClient) => {
302+
return queryClient.fetchQuery(['workflowApp', siteResourceId], async () => getWorkflowApp(siteResourceId, hostingPlan));
303+
};
304+
305+
const getWorkflowApp = async (siteResourceId: string, hostingPlan: HostingPlanTypes) => {
306+
const apiVersions = {
307+
consumption: '2016-10-01',
308+
standard: '2018-11-01',
309+
hybrid: '2023-11-02-preview',
310+
};
311+
const uri = `${baseUrl}${siteResourceId}?api-version=${apiVersions[hostingPlan] || '2018-11-01'}`;
312+
const response = await axios.get(uri, {
313+
headers: {
314+
Authorization: `Bearer ${environment.armToken}`,
312315
},
313-
{
314-
refetchOnMount: false,
315-
refetchOnReconnect: false,
316-
refetchOnWindowFocus: false,
317-
}
318-
);
316+
});
317+
318+
return response.data;
319319
};
320320

321321
export const useAppSettings = (siteResourceId: string) => {
322-
return useQuery(
323-
['appSettings', siteResourceId],
324-
async () => {
325-
if (HybridAppUtility.isHybridLogicApp(siteResourceId)) {
326-
const containerAppInfo = (
327-
await axios.get(`${baseUrl}${siteResourceId}?api-version=2024-02-02-preview`, {
328-
headers: {
329-
Authorization: `Bearer ${environment.armToken}`,
330-
},
331-
})
332-
).data;
333-
containerAppInfo.properties = containerAppInfo.properties.template.containers[0].env;
334-
containerAppInfo.properties = containerAppInfo.properties.reduce((acc: any, cur: any) => {
335-
acc[cur.name] = cur.value;
336-
return acc;
337-
}, {});
338-
return containerAppInfo;
339-
}
322+
return useQuery(['appSettings', siteResourceId], async () => getAppSettings(siteResourceId), {
323+
refetchOnMount: false,
324+
refetchOnReconnect: false,
325+
refetchOnWindowFocus: false,
326+
});
327+
};
340328

341-
const uri = `${baseUrl}${siteResourceId}/config/appsettings/list?api-version=2018-11-01`;
342-
return (
343-
await axios.post(uri, null, {
344-
headers: {
345-
Authorization: `Bearer ${environment.armToken}`,
346-
},
347-
})
348-
).data;
349-
},
350-
{
351-
refetchOnMount: false,
352-
refetchOnReconnect: false,
353-
refetchOnWindowFocus: false,
354-
}
355-
);
329+
export const getAppSettings = async (siteResourceId: string) => {
330+
if (HybridAppUtility.isHybridLogicApp(siteResourceId)) {
331+
const containerAppInfo = (
332+
await axios.get(`${baseUrl}${siteResourceId}?api-version=2024-02-02-preview`, {
333+
headers: {
334+
Authorization: `Bearer ${environment.armToken}`,
335+
},
336+
})
337+
).data;
338+
containerAppInfo.properties = containerAppInfo.properties.template.containers[0].env;
339+
containerAppInfo.properties = containerAppInfo.properties.reduce((acc: any, cur: any) => {
340+
acc[cur.name] = cur.value;
341+
return acc;
342+
}, {});
343+
return containerAppInfo;
344+
}
345+
346+
const uri = `${baseUrl}${siteResourceId}/config/appsettings/list?api-version=2018-11-01`;
347+
return (
348+
await axios.post(uri, null, {
349+
headers: {
350+
Authorization: `Bearer ${environment.armToken}`,
351+
},
352+
})
353+
).data;
356354
};
357355

358356
export const useCurrentTenantId = () => {

0 commit comments

Comments
 (0)