Skip to content

Commit

Permalink
[Track-297] RF update work title in model to remove hanging dash (#2467)
Browse files Browse the repository at this point in the history
  • Loading branch information
tolkamps1 authored Dec 6, 2024
1 parent 586b0bc commit be731e8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
11 changes: 10 additions & 1 deletion epictrack-api/src/api/models/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
String,
Text,
and_,
case,
exists,
func,
or_
Expand Down Expand Up @@ -143,7 +144,15 @@ def title(self):
def title(self):
"""SQL expression for title."""
from api.models.work_type import WorkType # pylint:disable=import-outside-toplevel
return func.concat(Project.name, " - ", WorkType.name, " - ", self.simple_title) # pylint:disable=not-callable
return (
case(
(
func.coalesce(self.simple_title, "") != "",
func.concat(Project.name, " - ", WorkType.name, " - ", self.simple_title), # pylint:disable=not-callable
),
else_=func.concat(Project.name, " - ", WorkType.name)
)
)

@hybrid_property
def anticipated_referral_date(self):
Expand Down
2 changes: 1 addition & 1 deletion epictrack-api/tests/unit/apis/test_works.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_validate_work(client, auth_header):
del payload["work_id"]
response = client.get(url, query_string=payload, headers=auth_header)
assert response.status_code == HTTPStatus.OK
assert response.json["exists"] is False
assert response.json["exists"]

# Scenario 3: Creating new work with new name
payload = TestWorkInfo.validation_work.value
Expand Down
10 changes: 9 additions & 1 deletion epictrack-web/src/components/work/WorkForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,15 @@ export default function WorkForm({
}, [workTypeId, projectId, projects, workTypes]);

React.useEffect(() => {
setValue("title", `${titlePrefix}${simple_title}`);
if (simple_title) {
setValue("title", `${titlePrefix}${simple_title}`);
} else {
// If simple_title is not set, remove the hanging separator
const trimmedPrefix = titlePrefix.endsWith(titleSeparator)
? titlePrefix.slice(0, -titleSeparator.length)
: titlePrefix;
setValue("title", trimmedPrefix);
}
}, [titlePrefix, simple_title]);

const handleProjectChange = async (id: string) => {
Expand Down

0 comments on commit be731e8

Please sign in to comment.