Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reference datatype #10572

Merged
merged 59 commits into from
Mar 8, 2024

Conversation

chiatt
Copy link
Member

@chiatt chiatt commented Feb 1, 2024

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Description of Change

Stubs out the reference data type with a basic widget and node config.

Issues Solved

#10552

For reviewer:

  1. After running migrations you can test using lists in the test data: PYTHONPATH="../arches" python3 manage.py shell -c "from tests.views.controlled_lists_tests import ControlledListTests; ControlledListTests.setUpTestData()"

You could also use the following which has some pref labels in German for localization testing :

insert into controlled_lists (id, name, dynamic) values ('06b58ca6-bcb6-46b3-8aaa-64cca94ab8f8', 'menu', FALSE); 
insert into controlled_list_items values ('1ea5f71d-7d56-42d4-8d71-c806b0766d29', 'https://www.subec.com/lunch', 0, '06b58ca6-bcb6-46b3-8aaa-64cca94ab8f8', NULL);
insert into controlled_list_items values ('fd9508dc-2aab-4c46-85ae-dccce1200035', 'https://www.subec.com/dinner', 2, '06b58ca6-bcb6-46b3-8aaa-64cca94ab8f8', NULL);
insert into controlled_list_item_labels values ('26c6a505-3d20-4fa3-9a42-44678a754164', 'lunch', '1ea5f71d-7d56-42d4-8d71-c806b0766d29', 'en', 'prefLabel');
insert into controlled_list_item_labels values ('ca1a40cf-8642-48cb-8fdb-c4cdab0b711d', 'Mittagessen', '1ea5f71d-7d56-42d4-8d71-c806b0766d29', 'de', 'prefLabel');
insert into controlled_list_item_labels values ('23b4efbd-2e46-4b3f-8d75-2f3b2bb96af2', 'dinner', 'fd9508dc-2aab-4c46-85ae-dccce1200035', 'en', 'prefLabel');
insert into controlled_list_item_labels values ('5ce4841d-e543-42f2-b47b-1fbca21f6a04', 'supper', 'fd9508dc-2aab-4c46-85ae-dccce1200035', 'en', 'altLabel');
insert into controlled_list_item_labels values ('e8676242-f0c7-4e3d-b031-fded4960cd86', 'Abendessen', 'fd9508dc-2aab-4c46-85ae-dccce1200035', 'de', 'prefLabel');

insert into controlled_list_items values ('228b53af-80ba-4bb2-ad46-1d873c2ff4ec', 'https://www.subec.com/sandwich', 1, '06b58ca6-bcb6-46b3-8aaa-64cca94ab8f8', '1ea5f71d-7d56-42d4-8d71-c806b0766d29');
insert into controlled_list_items values ('a050ddbd-a1d9-42a6-a0b5-101683b0a0c9', 'https://www.subec.com/salmon', 3, '06b58ca6-bcb6-46b3-8aaa-64cca94ab8f8', 'fd9508dc-2aab-4c46-85ae-dccce1200035');

insert into controlled_list_item_labels values ('2dbe4f9d-b16d-4ba7-8fbb-7b56dc9f334d', 'sandwich', '228b53af-80ba-4bb2-ad46-1d873c2ff4ec', 'en', 'prefLabel');
insert into controlled_list_item_labels values ('27524045-e76c-4698-9cb6-8e567b25a586', 'salmon', 'a050ddbd-a1d9-42a6-a0b5-101683b0a0c9', 'en', 'prefLabel');
insert into controlled_list_item_labels values ('3583c278-b953-40c4-8c09-8ad62c0a93f5', 'lox', 'a050ddbd-a1d9-42a6-a0b5-101683b0a0c9', 'en', 'altLabel');
insert into controlled_list_item_labels values ('c18e6183-3d95-4c1c-909e-a13b946ae2d9', 'Sandwich', '228b53af-80ba-4bb2-ad46-1d873c2ff4ec', 'de', 'prefLabel');
insert into controlled_list_item_labels values ('8ce82adc-ce0f-4968-8e67-acd1d942cf23', 'Lachs', 'a050ddbd-a1d9-42a6-a0b5-101683b0a0c9', 'de', 'prefLabel');
  1. Create a node with using the reference datatype
  2. Leave multiple values off. (The multiple values parameter controls whether the node will accept only one list item value or many. If false, the widget will display a concept dropdown for a single item. If true the widget will support multiple selections.
  3. Create a tile ensuring that the concept widget only supports selection of one value.
  4. Go back to the graph designer and switch multiple values to true. Refresh your card in the resource editor. The widget should now support multiple values.
  5. Data saved to the tile should have this structure:
    {
      "uri": "https://www.subec.com/dinner",
      "labels": [
        {
          "id": "23b4efbd-2e46-4b3f-8d75-2f3b2bb96af2",
          "value": "dinner",
          "language": "en",
          "valuetype": "prefLabel"
        },
        {
          "id": "5ce4841d-e543-42f2-b47b-1fbca21f6a04",
          "value": "supper",
          "language": "en",
          "valuetype": "altLabel"
        },
        {
          "id": "e8676242-f0c7-4e3d-b031-fded4960cd86",
          "value": "Abendessen",
          "language": "de",
          "valuetype": "prefLabel"
        }
      ],
      "listid": "fd9508dc-2aab-4c46-85ae-dccce1200035"
    }
  ]
  1. Change your system language to de and ensure the widget localizes the options and selected values.

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Cyrus! I left some initial comments, and I'll look forward to giving this a functional test next week.

What do you think about taking the opportunity to write one sanity-check unit test in datatype_tests.py?

@jacobtylerwalls jacobtylerwalls force-pushed the controlled-list-item-editor branch from f27434d to 4203f3c Compare February 8, 2024 19:20
@chiatt chiatt force-pushed the add-reference-datatype branch 2 times, most recently from 207e602 to 4e71fbd Compare February 8, 2024 21:27
@chiatt chiatt force-pushed the add-reference-datatype branch 2 times, most recently from f6e13d9 to 1872a49 Compare February 22, 2024 16:34
jacobtylerwalls

This comment was marked as resolved.

@jacobtylerwalls

This comment was marked as resolved.

@jacobtylerwalls jacobtylerwalls force-pushed the controlled-list-item-editor branch from a5ce96c to 9410ad1 Compare February 22, 2024 23:19
Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updates looks great! One last Q for this re: the valueAndSelectionDiffer(), and then I'll merge. 👍

current_language = requested_language or get_language()
for item in self.get_tile_data(tile)[str(node.nodeid)]:
for label in item["labels"]:
if label["language"] == current_language and label["valuetype"] == "prefLabel":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is okay for now, but in the next iteration we could probably use rank_label() so that we have good fallbacks. Right now it will fallback to nothing.

@chiatt
Copy link
Member Author

chiatt commented Mar 8, 2024

Updates looks great! One last Q for this re: the valueAndSelectionDiffer(), and then I'll merge. 👍

Nice catch - thanks for looking into that. I'm not sure why I decided I needed to call that method in the value subscription. I've removed it and made a couple minor changes to ensure the dirty state clears properly if a user choses the same options with which the tile loaded (as opposed to just clicking 'Cancel Edit').

@jacobtylerwalls jacobtylerwalls force-pushed the add-reference-datatype branch from 1438197 to d7daa7c Compare March 8, 2024 22:39
Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looking great!

@jacobtylerwalls jacobtylerwalls merged commit 6dc5da9 into controlled-list-item-editor Mar 8, 2024
4 checks passed
@jacobtylerwalls jacobtylerwalls deleted the add-reference-datatype branch March 8, 2024 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add reference datatype
4 participants