Skip to content

Commit

Permalink
LfTags improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
afonic committed Jan 25, 2025
1 parent afbd4c8 commit e327563
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
40 changes: 38 additions & 2 deletions resources/lang/en/ui.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
<?php

return [
// UI Elements
'all' => 'All',
'clear_filters' => 'Clear filter',
'default' => 'Default',
'entries' => '{0} entries|{1} entry|[2,*] entries',
'all' => 'All',
'value' => 'Value',
'to' => 'to',
'value' => 'Value',

// Conditions
'any' => ':',
'contains' => ' contains',
'doesnt_contain' => ' does not contain',
'doesnt_end_with' => ' does not end with',
'doesnt_exist' => ' does not exist',
'doesnt_match' => ' does not match pattern',
'doesnt_start_with' => ' does not start with',
'ends_with' => ' ends with',
'equals' => ' equals',
'exists' => ' exists',
'gt' => ' more than',
'gte' => ' at least',
'in' => ' is in',
'is' => ':',
'is_after' => ' is after',
'is_alpha' => ' is alphabetical',
'is_alpha_numeric' => ' is alphanumeric',
'is_before' => ' is before',
'is_email' => ' is email',
'is_embeddable' => ' is embeddable',
'is_empty' => ' is empty',
'is_numeric' => ' is numeric',
'is_url' => ' is URL',
'isnt' => ' is not',
'lt' => ' less than',
'lte' => ' at most',
'matches' => ' matches',
'not' => ' not',
'not_in' => ' is not in',
'null' => ' is null',
'regex' => ' matches ',
'starts_with' => ' starts with',
'query_scope' => ':',
];
2 changes: 1 addition & 1 deletion resources/views/livewire/ui/tags.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class="py-2.5 px-5 me-2 mb-2 text-sm font-medium inline-flex items-center text-g
hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-4 focus:ring-gray-100 cursor-default transition-opacity duration-500"
wire:loading.class="opacity-40"
>
<span class="whitespace-nowrap">{{ $tag['fieldLabel'] }}: {{ $tag['optionLabel'] }}</span>
<span class="whitespace-nowrap">{{ $tag['fieldLabel'] }}{{ trans('statamic-livewire-filters::ui.'.$tag['condition']) }} {{ $tag['optionLabel'] }}</span>
<div class="ml-3 cursor-pointer" wire:click="removeOption('{{ $tag['field'] }}', '{{ $tag['value'] }}')">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12" />
Expand Down
24 changes: 24 additions & 0 deletions src/Http/Livewire/LfTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function updateTags($params)
// Order is critical here
$this->parseQueryScopes();
$this->parseTaxonomyTerms();
$this->parseRanges();
$this->parseConditions();
}

Expand All @@ -81,6 +82,28 @@ public function parseConditions()
});
}

public function parseRanges()
{
$rangeConditions = ['gte', 'lte', 'gt', 'lt', 'is_after', 'is_before'];

$ranges = $this->params->filter(fn ($value, $key) => Str::contains($key, $rangeConditions)
);

if ($ranges->isEmpty()) {
return;
}

$ranges->each(function ($value, $key) {
[$field, $condition] = explode(':', $key);
collect(explode('|', $value))->each(function ($value) use ($field, $condition) {
$this->addFieldOptionToTags($field, $value, $condition);
});
});

$this->params = $this->params->reject(fn ($value, $key) => Str::contains($key, $rangeConditions)
);
}

public function parseTaxonomyTerms()
{
$taxonomies = $this->params->filter(fn ($value, $key) => Str::startsWith($key, 'taxonomy:'));
Expand Down Expand Up @@ -148,6 +171,7 @@ public function addFieldOptionToTags($field, $value, $condition = null)
}
$fieldLabel = $this->statamicFields->get($field)['display'] ?? $field;
$optionLabel = $this->statamicFields->get($field)['options'][$value] ?? $value;

$tag = [
'field' => $field,
'value' => $value,
Expand Down

0 comments on commit e327563

Please sign in to comment.