Skip to content

Commit dcb2608

Browse files
authored
Merge branch 'filamentphp:3.x' into 3.x
2 parents ab315c7 + 1e65d92 commit dcb2608

File tree

6 files changed

+84
-24
lines changed

6 files changed

+84
-24
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div
2-
{{ $attributes->class(['fi-fo-field-wrp-helper-text break-words text-sm text-gray-500']) }}
2+
{{ $attributes->class(['fi-fo-field-wrp-helper-text break-words text-sm text-gray-500 dark:text-gray-400']) }}
33
>
44
{{ $slot }}
55
</div>

packages/forms/resources/views/components/field-wrapper/hint.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@class([
1818
'fi-fo-field-wrp-hint-label',
1919
match ($color) {
20-
'gray' => 'text-gray-500',
20+
'gray' => 'text-gray-500 dark:text-gray-400',
2121
default => 'fi-color-custom text-custom-600 dark:text-custom-400',
2222
},
2323
is_string($color) ? "fi-color-{$color}" : null,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div
2-
{{ $attributes->class(['fi-in-entry-wrp-helper-text break-words text-sm text-gray-500']) }}
2+
{{ $attributes->class(['fi-in-entry-wrp-helper-text break-words text-sm text-gray-500 dark:text-gray-400']) }}
33
>
44
{{ $slot }}
55
</div>

packages/infolists/resources/views/components/entry-wrapper/hint.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@class([
1818
'fi-in-entry-wrp-hint-label',
1919
match ($color) {
20-
'gray' => 'text-gray-500',
20+
'gray' => 'text-gray-500 dark:text-gray-400',
2121
default => 'fi-color-custom text-custom-600 dark:text-custom-400',
2222
},
2323
is_string($color) ? "fi-color-{$color}" : null,

packages/support/src/helpers.php

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -166,26 +166,38 @@ function generate_search_column_expression(string $column, ?bool $isSearchForced
166166
$column = match ($driverName) {
167167
'pgsql' => (
168168
str($column)->contains('->')
169-
? (
170-
// Handle `table.field` part with double quotes
171-
str($column)
172-
->before('->')
173-
->explode('.')
174-
->map(fn (string $part): string => (string) str($part)->wrap('"'))
175-
->implode('.')
176-
) . collect(str($column)->after('->')->explode('->')) // Handle JSON path parts
177-
->map(function ($segment, $index) use ($column): string {
178-
$totalParts = substr_count($column, '->');
179-
180-
return ($index === ($totalParts - 1))
181-
? "->>'{$segment}'"
182-
: "->'{$segment}'";
183-
})
184-
->implode('')
185-
: str($column)
186-
->explode('.')
187-
->map(fn (string $part): string => (string) str($part)->wrap('"'))
188-
->implode('.')
169+
? (
170+
// Handle `table.field` part with double quotes
171+
str($column)
172+
->before('->')
173+
->explode('.')
174+
->map(fn (string $part): string => (string) str($part)->wrap('"'))
175+
->implode('.')
176+
) . collect(str($column)->after('->')->explode('->')) // Handle JSON path parts
177+
->map(function ($segment, $index) use ($column): string {
178+
// If segment already starts with `>` (from `->>` operator), preserve it
179+
$isExplicitOperatorPrefixed = str($segment)->startsWith('>');
180+
$segment = $isExplicitOperatorPrefixed ? (string) str($segment)->after('>') : $segment;
181+
182+
// Remove single quotes from segment if present to avoid redundant quoting
183+
$isWrappedWithSingleQuotes = str($segment)->startsWith("'") && str($segment)->endsWith("'");
184+
$segment = $isWrappedWithSingleQuotes ? (string) str($segment)->trim("'") : $segment;
185+
186+
if ($isExplicitOperatorPrefixed) {
187+
return "->>'{$segment}'";
188+
}
189+
190+
$totalParts = substr_count($column, '->');
191+
192+
return ($index === ($totalParts - 1))
193+
? "->>'{$segment}'"
194+
: "->'{$segment}'";
195+
})
196+
->implode('')
197+
: str($column)
198+
->explode('.')
199+
->map(fn (string $part): string => (string) str($part)->wrap('"'))
200+
->implode('.')
189201
) . '::text',
190202
default => $column,
191203
};

tests/src/Support/helpersTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,51 @@
112112
['blog:posts.title', 'lower("blog:posts"."title"::text)'],
113113
['blog:posts:comments.author.name', 'lower("blog:posts:comments"."author"."name"::text)'],
114114
]);
115+
116+
it('will generate a JSON search column expression for Postgres with explicit ->> operator', function () {
117+
$column = 'data->>name';
118+
$isSearchForcedCaseInsensitive = true;
119+
120+
$databaseConnection = Mockery::mock(Connection::class);
121+
$databaseConnection->shouldReceive('getDriverName')->andReturn('pgsql');
122+
$databaseConnection->shouldReceive('getConfig')->with('search_collation')->andReturn(null);
123+
124+
$grammar = new PostgresGrammar($databaseConnection);
125+
126+
$expression = generate_search_column_expression($column, $isSearchForcedCaseInsensitive, $databaseConnection);
127+
128+
expect($expression->getValue($grammar))
129+
->toBe("lower(\"data\"->>'name'::text)");
130+
});
131+
132+
it('will generate a nested JSON search column expression for Postgres with explicit ->> operator on the last segment', function () {
133+
$column = 'data->name->>ar';
134+
$isSearchForcedCaseInsensitive = true;
135+
136+
$databaseConnection = Mockery::mock(Connection::class);
137+
$databaseConnection->shouldReceive('getDriverName')->andReturn('pgsql');
138+
$databaseConnection->shouldReceive('getConfig')->with('search_collation')->andReturn(null);
139+
140+
$grammar = new PostgresGrammar($databaseConnection);
141+
142+
$expression = generate_search_column_expression($column, $isSearchForcedCaseInsensitive, $databaseConnection);
143+
144+
expect($expression->getValue($grammar))
145+
->toBe("lower(\"data\"->'name'->>'ar'::text)");
146+
});
147+
148+
it('will generate a JSON search column expression for Postgres with explicit ->> operator and simple key', function () {
149+
$column = 'name->>\'en\'';
150+
$isSearchForcedCaseInsensitive = true;
151+
152+
$databaseConnection = Mockery::mock(Connection::class);
153+
$databaseConnection->shouldReceive('getDriverName')->andReturn('pgsql');
154+
$databaseConnection->shouldReceive('getConfig')->with('search_collation')->andReturn(null);
155+
156+
$grammar = new PostgresGrammar($databaseConnection);
157+
158+
$expression = generate_search_column_expression($column, $isSearchForcedCaseInsensitive, $databaseConnection);
159+
160+
expect($expression->getValue($grammar))
161+
->toBe("lower(\"name\"->>'en'::text)");
162+
});

0 commit comments

Comments
 (0)