Skip to content

Commit 553216d

Browse files
preetriti1Priti Sambandam
and
Priti Sambandam
authored
feat(templates): Adding support to load custom templates from service for gallery (#7146)
* Adding support to load custom templates from service for gallery * Updating the package version since its duplicate package exists --------- Co-authored-by: Priti Sambandam <psamband@microsoft.com>
1 parent 7390eea commit 553216d

File tree

7 files changed

+51
-7
lines changed

7 files changed

+51
-7
lines changed

Localize/lang/strings.json

-3
Original file line numberDiff line numberDiff line change
@@ -3260,7 +3260,6 @@
32603260
"_x+6ccf.comment": "Day of the week",
32613261
"_x0or2o.comment": "Required collection parameter to apply length Function",
32623262
"_x2JTW5.comment": "Label for description of the custom 'removeProperty' function",
3263-
"_x2z3kg.comment": "Error message when the workflow name is empty.",
32643263
"_x3dWOL.comment": "Time zone value ",
32653264
"_x7IYBg.comment": "The status message to show in monitoring view.",
32663265
"_xBIh0S.comment": "Workflow type label",
@@ -4157,7 +4156,6 @@
41574156
"x+6ccf": "Wednesday",
41584157
"x0or2o": "Required. The collection for which to get the length.",
41594158
"x2JTW5": "Returns an object with the specified property removed.",
4160-
"x2z3kg": "Workflow name is required.",
41614159
"x3dWOL": "(UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna",
41624160
"x7IYBg": "Aborted",
41634161
"xBIh0S": "Workflow type",
@@ -4231,7 +4229,6 @@
42314229
"zCsGWP": "Enter value",
42324230
"zIDVd9": "Required. The string that is converted to a native type value.",
42334231
"zK5VPq": "Workflows in this Accelerator",
4234-
"zMKxg9": "Name can only contain letters, numbers, and '-', '(', ')', '_' or '.",
42354232
"zNesUZ": "A retry policy applies to intermittent failures, characterized as HTTP status codes 408, 429, and 5xx, in addition to any connectivity exceptions. The default is an exponential interval policy set to retry 4 times.",
42364233
"zOq84J": "Can't delete the last agent parameter.",
42374234
"zOvGF8": "(UTC+02:00) Athens, Bucharest",

libs/designer/src/lib/core/actions/bjsworkflow/templates.ts

+21
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { updateAllTemplateParameterDefinitions } from '../../state/templates/tem
3131
import { checkWorkflowNameWithRegex, getCurrentWorkflowNames } from '../../templates/utils/helper';
3232
import { loadGithubManifestNames, setavailableTemplates, setavailableTemplatesNames } from '../../state/templates/manifestSlice';
3333
import { clearConnectionCaches } from '../../queries/connections';
34+
import { getCustomTemplates } from '../../templates/utils/queries';
3435

3536
export interface WorkflowTemplateData {
3637
id: string;
@@ -223,6 +224,26 @@ export const loadTemplate = createAsyncThunk(
223224
}
224225
);
225226

227+
export const loadCustomTemplates = createAsyncThunk(
228+
'loadCustomTemplates',
229+
async (_, { getState }): Promise<Record<string, Template.TemplateManifest>> => {
230+
try {
231+
const { subscriptionId, resourceGroup } = (getState() as RootState).workflow;
232+
const customTemplates = await getCustomTemplates(subscriptionId, resourceGroup);
233+
return customTemplates.reduce((result: Record<string, Template.TemplateManifest>, template) => {
234+
result[template.id.toLowerCase()] = {
235+
...template.manifest,
236+
};
237+
238+
return result;
239+
}, {});
240+
} catch (ex) {
241+
console.error(ex);
242+
return {};
243+
}
244+
}
245+
);
246+
226247
export const validateWorkflowsBasicInfo = createAsyncThunk(
227248
'validateWorkflowsBasicInfo',
228249
async (

libs/designer/src/lib/core/state/templates/manifestSlice.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { PayloadAction } from '@reduxjs/toolkit';
33
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
44
import type { RootState } from './store';
55
import type { FilterObject } from '@microsoft/designer-ui';
6-
import { loadManifestsFromPaths } from '../../actions/bjsworkflow/templates';
6+
import { loadCustomTemplates, loadManifestsFromPaths } from '../../actions/bjsworkflow/templates';
77
import { resetTemplatesState } from '../global';
88

99
export const templatesCountPerPage = 25;
@@ -121,6 +121,10 @@ export const manifestSlice = createSlice({
121121
state.availableTemplates = undefined;
122122
});
123123

124+
builder.addCase(loadCustomTemplates.fulfilled, (state, action) => {
125+
state.availableTemplates = { ...state.availableTemplates, ...(action.payload ?? {}) };
126+
});
127+
124128
builder.addCase(lazyLoadGithubManifests.fulfilled, (state, action) => {
125129
state.availableTemplates = { ...state.availableTemplates, ...(action.payload ?? {}) };
126130
});

libs/designer/src/lib/core/templates/TemplatesDataProvider.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import {
1111
} from '../state/templates/manifestSlice';
1212
import { type ResourceDetails, setInitialData } from '../state/templates/workflowSlice';
1313
import type { ConnectionReferences } from '../../common/models/workflow';
14-
import { initializeTemplateServices, initializeWorkflowMetadata, reloadTemplates } from '../actions/bjsworkflow/templates';
14+
import {
15+
initializeTemplateServices,
16+
initializeWorkflowMetadata,
17+
loadCustomTemplates,
18+
reloadTemplates,
19+
} from '../actions/bjsworkflow/templates';
1520
import { InitTemplateService, type Template } from '@microsoft/logic-apps-shared';
1621
import { setEnableResourceSelection, setViewTemplateDetails } from '../state/templates/templateOptionsSlice';
1722
import { changeCurrentTemplateName } from '../state/templates/templateSlice';
@@ -39,6 +44,7 @@ const DataProviderInner = ({ children, reload, services }: TemplatesDataProvider
3944

4045
useEffect(() => {
4146
dispatch(loadGithubManifestNames());
47+
dispatch(loadCustomTemplates());
4248
}, [dispatch]);
4349

4450
useEffect(() => {

libs/designer/src/lib/core/templates/utils/queries.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import type { UseQueryResult } from '@tanstack/react-query';
22
import { useQuery } from '@tanstack/react-query';
33
import { getConnector, getOperation } from '../../queries/operation';
44
import type { LogicAppResource, Resource } from '@microsoft/logic-apps-shared';
5-
import { ResourceService } from '@microsoft/logic-apps-shared';
5+
import { ResourceService, TemplateService } from '@microsoft/logic-apps-shared';
6+
import { getReactQueryClient } from '../../ReactQueryProvider';
67

78
export interface ConnectorInfo {
89
id: string;
@@ -118,3 +119,10 @@ export const useLogicApps = (
118119
}
119120
);
120121
};
122+
123+
export const getCustomTemplates = async (subscriptionId: string, resourceGroup: string) => {
124+
const queryClient = getReactQueryClient();
125+
return queryClient.fetchQuery(['customtemplates', subscriptionId.toLowerCase(), resourceGroup.toLowerCase()], async () => {
126+
return (await TemplateService()?.getCustomTemplates?.(subscriptionId, resourceGroup)) ?? [];
127+
});
128+
};

libs/logic-apps-shared/src/designer-client-services/lib/template.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import type { LogicAppsV2, Template } from '../../utils/src';
22
import { AssertionErrorCode, AssertionException } from '../../utils/src';
33

4+
export interface CustomTemplateResource {
5+
id: string;
6+
name: string;
7+
state: string;
8+
manifest: Template.TemplateManifest;
9+
}
10+
411
export interface ITemplateService {
512
getExistingWorkflowNames?: () => Promise<string[]>;
613
isResourceAvailable?: (resourceId: string) => Promise<boolean>;
714
openBladeAfterCreate?: (workflowName: string | undefined) => void;
815
onAddBlankWorkflow?: () => Promise<void>;
916
getAllTemplateNames: () => Promise<string[]>;
17+
getCustomTemplates?: (subscrpitionId: string, resourceGroup: string) => Promise<CustomTemplateResource[]>;
1018
getResourceManifest: (resourcePath: string) => Promise<Template.TemplateManifest | Template.WorkflowManifest>;
1119
getWorkflowDefinition: (templateId: string, workflowId: string) => Promise<LogicAppsV2.WorkflowDefinition>;
1220
getContentPathUrl: (templatePath: string, resourcePath: string) => string;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@microsoft/logicappsux",
3-
"version": "5.94.1",
3+
"version": "5.94.2",
44
"devDependencies": {
55
"@biomejs/biome": "1.9.4",
66
"@eslint/eslintrc": "^3.0.2",

0 commit comments

Comments
 (0)