Spaces:
Running
Running
File size: 1,511 Bytes
cb5b71d dc92053 cb5b71d edf454b cb5b71d edf454b dc92053 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import enum
import streamlit as st
from core.query_params import expand_record_set
from core.state import Metadata
from core.state import RecordSet
class RecordSetEvent(enum.Enum):
"""Event that triggers a RecordSet change."""
NAME = "NAME"
DESCRIPTION = "DESCRIPTION"
IS_ENUMERATION = "IS_ENUMERATION"
HAS_DATA = "HAS_DATA"
CHANGE_DATA = "CHANGE_DATA"
def handle_record_set_change(event: RecordSetEvent, record_set: RecordSet, key: str):
value = st.session_state[key]
if event == RecordSetEvent.NAME:
old_name = record_set.name
new_name = value
if old_name != new_name:
metadata: Metadata = st.session_state[Metadata]
metadata.rename_record_set(old_name=old_name, new_name=new_name)
record_set.name = value
elif event == RecordSetEvent.DESCRIPTION:
record_set.description = value
elif event == RecordSetEvent.IS_ENUMERATION:
record_set.is_enumeration = value
elif event == RecordSetEvent.HAS_DATA:
if value:
record_set.data = []
else:
record_set.data = None
elif event == RecordSetEvent.CHANGE_DATA:
for index, new_value in value["edited_rows"].items():
record_set.data[index] = {**record_set.data[index], **new_value}
for row in value["added_rows"]:
record_set.data.append(row)
for row in value["deleted_rows"]:
del record_set.data[row]
expand_record_set(record_set=record_set)
|