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

refactor(areas): remove UI properties form fields #1950

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 0 additions & 33 deletions antarest/study/business/areas/properties_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@
# Keep the order
FILTER_OPTIONS = ["hourly", "daily", "weekly", "monthly", "annual"]
DEFAULT_FILTER_VALUE = FILTER_OPTIONS
DEFAULT_UI = {
"color_r": 230,
"color_g": 108,
"color_b": 44,
}


def encode_color(ui: Dict[str, Any]) -> str:
data = {**DEFAULT_UI, **ui}
return f"{data['color_r']},{data['color_g']},{data['color_b']}"


def decode_color(encoded_color: str, current_ui: Optional[Dict[str, int]]) -> Dict[str, Any]:
r, g, b = map(int, encoded_color.split(","))
return {**(current_ui or {}), "color_r": r, "color_g": g, "color_b": b}


def sort_filter_options(options: Iterable[str]) -> List[str]:
Expand All @@ -60,9 +45,6 @@ class AdequacyPatchMode(EnumIgnoreCase):


class PropertiesFormFields(FormFieldsBaseModel):
color: Optional[str] = Field(regex="^\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*$")
pos_x: Optional[float]
pos_y: Optional[float]
energy_cost_unsupplied: Optional[float]
energy_cost_spilled: Optional[float]
non_dispatch_power: Optional[bool]
Expand All @@ -89,21 +71,6 @@ def validation(cls, values: Dict[str, Any]) -> Dict[str, Any]:


FIELDS_INFO: Dict[str, FieldInfo] = {
# `color` must be before `pos_x` and `pos_y`, because they are include in the `decode_color`'s return dict value
"color": {
"path": UI_PATH,
"encode": encode_color,
"decode": decode_color,
"default_value": encode_color(DEFAULT_UI),
},
"pos_x": {
"path": f"{UI_PATH}/x",
"default_value": 0.0,
},
"pos_y": {
"path": f"{UI_PATH}/y",
"default_value": 0.0,
},
"energy_cost_unsupplied": {
"path": THERMAL_PATH.format(field="unserverdenergycost"),
"default_value": 0.0,
Expand Down
9 changes: 0 additions & 9 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,9 +1095,6 @@ def test_area_management(client: TestClient, admin_access_token: str, study_id:
res_properties_config_json["filterSynthesis"] = set(res_properties_config_json["filterSynthesis"])
res_properties_config_json["filterByYear"] = set(res_properties_config_json["filterByYear"])
assert res_properties_config_json == {
"color": "230,108,44",
"posX": 0.0,
"posY": 0.0,
"energyCostUnsupplied": 0.0,
"energyCostSpilled": 0.0,
"nonDispatchPower": True,
Expand All @@ -1112,9 +1109,6 @@ def test_area_management(client: TestClient, admin_access_token: str, study_id:
f"/v1/studies/{study_id}/areas/area 1/properties/form",
headers=admin_headers,
json={
"color": "123,108,96",
"posX": 3.4,
"posY": 9.0,
"energyCostUnsupplied": 2.0,
"energyCostSpilled": 4.0,
"nonDispatchPower": False,
Expand All @@ -1130,9 +1124,6 @@ def test_area_management(client: TestClient, admin_access_token: str, study_id:
res_properties_config_json["filterSynthesis"] = set(res_properties_config_json["filterSynthesis"])
res_properties_config_json["filterByYear"] = set(res_properties_config_json["filterByYear"])
assert res_properties_config_json == {
"color": "123,108,96",
"posX": 3.4,
"posY": 9.0,
"energyCostUnsupplied": 2.0,
"energyCostSpilled": 4.0,
"nonDispatchPower": False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useOutletContext } from "react-router";
import { useMemo } from "react";
import SelectFE from "../../../../../../common/fieldEditors/SelectFE";
import Fieldset from "../../../../../../common/Fieldset";
import ColorPickerFE from "../../../../../../common/fieldEditors/ColorPickerFE";
import SwitchFE from "../../../../../../common/fieldEditors/SwitchFE";
import NumberFE from "../../../../../../common/fieldEditors/NumberFE";
import { useFormContextPlus } from "../../../../../../common/Form";
Expand All @@ -27,23 +26,6 @@ function Fields() {

return (
<>
<Fieldset legend={t("global.general")}>
<ColorPickerFE
name="color"
label={t("global.color")}
control={control}
/>
<NumberFE
name="posX"
label={t("study.modelization.properties.posX")}
control={control}
/>
<NumberFE
name="posY"
label={t("study.modelization.properties.posY")}
control={control}
/>
</Fieldset>
<Fieldset legend={t("study.modelization.properties.energyCost")}>
<NumberFE
name="energyCostUnsupplied"
Expand Down
Loading