Skip to content

Commit d90a91b

Browse files
committed
Small fixes
1 parent 434c05a commit d90a91b

7 files changed

Lines changed: 34 additions & 22 deletions

File tree

src/Dashboards/Redis/RedisTrait.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,12 @@ private function viewKey(Redis $redis): string {
322322
[$value, $encode_fn, $is_formatted] = Helpers::decodeAndFormatValue($value);
323323
}
324324

325+
$ttl = $redis->ttl($key);
326+
325327
return $this->template->render('partials/view_key', [
326328
'value' => $value,
327329
'type' => $type,
328-
'ttl' => Helpers::formatSeconds($redis->ttl($key)),
330+
'ttl' => $ttl ? Helpers::formatSeconds($ttl) : null,
329331
'encode_fn' => $encode_fn,
330332
'formatted' => $is_formatted,
331333
'add_subkey' => Http::queryString(['db'], ['form' => 'new', 'key' => $key]),

src/Helpers.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ public static function formatBytes(int $bytes): string {
8080
* @return string
8181
*/
8282
public static function formatSeconds(int $time): string {
83+
if ($time === -1) {
84+
return (string) $time;
85+
}
86+
8387
$seconds_in_minute = 60;
8488
$seconds_in_hour = 60 * $seconds_in_minute;
8589
$seconds_in_day = 24 * $seconds_in_hour;
@@ -292,9 +296,9 @@ public static function getEncoders(): array {
292296
* @param string $value
293297
* @param string $encoder
294298
*
295-
* @return mixed
299+
* @return string
296300
*/
297-
public static function encodeValue(string $value, string $encoder) {
301+
public static function encodeValue(string $value, string $encoder): string {
298302
$encoder = Config::get('encoding')[$encoder];
299303

300304
if (is_callable($encoder['save']) && $encoder['save']($value) !== null) {
@@ -310,9 +314,9 @@ public static function encodeValue(string $value, string $encoder) {
310314
* @param string $value
311315
* @param string $decoder
312316
*
313-
* @return mixed
317+
* @return string
314318
*/
315-
public static function decodeValue(string $value, string $decoder) {
319+
public static function decodeValue(string $value, string $decoder): string {
316320
$decoder = Config::get('encoding')[$decoder];
317321

318322
if (is_callable($decoder['view']) && $decoder['view']($value) !== null) {

templates/components/input.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="mb-3"{{ extra_attr|raw }}>
22
<label for="{{ id }}" class="block text-sm font-semibold mb-2">{{ label }}</label>
33
<input id="{{ id }}" name="{{ id }}" type="{{ type ? type : 'text' }}" value="{{ value }}"
4-
class="input w-full rounded py-2 px-4 focus:ring-{{ color }}-100 focus:border-{{ color }}-300"{{ required ? ' required' : '' }}>
4+
class="input w-full rounded py-2 px-4 focus:ring-{{ color }}-100 focus:border-{{ color }}-300"{{ required ? ' required' : '' }}{{ attr|raw }}>
55
{% if help %}
66
<small class="text-xs text-gray-400">{{ help }}</small>
77
{% endif %}

templates/dashboards/redis/form.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
type: 'number',
5656
help: '-1 removes expiration (default).',
5757
value: expire,
58+
attr: ' min="-1" max="2147483647"',
5859
}) }}
5960

6061
{% if encoders %}

templates/dashboards/redis/redis.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
</div>
2222
</div>
2323

24-
{{ include('partials/keys_table.twig', {ttl: true}) }}
24+
{{ include('partials/keys_table.twig') }}

templates/partials/keys_table.twig

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
</th>
1313
<th class="px-3 md:px-5 py-2 text-xs uppercase font-bold whitespace-nowrap">Key</th>
1414
<th class="hidden md:table-cell w-24 px-3 md:px-5 py-2 text-xs uppercase font-bold whitespace-nowrap">Type</th>
15-
{% if ttl %}
16-
<th class="w-32 px-3 md:px-5 py-2 text-xs uppercase font-bold whitespace-nowrap">TTL</th>
17-
{% endif %}
15+
<th class="w-32 px-3 md:px-5 py-2 text-xs uppercase font-bold whitespace-nowrap">TTL</th>
1816
<th class="w-14 md:w-24 lg:w-40 rounded-tr px-3 md:px-5 py-2 text-xs uppercase font-bold whitespace-nowrap">Actions</th>
1917
</tr>
2018
</thead>
@@ -27,21 +25,20 @@
2725
class="checkbox-key checkbox text-{{ color }}-500 focus:border-{{ color }}-300 focus:ring-{{ color }}-200" aria-label="">
2826
</td>
2927
<td class="border-b border-gray-100 px-3 md:px-5 py-2 text-sm whitespace-nowrap truncate">
30-
<a class="text-{{ color }}-500 hover:text-{{ color }}-700" href="{{ view_url ~ key.key }}" title="{{ key.key }}">
28+
<a class="text-{{ color }}-500 hover:text-{{ color }}-700" href="{{ view_url|replace({'ttl_value': key.ttl}) ~ key.key }}" title="{{ key.key }}">
3129
{{ (key.items_total ? '<span class="hidden md:inline-block">(' ~ key.items_total ~ ' items)&nbsp;</span>' : '')|raw }}{{ key.key }}
3230
</a>
3331
</td>
3432
<td class="hidden md:table-cell border-b border-gray-100 px-3 md:px-5 py-2 text-sm whitespace-nowrap">{{ key_badge.key_type(key.type) }}</td>
35-
{% if ttl %}
36-
<td class="border-b border-gray-100 px-3 md:px-5 py-2 text-sm whitespace-nowrap">
37-
{% if key.ttl == -1 %}
38-
Does not expire
39-
{% else %}
40-
{{ key.ttl }}
41-
{% endif %}
42-
</td>
43-
{% endif %}
4433
<td class="border-b border-gray-100 px-3 md:px-5 py-2 text-sm whitespace-nowrap">
34+
{% if key.ttl == -1 %}
35+
Doesn't expire
36+
{% else %}
37+
{{ key.ttl }}
38+
{% endif %}
39+
</td>
40+
<td class="border-b border-gray-100 px-3 md:px-5 py-2 text-sm whitespace-nowrap">
41+
{% set edit_url = edit_url|replace({'ttl_value': key_ttl}) %}
4542
<a class="text-gray-500 hover:text-gray-700 font-semibold mr-3" href="{{ edit_url ~ key.key }}" title="Edit">
4643
{{ svg('edit', 12) }}<span class="hidden lg:inline-block ml-1">Edit</span>
4744
</a>
@@ -53,7 +50,7 @@
5350
{% endfor %}
5451
{% else %}
5552
<tr>
56-
<td colspan="{{ ttl ? 5 : 4 }}" class="text-center p-5">No keys.</td>
53+
<td colspan="5" class="text-center p-5">No keys.</td>
5754
</tr>
5855
{% endif %}
5956
</tbody>

templates/partials/view_key.twig

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
<span>Type {{ key_badge.key_type(type) }}</span>
55

66
{% if ttl %}
7-
<span>TTL {{ include('components/badge.twig', {text: ttl, pill: true, class: 'uppercase font-bold', bg: 'bg-slate-500'}) }}</span>
7+
<span>
8+
TTL
9+
{{ include('components/badge.twig', {
10+
text: ttl == -1 ? 'Doesn\'t expire' : ttl,
11+
pill: true,
12+
class: 'uppercase font-bold',
13+
bg: 'bg-slate-500',
14+
}) }}
15+
</span>
816
{% endif %}
917

1018
{% if encode_fn %}

0 commit comments

Comments
 (0)