refactor: consolidate JS toggle components, grid query parsers, and add tests
JS components: migrate app-custom-field-options-toggle, app-color-default-toggle, and app-settings-telemetry to shared conditional-controls factory/utility, removing duplicated syncControlState logic and init boilerplate. grid.php: extract gridQueryCsvInput() to DRY up 3 CSV parsers, simplify multi_csv handler via gridNormalizeLabelList, delegate order type to gridQueryEnum. Tests: add 23 SearchQueryNormalizer tests (LIKE escaping, wildcards, Unicode) and 7 additional Crypto edge-case tests (empty input, missing fields, special chars, binary content, truncation). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -269,26 +269,7 @@ function gridBuildToolbarFilterState(array $toolbarSchema, array $filterState):
|
||||
$value = array_key_exists($key, $filterState) ? $filterState[$key] : $default;
|
||||
|
||||
if ($type === 'multi_csv') {
|
||||
if (is_array($value)) {
|
||||
$items = array_values(array_filter(
|
||||
array_map(static fn (mixed $item): string => trim((string) $item), $value),
|
||||
static fn (string $item): bool => $item !== ''
|
||||
));
|
||||
$state[$key] = array_values(array_unique($items));
|
||||
continue;
|
||||
}
|
||||
|
||||
$text = trim((string) $value);
|
||||
if ($text === '') {
|
||||
$state[$key] = [];
|
||||
continue;
|
||||
}
|
||||
|
||||
$items = array_values(array_filter(
|
||||
array_map(static fn (string $item): string => trim($item), explode(',', $text)),
|
||||
static fn (string $item): bool => $item !== ''
|
||||
));
|
||||
$state[$key] = array_values(array_unique($items));
|
||||
$state[$key] = array_values(array_unique(gridNormalizeLabelList($value, ',')));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -614,9 +595,7 @@ function gridParseFilters(array $query, array $schema): array
|
||||
(array) ($rule['allowed'] ?? [])
|
||||
), static fn (string $item): bool => $item !== ''));
|
||||
$default = (string) ($rule['default'] ?? ($allowed[0] ?? ''));
|
||||
$parsed[$key] = in_array(trim((string) ($query[$source] ?? $default)), $allowed, true)
|
||||
? trim((string) ($query[$source] ?? $default))
|
||||
: $default;
|
||||
$parsed[$key] = gridQueryEnum($query, $source, $allowed, $default);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -719,6 +698,28 @@ function gridQueryEnum(array $query, string $key, array $allowed, string $defaul
|
||||
return in_array($value, $allowed, true) ? $value : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract raw items from a comma-separated or array query parameter.
|
||||
*
|
||||
* @return list<mixed>
|
||||
*/
|
||||
function gridQueryCsvInput(array $query, string $key): array
|
||||
{
|
||||
$value = $query[$key] ?? '';
|
||||
if (is_string($value)) {
|
||||
return $value === '' ? [] : explode(',', $value);
|
||||
}
|
||||
if (is_array($value)) {
|
||||
$items = [];
|
||||
array_walk_recursive($value, static function (mixed $item) use (&$items): void {
|
||||
$items[] = $item;
|
||||
});
|
||||
return $items;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize comma-separated positive IDs from query params.
|
||||
*
|
||||
@@ -730,15 +731,7 @@ function gridQueryCsvIds(array $query, string $key, int $max = 200): array
|
||||
return [];
|
||||
}
|
||||
|
||||
$value = $query[$key] ?? '';
|
||||
$items = [];
|
||||
if (is_string($value)) {
|
||||
$items = $value === '' ? [] : explode(',', $value);
|
||||
} elseif (is_array($value)) {
|
||||
array_walk_recursive($value, static function (mixed $item) use (&$items): void {
|
||||
$items[] = $item;
|
||||
});
|
||||
}
|
||||
$items = gridQueryCsvInput($query, $key);
|
||||
|
||||
$ids = [];
|
||||
$seen = [];
|
||||
@@ -768,15 +761,7 @@ function gridQueryCsvUuids(array $query, string $key, int $max = 200): array
|
||||
return [];
|
||||
}
|
||||
|
||||
$value = $query[$key] ?? '';
|
||||
$items = [];
|
||||
if (is_string($value)) {
|
||||
$items = $value === '' ? [] : explode(',', $value);
|
||||
} elseif (is_array($value)) {
|
||||
array_walk_recursive($value, static function (mixed $item) use (&$items): void {
|
||||
$items[] = $item;
|
||||
});
|
||||
}
|
||||
$items = gridQueryCsvInput($query, $key);
|
||||
|
||||
$uuids = [];
|
||||
$seen = [];
|
||||
@@ -806,15 +791,7 @@ function gridQueryCsvStrings(array $query, string $key, int $max = 200, ?callabl
|
||||
return [];
|
||||
}
|
||||
|
||||
$value = $query[$key] ?? '';
|
||||
$items = [];
|
||||
if (is_string($value)) {
|
||||
$items = $value === '' ? [] : explode(',', $value);
|
||||
} elseif (is_array($value)) {
|
||||
array_walk_recursive($value, static function (mixed $item) use (&$items): void {
|
||||
$items[] = $item;
|
||||
});
|
||||
}
|
||||
$items = gridQueryCsvInput($query, $key);
|
||||
|
||||
$result = [];
|
||||
$seen = [];
|
||||
|
||||
Reference in New Issue
Block a user