Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-B-Wu committed Jun 11, 2024
2 parents 4e9cc47 + 80835a5 commit 4517b87
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
5 changes: 2 additions & 3 deletions libs/designer-ui/src/lib/token/token.less
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
.msla-input-token {
background-repeat: no-repeat;
background-size: @token-height @token-height;
padding-left: 34px;
padding-left: 24px;
margin: 0 2px;
display: inline-flex;
padding-right: 4px;
position: relative;
gap: 4px;
user-select: none;
max-width: 120px;
max-width: 144px;

.msla-token-title {
overflow: hidden;
Expand Down
4 changes: 2 additions & 2 deletions libs/designer/src/lib/core/utils/parameters/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ import {
getRecordEntry,
replaceWhiteSpaceWithUnderscore,
isRecordNotEmpty,
isStringNonPrimitive,
isBodySegment,
canStringBeConverted,
} from '@microsoft/logic-apps-shared';
import type {
AuthProps,
Expand Down Expand Up @@ -1606,7 +1606,7 @@ function reduceRedundantSegments(segments: Segment[]): void {
}

export function transformInputParameter(inputParameter: InputParameter, parameterValue: any, invisible = false): InputParameter {
if (inputParameter.type === constants.SWAGGER.TYPE.ANY && typeof parameterValue === 'string' && isStringNonPrimitive(parameterValue)) {
if (inputParameter.type === constants.SWAGGER.TYPE.ANY && typeof parameterValue === 'string' && canStringBeConverted(parameterValue)) {
parameterValue = `"${parameterValue}"`;
}
return { ...inputParameter, hideInUI: invisible, value: parameterValue };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { escapeString, idDisplayCase, labelCase } from '../stringFunctions';
import { escapeString, idDisplayCase, labelCase, canStringBeConverted } from '../stringFunctions';
import { describe, it, expect } from 'vitest';
describe('label_case', () => {
it('should replace _ with spaces', () => {
Expand Down Expand Up @@ -48,3 +48,44 @@ describe('escapeString', () => {
expect(escapeString('')).toEqual('');
});
});
describe('canStringBeConverted', () => {
it('should return false for non-string inputs', () => {
expect(canStringBeConverted(123 as any)).toBe(false);
expect(canStringBeConverted({} as any)).toBe(false);
expect(canStringBeConverted([] as any)).toBe(false);
expect(canStringBeConverted(null as any)).toBe(false);
expect(canStringBeConverted(undefined as any)).toBe(false);
});

it('should return false for empty or whitespace-only strings', () => {
expect(canStringBeConverted('')).toBe(false);
expect(canStringBeConverted(' ')).toBe(false);
expect(canStringBeConverted('\t')).toBe(false);
expect(canStringBeConverted('\n')).toBe(false);
});

it('should return true for strings that are "true", "false", or "null"', () => {
expect(canStringBeConverted('true')).toBe(true);
expect(canStringBeConverted('false')).toBe(true);
expect(canStringBeConverted('null')).toBe(true);
});

it('should return true for strings that can be converted to a number', () => {
expect(canStringBeConverted('123')).toBe(true);
expect(canStringBeConverted('-456')).toBe(true);
expect(canStringBeConverted('0')).toBe(true);
expect(canStringBeConverted('7.89')).toBe(true);
});

it('should return true for strings that can be parsed as a JSON array', () => {
expect(canStringBeConverted('["a", "b", "c"]')).toBe(true);
expect(canStringBeConverted('[1, 2, 3]')).toBe(true);
expect(canStringBeConverted('[]')).toBe(true);
});

it('should return false for strings that cannot be parsed as a JSON array', () => {
expect(canStringBeConverted('not an array')).toBe(false);
expect(canStringBeConverted('{ "key": "value" }')).toBe(false);
expect(canStringBeConverted('{"a", "b", "c"}')).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const escapeString = (s: string): string => {
return s.replace(/\\/g, '\\\\').replace(/\n/g, '\\n');
};

export const isStringNonPrimitive = (s: string): boolean => {
export const canStringBeConverted = (s: string): boolean => {
if (typeof s !== 'string' || s.trim() === '') {
return false;
}
Expand All @@ -44,7 +44,12 @@ export const isStringNonPrimitive = (s: string): boolean => {
if (!Number.isNaN(Number(s))) {
return true;
}
return false;
try {
const parsed = JSON.parse(s);
return Array.isArray(parsed);
} catch (e) {
return false;
}
};

export const createIdCopy = (id: string) => `${id}-copy`;

0 comments on commit 4517b87

Please sign in to comment.