Skip to content

Commit f7677b0

Browse files
committed
server: fix updating HUMAN_TITLE in Edit Grammar Element UI
This change removes a previously implemented "clever" optimization that skipped saving an element if none of its fields appeared to be modified. Over time, this check became outdated due to the introduction of new features such as HUMAN_TITLE, PROPERTIES/IS_COMPOSITE, PROPERTIES/VIEW_STYLE, and others. Closes #2341
1 parent 02a4091 commit f7677b0

File tree

6 files changed

+183
-30
lines changed

6 files changed

+183
-30
lines changed

docs/strictdoc_04_release_notes.sdoc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ TITLE: Unreleased
5252
[TEXT]
5353
MID: c536381cea6842f0b77c1aa5ac942ce0
5454
STATEMENT: >>>
55-
This release includes the following enhancements.
55+
This release includes the following enhancements and bugfixes.
5656

5757
**1) A small improvement to the behavior of the LEVEL/AUTO_LEVEL fields.**
5858

@@ -102,6 +102,12 @@ In particular, some ReqIF files contain fields that follow neither ReqIF nor SDo
102102
Previously, the fields TITLE, STATEMENT, DESCRIPTION, or CONTENT were used to determine whether a field should be treated as single-line or multiline. Under the new behavior, if none of these fields are present, all fields will be treated as multiline by default.
103103

104104
In the future, we may introduce a separate field for the GrammarElement field declarations, for example, to explicitly specify whether a field should be interpreted as Title, Meta, Content, etc.
105+
106+
**7) Fix for updating HUMAN_TITLE in Edit Grammar Element UI.**
107+
108+
This change removes a previously implemented "clever" optimization that skipped saving a grammar element if none of its fields appeared to be modified. Over time, this check became outdated due to the introduction of new grammar element features such as HUMAN_TITLE, PROPERTIES/IS_COMPOSITE, PROPERTIES/VIEW_STYLE, and others. As a result, the issue manifested as a no-op where updates, such as changing a HUMAN_TITLE, were not saved to disk after submitting the form.
109+
110+
Thanks to @zheylmun for reporting this issue.
105111
<<<
106112

107113
[[/SECTION]]

