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
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function edit(ScreenBuilderManager $manager, Screen $screen, $processId =
'computed',
'custom_css',
'watchers',
'preview_presets',
]));
}

Expand Down
46 changes: 43 additions & 3 deletions ProcessMaker/Mcp/Screens/ScreenCatalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(private readonly ScreenConfigValidator $validator)
/**
* @var list<string>
*/
private const JSON_FIELDS = ['config', 'computed', 'watchers'];
private const JSON_FIELDS = ['config', 'computed', 'watchers', 'preview_presets'];

private const JSON_FIELD_MESSAGE = ' must be a JSON object or array.';

Expand Down Expand Up @@ -151,7 +151,7 @@ public function update(User $user, array $input): array
$attributes = $this->writable($validated);
if ($attributes === []) {
throw ValidationException::withMessages([
'screen' => 'Provide at least one field to update: title, description, type, screen_category_id, config, computed, watchers, or custom_css.',
'screen' => 'Provide at least one field to update: title, description, type, screen_category_id, config, computed, watchers, preview_presets, or custom_css.',
]);
}

Expand Down Expand Up @@ -321,9 +321,48 @@ private function normalize(array $input): array
$input['config'] = $this->normalizeConfig($input['config']);
}

if (isset($input['preview_presets']) && is_array($input['preview_presets'])) {
$input['preview_presets'] = $this->normalizePreviewPresets($input['preview_presets']);
}

return $input;
}

/**
* Designer stores each preset.data as a JSON string so empty objects survive PHP json_decode.
*
* @param array<int, mixed> $presets
* @return list<array{title: string, data: string}>
*/
private function normalizePreviewPresets(array $presets): array
{
$normalized = [];
foreach ($presets as $preset) {
if (!is_array($preset)) {
continue;
}
$title = isset($preset['title']) && is_string($preset['title']) ? $preset['title'] : '';
$data = $preset['data'] ?? '{}';
if (is_array($data)) {
$data = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?: '{}';
} elseif (!is_string($data)) {
$data = '{}';
} else {
try {
json_decode($data, true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException) {
$data = '{}';
}
}
$normalized[] = [
'title' => $title,
'data' => $data,
];
}

return $normalized;
}

/**
* Ensure pages/items are Screen Builder–safe (missing inspector crashes the designer).
*
Expand Down Expand Up @@ -404,7 +443,7 @@ private function decodeJson(string $field, string $value): array
*/
private function writable(array $input): array
{
$fields = ['title', 'description', 'type', 'screen_category_id', 'config', 'computed', 'custom_css', 'watchers'];
$fields = ['title', 'description', 'type', 'screen_category_id', 'config', 'computed', 'custom_css', 'watchers', 'preview_presets'];

return array_intersect_key($input, array_flip($fields));
}
Expand Down Expand Up @@ -434,6 +473,7 @@ private function detail(Screen $screen): array
'config' => $screen->config,
'computed' => $screen->computed,
'watchers' => $screen->watchers,
'preview_presets' => $screen->preview_presets,
'custom_css' => $screen->custom_css,
'created_at' => $this->timestamp($screen->created_at),
];
Expand Down
3 changes: 2 additions & 1 deletion ProcessMaker/Mcp/Servers/ScreenServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
config is the screen builder page array; every control in page.items must include `"inspector": []` (or a real inspector list) or the designer crashes.
create/update reject configs with empty FormSelectList options (missing optionsList).
New FORM/DISPLAY screens are built as a Vue Component Editor mount (VueComponentRenderTemplate with a thin contentVue); do not add native FileUpload / FormSelectList / SignaturePad siblings.
For the full rules (control shape, component registration, domain fields, refactor parity), follow the `pm4-screen` skill from the ProcessMaker Skills repository (`npx skills add processmaker/skills`).
On every create and every Vue refactor, set `preview_presets`: named Preview payloads covering empty/start, happy path, and each major UI branch. Each item is `{ "title": "...", "data": "<json-string>" }` — `data` must be a JSON string so `{}` survives PHP decode.
For the full rules (control shape, component registration, domain fields, refactor parity, preview presets), follow the `pm4-screen` skill from the ProcessMaker Skills repository (`npx skills add processmaker/skills`), especially `preview-presets.md`.
update-screen changes only the fields you send.
delete-screen cannot remove a default screen.
MARKDOWN)]
Expand Down
3 changes: 2 additions & 1 deletion ProcessMaker/Mcp/Tools/Screens/CreateScreenTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#[Name('create-screen')]
#[Title('Create Screen')]
#[Description('Creates a ProcessMaker screen. Requires title, description, type, and screen_category_id. Rejects invalid config (e.g. FormSelectList without optionsList). Prefer validate-screen first.')]
#[Description('Creates a ProcessMaker screen. Requires title, description, type, and screen_category_id. Rejects invalid config (e.g. FormSelectList without optionsList). Prefer validate-screen first. Always include preview_presets covering empty/start, happy path, and each major UI branch; each preset.data must be a JSON string.')]
class CreateScreenTool extends ScreenTool
{
public function handle(Request $request, ScreenCatalog $screens): Response|ResponseFactory
Expand All @@ -39,6 +39,7 @@ public function schema(JsonSchema $schema): array
'config' => ScreenFields::config($schema),
'computed' => $schema->array()->description('Computed properties for the screen.'),
'watchers' => $schema->array()->description('Screen watchers.'),
'preview_presets' => ScreenFields::previewPresets($schema),
'custom_css' => $schema->string()->description('Custom CSS applied when the screen renders.'),
];
}
Expand Down
9 changes: 9 additions & 0 deletions ProcessMaker/Mcp/Tools/Screens/ScreenFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ final class ScreenFields

