Skip to content

Commit

Permalink
fix issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-B-Wu committed Apr 1, 2024
1 parent 87a664e commit f02aba2
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
getReactQueryClient,
serializeBJSWorkflow,
store as DesignerStore,
Constants,
} from '@microsoft/logic-apps-designer';
import * as React from 'react';
import { useDispatch, useSelector } from 'react-redux';
Expand Down Expand Up @@ -210,7 +211,7 @@ const DesignerEditorConsumption = () => {
showConnectionsPanel,
hostOptions: {
...hostOptions,
recurrenceInterval: { interval: 3, frequency: 'Minute' },
recurrenceInterval: Constants.RECURRENCE_OPTIONS.CONSUMPTION,
},
}}
>
Expand Down Expand Up @@ -434,6 +435,8 @@ const getDesignerServices = (
location: 'westcentralus',
});

const hostService = {};

return {
appServiceService,
connectionService,
Expand All @@ -447,6 +450,7 @@ const getDesignerServices = (
apimService,
functionService,
runService,
hostService,
chatbotService,
};
};
Expand Down
12 changes: 6 additions & 6 deletions libs/designer-ui/src/lib/code/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const customCodeIconStyle = {

export interface CodeEditorProps extends BaseEditorProps {
language: EditorLanguage;
isCustomCode?: boolean;
customCodeEditor?: boolean;
nodeTitle?: string;
}

Expand All @@ -38,7 +38,7 @@ export function CodeEditor({
getTokenPicker,
label,
nodeTitle,
isCustomCode,
customCodeEditor,
}: CodeEditorProps): JSX.Element {
const intl = useIntl();
const codeEditorRef = useRef<editor.IStandaloneCodeEditor | null>(null);
Expand Down Expand Up @@ -70,7 +70,7 @@ export function CodeEditor({
if (!getInTokenPicker()) {
setShowTokenPickerButton(false);
}
if (isCustomCode) {
if (customCodeEditor) {
onChange?.({
value: [createLiteralValueSegment(getFileName())],
viewModel: {
Expand Down Expand Up @@ -140,8 +140,8 @@ export function CodeEditor({
});

return (
<div className={isCustomCode ? 'msla-custom-code-editor-body' : 'msla-code-editor-body'} id={editorId}>
{isCustomCode ? (
<div className={customCodeEditor ? 'msla-custom-code-editor-body' : 'msla-code-editor-body'} id={editorId}>
{customCodeEditor ? (
<div className="msla-custom-code-editor-file">
<Icon iconName="FileCode" styles={customCodeIconStyle} />
<div className="msla-custom-code-editor-fileName">{getFileName()}</div>
Expand Down Expand Up @@ -180,7 +180,7 @@ export function CodeEditor({
tokenClicked
)
: null}
{isCustomCode && showMessageBar ? (
{customCodeEditor && showMessageBar ? (
<MessageBar
messageBarType={MessageBarType.info}
className="msla-custom-code-editor-message-bar"
Expand Down
4 changes: 4 additions & 0 deletions libs/designer-ui/src/lib/code/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,7 @@ export const getEditorHeight = (input = ''): string => {
export const getCodeEditorHeight = (input = ''): string => {
return Math.min(Math.max(input?.split('\n').length * 20, 228), 456) + 'px';
};

export const isCustomCode = (editor?: string, language?: string): boolean => {
return equals(editor, constants.PARAMETER.EDITOR.CODE) && !equals(language, constants.PARAMETER.EDITOR_OPTIONS.LANGUAGE.JAVASCRIPT);
};
1 change: 1 addition & 0 deletions libs/designer-ui/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@ export * from './useId';
export { FunctionGroupDefinitions as TemplateFunctions } from './workflow/languageservice/templatefunctions';
export type { FunctionDefinition } from './workflow/languageservice/templatefunctions';
export { removeUTFExpressions } from './workflow/languageservice/workflowlanguageservice';
export { isCustomCode } from './code/util';
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ArrayEditor } from '../../arrayeditor';
import { AuthenticationEditor } from '../../authentication';
import { CodeEditor } from '../../code';
import { isCustomCode } from '../../code/util';
import { Combobox } from '../../combobox';
import constants from '../../constants';
import { CopyInputControl } from '../../copyinputcontrol';
Expand Down Expand Up @@ -158,9 +159,9 @@ export const TokenField = ({
);
case constants.PARAMETER.EDITOR.CODE:
return (() => {
const isCustomCode = editorOptions?.language !== constants.PARAMETER.EDITOR_OPTIONS.LANGUAGE.JAVASCRIPT;
const customCodeEditor = isCustomCode(editor, editorOptions?.language);
const initialValue =
editorOptions?.language && isCustomCode ? [createLiteralValueSegment(editorViewModel?.customCodeData?.fileData)] : value;
editorOptions?.language && customCodeEditor ? [createLiteralValueSegment(editorViewModel?.customCodeData?.fileData)] : value;
const language = editorOptions.language ?? EditorLanguage.javascript;

return (
Expand All @@ -172,7 +173,7 @@ export const TokenField = ({
onChange={onValueChange}
readonly={readOnly}
placeholder={placeholder}
isCustomCode={isCustomCode}
customCodeEditor={customCodeEditor}
nodeTitle={nodeTitle}
/>
);
Expand Down
5 changes: 3 additions & 2 deletions libs/designer/src/lib/core/actions/bjsworkflow/delete.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isCustomCode } from '@microsoft/designer-ui';
import type { RootState } from '../../..';
import constants from '../../../common/constants';
import type { WorkflowNode } from '../../parsers/models/workflowNode';
Expand All @@ -11,7 +12,7 @@ import { deinitializeTokensAndVariables } from '../../state/tokens/tokensSlice';
import { clearFocusNode, deleteNode } from '../../state/workflow/workflowSlice';
import { getParameterFromName } from '../../utils/parameters/helper';
import { updateAllUpstreamNodes } from './initialize';
import { WORKFLOW_NODE_TYPES, getRecordEntry, CustomCodeService } from '@microsoft/logic-apps-shared';
import { WORKFLOW_NODE_TYPES, getRecordEntry } from '@microsoft/logic-apps-shared';
import type { Dispatch } from '@reduxjs/toolkit';
import { createAsyncThunk } from '@reduxjs/toolkit';
import { batch } from 'react-redux';
Expand Down Expand Up @@ -56,7 +57,7 @@ const deleteCustomCodeInfo = (nodeId: string, dispatch: Dispatch, state: RootSta
const nodeInputs = getRecordEntry(state.operations.inputParameters, nodeId);
if (nodeInputs) {
const parameter = getParameterFromName(nodeInputs, constants.DEFAULT_CUSTOM_CODE_INPUT);
if (CustomCodeService().isCustomCode(parameter?.editor, parameter?.editorOptions?.language)) {
if (isCustomCode(parameter?.editor, parameter?.editorOptions?.language)) {
const fileName = parameter?.editorViewModel?.customCodeData?.fileName;
// if the file name is not present, then it is a new custom code and we just need to remove the file data
dispatch(deleteCustomCode({ nodeId, fileName }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ import { CommentMenuItem } from '../../menuItems/commentMenuItem';
import { DeleteMenuItem } from '../../menuItems/deleteMenuItem';
import { usePanelTabs } from './usePanelTabs';
import type { CommonPanelProps, PageActionTelemetryData } from '@microsoft/designer-ui';
import { PanelContainer, PanelScope, PanelSize } from '@microsoft/designer-ui';
import { PanelContainer, PanelScope, PanelSize, isCustomCode } from '@microsoft/designer-ui';
import {
CustomCodeService,
WorkflowService,
SUBGRAPH_TYPES,
isNullOrUndefined,
Expand Down Expand Up @@ -117,7 +116,7 @@ export const NodeDetailsPanel = (props: CommonPanelProps): JSX.Element => {
// delete the existing custom code file name and upload the new file with updated name
const onTitleBlur = (prevTitle: string) => {
const parameter = getParameterFromName(inputs, constants.DEFAULT_CUSTOM_CODE_INPUT);
if (parameter && CustomCodeService().isCustomCode(parameter?.editor, parameter?.editorOptions?.language)) {
if (parameter && isCustomCode(parameter?.editor, parameter?.editorOptions?.language)) {
const newFileName = getCustomCodeFileName(selectedNode, inputs, idReplacements);
const [, fileExtension] = splitFileName(newFileName);
const oldFileName = replaceWhiteSpaceWithUnderscore(prevTitle) + fileExtension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ import {
TokenPicker,
TokenPickerButtonLocation,
TokenType,
isCustomCode,
toCustomEditorAndOptions,
} from '@microsoft/designer-ui';
import type { ChangeState, ParameterInfo, ValueSegment, OutputToken, TokenPickerMode, PanelTabFn } from '@microsoft/designer-ui';
import {
CustomCodeService,
EditorService,
equals,
getPropertyValue,
Expand Down Expand Up @@ -234,7 +234,7 @@ const ParameterSection = ({
}
}

if (CustomCodeService().isCustomCode(parameter?.editor, parameter?.editorOptions?.language)) {
if (isCustomCode(parameter?.editor, parameter?.editorOptions?.language)) {
const { fileData, fileExtension, fileName } = viewModel.customCodeData;
dispatch(addOrUpdateCustomCode({ nodeId, fileData, fileExtension, fileName }));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,7 @@ export interface VFSObject {
path: string;
}

export const CustomCodeConstants = {
EDITOR: {
CODE: 'code',
},
EDITOR_OPTIONS: {
LANGUAGE: {
JAVASCRIPT: 'javascript',
},
},
};

export interface ICustomCodeService {
isCustomCode(editor?: string, language?: string): boolean;
getAllCustomCodeFiles(): Promise<VFSObject[]>;
getCustomCodeFile(fileName: string): Promise<string>;
uploadCustomCode(customCode: UploadCustomCode): Promise<void>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { ICustomCodeService, UploadCustomCode, VFSObject } from '../customcode';
import { CustomCodeConstants } from '../customcode';
import type { IHttpClient } from '../httpClient';
import { equals } from '@microsoft/logic-apps-shared';

export interface CustomCodeServiceOptions {
apiVersion: string;
Expand Down Expand Up @@ -33,10 +31,6 @@ export class StandardCustomCodeService implements ICustomCodeService {
}
}

isCustomCode(editor?: string, language?: string): boolean {
return equals(editor, CustomCodeConstants.EDITOR.CODE) && !equals(language, CustomCodeConstants.EDITOR_OPTIONS.LANGUAGE.JAVASCRIPT);
}

async getAllCustomCodeFiles(): Promise<VFSObject[]> {
const { apiVersion, baseUrl, subscriptionId, resourceGroup, appName, workflowName, httpClient } = this.options;
const uri = `${baseUrl}/subscriptions/${subscriptionId}/resourceGroups/${resourceGroup}/providers/Microsoft.Web/sites/${appName}/hostruntime/admin/vfs/${workflowName}`;
Expand Down

0 comments on commit f02aba2

Please sign in to comment.