diff --git a/appinfo/info.xml b/appinfo/info.xml index 65dc9c900..02329068f 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -151,6 +151,9 @@ Vrij en open source onder de EUPL-1.2-licentie. OCA\LaunchPad\Repair\MintAnnouncementKeys + + OCA\LaunchPad\Repair\ConvertGroupLinksToTiles OCA\LaunchPad\Repair\InitializeActions diff --git a/lib/Repair/ConvertGroupLinksToTiles.php b/lib/Repair/ConvertGroupLinksToTiles.php new file mode 100644 index 000000000..1d2f2dfe5 --- /dev/null +++ b/lib/Repair/ConvertGroupLinksToTiles.php @@ -0,0 +1,96 @@ + + * @copyright 2026 Conduction B.V. + * @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 + * + * @version GIT: + * + * @link https://conduction.nl + * + * SPDX-FileCopyrightText: 2026 Conduction B.V. + * SPDX-License-Identifier: EUPL-1.2 + */ + +declare(strict_types=1); + +namespace OCA\LaunchPad\Repair; + +use OCA\LaunchPad\Db\WidgetPlacementMapper; +use OCA\LaunchPad\Service\GroupTileNode; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; +use Psr\Log\LoggerInterface; +use Throwable; + +/** + * Turn the address links of every stored group into tile nodes. Idempotent: + * a group with no address links left is not written again. + * + * @spec openspec/changes/tile-form-board-sync/specs/tiles/spec.md#requirement-a-tiles-group-and-the-groups-order-req-tile-041 + */ +class ConvertGroupLinksToTiles implements IRepairStep { + /** + * Constructor. + * + * @param WidgetPlacementMapper $placements The placement store. + * @param LoggerInterface $logger PSR-3 logger. + */ + public function __construct( + private readonly WidgetPlacementMapper $placements, + private readonly LoggerInterface $logger, + ) { + }//end __construct() + + /** + * Return the human-readable name of this repair step. + * + * @return string The step name. + * + * @spec openspec/changes/tile-form-board-sync/specs/tiles/spec.md#requirement-a-tiles-group-and-the-groups-order-req-tile-041 + */ + public function getName(): string { + return 'Turn the links inside tile groups into tiles'; + }//end getName() + + /** + * Run the step. A failure is a warning, never a failed upgrade. + * + * @param IOutput $output Migration output stream. + * + * @return void + * + * @spec openspec/changes/tile-form-board-sync/specs/tiles/spec.md#requirement-a-tiles-group-and-the-groups-order-req-tile-041 + */ + public function run(IOutput $output): void { + $groups = 0; + $tiles = 0; + try { + foreach ($this->placements->findByWidgetId(widgetId: 'container') as $placement) { + $result = GroupTileNode::convertGroup(content: $placement->getContentArray()); + if ($result['changed'] === 0) { + continue; + } + + $placement->setContentArray(content: $result['content']); + $this->placements->update(entity: $placement); + $groups++; + $tiles += $result['changed']; + } + } catch (Throwable $e) { + $this->logger->warning(message: '[ConvertGroupLinksToTiles] could not turn the group links into tiles: ' . $e->getMessage()); + $output->warning(message: 'The links inside tile groups were not turned into tiles: ' . $e->getMessage()); + return; + } + + $output->info(message: sprintf('%d link(s) in %d group(s) became tiles.', $tiles, $groups)); + }//end run() +}//end class diff --git a/lib/Service/BookmarkImportPlan.php b/lib/Service/BookmarkImportPlan.php index cf008ed4b..555f38cce 100644 --- a/lib/Service/BookmarkImportPlan.php +++ b/lib/Service/BookmarkImportPlan.php @@ -225,18 +225,21 @@ public function layout(int $bottom): array { }//end layout() /** - * The link children of a container, two to a row of its four-column grid. + * The tiles of a container, two to a row of its four-column grid. Each + * bookmark is a full tile node (REQ-TILE-041), so the tile form edits it. * * @param list $bookmarks The folder's bookmarks. * * @return list> + * + * @spec openspec/changes/tile-form-board-sync/specs/tiles/spec.md#requirement-a-tiles-group-and-the-groups-order-req-tile-041 */ private static function children(array $bookmarks): array { $children = []; foreach (array_values($bookmarks) as $index => $bookmark) { $children[] = [ - 'type' => 'link', - 'content' => ['label' => $bookmark['title'], 'url' => $bookmark['url'], 'actionType' => 'external'], + 'type' => 'tile', + 'content' => ['title' => $bookmark['title'], 'iconType' => 'svg', 'linkType' => 'url', 'linkValue' => $bookmark['url']], 'gridX' => (($index % 2) * self::TILE_SIZE), 'gridY' => (intdiv($index, 2) * self::TILE_SIZE), 'gridWidth' => self::TILE_SIZE, diff --git a/lib/Service/GroupTileNode.php b/lib/Service/GroupTileNode.php new file mode 100644 index 000000000..b3255a91c --- /dev/null +++ b/lib/Service/GroupTileNode.php @@ -0,0 +1,142 @@ + + * @copyright 2026 Conduction B.V. + * @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 + * + * @version GIT: + * + * @link https://conduction.nl + * + * SPDX-FileCopyrightText: 2026 Conduction B.V. + * SPDX-License-Identifier: EUPL-1.2 + */ + +declare(strict_types=1); + +namespace OCA\LaunchPad\Service; + +/** + * Turns the address links of a group into tile nodes, in a group's content + * and in the groups nested in it. A link that runs an action or lists + * several links stays a link; every other key of a child is kept. + * + * @spec openspec/changes/tile-form-board-sync/specs/tiles/spec.md#requirement-a-tiles-group-and-the-groups-order-req-tile-041 + */ +final class GroupTileNode { + + /** + * The link actions that only open an address. + */ + private const ADDRESS_ACTIONS = ['', 'external', 'internal']; + + /** + * The keys of a link child that the tile node replaces. A link's icon is an + * icon name, which a tile does not draw, so it goes too. + */ + private const LINK_ONLY_KEYS = ['label', 'url', 'actionType', 'icon', 'iconType']; + + /** + * The tile node for an address link child, or null for any other child. + * + * @param array $child The container child. + * + * @return array|null + * + * @spec openspec/changes/tile-form-board-sync/specs/tiles/spec.md#requirement-a-tiles-group-and-the-groups-order-req-tile-041 + */ + public static function fromLink(array $child): ?array { + $content = $child['content'] ?? null; + if (($child['type'] ?? null) !== 'link' || is_array($content) === false || self::isAddressLink(content: $content) === false) { + return null; + } + + $tile = array_diff_key($content, array_flip(self::LINK_ONLY_KEYS)); + $tile['title'] = trim((string) ($content['label'] ?? '')); + $tile['iconType'] = 'svg'; + $tile['linkType'] = 'url'; + $tile['linkValue'] = trim((string) $content['url']); + + $child['type'] = 'tile'; + $child['content'] = $tile; + return $child; + }//end fromLink() + + /** + * A group's content with every address link, also in nested groups, as a + * tile node. Content without children comes back unchanged. + * + * @param array $content The group's content. + * + * @return array{content: array, changed: int} The content and how many children changed. + * + * @spec openspec/changes/tile-form-board-sync/specs/tiles/spec.md#requirement-a-tiles-group-and-the-groups-order-req-tile-041 + */ + public static function convertGroup(array $content): array { + $children = $content['placements'] ?? null; + if (is_array($children) === false) { + return ['content' => $content, 'changed' => 0]; + } + + $changed = 0; + foreach ($children as $index => $child) { + if (is_array($child) === false) { + continue; + } + + [$children[$index], $count] = self::convertChild(child: $child); + $changed += $count; + } + + $content['placements'] = $children; + return ['content' => $content, 'changed' => $changed]; + }//end convertGroup() + + /** + * One child as a tile node, or with its own group converted. + * + * @param array $child The container child. + * + * @return array{0: array, 1: int} The child and how many children changed. + */ + private static function convertChild(array $child): array { + $tile = self::fromLink(child: $child); + if ($tile !== null) { + return [$tile, 1]; + } + + if (is_array($child['content'] ?? null) === false) { + return [$child, 0]; + } + + $nested = self::convertGroup(content: $child['content']); + $child['content'] = $nested['content']; + return [$child, $nested['changed']]; + }//end convertChild() + + /** + * Whether a link's content only opens one address. + * + * @param array $content The link child's content. + * + * @return bool + */ + private static function isAddressLink(array $content): bool { + $url = $content['url'] ?? null; + $action = (string) ($content['actionType'] ?? ''); + return is_string($url) === true + && trim($url) !== '' + && is_array($content['links'] ?? null) === false + && in_array($action, self::ADDRESS_ACTIONS, true) === true; + }//end isAddressLink() +}//end class diff --git a/openspec/changes/tile-form-board-sync/tasks.md b/openspec/changes/tile-form-board-sync/tasks.md index 423430bff..e0b09fe2e 100644 --- a/openspec/changes/tile-form-board-sync/tasks.md +++ b/openspec/changes/tile-form-board-sync/tasks.md @@ -2,7 +2,8 @@ - [x] Tile form layout: name and group, type and open-in as choice cards, addresses side by side, icon with upload, swatches (from icon-only-app-tiles), sort order, availability switch (the colour keeps its two pickers until icon-only-app-tiles lands its swatches) - [x] Group field and the group's sort order (last used first, alphabetical, random, as placed): a tile inside a group opens the tile form from its own tile menu, with the group's name and order; the save writes the tile into the group's `content.placements` and the order onto the container's `content.sortBy` in one update (src/utils/groupTiles.js, ContainerChild, ContainerWidget, Views, TileEditor `inGroup`). Decision: a tile in a group has no placement of its own on the server and renders through the shared tile renderer, so its form offers only a web address (no launch types, internal address, Open in or availability check); settings of that kind it carries are kept, not dropped; a bookmark link child becomes a tile node when saved -- [ ] Moving a tile into a group keeps its launch, health and network settings (the child is a full tile node, 25 Nov decision), and a repair step turns stored link children `{type: link, content: {label, url, actionType}}` into tile nodes +- [x] Stored link children become tile nodes: a repair step (lib/Repair/ConvertGroupLinksToTiles.php, via lib/Service/GroupTileNode.php) turns every address link `{type: link, content: {label, url, actionType}}` inside a group, also in nested groups, into `{type: tile, content: {title, iconType, linkType: url, linkValue}}`, keeping its layout and other keys; the bookmark import writes tile nodes directly. An action link or a link list stays a link +- [ ] Moving a tile from the dashboard into a group keeps its launch, health and network settings (the child is a full tile node, 25 Nov decision). There is no move-into-group yet: the inner grid accepts a drop (GridStack `acceptWidgets`) but nothing stores it, so this is a new drag interaction that needs a live drag check - [x] Last availability result under the switch (reachable or not, with the time) - [x] Delete tile at the bottom left, Cancel and Save at the right - [x] Translations in every shipped locale diff --git a/src/utils/groupTiles.js b/src/utils/groupTiles.js index 2c2e53b24..838cdeb43 100644 --- a/src/utils/groupTiles.js +++ b/src/utils/groupTiles.js @@ -31,8 +31,11 @@ const FORM_KEYS = Object.freeze([ /** The link actions that only open an address, so a tile can take them over. */ const ADDRESS_ACTIONS = Object.freeze(['', 'external', 'internal']) -/** The keys of a link child that the tile node replaces. */ -const LINK_ONLY_KEYS = Object.freeze(['label', 'url', 'actionType']) +/** + * The keys of a link child that the tile node replaces. A link's icon is an + * icon name, which a tile does not draw, so it goes too. + */ +const LINK_ONLY_KEYS = Object.freeze(['label', 'url', 'actionType', 'icon', 'iconType']) /** * Whether a container child is a tile the tile form can edit: a `tile` child @@ -116,8 +119,7 @@ function setFormFields(source) { function linkToTile(content) { return setFormFields({ title: content.label, - icon: content.icon, - iconType: isSet(content.iconType) ? content.iconType : 'svg', + iconType: 'svg', linkType: 'url', linkValue: content.url, }) diff --git a/tests/Unit/Repair/ConvertGroupLinksToTilesTest.php b/tests/Unit/Repair/ConvertGroupLinksToTilesTest.php new file mode 100644 index 000000000..69769fc9b --- /dev/null +++ b/tests/Unit/Repair/ConvertGroupLinksToTilesTest.php @@ -0,0 +1,92 @@ + + * @copyright 2026 Conduction b.v. + * @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 + * + * SPDX-FileCopyrightText: 2026 Conduction B.V. + * SPDX-License-Identifier: EUPL-1.2 + * + * @spec openspec/changes/tile-form-board-sync/specs/tiles/spec.md#requirement-a-tiles-group-and-the-groups-order-req-tile-041 + */ + +declare(strict_types=1); + +namespace Unit\Repair; + +use OCA\LaunchPad\Db\WidgetPlacement; +use OCA\LaunchPad\Db\WidgetPlacementMapper; +use OCA\LaunchPad\Repair\ConvertGroupLinksToTiles; +use OCP\Migration\IOutput; +use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; +use RuntimeException; + +class ConvertGroupLinksToTilesTest extends TestCase { + + /** + * A group placement with the given content. + * + * @param array $content The content. + * + * @return WidgetPlacement + */ + private static function group(array $content): WidgetPlacement { + $placement = new WidgetPlacement(); + $placement->setWidgetId('container'); + $placement->setContentArray(content: $content); + return $placement; + }//end group() + + /** + * Only a group with address links is written, with its links as tiles. + * + * @return void + */ + public function testWritesOnlyTheGroupsWithLinks(): void { + $withLinks = self::group(content: ['title' => 'Werk', 'placements' => [ + ['type' => 'link', 'content' => ['label' => 'Intranet', 'url' => 'https://intranet.example.org', 'actionType' => 'external']], + ['type' => 'link', 'content' => ['label' => 'Wiki', 'url' => '/apps/collectives']], + ]]); + $done = self::group(content: ['title' => 'Apps', 'placements' => [ + ['type' => 'tile', 'content' => ['title' => 'Mail', 'linkType' => 'url', 'linkValue' => '/apps/mail']], + ]]); + $mapper = $this->createMock(originalClassName: WidgetPlacementMapper::class); + $mapper->method('findByWidgetId')->with('container')->willReturn([$withLinks, $done]); + $mapper->expects($this->once())->method('update')->with($withLinks)->willReturnArgument(0); + $output = $this->createMock(originalClassName: IOutput::class); + $output->expects($this->once())->method('info')->with('2 link(s) in 1 group(s) became tiles.'); + + $step = new ConvertGroupLinksToTiles(placements: $mapper, logger: $this->createMock(originalClassName: LoggerInterface::class)); + $this->assertSame(expected: 'Turn the links inside tile groups into tiles', actual: $step->getName()); + $step->run(output: $output); + + $children = $withLinks->getContentArray()['placements']; + $this->assertSame(expected: ['tile', 'tile'], actual: array_column($children, 'type')); + $this->assertSame(expected: 'Werk', actual: $withLinks->getContentArray()['title']); + $this->assertSame(expected: '/apps/collectives', actual: $children[1]['content']['linkValue']); + }//end testWritesOnlyTheGroupsWithLinks() + + /** + * A failure is a warning. + * + * @return void + */ + public function testAFailureIsAWarning(): void { + $mapper = $this->createMock(originalClassName: WidgetPlacementMapper::class); + $mapper->method('findByWidgetId')->willThrowException(new RuntimeException('database gone')); + $output = $this->createMock(originalClassName: IOutput::class); + $output->expects($this->once())->method('warning')->with('The links inside tile groups were not turned into tiles: database gone'); + $output->expects($this->never())->method('info'); + + (new ConvertGroupLinksToTiles(placements: $mapper, logger: $this->createMock(originalClassName: LoggerInterface::class)))->run(output: $output); + }//end testAFailureIsAWarning() +}//end class diff --git a/tests/Unit/Service/BookmarkImportPlanTest.php b/tests/Unit/Service/BookmarkImportPlanTest.php index 2e2064ba7..afce7a340 100644 --- a/tests/Unit/Service/BookmarkImportPlanTest.php +++ b/tests/Unit/Service/BookmarkImportPlanTest.php @@ -52,7 +52,7 @@ public function testAScriptBookmarkIsSkippedWithItsReason(): void { self::assertSame('Werk', $layout[0]['content']['title']); self::assertCount(5, $layout[0]['content']['placements']); self::assertSame( - ['type' => 'link', 'content' => ['label' => 'Site 1', 'url' => 'https://example.org/1', 'actionType' => 'external'], 'gridX' => 0, 'gridY' => 0, 'gridWidth' => 2, 'gridHeight' => 2], + ['type' => 'tile', 'content' => ['title' => 'Site 1', 'iconType' => 'svg', 'linkType' => 'url', 'linkValue' => 'https://example.org/1'], 'gridX' => 0, 'gridY' => 0, 'gridWidth' => 2, 'gridHeight' => 2], $layout[0]['content']['placements'][0] ); self::assertSame([2, 0], [$layout[0]['content']['placements'][1]['gridX'], $layout[0]['content']['placements'][1]['gridY']]); @@ -118,7 +118,7 @@ public function testTitlesAreBoundedAndNeverEmpty(): void { $container = $plan->layout(bottom: 0)[0]['content']; self::assertSame('Bookmarks', $container['title']); - self::assertSame(255, mb_strlen($container['placements'][0]['content']['label'])); + self::assertSame(255, mb_strlen($container['placements'][0]['content']['title'])); }//end testTitlesAreBoundedAndNeverEmpty() /** diff --git a/tests/Unit/Service/GroupTileNodeTest.php b/tests/Unit/Service/GroupTileNodeTest.php new file mode 100644 index 000000000..ebb098865 --- /dev/null +++ b/tests/Unit/Service/GroupTileNodeTest.php @@ -0,0 +1,107 @@ + + * @copyright 2026 Conduction b.v. + * @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 + * + * SPDX-FileCopyrightText: 2026 Conduction B.V. + * SPDX-License-Identifier: EUPL-1.2 + * + * @spec openspec/changes/tile-form-board-sync/specs/tiles/spec.md#requirement-a-tiles-group-and-the-groups-order-req-tile-041 + */ + +declare(strict_types=1); + +namespace Unit\Service; + +use OCA\LaunchPad\Service\GroupTileNode; +use PHPUnit\Framework\TestCase; + +class GroupTileNodeTest extends TestCase { + + /** + * A bookmark link becomes a tile node with its layout and other keys. + * + * @return void + */ + public function testAnAddressLinkBecomesATileNode(): void { + $link = [ + 'type' => 'link', + 'uuid' => 'c-1', + 'gridX' => 2, + 'gridY' => 0, + 'content' => ['label' => ' Intranet ', 'url' => 'https://intranet.example.org', 'actionType' => 'external', 'icon' => 'web', 'backgroundColor' => '#123456'], + ]; + $this->assertSame( + expected: [ + 'type' => 'tile', + 'uuid' => 'c-1', + 'gridX' => 2, + 'gridY' => 0, + 'content' => ['backgroundColor' => '#123456', 'title' => 'Intranet', 'iconType' => 'svg', 'linkType' => 'url', 'linkValue' => 'https://intranet.example.org'], + ], + actual: GroupTileNode::fromLink(child: $link) + ); + }//end testAnAddressLinkBecomesATileNode() + + /** + * Action links, link lists, empty addresses and other widgets stay. + * + * @return void + */ + public function testOtherChildrenStay(): void { + $this->assertNull(GroupTileNode::fromLink(child: ['type' => 'link', 'content' => ['url' => 'x', 'actionType' => 'createFile']])); + $this->assertNull(GroupTileNode::fromLink(child: ['type' => 'link', 'content' => ['url' => 'x', 'links' => [['url' => 'y']]]])); + $this->assertNull(GroupTileNode::fromLink(child: ['type' => 'link', 'content' => ['url' => ' ']])); + $this->assertNull(GroupTileNode::fromLink(child: ['type' => 'link', 'content' => 'broken'])); + $this->assertNull(GroupTileNode::fromLink(child: ['type' => 'tile', 'content' => ['linkValue' => 'x']])); + $this->assertNull(GroupTileNode::fromLink(child: ['type' => 'label', 'content' => ['url' => 'x']])); + }//end testOtherChildrenStay() + + /** + * A group is converted with the groups nested in it, and says how many. + * + * @return void + */ + public function testAGroupIsConvertedWithItsNestedGroups(): void { + $content = [ + 'title' => 'Werk', + 'sortBy' => 'alphabetical', + 'placements' => [ + ['type' => 'link', 'content' => ['label' => 'A', 'url' => 'https://a.example.org']], + ['type' => 'label', 'content' => ['text' => 'Hi']], + 'broken', + ['type' => 'container', 'content' => ['placements' => [ + ['type' => 'link', 'content' => ['label' => 'B', 'url' => '/apps/files', 'actionType' => 'internal']], + ]]], + ], + ]; + $result = GroupTileNode::convertGroup(content: $content); + $this->assertSame(expected: 2, actual: $result['changed']); + $this->assertSame(expected: 'alphabetical', actual: $result['content']['sortBy']); + $this->assertSame(expected: 'tile', actual: $result['content']['placements'][0]['type']); + $this->assertSame(expected: ['type' => 'label', 'content' => ['text' => 'Hi']], actual: $result['content']['placements'][1]); + $this->assertSame(expected: 'broken', actual: $result['content']['placements'][2]); + $this->assertSame(expected: '/apps/files', actual: $result['content']['placements'][3]['content']['placements'][0]['content']['linkValue']); + }//end testAGroupIsConvertedWithItsNestedGroups() + + /** + * Content without children, and a converted group, come back unchanged. + * + * @return void + */ + public function testNothingToConvertIsUnchanged(): void { + $this->assertSame(expected: ['content' => ['text' => 'Hi'], 'changed' => 0], actual: GroupTileNode::convertGroup(content: ['text' => 'Hi'])); + $once = GroupTileNode::convertGroup(content: ['placements' => [['type' => 'link', 'content' => ['label' => 'A', 'url' => 'https://a.example.org']]]]); + $this->assertSame(expected: 0, actual: GroupTileNode::convertGroup(content: $once['content'])['changed']); + }//end testNothingToConvertIsUnchanged() +}//end class