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

feature/mx-1649 prevent and subtract #192

Merged
merged 84 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
8ca3090
first draft
cutoffthetop Sep 18, 2024
35601ab
Merge branch 'main' of https://github.com/robert-koch-institut/mex-ed…
cutoffthetop Sep 18, 2024
7256377
wip
cutoffthetop Sep 25, 2024
686f79e
rework, prepare, clean
cutoffthetop Sep 25, 2024
f49a9d4
add temporal case and up tests
cutoffthetop Sep 30, 2024
2555b67
Merge branch 'main' of https://github.com/robert-koch-institut/mex-ed…
cutoffthetop Sep 30, 2024
30b7fc4
lock
cutoffthetop Sep 30, 2024
a3790f1
Merge branch 'main' of https://github.com/robert-koch-institut/mex-ed…
cutoffthetop Oct 21, 2024
55aaa63
lock
cutoffthetop Oct 21, 2024
872108f
Merge branch 'main' of https://github.com/robert-koch-institut/mex-ed…
cutoffthetop Oct 24, 2024
49969ca
fix merge
cutoffthetop Oct 24, 2024
167cb37
lock
cutoffthetop Oct 25, 2024
c07ccde
lock and lint
cutoffthetop Oct 28, 2024
2493f98
fix handler
cutoffthetop Oct 29, 2024
f7c03fd
update common, pin requests
cutoffthetop Oct 29, 2024
6ef1c5a
Merge branch 'main' of https://github.com/robert-koch-institut/mex-ed…
cutoffthetop Oct 29, 2024
13e72cc
fix tests
cutoffthetop Oct 29, 2024
0724548
lint
cutoffthetop Oct 29, 2024
54aa8b1
fix test
cutoffthetop Oct 29, 2024
1199332
CL
cutoffthetop Oct 29, 2024
b55ea66
fix tests
cutoffthetop Oct 29, 2024
621efbb
include all pngs
cutoffthetop Oct 29, 2024
9acc637
feature/model update v3 (#137)
cutoffthetop Oct 29, 2024
4069837
fix yaml
cutoffthetop Oct 29, 2024
abed263
Merge branch 'feature/mx-1702-resolve-types' of https://github.com/ro…
cutoffthetop Oct 29, 2024
078887f
CL
cutoffthetop Oct 30, 2024
14df0c5
try multiprocessing.Process
cutoffthetop Oct 30, 2024
891d955
add ResettingGraphConnector to fix tests
cutoffthetop Oct 30, 2024
3ee21ba
enhance log msgs
cutoffthetop Oct 31, 2024
99fc450
make frontend_url a fixture for tests
cutoffthetop Oct 31, 2024
e05ba89
Update ghcr.io/robert-koch-institut/mex-backend Docker tag to v0.21.0…
RKIMetadataExchange Nov 4, 2024
f483a7e
Merge branch 'feature/mx-1702-resolve-types' of https://github.com/ro…
cutoffthetop Nov 4, 2024
6a615c7
Merge remote-tracking branch 'origin/main' into feature/mx-1703-resol…
cutoffthetop Nov 8, 2024
c10be8a
lint
cutoffthetop Nov 8, 2024
b3df13f
prepare editing WIP
cutoffthetop Nov 11, 2024
993f4fc
Merge branch 'main' of https://github.com/robert-koch-institut/mex-ed…
cutoffthetop Nov 11, 2024
72c558a
lock
cutoffthetop Nov 12, 2024
4507816
Merge remote-tracking branch 'origin/feature/mx-1702-resolve-types' i…
cutoffthetop Nov 12, 2024
64ce7df
lock
cutoffthetop Nov 12, 2024
63a598c
wip
cutoffthetop Nov 14, 2024
b2e1854
Merge branch 'main' of https://github.com/robert-koch-institut/mex-ed…
cutoffthetop Nov 20, 2024
b43b90c
restore gitignore
cutoffthetop Nov 20, 2024
6367524
clean up typing
cutoffthetop Nov 20, 2024
3a3041e
hold back preview-dialog for now
cutoffthetop Nov 20, 2024
d53c65f
bump versions
cutoffthetop Dec 2, 2024
55b9f6a
Merge branch 'main' of https://github.com/robert-koch-institut/mex-ed…
cutoffthetop Dec 2, 2024
1ba416d
Merge branch 'main' of https://github.com/robert-koch-institut/mex-ed…
cutoffthetop Dec 2, 2024
38dfdf8
lock
cutoffthetop Dec 2, 2024
5e733fb
fix logout signature
cutoffthetop Dec 2, 2024
0e08d9e
fix tests
cutoffthetop Dec 2, 2024
dd7dc1a
rename fixedX and editableX to editorX
cutoffthetop Dec 5, 2024
e289858
rename and clarify stuff
cutoffthetop Dec 11, 2024
4ff6175
Merge branch 'main' of https://github.com/robert-koch-institut/mex-ed…
cutoffthetop Dec 11, 2024
8f733eb
remove backend dep
cutoffthetop Dec 12, 2024
4436549
add ID provider, fix tests
cutoffthetop Dec 12, 2024
5deb1fe
Merge branch 'main' of https://github.com/robert-koch-institut/mex-ed…
cutoffthetop Dec 18, 2024
e6aadf0
add first transform test
cutoffthetop Dec 18, 2024
ca4e6d4
update CL and TODOs
cutoffthetop Dec 18, 2024
c3476cc
Merge branch 'main' of https://github.com/robert-koch-institut/mex-ed…
cutoffthetop Dec 18, 2024
08ccc61
configure ci
cutoffthetop Dec 18, 2024
f07fe7c
clean up
cutoffthetop Dec 18, 2024
8dc2d09
CL
cutoffthetop Dec 18, 2024
eee0bbc
update transform tests
cutoffthetop Dec 18, 2024
4a4f3ac
stringify identifiers
cutoffthetop Dec 18, 2024
4bcd41d
split up long transform func
cutoffthetop Dec 19, 2024
482f52d
add test stubs
cutoffthetop Dec 19, 2024
782d36e
more tests
cutoffthetop Dec 19, 2024
4bdafae
even more tests
cutoffthetop Dec 19, 2024
9d4d5e6
ever more tests
cutoffthetop Dec 19, 2024
5228816
stabilize test
cutoffthetop Dec 19, 2024
7fc2749
bump mex-backend
cutoffthetop Dec 19, 2024
1d7c86e
fix tests
cutoffthetop Dec 19, 2024
f77aef1
fix unset stemType
cutoffthetop Dec 19, 2024
c3e0359
and roundtrip test
cutoffthetop Dec 20, 2024
a200765
fix tests
cutoffthetop Dec 20, 2024
d8bdad9
Merge branch 'main' of https://github.com/robert-koch-institut/mex-ed…
cutoffthetop Jan 15, 2025
2cc5b39
Merge branch 'main' of https://github.com/robert-koch-institut/mex-ed…
cutoffthetop Jan 15, 2025
0f2c305
fix toast tests
cutoffthetop Jan 15, 2025
3f2208a
reset settings
cutoffthetop Jan 15, 2025
04a0fd3
Update tests/conftest.py
cutoffthetop Jan 21, 2025
92f1620
fix syntax
cutoffthetop Jan 21, 2025
588f5fa
explain b019 noqa
cutoffthetop Jan 21, 2025
69aea36
Merge branch 'main' of https://github.com/robert-koch-institut/mex-ed…
cutoffthetop Jan 21, 2025
a66e32d
make rules non-optional for transforms; explain enabled condition
cutoffthetop Jan 21, 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
5 changes: 4 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ jobs:
ports:
- 7687:7687
backend:
image: ghcr.io/robert-koch-institut/mex-backend:0.22.0
image: ghcr.io/robert-koch-institut/mex-backend:0.28.0
env:
MEX_BACKEND_API_USER_DATABASE: ${{ secrets.MEX_BACKEND_API_USER_DATABASE }}
MEX_BACKEND_API_KEY_DATABASE: ${{ secrets.MEX_BACKEND_API_KEY_DATABASE }}
MEX_IDENTITY_PROVIDER: graph
MEX_GRAPH_URL: neo4j://neo4j:7687
MEX_DEBUG: True
ports:
- 8080:8080

Expand Down Expand Up @@ -81,6 +83,7 @@ jobs:
env:
MEX_BACKEND_API_USER_DATABASE: ${{ secrets.MEX_BACKEND_API_USER_DATABASE }}
MEX_BACKEND_API_KEY: ${{ secrets.MEX_BACKEND_API_KEY }}
MEX_IDENTITY_PROVIDER: backend
run: |
pdm run editor run &
sleep 30 &&
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- add toggles for preventive and subtractive rules
- add functionality to edit component for submitting rules
- add utility function to escalate errors to all consoles
- temporarily add BackendIdentityProvider (stop-gap MX-1763)

### Changes

- bump cookiecutter template to 57e9b7
- rename FixedX and EditableX classes to EditorX for consistency

### Deprecated

### Removed

- drop dev-dependency to mex-backend, use the flush endpoint instead
- temporarily removed localization of temporals entity output

### Fixed

### Security
Expand Down
34 changes: 17 additions & 17 deletions mex/editor/components.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import reflex as rx

from mex.editor.edit.models import FixedValue
from mex.editor.edit.models import EditorValue


def fixed_internal_link(value: FixedValue) -> rx.Component:
"""Render a fixed value as a clickable internal link that reloads the edit page."""
def render_internal_link(value: EditorValue) -> rx.Component:
"""Render an editor value as a clickable internal link that loads the edit page."""
return rx.link(
value.text,
href=value.href,
Expand All @@ -13,8 +13,8 @@ def fixed_internal_link(value: FixedValue) -> rx.Component:
)


def fixed_external_link(value: FixedValue) -> rx.Component:
"""Render a fixed value as a clickable external link that opens in a new window."""
def render_external_link(value: EditorValue) -> rx.Component:
"""Render an editor value as a clickable external link that opens in a new tab."""
return rx.link(
value.text,
href=value.href,
Expand All @@ -24,25 +24,25 @@ def fixed_external_link(value: FixedValue) -> rx.Component:
)


def fixed_link(value: FixedValue) -> rx.Component:
"""Render a fixed value as a clickable link that reloads the edit page."""
def render_link(value: EditorValue) -> rx.Component:
"""Render an editor value as an internal or external link."""
return rx.cond(
value.external,
fixed_external_link(value),
fixed_internal_link(value),
render_external_link(value),
render_internal_link(value),
)


def fixed_text(value: FixedValue) -> rx.Component:
"""Render a fixed value as a text span."""
def render_text(value: EditorValue) -> rx.Component:
"""Render an editor value as a text span."""
return rx.text(
value.text,
as_="span",
)


def postfix_badge(value: FixedValue) -> rx.Component:
"""Render a generic badge after the fixed value."""
def postfix_badge(value: EditorValue) -> rx.Component:
"""Render a generic badge after an editor value."""
return rx.badge(
value.badge,
radius="full",
Expand All @@ -51,13 +51,13 @@ def postfix_badge(value: FixedValue) -> rx.Component:
)


def fixed_value(value: FixedValue) -> rx.Component:
"""Return a single fixed value."""
def render_value(value: EditorValue) -> rx.Component:
"""Render a single editor value."""
return rx.hstack(
rx.cond(
value.href,
fixed_link(value),
fixed_text(value),
render_link(value),
render_text(value),
),
rx.cond(
value.badge,
Expand Down
179 changes: 135 additions & 44 deletions mex/editor/edit/main.py
Original file line number Diff line number Diff line change
@@ -1,94 +1,185 @@
from typing import cast

import reflex as rx

from mex.editor.components import fixed_value
from mex.editor.edit.models import EditableField, EditablePrimarySource, FixedValue
from mex.editor.components import render_value
from mex.editor.edit.models import EditorField, EditorPrimarySource, EditorValue
from mex.editor.edit.state import EditState
from mex.editor.layout import page


def fixed_value_card(
field_name: str, primary_source: str | None, index: int, value: FixedValue
def editor_value_switch(
field_name: str,
primary_source: str | None,
value: EditorValue,
index: int,
) -> rx.Component:
"""Return a switch for toggling subtractive rules."""
return rx.switch(
checked=value.enabled,
on_change=lambda enabled: cast(EditState, EditState).toggle_field_value(
rababerladuseladim marked this conversation as resolved.
Show resolved Hide resolved
field_name,
value,
enabled,
),
custom_attrs={"data-testid": f"switch-{field_name}-{primary_source}-{index}"},
)


def editor_value_card(
field_name: str,
primary_source: str | None,
index: int,
value: EditorValue,
) -> rx.Component:
"""Return a card containing a single fixed value."""
"""Return a card containing a single editor value."""
return rx.card(
fixed_value(value),
rx.hstack(
render_value(value),
rx.cond(
cast(rx.vars.ArrayVar, EditState.editor_fields).contains(field_name),
editor_value_switch(field_name, primary_source, value, index),
),
),
style={"width": "30vw"},
custom_attrs={"data-testid": f"value-{field_name}_{primary_source}_{index}"},
custom_attrs={"data-testid": f"value-{field_name}-{primary_source}-{index}"},
)


def primary_source_switch(
field_name: str,
model: EditorPrimarySource,
) -> rx.Component:
"""Return a switch for toggling preventive rules."""
return rx.switch(
checked=model.enabled,
on_change=lambda enabled: cast(EditState, EditState).toggle_primary_source(
field_name,
cast(str, model.name.href),
enabled,
),
custom_attrs={"data-testid": f"switch-{field_name}-{model.identifier}"},
)


def editable_primary_source(
field_name: str, model: EditablePrimarySource
def primary_source_name(
field_name: str,
model: EditorPrimarySource,
) -> rx.Component:
"""Return the name of a primary source as a card with a preventive rule toggle."""
return rx.card(
rx.hstack(
render_value(model.name),
rx.cond(
cast(rx.vars.ArrayVar, EditState.editor_fields).contains(field_name),
primary_source_switch(field_name, model),
),
),
style={"width": "20vw"},
custom_attrs={
"data-testid": f"primary-source-{field_name}-{model.name.text}-name"
},
)


def editor_primary_source(
field_name: str,
model: EditorPrimarySource,
) -> rx.Component:
"""Return a horizontal grid of cards for editing one primary source."""
return rx.hstack(
rx.card(
fixed_value(model.name),
style={"width": "20vw"},
custom_attrs={
"data-testid": f"primary-source-{field_name}_{model.name.text}"
},
),
primary_source_name(field_name, model),
rx.vstack(
rx.foreach(
model.editor_values,
lambda value, index: fixed_value_card(
lambda value, index: editor_value_card(
field_name,
model.name.text,
index,
value,
),
)
),
),
custom_attrs={
"data-testid": f"primary-source-{field_name}-{model.name.text}",
},
)


def editable_field(model: EditableField) -> rx.Component:
def editor_field(model: EditorField) -> rx.Component:
"""Return a horizontal grid of cards for editing one field."""
return rx.hstack(
rx.card(
rx.text(model.name),
style={"width": "15vw"},
custom_attrs={"data-testid": f"field-{model.name}"},
custom_attrs={"data-testid": f"field-{model.name}-name"},
),
rx.foreach(
model.primary_sources,
lambda primary_source: editable_primary_source(
model.name,
primary_source,
),
rx.vstack(
rx.foreach(
model.primary_sources,
lambda primary_source: editor_primary_source(
model.name,
primary_source,
),
)
),
width="90vw",
custom_attrs={"data-testid": f"field-{model.name}"},
role="row",
)


def submit_button() -> rx.Component:
"""Render a submit button to save the rule set."""
return rx.button(
"Save",
color_scheme="jade",
size="3",
on_click=EditState.submit_rule_set,
style={"margin": "1em 0"},
custom_attrs={"data-testid": "submit-button"},
)


def edit_heading() -> rx.Component:
"""Return the heading for the edit page."""
return rx.heading(
rx.hstack(
rx.foreach(
EditState.item_title,
render_value,
),
),
custom_attrs={"data-testid": "edit-heading"},
style={
"margin": "1em 0",
"whiteSpace": "nowrap",
"overflow": "hidden",
"textOverflow": "ellipsis",
"maxWidth": "80vw",
},
)


def index() -> rx.Component:
"""Return the index for the edit component."""
return page(
rx.box(
rx.heading(
rx.hstack(
rx.foreach(
EditState.item_title,
fixed_value,
)
),
custom_attrs={"data-testid": "edit-heading"},
style={
"margin": "1em 0",
"whiteSpace": "nowrap",
"overflow": "hidden",
"textOverflow": "ellipsis",
"maxWidth": "80%",
},
),
edit_heading(),
rx.vstack(
rx.foreach(
EditState.fields,
editable_field,
editor_field,
),
rx.cond(
EditState.fields,
submit_button(),
),
),
style={"width": "100%", "margin": "0 2em 1em"},
style={
"width": "100%",
"margin": "0 2em 1em",
},
custom_attrs={"data-testid": "edit-section"},
),
)
15 changes: 9 additions & 6 deletions mex/editor/edit/models.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import reflex as rx

from mex.editor.models import FixedValue
from mex.common.types import MergedPrimarySourceIdentifier
from mex.editor.models import EditorValue


class EditablePrimarySource(rx.Base):
class EditorPrimarySource(rx.Base):
"""Model for describing the editor state for one primary source."""

name: FixedValue
editor_values: list[FixedValue]
name: EditorValue
identifier: MergedPrimarySourceIdentifier
editor_values: list[EditorValue] = []
enabled: bool = True


class EditableField(rx.Base):
class EditorField(rx.Base):
"""Model for describing the editor state for a single field."""

name: str
primary_sources: list[EditablePrimarySource]
primary_sources: list[EditorPrimarySource] = []
Loading
Loading