Replace local maybe_put helpers

This commit is contained in:
2026-06-21 14:30:40 +02:00
parent cd4a01a2c8
commit d3c21247e0
7 changed files with 32 additions and 39 deletions

View File

@@ -45,6 +45,7 @@ after each item.
- [x] `desktop/shell_live/code_entity_editor.ex`
- [x] `scripting/runtime.ex`
- [x] `desktop/external_links.ex`
- [x] `MapUtils.maybe_put/3` replacements
- [x] `desktop/error_html.ex` (verified keep: still required by Phoenix `render_errors` wiring)
- [x] `desktop/health_controller.ex` (verified keep: current Phoenix route wiring still expects a controller module)
- [x] `desktop/folder_picker.ex` (verified keep: no equivalent `Desktop.OS` picker primitive exists to inline onto)

View File

@@ -942,13 +942,16 @@ defmodule BDS.AI.ChatTools do
defp search_filters(arguments) do
%{}
|> maybe_put(:category, arguments["category"])
|> maybe_put(:tags, arguments["tags"])
|> maybe_put(:language, arguments["language"])
|> maybe_put(:missing_translation_language, arguments["missingTranslationLanguage"])
|> maybe_put(:year, arguments["year"])
|> maybe_put(:month, arguments["month"])
|> maybe_put(:status, BDS.BoundedAtoms.post_status(arguments["status"]))
|> BDS.MapUtils.maybe_put(:category, BDS.MapUtils.blank_to_nil(arguments["category"]))
|> BDS.MapUtils.maybe_put(:tags, BDS.MapUtils.blank_to_nil(arguments["tags"]))
|> BDS.MapUtils.maybe_put(:language, BDS.MapUtils.blank_to_nil(arguments["language"]))
|> BDS.MapUtils.maybe_put(
:missing_translation_language,
BDS.MapUtils.blank_to_nil(arguments["missingTranslationLanguage"])
)
|> BDS.MapUtils.maybe_put(:year, arguments["year"])
|> BDS.MapUtils.maybe_put(:month, arguments["month"])
|> BDS.MapUtils.maybe_put(:status, BDS.BoundedAtoms.post_status(arguments["status"]))
|> Map.put(:offset, normalize_offset(arguments["offset"]))
|> Map.put(:limit, normalize_limit(arguments["limit"]))
end
@@ -995,10 +998,6 @@ defmodule BDS.AI.ChatTools do
end
end
defp maybe_put(map, _key, nil), do: map
defp maybe_put(map, _key, ""), do: map
defp maybe_put(map, key, value), do: Map.put(map, key, value)
defp counted_terms(project_id, field) do
Repo.all(
from post in Post, where: post.project_id == ^project_id, select: field(post, ^field)
@@ -1012,7 +1011,11 @@ defmodule BDS.AI.ChatTools do
defp metadata_attrs(arguments, keys) do
Enum.reduce(keys, %{}, fn key, acc ->
maybe_put(acc, BDS.MapUtils.safe_atomize_key(key), arguments[key])
BDS.MapUtils.maybe_put(
acc,
BDS.MapUtils.safe_atomize_key(key),
BDS.MapUtils.blank_to_nil(arguments[key])
)
end)
end

View File

@@ -693,7 +693,7 @@ defmodule BDS.Desktop.ShellLive.ImportEditor do
wxr_file_path: analysis_state.file_path,
last_analysis_result: report
}
|> maybe_put(:name, AnalysisState.suggested_definition_name(report))
|> BDS.MapUtils.maybe_put(:name, AnalysisState.suggested_definition_name(report))
case ImportDefinitions.update_definition(definition_id, attrs) do
{:ok, _definition} ->
@@ -1453,7 +1453,4 @@ defmodule BDS.Desktop.ShellLive.ImportEditor do
defp blank?(value), do: value in [nil, ""]
defp blank_to_nil(""), do: nil
defp blank_to_nil(value), do: value
defp maybe_put(map, _key, nil), do: map
defp maybe_put(map, key, value), do: Map.put(map, key, value)
end

View File