public const CONFIG = 'Screen builder config. An array of page objects. Each control in page.items must include inspector (use [] when unknown); pages should include items ([]) even when empty.';

public const PREVIEW_PRESETS = 'Named Screen Builder Preview payloads. Array of { title, data }. data MUST be a JSON string (not a nested object) so empty {} survive PHP json_decode. Required on create and Vue refactor: cover empty/start, happy path, and each major UI branch.';

public static function id(JsonSchema $schema): IntegerType
{
return $schema->integer()
Expand Down Expand Up @@ -62,4 +64,11 @@ public static function config(JsonSchema $schema): ArrayType
->items($schema->object())
->description(self::CONFIG);
}

public static function previewPresets(JsonSchema $schema): ArrayType
{
return $schema->array()
->items($schema->object())
->description(self::PREVIEW_PRESETS);
}
}
3 changes: 2 additions & 1 deletion ProcessMaker/Mcp/Tools/Screens/UpdateScreenTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#[Name('update-screen')]
#[Title('Update Screen')]
#[Description('Updates a ProcessMaker screen. Send only the fields that should change. Rejects invalid config (e.g. FormSelectList without optionsList). Prefer validate-screen first. Does not reset config to the last published version.')]
#[Description('Updates a ProcessMaker screen. Send only the fields that should change. Rejects invalid config (e.g. FormSelectList without optionsList). Prefer validate-screen first. Does not reset config to the last published version. On create/refactor follow-ups, set preview_presets (each data as JSON string) covering all major UI cases.')]
#[IsIdempotent]
class UpdateScreenTool extends ScreenTool
{
Expand All @@ -42,6 +42,7 @@ public function schema(JsonSchema $schema): array
'config' => ScreenFields::config($schema),
'computed' => $schema->array()->description('Computed properties for the screen.'),
'watchers' => $schema->array()->description('Screen watchers.'),
'preview_presets' => ScreenFields::previewPresets($schema),
'custom_css' => $schema->string()->description('Custom CSS applied when the screen renders.'),
];
}
Expand Down
3 changes: 3 additions & 0 deletions ProcessMaker/Models/Screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* @property array computed
* @property array custom_css
* @property array watchers
* @property array preview_presets
* @property string label
* @property Carbon type
* @property Carbon $updated_at
Expand All @@ -44,6 +45,7 @@
* @OA\Property(property="config", type="array", @OA\Items(type="object")),
* @OA\Property(property="computed", type="array", @OA\Items(type="object")),
* @OA\Property(property="watchers", type="array", @OA\Items(type="object")),
* @OA\Property(property="preview_presets", type="array", @OA\Items(type="object")),
* @OA\Property(property="custom_css", type="string"),
* @OA\Property(property="screen_category_id", type="string"),
* ),
Expand Down Expand Up @@ -89,6 +91,7 @@ class Screen extends ProcessMakerModel implements ScreenInterface, PrometheusMet
'config' => 'array',
'computed' => 'array',
'watchers' => 'array',
'preview_presets' => 'array',
'translations' => 'array',
];

Expand Down
1 change: 1 addition & 0 deletions ProcessMaker/Models/ScreenVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ScreenVersion extends ProcessMakerModel implements ScreenInterface, Promet
'config' => 'array',
'computed' => 'array',
'watchers' => 'array',
'preview_presets' => 'array',
'translations' => 'array',
];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('screens', function (Blueprint $table) {
$table->mediumText('preview_presets')->nullable()->after('watchers');
});

Schema::table('screen_versions', function (Blueprint $table) {
$table->mediumText('preview_presets')->nullable()->after('watchers');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('screen_versions', function (Blueprint $table) {
$table->dropColumn('preview_presets');
});

Schema::table('screens', function (Blueprint $table) {
$table->dropColumn('preview_presets');
});
}
};
Loading
Loading