|
12 | 12 | import dash_uploader as du |
13 | 13 | import pandas as pd |
14 | 14 | import plotly.graph_objects as go |
15 | | -from config import GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS |
| 15 | +from config import GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS_PRE_V4 |
| 16 | +from config import GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS_V4 |
16 | 17 | from config import GM_FILTER_DROPDOWN_MENU_OPTIONS |
17 | 18 | from config import GM_RESULTS_TABLE_CHECKL_OPTIONAL_COLUMNS |
18 | 19 | from config import GM_RESULTS_TABLE_MANDATORY_COLUMNS |
@@ -528,7 +529,7 @@ def gm_filter_create_initial_block(block_id: str) -> dmc.Grid: |
528 | 529 | ), |
529 | 530 | dcc.Dropdown( |
530 | 531 | id={"type": "gm-filter-dropdown-bgc-class-dropdown", "index": block_id}, |
531 | | - options=GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS, |
| 532 | + options=GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS_PRE_V4, |
532 | 533 | multi=True, |
533 | 534 | style={"display": "none"}, |
534 | 535 | ), |
@@ -631,7 +632,7 @@ def gm_filter_display_blocks( |
631 | 632 | "type": "gm-filter-dropdown-bgc-class-dropdown", |
632 | 633 | "index": new_block_id, |
633 | 634 | }, |
634 | | - options=GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS, |
| 635 | + options=GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS_PRE_V4, |
635 | 636 | multi=True, |
636 | 637 | style={"display": "none"}, |
637 | 638 | ), |
@@ -663,36 +664,64 @@ def gm_filter_display_blocks( |
663 | 664 | Output({"type": "gm-filter-dropdown-bgc-class-dropdown", "index": MATCH}, "placeholder"), |
664 | 665 | Output({"type": "gm-filter-dropdown-ids-text-input", "index": MATCH}, "value"), |
665 | 666 | Output({"type": "gm-filter-dropdown-bgc-class-dropdown", "index": MATCH}, "value"), |
| 667 | + Output({"type": "gm-filter-dropdown-bgc-class-dropdown", "index": MATCH}, "options"), |
666 | 668 | Input({"type": "gm-filter-dropdown-menu", "index": MATCH}, "value"), |
| 669 | + Input("mibig-version-selector", "value"), |
| 670 | + State({"type": "gm-filter-dropdown-bgc-class-dropdown", "index": MATCH}, "value"), |
667 | 671 | ) |
668 | 672 | def gm_filter_update_placeholder( |
669 | | - selected_value: str, |
670 | | -) -> tuple[dict[str, str], dict[str, str], str, str, str, list[Any]]: |
671 | | - """Update the placeholder text and style of input fields based on the dropdown selection. |
| 673 | + selected_value: str, mibig_version: str, current_bgc_value: list |
| 674 | +) -> tuple[dict[str, str], dict[str, str], str, str, str, list[Any], list[dict]]: |
| 675 | + """Update the placeholder text, style, and options of input fields based on the dropdown selection and MIBiG version. |
672 | 676 |
|
673 | 677 | Args: |
674 | 678 | selected_value: The value selected in the dropdown menu. |
| 679 | + mibig_version: The selected MIBiG version. |
| 680 | + current_bgc_value: Currently selected BGC class values. |
675 | 681 |
|
676 | 682 | Returns: |
677 | | - A tuple containing style, placeholder, and value updates for the input fields. |
| 683 | + A tuple containing style, placeholder, value, and options updates for the input fields. |
678 | 684 | """ |
679 | | - if not ctx.triggered: |
680 | | - # Callback was not triggered by user interaction, don't change anything |
681 | | - raise dash.exceptions.PreventUpdate |
| 685 | + # Determine which option set to use based on MIBiG version |
| 686 | + if mibig_version == "v4_plus": |
| 687 | + bgc_options = GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS_V4 |
| 688 | + else: |
| 689 | + bgc_options = GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS_PRE_V4 |
| 690 | + |
| 691 | + # Check what triggered the callback |
| 692 | + triggered_id = ctx.triggered_id |
| 693 | + |
| 694 | + # If MIBiG version changed, clear the BGC class selection |
| 695 | + if triggered_id == "mibig-version-selector": |
| 696 | + new_bgc_value = [] |
| 697 | + else: |
| 698 | + # Otherwise keep the current selection |
| 699 | + new_bgc_value = current_bgc_value |
| 700 | + |
| 701 | + # Update the styles and placeholders based on the dropdown selection |
682 | 702 | if selected_value == "GCF_ID": |
683 | | - return {"display": "block"}, {"display": "none"}, "1, 2, 3, ...", "", "", [] |
| 703 | + return ( |
| 704 | + {"display": "block"}, |
| 705 | + {"display": "none"}, |
| 706 | + "1, 2, 3, ...", |
| 707 | + "", |
| 708 | + "", |
| 709 | + new_bgc_value, |
| 710 | + bgc_options, |
| 711 | + ) |
684 | 712 | elif selected_value == "BGC_CLASS": |
685 | 713 | return ( |
686 | 714 | {"display": "none"}, |
687 | 715 | {"display": "block"}, |
688 | 716 | "", |
689 | 717 | "Select one or more BGC classes", |
690 | 718 | "", |
691 | | - [], |
| 719 | + new_bgc_value, |
| 720 | + bgc_options, |
692 | 721 | ) |
693 | 722 | else: |
694 | 723 | # This case should never occur due to the Literal type, but it satisfies mypy |
695 | | - return {"display": "none"}, {"display": "none"}, "", "", "", [] |
| 724 | + return {"display": "none"}, {"display": "none"}, "", "", "", new_bgc_value, bgc_options |
696 | 725 |
|
697 | 726 |
|
698 | 727 | # ------------------ MG Filter functions ------------------ # |
|
0 commit comments