Skip to content

Commit

Permalink
fix after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy132 committed Aug 20, 2024
1 parent 36de986 commit 493e0f8
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions app/Filament/App/Pages/Startup.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function form(Form $form): Form
$text = TextInput::make('variable_value')
->hidden($this->shouldHideComponent(...))
->disabled(fn (ServerVariable $serverVariable) => !$serverVariable->variable->user_editable)
->required(fn (ServerVariable $serverVariable) => in_array('required', explode('|', $serverVariable->variable->rules)))
->required(fn (ServerVariable $serverVariable) => $serverVariable->variable->getRequiredAttribute())
->rules([
fn (ServerVariable $serverVariable): Closure => function (string $attribute, $value, Closure $fail) use ($serverVariable) {
$validator = Validator::make(['validatorkey' => $value], [
Expand Down Expand Up @@ -126,26 +126,22 @@ protected function authorizeAccess(): void

private function shouldHideComponent(ServerVariable $serverVariable, Component $component): bool
{
$containsRuleIn = str($serverVariable->variable->rules)->explode('|')->reduce(
fn ($result, $value) => $result === true && !str($value)->startsWith('in:'), true
);
$containsRuleIn = array_first($serverVariable->variable->rules, fn ($value) => str($value)->startsWith('in:'), false);

if ($component instanceof Select) {
return $containsRuleIn;
return !$containsRuleIn;
}

if ($component instanceof TextInput) {
return !$containsRuleIn;
return $containsRuleIn;
}

throw new \Exception('Component type not supported: ' . $component::class);
}

private function getSelectOptionsFromRules(ServerVariable $serverVariable): array
{
$inRule = str($serverVariable->variable->rules)->explode('|')->reduce(
fn ($result, $value) => str($value)->startsWith('in:') ? $value : $result, ''
);
$inRule = array_first($serverVariable->variable->rules, fn ($value) => str($value)->startsWith('in:'));

return str($inRule)
->after('in:')
Expand Down

0 comments on commit 493e0f8

Please sign in to comment.