@@ -160,7 +160,7 @@ defmodule BDS.Desktop.ShellLive.ImportEditor.AnalysisState do
wxr_file_path: analysis_state.file_path,
last_analysis_result: report
}
|> maybe_put(:name, suggested_definition_name(report))
|> BDS.MapUtils.maybe_put(:name, suggested_definition_name(report))
case ImportDefinitions.update_definition(definition_id, attrs) do
{:ok, _definition} ->
@@ -274,10 +274,6 @@ defmodule BDS.Desktop.ShellLive.ImportEditor.AnalysisState do
get_in(report, [:site_info, :url]) || get_in(report, [:site_info, :title])
end
@spec maybe_put(term(), term(), term()) :: term()
def maybe_put(map, _key, nil), do: map
def maybe_put(map, key, value), do: Map.put(map, key, value)
@spec allow_repo_sandbox(term()) :: term()
def allow_repo_sandbox(pid) when is_pid(pid) do
if Code.ensure_loaded?(Ecto.Adapters.SQL.Sandbox) do

View File

@@ -264,7 +264,7 @@ defmodule BDS.ImportAnalysis do
status: item.status
}
maybe_put(base, :resolution, item.resolution)
BDS.MapUtils.maybe_put(base, :resolution, item.resolution)
end
defp summary_item(item) do
@@ -276,7 +276,7 @@ defmodule BDS.ImportAnalysis do
status: item.status
}
maybe_put(base, :resolution, item.resolution)
BDS.MapUtils.maybe_put(base, :resolution, item.resolution)
end
defp summarize_post_items(items) do
@@ -546,9 +546,6 @@ defmodule BDS.ImportAnalysis do
end)
end
defp maybe_put(map, _key, nil), do: map
defp maybe_put(map, key, value), do: Map.put(map, key, value)
defp blank_to_nil(nil), do: nil
defp blank_to_nil(""), do: nil
defp blank_to_nil(value), do: value

View File

@@ -40,10 +40,13 @@ defmodule BDS.ImportDefinitions do
%ImportDefinition{} = definition ->
updates =
%{}
|> maybe_put(:name, BDS.MapUtils.attr(attrs, :name))
|> maybe_put(:wxr_file_path, BDS.MapUtils.attr(attrs, :wxr_file_path))
|> maybe_put(:uploads_folder_path, BDS.MapUtils.attr(attrs, :uploads_folder_path))
|> maybe_put(
|> BDS.MapUtils.maybe_put(:name, BDS.MapUtils.attr(attrs, :name))
|> BDS.MapUtils.maybe_put(:wxr_file_path, BDS.MapUtils.attr(attrs, :wxr_file_path))
|> BDS.MapUtils.maybe_put(
:uploads_folder_path,
BDS.MapUtils.attr(attrs, :uploads_folder_path)
)
|> BDS.MapUtils.maybe_put(
:last_analysis_result,
normalize_analysis_result(BDS.MapUtils.attr(attrs, :last_analysis_result))
)
@@ -86,9 +89,6 @@ defmodule BDS.ImportDefinitions do
)
end
defp maybe_put(map, _key, nil), do: map
defp maybe_put(map, key, value), do: Map.put(map, key, value)
alias BDS.MapUtils
defp normalize_analysis_result(nil), do: nil

View File

@@ -266,8 +266,11 @@ defmodule BDS.Tags do
|> Enum.sort_by(&String.downcase(&1.name))
|> Enum.map(fn tag ->
%{"name" => tag.name}
|> maybe_put("color", tag.color)
|> maybe_put("postTemplateSlug", tag.post_template_slug)
|> BDS.MapUtils.maybe_put("color", BDS.MapUtils.blank_to_nil(tag.color))
|> BDS.MapUtils.maybe_put(
"postTemplateSlug",
BDS.MapUtils.blank_to_nil(tag.post_template_slug)
)
end)
Persistence.atomic_write(path, Jason.encode!(payload, pretty: true))
@@ -386,8 +389,4 @@ defmodule BDS.Tags do
:ok
end
defp maybe_put(map, _key, nil), do: map
defp maybe_put(map, _key, ""), do: map
defp maybe_put(map, key, value), do: Map.put(map, key, value)
end