Skip to content

Commit

Permalink
Merge pull request #87 from bcgov/Improve-FormVersion-element-labels-…
Browse files Browse the repository at this point in the history
…ADO-2318

Improved FormVersion element headers
  • Loading branch information
saranyaviswam authored Jan 27, 2025
2 parents f487c49 + ed70ddd commit cf0b72d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 26 deletions.
79 changes: 56 additions & 23 deletions app/Filament/Forms/Resources/FormVersionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,31 @@ public static function form(Form $form): Form
->cloneable()
->collapsible()
->collapsed(true)
->live()
->itemLabel(function ($state) {
if ($state['component_type'] === 'form_field') {
$field = FormField::find($state['form_field_id']) ?: null;
$field ? $label = ($state['custom_label'] ?: ($field->label ?? ''))
. ' - ' . $field->dataType->short_description
. ' (' . ($field->name ?? '') . ')'
: $label = 'New Field';
return $label;
if ($field) {
$label = '';
if ($state['customize_label'] !== 'hide') {
$label .= ($state['custom_label'] ?? $field->label ?? 'null') . ' | ';
} else {
$label .= '(label hidden) | ';
}
$label .= ($field->dataType->name ?? '')
. ' | id: ' . ($state['custom_instance_id'] ?? $state['instance_id'] ?? '');
return $label;
}
return 'New Field';
} elseif ($state['component_type'] === 'field_group') {
$group = FieldGroup::find($state['field_group_id']);
$group ? $label = ($state['group_label'] ?: ($group->label ?? ''))
. ' (' . ($group->name ?? '') . ')'
: $label = 'New Group';
return $label;
if ($group) {
$label = ($state['group_label'] ?? $group->label ?? '(no label)')
. ' | group '
. ' | id: ' . ($state['custom_instance_id'] ?? $state['instance_id'] ?? '');
return $label;
}
return 'New Group';
}
return 'Component';
})
Expand All @@ -154,13 +165,14 @@ public static function form(Form $form): Form
foreach ($options as $id => $option) {
$field = FormField::find($id) ?: null;
$options[$id] = $option
. ' - ' . $field->dataType->short_description
. ' (' . ($field->name ?? '') . ')';
. ' | ' . $field->dataType->name
. ' | name: ' . ($field->name ?? '');
}
return $options;
})
->searchable()
->required(),
->required()
->reactive(),
Fieldset::make('Field Value')
->visible(fn($get) => FormField::find($get('form_field_id'))?->isValueInputNeededForField() ?? false)
->columns(1)
Expand Down Expand Up @@ -262,9 +274,15 @@ public static function form(Form $form): Form
->default('default')
->inline()
->inlineLabel(false)
->live(),
->live()
->afterStateUpdated(function ($state, callable $set) {
if ($state !== 'customize') {
$set('custom_label', null);
}
}),
TextInput::make('custom_label')
->label(false)
->reactive()
->visible(fn($get) => $get('customize_label') == 'customize'),
]),
Fieldset::make('Instance ID')
Expand Down Expand Up @@ -330,7 +348,7 @@ public static function form(Form $form): Form
// Compose option labels
$options = FieldGroup::pluck('label', 'id');
foreach ($options as $id => $option) {
$options[$id] = $option . ' (' . (FieldGroup::find($id)->name ?? '') . ')';
$options[$id] = ($option ?? '(no label)') . ' | group | name: ' . (FieldGroup::find($id)->name ?? '');
}
return $options;
})
Expand Down Expand Up @@ -407,13 +425,21 @@ public static function form(Form $form): Form
->cloneable()
->collapsible()
->collapsed()
->live()
->itemLabel(function ($state) {
$field = FormField::find($state['form_field_id']) ?: null;
$field ? $label = ($state['label'] ?: ($field->label ?? 'New Field'))
. ' - ' . $field->dataType->short_description
. ' (' . ($field->name ?? 'empty') . ')'
: $label = 'New Field';
return $label;
if ($field) {
$label = '';
if ($state['customize_label'] !== 'hide') {
$label .= ($state['custom_label'] ?? $field->label ?? '') . ' | ';
} else {
$label .= '(label hidden) | ';
}
$label .= ($field->dataType->name ?? '')
. ' | id: ' . ($state['custom_instance_id'] ?? $state['instance_id'] ?? '');
return $label;
}
return 'New Field';
})
->defaultItems(0)
->schema([
Expand All @@ -425,13 +451,14 @@ public static function form(Form $form): Form
foreach ($options as $id => $option) {
$field = FormField::find($id) ?: null;
$options[$id] = $option
. ' - ' . $field->dataType->short_description
. ' (' . ($field->name ?? '') . ')';
. ' | ' . $field->dataType->name
. ' | name: ' . ($field->name ?? '');
}
return $options;
})
->searchable()
->required(),
->required()
->reactive(),
Fieldset::make('Field Value')
->visible(fn($get) => FormField::find($get('form_field_id'))?->isValueInputNeededForField() ?? false)
->columns(1)
Expand Down Expand Up @@ -533,9 +560,15 @@ public static function form(Form $form): Form
->default('default')
->inline()
->inlineLabel(false)
->live(),
->live()
->afterStateUpdated(function ($state, callable $set) {
if ($state !== 'customize') {
$set('custom_label', null);
}
}),
TextInput::make('custom_label')
->label(false)
->reactive()
->visible(fn($get) => $get('customize_label') == 'customize'),
]),
Fieldset::make('Instance ID')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function afterSave(): void
'form_version_id' => $formVersion->id,
'form_field_id' => $component['form_field_id'],
'order' => $order,
'custom_label' => $component['customize_label'] == 'customize' ? $component['custom_label'] : null,
'custom_label' => $component['customize_label'] === 'customize' ? $component['custom_label'] : null,
'customize_label' => $component['customize_label'] ?? null,
'custom_data_binding_path' => $component['customize_data_binding_path'] ? $component['custom_data_binding_path'] : null,
'custom_data_binding' => $component['customize_data_binding'] ? $component['custom_data_binding'] : null,
Expand Down Expand Up @@ -194,7 +194,7 @@ protected function mutateFormDataBeforeFill(array $data): array
$components[] = [
'component_type' => 'form_field',
'form_field_id' => $field->form_field_id,
'custom_label' => $field->custom_label ?? $formField->label,
'custom_label' => $field->custom_label ?? null,
'customize_label' => $field->customize_label ?? null,
'custom_data_binding_path' => $field->custom_data_binding_path ?? $formField->data_binding_path,
'customize_data_binding_path' => $field->custom_data_binding_path ?? null,
Expand Down Expand Up @@ -246,7 +246,7 @@ protected function mutateFormDataBeforeFill(array $data): array
$formFieldsData[] = [
'form_field_id' => $field->form_field_id,
'label' => $field->label,
'custom_label' => $field->custom_label ?? $formField->label,
'custom_label' => $field->custom_label ?? null,
'customize_label' => $field->customize_label ?? null,
'custom_data_binding_path' => $field->custom_data_binding_path ?? $formField->data_binding_path,
'customize_data_binding_path' => $field->custom_data_binding_path ?? null,
Expand Down

0 comments on commit cf0b72d

Please sign in to comment.