Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-8132: [UDW] For object relation field user can remove selected item from bookmarks #1340

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 @@ -307,8 +307,8 @@
<note>key: selected_locations.collapse.sidebar</note>
</trans-unit>
<trans-unit id="d4462bb9386e96a0984586618fbfbcd0852fd4ea" resname="selected_locations.deselect_all">
<source>Deselect all</source>
<target state="new">Deselect all</target>
<source>{1}Deselect|[2,Inf]Deselect all</source>
<target state="new">{1}Deselect|[2,Inf]Deselect all</target>
<note>key: selected_locations.deselect_all</note>
</trans-unit>
<trans-unit id="19700661da70137e52d0009660c9a87f5bcb99bd" resname="selected_locations.expand.sidebar">
Expand All @@ -317,8 +317,8 @@
<note>key: selected_locations.expand.sidebar</note>
</trans-unit>
<trans-unit id="fe05e738022445778cb775ca099ba54291ae88e9" resname="selected_locations.selected_items">
<source>%count% selected item(s)</source>
<target state="new">%count% selected item(s)</target>
<source>{1}%count% selected item|[2,Inf]%count% selected items</source>
<target state="new">{1}%count% selected item|[2,Inf]%count% selected items</target>
<note>key: selected_locations.selected_items</note>
</trans-unit>
<trans-unit id="6b02292efbef3c6800f618acb3c41f968d9ea305" resname="sorting.date.label">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ const SelectedLocations = () => {
setIsExpanded(!isExpanded);
};
const renderSelectionCounter = () => {
const selectedLabel = Translator.trans(
/*@Desc("%count% selected item(s)")*/ 'selected_locations.selected_items',
const selectedLabel = Translator.transChoice(
/*@Desc("{1}%count% selected item|[2,Inf]%count% selected items")*/ 'selected_locations.selected_items',
selectedLocations.length,
{ count: selectedLocations.length },
'ibexa_universal_discovery_widget',
);
Expand All @@ -67,8 +68,9 @@ const SelectedLocations = () => {
);
};
const renderActionButtons = () => {
const removeAllLabel = Translator.trans(
/*@Desc("Deselect all")*/ 'selected_locations.deselect_all',
const removeLabel = Translator.transChoice(
/*@Desc("{1}Deselect|[2,Inf]Deselect all")*/ 'selected_locations.deselect_all',
selectedLocations.length,
{},
'ibexa_universal_discovery_widget',
);
Expand All @@ -80,7 +82,7 @@ const SelectedLocations = () => {
className="c-selected-locations__clear-selection-button btn ibexa-btn ibexa-btn--small ibexa-btn--secondary"
onClick={clearSelection}
>
{removeAllLabel}
{removeLabel}
</button>
</div>
);
Expand All @@ -107,6 +109,10 @@ const SelectedLocations = () => {
};

useEffect(() => {
if (!allowConfirmation) {
return;
}

parseTooltip(refSelectedLocations.current);
hideAllTooltips();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ import SelectedLocations from '../selected-locations/selected.locations';
import ContentCreateWidget from '../content-create-widget/content.create.widget';
import ContentMetaPreview from '../../content.meta.preview.module';

import { SelectedLocationsContext, DropdownPortalRefContext, MultipleConfigContext } from '../../universal.discovery.module';
import { SelectedLocationsContext, DropdownPortalRefContext } from '../../universal.discovery.module';

const Tab = ({ children, actionsDisabledMap }) => {
const topBarRef = useRef();
const bottomBarRef = useRef();
const [contentHeight, setContentHeight] = useState('100%');
const [selectedLocations] = useContext(SelectedLocationsContext);
const dropdownPortalRef = useContext(DropdownPortalRefContext);
const [multiple] = useContext(MultipleConfigContext);
const selectedLocationsComponent = !!selectedLocations.length && multiple ? <SelectedLocations /> : null;
const selectedLocationsComponent = !!selectedLocations.length ? <SelectedLocations /> : null;
const contentStyles = {
height: contentHeight,
};
Expand Down
30 changes: 22 additions & 8 deletions src/lib/Translation/Extractor/JavaScriptFileVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ class JavaScriptFileVisitor implements FileVisitorInterface, LoggerAwareInterfac
use LoggerAwareTrait;

public const TRANSLATOR_OBJECT = 'Translator';
public const TRANSLATOR_METHOD = 'trans';
public const TRANSLATOR_TRANS_METHOD = 'trans';
public const TRANSLATOR_TRANS_CHOICE_METHOD = 'transChoice';

public const ID_ARG = 0;
public const DOMAIN_ARG = 2;
public const TRANS_DOMAIN_ARG = 2;
public const TRANS_CHOICE_DOMAIN_ARG = 3;

/** @var \Doctrine\Common\Annotations\DocParser */
private $docParser;
Expand Down Expand Up @@ -85,12 +87,19 @@ public function visitFile(SplFileInfo $file, MessageCatalogue $catalogue)
}

$ast->traverse(function ($node) use ($catalogue, $file) {
if ($this->isMethodCall($node, self::TRANSLATOR_OBJECT, self::TRANSLATOR_METHOD)) {
if ($this->isMethodCall($node, self::TRANSLATOR_OBJECT, self::TRANSLATOR_TRANS_METHOD)
|| $this->isMethodCall($node, self::TRANSLATOR_OBJECT, self::TRANSLATOR_TRANS_CHOICE_METHOD)
) {
$arguments = $node->getArguments();

$id = $this->extractId($file, $arguments);
if ($id !== null) {
$message = new Message($id, $this->extractDomain($file, $arguments) ?? $this->defaultDomain);
$callee = $node->getCallee();
$property = $callee->getProperty();

$message = new Message(
$id,
$this->extractDomain($file, $arguments, $property->getName()) ?? $this->defaultDomain
);
$message->setDesc($this->extractDesc($arguments));
$message->addSource(new FileSource((string)$file));

Expand Down Expand Up @@ -171,13 +180,18 @@ private function extractId(SplFileInfo $file, array $arguments): ?string
*
* @param \SplFileInfo $file
* @param \Peast\Syntax\Node\Expression[] $arguments
* @param string $methodName
*
* @return string|null
*/
private function extractDomain(SplFileInfo $file, array $arguments): ?string
private function extractDomain(SplFileInfo $file, array $arguments, string $methodName): ?string
{
if (isset($arguments[self::DOMAIN_ARG])) {
$domainNode = $arguments[self::DOMAIN_ARG];
$domainArgIndex = $methodName === self::TRANSLATOR_TRANS_METHOD
? self::TRANS_DOMAIN_ARG
: self::TRANS_CHOICE_DOMAIN_ARG;

if (isset($arguments[$domainArgIndex])) {
$domainNode = $arguments[$domainArgIndex];

if (!($domainNode instanceof Node\StringLiteral)) {
$position = $domainNode->getLocation()->getStart();
Expand Down
Loading