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

fix(utils): replace itemLinkTo string with correct object #19

Merged
merged 1 commit into from
May 16, 2024
Merged
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
2 changes: 1 addition & 1 deletion convert_source_description/default_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

defaultContentItem: ContentItem = {
"item": "",
"itemLinkTo": "",
"itemLinkTo": {},
"itemDescription": "",
"folios": []
}
Expand Down
8 changes: 7 additions & 1 deletion convert_source_description/typed_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ class Folio(TypedDict):
systemGroups: List[List[System]]


class ContentItemLinkTo(TypedDict):
"""A typed dictionary that represents a content item linkTo section."""
complexId: str
sheetId: str


class ContentItem(TypedDict):
"""A typed dictionary that represents a content item."""
item: str
itemLinkTo: str
itemLinkTo: ContentItemLinkTo
itemDescription: str
folios: List[Folio]

Expand Down
15 changes: 8 additions & 7 deletions convert_source_description/utils_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def _get_item(self, para: Tag) -> ContentItem:
"""
# Initialize variables
item_label = ""
item_link_to = ""
item_link_to = {}
item_description = ""
delimiter = "("

Expand All @@ -475,16 +475,17 @@ def _get_item(self, para: Tag) -> ContentItem:
# Extract itemLabel
item_label = stripped_para_text[0].strip()

# Create itemLinkTo dictionary
sheet_id = item_label.replace(" ", "_").replace(".", "_").replace("*", "star")
complex_id = "".join(sheet_id.split("_")[0:2]).lower()

item_link_to = {"complexId": complex_id, "sheetId": sheet_id}

# When there is a slash in the item label,
# it means that we probably have multiple sketch items for a row table.
# In that case, link to 'SkRT'
if item_label.find("/") != -1:
item_link_to = "SkRT"
# In all other cases, link to the id created from the itemLabel
else:
item_link_to = (
item_label.replace(" ", "_").replace(".", "_").replace("*", "star")
)
item_link_to["sheetId"] = "SkRT"

# Extract itemDescription
# (re-add delimiter that was removed in the stripping action above
Expand Down