Skip to content

Commit

Permalink
FIX Defaul link type title and icon for disabled link types
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabina Talipova committed Jan 19, 2024
1 parent 4bc4883 commit 185867c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion client/src/components/LinkPicker/LinkPickerMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ const LinkPickerMenu = ({ types, onSelect }) => {
{i18n._t('LinkField.ADD_LINK', 'Add Link')}
</DropdownToggle>
<DropdownMenu>
{types.map(({key, title, icon}) =>
{types.map(({key, title, icon, allowed}) => {
return allowed &&
<DropdownItem key={key} onClick={() => onSelect(key)}>
<span className={`link-picker__menu-icon ${icon}`}></span>
{title}
</DropdownItem>
}
)}
</DropdownMenu>
</Dropdown>
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/LinkPicker/tests/LinkPicker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import LinkPicker from '../LinkPicker';

function makeProps(obj = {}) {
return {
types: { phone: { key: 'phone', title: 'Phone', icon: 'font-icon-phone' } },
types: { phone: { key: 'phone', title: 'Phone', icon: 'font-icon-phone', allowed: true } },
canCreate: true,
onModalSuccess: () => {},
onModalClosed: () => {},
Expand Down
4 changes: 3 additions & 1 deletion src/Form/Traits/AllowedLinkClassesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public function getTypesProps(): string
{
$typesList = [];
$typeDefinitions = $this->genarateAllowedTypes();
foreach ($typeDefinitions as $key => $class) {
$allTypes = LinkTypeService::create()->generateAllLinkTypes();
foreach ($allTypes as $key => $class) {
$type = Injector::inst()->get($class);
if (!$type->canCreate()) {
continue;
Expand All @@ -97,6 +98,7 @@ public function getTypesProps(): string
'handlerName' => $type->LinkTypeHandlerName(),
'priority' => $class::config()->get('menu_priority'),
'icon' => $class::config()->get('icon'),
'allowed' => array_key_exists($key, $typeDefinitions),
];
}
uasort($typesList, function ($a, $b) {
Expand Down
20 changes: 18 additions & 2 deletions tests/php/Traits/AllowedLinkClassesTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ public function sortedTypesDataProvider() : array
'expected' => [
'sitetree',
'testphone',
'file',
'external',
'email',
'phone',
],
'reorder' => true,
],
Expand Down Expand Up @@ -200,41 +203,47 @@ public function typePropsDataProvider() : array
'title' => 'Page on this site',
'priority' => 0,
'icon' => 'font-icon-page',
'allowed' => true,
],
'EmailLink props' => [
'class' => EmailLink::class,
'key' => 'email',
'title' => 'Link to email address',
'priority' => 30,
'icon' => 'font-icon-p-mail',
'allowed' => false,
],
'ExternalLink props' => [
'class' => ExternalLink::class,
'key' => 'external',
'title' => 'Link to external URL',
'priority' => 20,
'icon' => 'font-icon-external-link',
'allowed' => false,
],
'FileLink props' => [
'class' => FileLink::class,
'key' => 'file',
'title' => 'Link to a file',
'priority' => 10,
'icon' => 'font-icon-image',
'allowed' => true,
],
'PhoneLink props' => [
'class' => PhoneLink::class,
'key' => 'phone',
'title' => 'Phone number',
'priority' => 40,
'icon' => 'font-icon-mobile',
'allowed' => true,
],
'TestPhoneLink props' => [
'class' => TestPhoneLink::class,
'key' => 'testphone',
'title' => 'Test Phone Link',
'priority' => 100,
'icon' => 'font-icon-link',
'allowed' => false,
],
];
}
Expand All @@ -247,14 +256,21 @@ public function testGetTypesProps(
string $key,
string $title,
int $priority,
string $icon
string $icon,
bool $allowed
): void {
$linkField = LinkField::create('LinkField');
$linkField->setAllowedTypes([$class]);
if ($allowed) {
$linkField->setAllowedTypes([$class]);
} else {
$diff = array_diff($this->link_types, [$class]);
$linkField->setAllowedTypes($diff);
}
$json = json_decode($linkField->getTypesProps(), true);
$this->assertEquals($key, $json[$key]['key']);
$this->assertEquals($title, $json[$key]['title']);
$this->assertEquals($priority, $json[$key]['priority']);
$this->assertEquals($icon, $json[$key]['icon']);
$this->assertEquals($allowed, $json[$key]['allowed']);
}
}

0 comments on commit 185867c

Please sign in to comment.