8000 Add index definitions to the data dictionary form/Separate index form by beeyayjay · Pull Request #4375 · GetDKAN/dkan · GitHub
[go: up one dir, main page]

Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2c2d0e4
Initial commit of updates to include indexes and index fields to the …
kaise-lafrai Apr 29, 2024
5396653
Added working cancel button for index, fixed errors appearing in log
kaise-lafrai May 14, 2024
bb42cf8
Removed unused code, fixed index fields cancel button
kaise-lafrai May 20, 2024
5e0ee4c
Added validation for index fields form, refactored code, refactored t…
kaise-lafrai May 24, 2024
e529acc
Fully functional edit experience for index fields (#4204)
kaise-lafrai Jul 8, 2024
620bced
Editable Index (#4239)
kaise-lafrai Aug 1, 2024
2250243
Index UI unit tests (#4262)
dmundra Aug 19, 2024
b7f844b
Updated data dictionary widget functional test to test all fields in …
dmundra Aug 29, 2024
b10bd49
Added Indexes edit unit tests (#4266)
dmundra Aug 30, 2024
567107f
Some simple code cleanup (white space, removal of commented out code,…
dmundra Sep 5, 2024
a9ccde9
WCMS-20047: Data Dictionary Documentation (#4271)
rovcase Sep 6, 2024
bb76f74
Data dictionary indexes code refactoring (#4280)
dmundra Sep 10, 2024
c7d7cfe
Reverted changes to checkIndexEditingField and checkIndexEditing. Upd…
dmundra Sep 10, 2024
4b4cf50
Adding code comments. (#4289)
dmundra Sep 18, 2024
ea018c7
Dictionary-Widget: Streamline the button labels for the Index and Ind…
rovcase Oct 24, 2024
ffb4d44
Provisional commit
Nov 27, 2024
ae7e367
In progress
Dec 3, 2024
a320129
Added indexes to admin view.
Dec 3, 2024
53fe56f
Temp save
Dec 4, 2024
0d46835
Temp save
Dec 4, 2024
2f45d07
Temp save
Dec 9, 2024
ec4fdf8
Temp save
Dec 9, 2024
058a91a
Index keyname changes and bug fixes.
Dec 12, 2024
1f3c275
Other indexes.
Jan 2, 2025
982d12f
Index edit works.
Jan 5, 2025
326d0b5
Add index field and cancel work.
Jan 5, 2025
69ee91f
Some cleanup.
Jan 6, 2025
622f4a9
More stuff
Jan 6, 2025
c9b743b
Some cleanup
Jan 6, 2025
3e82443
Updated data dictionary admin list. Added 'Add index' link.
Jan 6, 2025
a3bf332
Removed test field and made index length optional.
Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add index field and cancel work.
  • Loading branch information
Beth Jacobson committed Jan 6, 2025
commit 326d0b518a7fbab53d7a0f041428a94bb5fb2f3e
8 changes: 4 additions & 4 deletions modules/data_dictionary_widget/src/Fields/FieldCallbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ public static function addSubformCallback(array &$form, FormStateInterface $form
$op = $trigger['#op'];
$form_state->set('add_new_field', '');
// Get the current fields data.
$current_index_fields = $form["field_json_metadata"]["widget"][0]["dictionary_fields"]["data"]["#rows"];
$current_dictionary_fields = $form["field_json_metadata"]["widget"][0]["dictionary_fields"]["data"]["#rows"];
$current_index = $form["field_json_metadata"]["widget"][0]['indexes']["data"]["#rows"];
// $current_index_fields = $form["field_json_metadata"]["widget"][0]['indexes']["fields"]["data"]["#rows"] ?? [];

if ($current_index_fields) {
$form_state->set('current_dictionary_fields', $current_index_fields);
if ($current_dictionary_fields) {
$form_state->set('current_dictionary_fields', $current_dictionary_fields);
}

if ($op === 'cancel') {
Expand All @@ -125,7 +125,7 @@ public static function addSubformCallback(array &$form, FormStateInterface $form
$form_state->set('cancel', FALSE);
}

8000 $form_state->set('current_dictionary_fields', $current_index_fields);
$form_state->set('current_dictionary_fields', $current_dictionary_fields);
$form_state->set('current_index', $current_index);
$form_state->setRebuild();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static function addIndex() {
],
];

$add_index['group']['index']['fields'] = [
$add_index['group'] = [
'#type' => 'fieldset',
'#title' => t('Fields'),
'#prefix' => '<div id = field-json-metadata-index-fields>',
Expand All @@ -59,7 +59,7 @@ public static function addIndex() {
],
];

$add_index['group']['index']['fields']['add_row_button'] = IndexFieldButtons::addIndexFieldButton();
$add_index['group']['add_row_button'] = IndexFieldButtons::addIndexFieldButton();
$add_index['group']['index']['save_index'] = IndexFieldButtons::submitIndexButton('add_index', NULL);
$add_index['group']['index']['cancel_index'] = IndexFieldButtons::cancelIndexButton('cancel_index', NULL);

Expand All @@ -69,7 +69,7 @@ public static function addIndex() {
/**
* Create fields for adding an index field.
*/
public static function addIndexFields($current_index_fields) {
public static function addIndexFields() {
$id = "field-json-metadata-index-fields-new";
$add_index_fields['#access'] = FALSE;
$add_index_fields['group'] = [
Expand All @@ -80,15 +80,15 @@ public static function addIndexFields($current_index_fields) {
'#markup' => t('<div class="claro-details__description">Must be keys from the fields object.</div>'),
];

$add_index_fields['group']['index']['fields']['name'] = [
'#name' => 'field_json_metadata[0][indexes][fields][field_collection][group][index][fields][name]',
$add_index_fields['group']['name'] = [
'#name' => 'field_json_metadata[0][indexes][fields][field_collection][group][name]',
'#type' => 'textfield',
'#title' => 'Name',
'#required' => TRUE,
];

$add_index_fields['group']['index']['fields']['length'] = self::createIndexFieldLengthField();
$add_index_fields['group']['index']['fields']['actions'] = self::createIndexActionFields($id);
$add_index_fields['group']['length'] = self::createIndexFieldLengthField();
$add_index_fields['group']['actions'] = self::createIndexActionFields($id);

return $add_index_fields;
}
Expand All @@ -98,7 +98,7 @@ public static function addIndexFields($current_index_fields) {
*/
private static function createIndexFieldLengthField() {
return [
'#name' => 'field_json_metadata[0][indexes][fields][field_collection][group][index][fields][length]',
'#name' => 'field_json_metadata[0][indexes][fields][field_collection][group][length]',
'#type' => 'number',
'#title' => 'Length',
'#required' => TRUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public static function submitIndexFieldButton($location, $indexKey) {
'indexes',
'fields',
'edit_fields',
$indexKeyExplode[3],
$indexKeyExplode[1],
'length',
],
];
Expand Down Expand Up @@ -240,11 +240,11 @@ public static function submitIndexButton($location, $indexKey) {
public static function cancelIndexFieldButton($location, $indexKey, $id) {
$callbackId = ($id === 'field-json-metadata-index-fields-new') ? 'subIndexFormExistingFieldAjax' : 'subIndexFormAjax';
$callbackClass = $location == 'edit' ? 'indexEditSubformCallback' : 'indexAddSubformCallback';
$op = $location == 'edit' && $indexKey ? 'abort_' . $indexKey : 'cancel_index_field';
$op = $location == 'edit' && $indexKey ? 'abort_' . $indexKey : 'cancel';
$cancel_index_button = [
'#type' => 'submit',
'#value' => t('Cancel adding field to index'),
'#name' => 'cancel_index_field',
'#name' => 'cancel_dictionary_field',
'#op' => $op,
'#submit' => [
[
Expand All @@ -254,7 +254,7 @@ public static function cancelIndexFieldButton($location, $indexKey, $id) {
],
'#ajax' => [
'callback' => "Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::$callbackId",
'wrapper' => $id,
'wrapper' => 'field-json-metadata-dictionary-fields',
'effect' => 'fade',
],
'#limit_validation_errors' => [],
Expand Down
39 changes: 15 additions & 24 deletions modules/data_dictionary_widget/src/Indexes/IndexFieldCallbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ public static function indexAddSubformCallback(array &$form, FormStateInterface
// Get the current fields data.
$current_dictionary_fields = $form["field_json_metadata"]["widget"][0]["dictionary_fields"]["data"]["#rows"] ?? [];
$current_index = $form["field_json_metadata"]["widget"][0]['indexes']["data"]["#rows"] ?? [];
$current_index_fields = $form["field_json_metadata"]["widget"][0]['indexes']["fields"]["data"]["#rows"] ?? [];

if ($current_index_fields) {
$form_state->set('current_dictionary_fields', $current_index_fields);
if ($current_dictionary_fields) {
$form_state->set('current_dictionary_fields', $current_dictionary_fields);
}

// If cancelling index field.
if ($op === 'cancel_index_field') {
if ($op === 'cancel_dictionary_field') {
// Set the display to show the current index fields values.
$form_state->set('cancel_index_field', TRUE);
$form_state->set('cancel_dictionary_field', TRUE);
// Hide the field collection.
$form_state->set('add_new_field', '');
}
Expand All @@ -39,34 +38,33 @@ public static function indexAddSubformCallback(array &$form, FormStateInterface
// @TODO not being used so maybe removable or update the comment.
$form_state->set('add_field', '');
// Get the form fields for adding new index fields.
$add_index_fields = IndexFieldAddCreation::addIndexFields($current_index_fields);
$add_index_fields = IndexFieldAddCreation::addIndexFields($current_dictionary_fields);
// Set the fields in the field collection.
$form_state->set('add_new_field', $add_index_fields);
// @TODO not being used so maybe removable or update the comment.
$form_state->set('index_added', FALSE);
// @TODO not being used so maybe removable or update the comment.
$form_state->set('adding_new_index_fields', TRUE);
// $form_state->set('adding_new_index_fields', TRUE);
}

// If saving new index field.
if ($op === 'add_field') {
// @TODO not being used so maybe removable or update the comment.
$form_state->set('add_new_field', '');
// Get and save the entered values.
$form_state->set('new_index_fields', $form_state->getUserInput());
$form_state->set('new_dictionary_fields', $form_state->getUserInput());
// @TODO not being used so maybe removable or update the comment.
$form_state->set('add', TRUE);
// Set the display to show the entered values.
$form_state->set('cancel_index_field', FALSE);
// @TODO not being used so maybe removable or update the comment.
$form_state->set('adding_new_index_fields', FALSE);
// $form_state->set('adding_new_index_fields', FALSE);
}

// Let's retain the fields that are already stored on the form,
// but aren't currently being modified.
$form_state->set('current_dictionary_fields', $current_dictionary_fields);
$form_state->set('current_index', $current_index);
$form_state->set('current_dictionary_fields', $current_index_fields);
// Let's rebuild the form.
$form_state->setRebuild();
}
Expand Down Expand Up @@ -101,7 +99,7 @@ public static function indexAddCallback(array &$form, FormStateInterface $form_s
// 'Add index'
if ($op === 'add_new_field') {
// Get the form fields for adding new index.
$add_new_index = IndexFieldAddCreation::addIndex();
$add_new_index = IndexFieldAddCreation::addIndexFields();
// Set the new_index values to empty.
$form_state->set('add_new_field', '');
// Set the fields in the field collection.
Expand All @@ -113,13 +111,13 @@ public static function indexAddCallback(array &$form, FormStateInterface $form_s
// Empty the fields in the field collection.
$form_state->set('add_new_index', '');
// Get and save the entered values.
$form_state->set('new_index', $form_state->getUserInput());
$form_state->set('new_dictionary_fields', $form_state->getUserInput());
// @TODO not being used so maybe removable or update the comment.
$form_state->set('add', TRUE);
// @TODO not being used so maybe removable or update the comment.
$form_state->set('index_added', TRUE);
// Set the display to show the entered values.
$form_state->set('cancel_index', FALSE);
$form_state->set('cancel_update', FALSE);
}

// Let's retain the fields that are already stored on the form,
Expand Down Expand Up @@ -291,27 +289,20 @@ public static function indexFormAjax(array &$form, FormStateInterface $form_stat
// Validation errors skip submit callbacks, this will set the index fields
// in the correct location.
if ($index_fields["data"]) {
$form["field_json_metadata"]["widget"][0]["indexes"]["field_collection"]["group"]["index"]["fields"] = $index_fields;
$form["field_json_metadata"]["widget"][0]["dictionary_fields"]["field_collection"]["group"] = $index_fields;
$form["field_json_metadata"]["widget"][0]["dictionary_fields"]['#access'] = FALSE;
}

return $form["field_json_metadata"]["widget"][0]["indexes"];
}

/**
* Ajax callback to return index fields fieldset with 'Add Field' button.
*/
public static function subIndexFormFieldAjax(array &$form, FormStateInterface $form_state) {
return $form["field_json_metadata"]["widget"][0]["indexes"]["field_collection"]["group"]["index"]["fields"];
return $form["field_json_metadata"]["widget"][0]["dictionary_fields"];
}

/**
* Ajax callback to return index fields fieldset with existing fields and 'Add
* Field' button.
*/
public static function subIndexFormExistingFieldAjax(array &$form, FormStateInterface $form_state) {
$form["field_json_metadata"]["widget"][0]["indexes"]["field_collection"]["group"]["index"]["fields"]["add_row_button"]['#access'] = TRUE;
return $form["field_json_metadata"]["widget"][0]["indexes"]["field_collection"]["group"]["index"]["fields"]["add_row_button"];
$form["field_json_metadata"]["widget"][0]["indexes"]["field_collection"]["group"]["add_row_button"]['#access'] = TRUE;
return $form["field_json_metadata"]["widget"][0]["indexes"]["field_collection"]["group"]["add_row_button"];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function createIndexFieldsDataRows($index_field_values, $current_i
'#access' => ((bool) $current_index_fields || (bool) $index_fields_data_results),
'#type' => 'table',
'#header' => ['NAME', 'LENGTH'],
'#rows' => $form_state->get('cancel_index_field') ? $current_index_fields : ($index_fields_data_results ?? []),
'#rows' => $form_state->get('cancel_dictionary_field') ? $current_index_fields : ($index_fields_data_results ?? []),
'#tree' => TRUE,
'#theme' => 'custom_index_fields_table',
];
Expand All @@ -68,7 +68,7 @@ public static function createIndexDataRows($current_indexes, $index_data_results
'#header' => ['NAME', 'TYPE', 'FIELDS'],
'#prefix' => '<div id = field-json-metadata-indexes>',
'#suffix' => '</div>',
'#rows' => $form_state->get('cancel_index') ? $current_indexes : ($index_data_results ?? []),
'#rows' => $form_state->get('cancel_update') ? $current_indexes : ($index_data_results ?? []),
'#tree' => TRUE,
'#theme' => 'custom_index_table',
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public static function processIndexFieldsDataResults($index_data_results, $curre

$data_index_fields_pre = [
[
"name" => $index_field_group['index A93C ']['fields']["name"],
"length" => (int) $index_field_group['index']['fields']["length"],
"name" => $index_field_group["name"],
"length" => (int) $index_field_group["length"],
],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class IndexValidation {
* The complete form structure.
*/
public static function indexFieldsValidation(array $element, FormStateInterface $form_state, array &$form) {
$index_fields_fieldset = $form["field_json_metadata"]["widget"][0]["indexes"]["field_collection"]["group"]["index"]["fields"] ?? NULL;
$index_fields_fieldset = $form["field_json_metadata"]["widget"][0]["indexes"]["field_collection"]["group"] ?? NULL;
$fields = $form["field_json_metadata"]["widget"][0]["dictionary_fields"]["data"]["#rows"] ?? NULL;

if ($index_fields_fieldset && !$fields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ protected function processDataResults($data_results, $current_fields, $field_val
}

if (isset($field_values["field_json_metadata"][0]["dictionary_fields"]["field_collection"])) {
$index_field_group = $field_values["field_json_metadata"][0]["dictionary_fields"]["field_collection"]["group"];
$index_field_group = $field_values["field_json_metadata"][0]["indexes"]["fields"]["field_collection"]["group"];

$data_index_fields_pre = [
[
"name" => $index_field_group['index']['fields']["name"],
"length" => (int) $index_field_group['index']['fields']["length"],
"name" => $index_field_group["name"],
"length" => (int) $index_field_group["length"],
],
];
}
Expand Down Expand Up @@ -202,7 +202,7 @@ protected static function createDataRows($current_dictionary_fields, $data_resul
'#access' => ((bool) $current_dictionary_fields || (bool) $data_results),
'#type' => 'table',
'#header' => ['NAME', 'LENGTH'],
'#rows' => $form_state->get('cancel_index_field') ? $current_dictionary_fields : ($data_results ?? []),
'#rows' => $form_state->get('cancel_dictionary_field') ? $current_dictionary_fields : ($data_results ?? []),
'#tree' => TRUE,
'#theme' => 'custom_index_fields_table',
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public function testDataDictionaryWidgetBehavior() {
// Add an index field.
// Use the name to distinguish the button from the data dictionary fields.
$page->pressButton('add_field');
$page->fillField('field_json_metadata[0][indexes][fields][field_collection][group][index][fields][name]', $test_index_name);
$page->fillField('field_json_metadata[0][indexes][fields][field_collection][group][index][fields][length]', $test_index_length);
$page->fillField('field_json_metadata[0][indexes][fields][field_collection][group][name]', $test_index_name);
$page->fillField('field_json_metadata[0][indexes][fields][field_collection][group][length]', $test_index_length);
// Need to distinguish the add button on the index fields vs the one for data dictionary fields.
$page->pressButton('Save field to index');
$page->pressButton('Save index');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ public function testIndexesFieldCollectionDictionaryWidget() {

$this->assertNotNull($element["indexes"]["fields"]["field_collection"]);
$this->assertArrayHasKey('group', $element["indexes"]["fields"]["field_collection"], 'Indexes Fields Group Does Not Exist On The Data Dictionary Form');
$this->assertArrayHasKey('name', $element["indexes"]["fields"]["field_collection"]["group"]["index"]["fields"], 'Indexes Fields Name Does Not Exist On The Data Dictionary Form');
$this->assertArrayHasKey('length', $element["indexes"]["fields"]["field_collection"]["group"]["index"]["fields"], 'Indexes Fields Length Does Not Exist On The Data Dictionary Form');
$this->assertArrayHasKey('save_index_settings', $element["indexes"]["fields"]["field_collection"]["group"]["index"]["fields"]["actions"], 'Add button Does Not Exist On The Data Dictionary Form');
$this->assertArrayHasKey('cancel_index_setti 622B ngs', $element["indexes"]["fields"]["field_collection"]["group"]["index"]["fields"]["actions"], 'Cancel button Does Not Exist On The Data Dictionary Form');
$this->assertArrayHasKey('name', $element["indexes"]["fields"]["field_collection"]["group"], 'Indexes Fields Name Does Not Exist On The Data Dictionary Form');
$this->assertArrayHasKey('length', $element["indexes"]["fields"]["field_collection"]["group"], 'Indexes Fields Length Does Not Exist On The Data Dictionary Form');
$this->assertArrayHasKey('save_index_settings', $element["indexes"]["fields"]["field_collection"]["group"]["actions"], 'Add button Does Not Exist On The Data Dictionary Form');
$this->assertArrayHasKey('cancel_index_settings', $element["indexes"]["fields"]["field_collection"]["group"]["actions"], 'Cancel button Does Not Exist On The Data Dictionary Form');

$this->assertArrayHasKey('save_index', $element["indexes"]["field_collection"]["group"]["index"], 'Submit Index button Does Not Exist On The Data Dictionary Form');
$this->assertArrayHasKey('cancel_index', $element["indexes"]["field_collection"]["group"]["index"], 'Cancel Index button Does Not Exist On The Data Dictionary Form');
$this->assertArrayHasKey('cancel_update', $element["indexes"]["field_collection"]["group"]["index"], 'Cancel Index button Does Not Exist On The Data Dictionary Form');
}

/**
Expand Down
0