Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/playwright/impact-map.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@
"openmetadata-ui/src/main/resources/ui/vite/**"
],
"mappings": [
{
"_comment": "Task Form designer: field builder, schema round-trip, and the custom forms a task workflow renders from it.",
"sources": [
"openmetadata-ui/src/main/resources/ui/src/pages/TaskFormSettingsPage/**",
"openmetadata-ui/src/main/resources/ui/src/utils/TaskFormDesignerUtils*"
],
"projects": ["chromium"],
"specs": [
"playwright/e2e/Pages/TaskFormSettings.spec.ts",
"playwright/e2e/Features/Tasks/TaskCustomFormWorkflow.spec.ts"
]
},
{
"_comment": "MCP administrator controls and client revocation.",
"sources": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,10 @@
createEmptyDesignerField,
getDesignerPreviewPayload,
TaskFormDesignerField,
withFieldType,
} from '../../../utils/TaskFormDesignerUtils';
import TaskPayloadSchemaFields from '../../TasksPage/shared/TaskPayloadSchemaFields';

Check warning on line 50 in openmetadata-ui/src/main/resources/ui/src/pages/TaskFormSettingsPage/components/TaskFormBuilderSection.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

Page features must not import another page feature. Move shared code to components, hooks, interfaces, or pure utilities

/** Switching field type keeps options only for selects and defaults JSON to an object. */
const withFieldType = (
field: TaskFormDesignerField,
type: TaskFormDesignerField['type']
): TaskFormDesignerField => ({
...field,
type,
schemaType: type === 'json' ? field.schemaType ?? 'object' : field.schemaType,
options:
type === 'singleSelect' || type === 'multiSelect' ? field.options : [],
});

const withoutOption = (
field: TaskFormDesignerField,
key: Key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,72 @@
* limitations under the License.
*/

import { JsonSchemaObject } from '../rest/taskFormSchemasAPI';
import {
buildDesignerSchema,
buildStageMappings,
buildTransitionForms,
createEmptyDesignerField,
getDesignerPreviewPayload,
parseSchemaToDesignerFields,
parseStageMappings,
parseTransitionForms,
withFieldType,
} from './TaskFormDesignerUtils';

describe('TaskFormDesignerUtils', () => {
const reloadField = (property: JsonSchemaObject) =>
parseSchemaToDesignerFields({
type: 'object',
properties: { payload: property },
})[0];

it.each([
['a new field', createEmptyDesignerField(), 'object'],
['a reloaded text field', reloadField({ type: 'string' }), 'object'],
[
'a reloaded multi-select',
reloadField({ type: 'array', items: { type: 'string', enum: ['a'] } }),
'array',
],
])(
'saves %s switched to JSON and reloads it as JSON',
(_, field, expectedType) => {
const jsonField = withFieldType({ ...field, name: 'payload' }, 'json');
const { formSchema, uiSchema } = buildDesignerSchema([jsonField]);
const saved = (formSchema.properties as Record<string, unknown>).payload;

expect(jsonField.schemaType).toBe(expectedType);
expect(saved).toEqual(
expectedType === 'array'
? expect.objectContaining({
type: 'array',
items: { type: 'string' },
})
: expect.objectContaining({
type: 'object',
additionalProperties: true,
})
);
expect(parseSchemaToDesignerFields(formSchema, uiSchema)[0].type).toBe(
'json'
);
}
);

it('saves a JSON field as an object even when it arrives with a string schema type', () => {
const { formSchema } = buildDesignerSchema([
{ ...createEmptyDesignerField(), name: 'payload', type: 'json' },
]);

expect(formSchema.properties).toEqual({
payload: expect.objectContaining({
type: 'object',
additionalProperties: true,
}),
});
});

it('builds schemas from designer fields while preserving ui metadata', () => {
const { formSchema, uiSchema } = buildDesignerSchema(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* limitations under the License.
*/

import { cloneDeep } from 'lodash';
import { cloneDeep, omit } from 'lodash';
import { JsonSchemaObject, TaskFormSchema } from '../rest/taskFormSchemasAPI';

export type TaskFormDesignerFieldType =
Expand Down Expand Up @@ -147,6 +147,10 @@ type FieldPropertyBuilder = (
field: TaskFormDesignerField
) => void;

/** A JSON field is only ever an object or an array; anything else (e.g. a text field's 'string') defaults to object. */
export const toJsonSchemaType = (schemaType: unknown): 'object' | 'array' =>
schemaType === 'array' ? 'array' : 'object';

const applyStringProperty: FieldPropertyBuilder = (property) => {
property.type = 'string';
delete property.enum;
Expand Down Expand Up @@ -182,13 +186,15 @@ const FIELD_PROPERTY_BUILDERS: Partial<
delete property.enum;
},
json: (property, field) => {
property.type = field.schemaType ?? property.type ?? 'object';
property.type = toJsonSchemaType(field.schemaType ?? property.type);
delete property.enum;

if (property.type === 'array') {
property.items = (property.items as JsonSchemaObject | undefined) ?? {
type: 'string',
};
// A leftover items.enum would make the field reload as a multi-select.
property.items = omit(
(property.items as JsonSchemaObject | undefined) ?? { type: 'string' },
'enum'
);
} else if (
property.type === 'object' &&
!Object.prototype.hasOwnProperty.call(property, 'properties') &&
Expand Down Expand Up @@ -287,6 +293,19 @@ const buildUiSchema = (
export const stringifyDesignerJson = (value: unknown) =>
JSON.stringify(value ?? {}, null, 2);

/** Switching field type keeps options only for selects and defaults JSON to an object. */
export const withFieldType = (
field: TaskFormDesignerField,
type: TaskFormDesignerField['type']
): TaskFormDesignerField => ({
...field,
type,
schemaType:
type === 'json' ? toJsonSchemaType(field.schemaType) : field.schemaType,
options:
type === 'singleSelect' || type === 'multiSelect' ? field.options : [],
});

export const createEmptyDesignerField = (): TaskFormDesignerField => ({
key: createDesignerKey('field'),
name: '',
Expand Down
Loading