Skip to content

Commit

Permalink
Populate comboboxes only with available options according to the sele…
Browse files Browse the repository at this point in the history
…cted df version
  • Loading branch information
insolor committed Jun 30, 2024
1 parent 1b01e56 commit bf91ab2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# package-build

Run:

```commandline
poe run
```
13 changes: 9 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@

column1, column2 = st.columns(2)

df_version_options = hook_metadata.df_version_options

with column1:
df_version: str = st.selectbox(label="DF version", options=hook_metadata.df_versions)
operating_systems: str = st.selectbox(label="Operating system/platform", options=hook_metadata.operating_systems)
df_version: str = st.selectbox(label="DF version", options=sorted(df_version_options, reverse=True))
operating_systems: str = st.selectbox(
label="Operating system/platform",
options=df_version_options[df_version].operating_systems,
)

with column2:
df_variant: str = st.selectbox(label="DF variant", options=hook_metadata.variants)
df_variant: str = st.selectbox(label="DF variant", options=df_version_options[df_version].variants)
dict_entry: DictInfoEntry = st.selectbox(label="Language", options=dict_metadata)

hook_info = hook_metadata.mapping.get((df_version, df_variant, operating_systems))
hook_info = hook_metadata.hook_info.get((df_version, df_variant, operating_systems))

if not hook_info:
st.write("Cannot create package for these parameters")
Expand Down
34 changes: 18 additions & 16 deletions package_build/parse_metadata.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import re
from dataclasses import dataclass, field
from typing import NamedTuple

from .models import HookInfoEntry


@dataclass
class DFVersionOptions:
variants: set[str] = field(default_factory=set)
operating_systems: set[str] = field(default_factory=set)


class MetadataParsingResult(NamedTuple):
df_versions: list[str]
variants: list[str]
operating_systems: list[str]
mapping: dict[tuple[str, str, str], HookInfoEntry]
df_version_options: dict[str, DFVersionOptions]
hook_info: dict[tuple[str, str, str], HookInfoEntry]


def parse_url(url: str) -> tuple[str, str, str]:
Expand All @@ -21,21 +26,18 @@ def parse_url(url: str) -> tuple[str, str, str]:


def parse_metadata(metadata: list[HookInfoEntry]) -> MetadataParsingResult:
mapping = {}
df_versions = set()
variants = set()
operating_systems = set()
version_to_metadata_mapping: dict[str, DFVersionOptions] = {}
hook_info = {}

for item in metadata:
version, variant, os = parse_url(item.offsets)
mapping[(version, variant, os)] = item
df_versions.add(version)
variants.add(variant)
operating_systems.add(os)
hook_info[(version, variant, os)] = item
df_version_info = version_to_metadata_mapping.get(version, DFVersionOptions())
df_version_info.variants.add(variant)
df_version_info.operating_systems.add(os)
version_to_metadata_mapping[version] = df_version_info

return MetadataParsingResult(
sorted(df_versions, reverse=True),
sorted(variants),
sorted(operating_systems),
mapping,
version_to_metadata_mapping,
hook_info,
)

0 comments on commit bf91ab2

Please sign in to comment.