strictdoc/core/transforms/update_grammar_element.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(
2929
self.document: SDocDocument = document
3030
self.traceability_index: TraceabilityIndex = traceability_index
3131

32-
def perform(self) -> bool:
32+
def perform(self) -> None:
3333
form_object: GrammarElementFormObject = self.form_object
3434
document: SDocDocument = self.document
3535
existing_element: GrammarElement = document.grammar.get_element_by_mid(
@@ -61,23 +61,9 @@ def perform(self) -> bool:
6161
#
6262
document_grammar_field_names = updated_element.get_field_titles()
6363

64-
existing_document_grammar_field_names = (
65-
existing_element.get_field_titles()
66-
)
67-
grammar_changed = (
68-
document_grammar_field_names
69-
!= existing_document_grammar_field_names
70-
)
7164
existing_requirement_element = document.grammar.elements_by_type[
7265
existing_element.tag
7366
]
74-
grammar_changed = (
75-
grammar_changed
76-
or existing_requirement_element.relations
77-
!= updated_element.relations
78-
)
79-
if not grammar_changed:
80-
return False
8167

8268
document.grammar.update_element(existing_element, updated_element)
8369

@@ -138,5 +124,3 @@ def perform(self) -> bool:
138124
new_relations.append(requirement_relation_)
139125
requirement.relations = new_relations
140126
requirement.ordered_fields_lookup = new_ordered_fields_lookup
141-
142-
return True

strictdoc/server/routers/main_router.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,18 +2377,7 @@ async def document__save_grammar_element(request: Request) -> Response:
23772377
document=document,
23782378
traceability_index=export_action.traceability_index,
23792379
)
2380-
grammar_changed = update_grammar_action.perform()
2381-
2382-
# If the grammar has not changed, do nothing and save the edit form.
2383-
if not grammar_changed:
2384-
output = form_object.render_close_form()
2385-
return HTMLResponse(
2386-
content=output,
2387-
status_code=200,
2388-
headers={
2389-
"Content-Type": "text/vnd.turbo-stream.html",
2390-
},
2391-
)
2380+
update_grammar_action.perform()
23922381

23932382
# Re-generate the document's SDOC.
23942383
SDWriter(project_config).write_to_file(document)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[DOCUMENT]
2+
TITLE: Example 1
3+
UID: VC-SOFTWARE-SPEC
4+
VERSION: Git commit: @GIT_VERSION, Git branch: @GIT_BRANCH
5+
DATE: @GIT_COMMIT_DATETIME
6+
PREFIX: EXAMPLE-SPEC-
7+
ROOT: True
8+
9+
[GRAMMAR]
10+
ELEMENTS:
11+
- TAG: TEXT
12+
FIELDS:
13+
- TITLE: UID
14+
HUMAN_TITLE: Human title for UID
15+
TYPE: String
16+
REQUIRED: False
17+
- TITLE: STATEMENT
18+
TYPE: String
19+
REQUIRED: False
20+
- TAG: SECTION
21+
PROPERTIES:
22+
IS_COMPOSITE: True
23+
PREFIX: None
24+
VIEW_STYLE: Narrative
25+
FIELDS:
26+
- TITLE: UID
27+
TYPE: String
28+
REQUIRED: False
29+
- TITLE: TITLE
30+
TYPE: String
31+
REQUIRED: True
32+
- TITLE: STATEMENT
33+
TYPE: String
34+
REQUIRED: False
35+
- TAG: REQUIREMENT
36+
FIELDS:
37+
- TITLE: UID
38+
HUMAN_TITLE: UIDs will be human readable and follow a structure rather than use random strings
39+
TYPE: String
40+
REQUIRED: False
41+
- TITLE: STATUS
42+
TYPE: String
43+
REQUIRED: False
44+
- TITLE: TITLE
45+
TYPE: String
46+
REQUIRED: False
47+
- TITLE: STATEMENT
48+
TYPE: String
49+
REQUIRED: False
50+
- TITLE: RATIONALE
51+
TYPE: String
52+
REQUIRED: False
53+
- TITLE: COMMENT
54+
TYPE: String
55+
REQUIRED: False
56+
RELATIONS:
57+
- TYPE: Parent
58+
- TYPE: File
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[DOCUMENT]
2+
TITLE: Example 1
3+
UID: VC-SOFTWARE-SPEC
4+
VERSION: Git commit: @GIT_VERSION, Git branch: @GIT_BRANCH
5+
DATE: @GIT_COMMIT_DATETIME
6+
PREFIX: EXAMPLE-SPEC-
7+
ROOT: True
8+
9+
[GRAMMAR]
10+
ELEMENTS:
11+
- TAG: TEXT
12+
FIELDS:
13+
- TITLE: UID
14+
TYPE: String
15+
REQUIRED: False
16+
- TITLE: STATEMENT
17+
TYPE: String
18+
REQUIRED: False
19+
- TAG: SECTION
20+
PROPERTIES:
21+
IS_COMPOSITE: True
22+
PREFIX: None
23+
VIEW_STYLE: Narrative
24+
FIELDS:
25+
- TITLE: UID
26+
TYPE: String
27+
REQUIRED: False
28+
- TITLE: TITLE
29+
TYPE: String
30+
REQUIRED: True
31+
- TITLE: STATEMENT
32+
TYPE: String
33+
REQUIRED: False
34+
- TAG: REQUIREMENT
35+
FIELDS:
36+
- TITLE: UID
37+
HUMAN_TITLE: UIDs will be human readable and follow a structure rather than use random strings
38+
TYPE: String
39+
REQUIRED: False
40+
- TITLE: STATUS
41+
TYPE: String
42+
REQUIRED: False
43+
- TITLE: TITLE
44+
TYPE: String
45+
REQUIRED: False
46+
- TITLE: STATEMENT
47+
TYPE: String
48+
REQUIRED: False
49+
- TITLE: RATIONALE
50+
TYPE: String
51+
REQUIRED: False
52+
- TITLE: COMMENT
53+
TYPE: String
54+
REQUIRED: False
55+
RELATIONS:
56+
- TYPE: Parent
57+
- TYPE: File
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from tests.end2end.e2e_case import E2ECase
2+
from tests.end2end.end2end_test_setup import End2EndTestSetup
3+
from tests.end2end.helpers.screens.document.form_edit_grammar import (
4+
Form_EditGrammar,
5+
)
6+
from tests.end2end.helpers.screens.document.form_edit_grammar_elements import (
7+
Form_EditGrammarElements,
8+
)
9+
from tests.end2end.helpers.screens.project_index.screen_project_index import (
10+
Screen_ProjectIndex,
11+
)
12+
from tests.end2end.server import SDocTestServer
13+
14+
15+
class Test(E2ECase):
16+
def test(self):
17+
test_setup = End2EndTestSetup(path_to_test_file=__file__)
18+
19+
with SDocTestServer(
20+
input_path=test_setup.path_to_sandbox
21+
) as test_server:
22+
self.open(test_server.get_host_and_port())
23+
24+
screen_project_index = Screen_ProjectIndex(self)
25+
26+
screen_project_index.assert_on_screen()
27+
screen_project_index.assert_contains_document("Example 1")
28+
29+
screen_document = screen_project_index.do_click_on_first_document()
30+
31+
screen_document.assert_on_screen_document()
32+
screen_document.assert_header_document_title("Example 1")
33+
34+
screen_document.assert_text("Example 1")
35+
36+
form_edit_grammar: Form_EditGrammarElements = (
37+
screen_document.do_open_modal_form_edit_grammar()
38+
)
39+
form_edit_grammar.assert_on_grammar()
40+
41+
form_edit_grammar_element: Form_EditGrammar = (
42+
form_edit_grammar.do_click_edit_grammar_element(1)
43+
)
44+
form_edit_grammar_element.assert_on_grammar()
45+
46+
form_edit_grammar_element.assert_tab_is_open("Fields")
47+
48+
uid_field_mid = (
49+
form_edit_grammar_element.get_existing_mid_by_field_name("UID")
50+
)
51+
52+
uid_human_title = "Human title for UID"
53+
54+
form_edit_grammar_element.do_fill_in_grammar_field_human_title_mid(
55+
uid_field_mid, uid_human_title
56+
)
57+
form_edit_grammar_element.do_form_submit()
58+
59+
assert test_setup.compare_sandbox_and_expected_output()

0 commit comments

Comments
 (0)