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

Make interface display names more human readable #589

Merged
merged 28 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a1cb481
Make interface display names more human readable
rly Feb 6, 2024
2bd7066
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 6, 2024
2d715d4
Update to use latest neuroconv and avoid conflicts with rest of repo
garrettmflynn Feb 8, 2024
96c488b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 8, 2024
48fd848
Same change for converters
garrettmflynn Feb 8, 2024
ad3c0ac
Merge branch 'interface_display_name' of https://github.com/Neurodata…
garrettmflynn Feb 8, 2024
977bfe4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 8, 2024
67ef0b0
Merge branch 'main' into interface_display_name
CodyCBakerPhD Feb 8, 2024
efe5aae
Update test_neuroconv.py
garrettmflynn Feb 12, 2024
e588ca7
Merge branch 'main' into interface_display_name
CodyCBakerPhD Feb 12, 2024
c82667d
Use alternative description and search for extension
garrettmflynn Feb 12, 2024
4757ff3
Merge branch 'interface_display_name' of https://github.com/Neurodata…
garrettmflynn Feb 12, 2024
2816907
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 12, 2024
9291249
Update e2e.test.ts
garrettmflynn Feb 12, 2024
17a745c
Update for new neuroconv version
garrettmflynn Feb 15, 2024
c9c151e
Merge branch 'main' into interface_display_name
garrettmflynn Feb 15, 2024
8d9c51a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 15, 2024
850af00
Merge branch 'main' into interface_display_name
CodyCBakerPhD Feb 19, 2024
b4cbe89
improve global
CodyCBakerPhD Feb 19, 2024
5a3c735
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 19, 2024
3e3f288
trigger during startup
CodyCBakerPhD Feb 19, 2024
acf50b8
Update pyflask/apis/startup.py
CodyCBakerPhD Feb 19, 2024
6d291c3
adjust name
CodyCBakerPhD Feb 19, 2024
c4de4ed
adjust name
CodyCBakerPhD Feb 19, 2024
d36870c
expose
CodyCBakerPhD Feb 19, 2024
b07e8ab
Revert to manual attribute grabbing
garrettmflynn Feb 19, 2024
5f44492
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 19, 2024
16e3b84
Merge branch 'main' into interface_display_name
CodyCBakerPhD Feb 19, 2024
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
21 changes: 17 additions & 4 deletions pyflask/manageNeuroconv/manage_neuroconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,32 @@ def get_class_ref_in_docstring(input_string):


def derive_interface_info(interface):

info = {"keywords": getattr(interface, "keywords", []), "description": ""}
if interface.__doc__:

if hasattr(interface, "associated_suffixes"):
info["suffixes"] = interface.associated_suffixes

if hasattr(interface, "info"):
info["description"] = interface.info

elif interface.__doc__:
info["description"] = re.sub(
remove_extra_spaces_pattern, " ", re.sub(doc_pattern, r"<code>\1</code>", interface.__doc__)
)

info["name"] = interface.__name__

return info


def get_all_converter_info() -> dict:
from neuroconv import converters
from neuroconv.converters import converter_list

return {name: derive_interface_info(converter) for name, converter in module_to_dict(converters).items()}
return {
getattr(converter, "display_name", converter.__name__) or converter.__name__: derive_interface_info(converter)
for converter in converter_list
}


def get_all_interface_info() -> dict:
Expand All @@ -201,7 +214,7 @@ def get_all_interface_info() -> dict:
]

return {
interface.__name__: derive_interface_info(interface)
getattr(interface, "display_name", interface.__name__) or interface.__name__: derive_interface_info(interface)
for interface in interface_list
if not interface.__name__ in exclude_interfaces_from_selection
}
Expand Down
4 changes: 3 additions & 1 deletion pyflask/tests/test_neuroconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ def test_get_all_interfaces(client):
"^.*Interface$": {
"type": "object",
"properties": {
"name": {"type": "string"},
"suffixes": {"type": "array", "items": {"type": "string"}},
"label": {"type": "string"},
"description": {"type": "string"},
"keywords": {"type": "array", "items": {"type": "string"}},
},
"additionalProperties": False,
"required": ["keywords"],
"required": ["name", "keywords"],
}
},
},
Expand Down
54 changes: 43 additions & 11 deletions src/renderer/src/stories/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ export class Search extends LitElement {
z-index: 1;
}

.structured-keywords {
font-size: 90%;
color: dimgrey;
}

.option:hover {
background: #f2f2f2;
cursor: pointer;
Expand Down Expand Up @@ -204,8 +209,12 @@ export class Search extends LitElement {
const options = this.shadowRoot.querySelectorAll(".option");
this.#options = Array.from(options).map((option) => {
const keywordString = option.getAttribute("data-keywords");
const keywords = keywordString ? JSON.parse(keywordString) : [];
return { option, keywords, label: option.querySelector(".label").innerText };
const structuredKeywordString = option.getAttribute("data-structured-keywords");

const keywords = keywordString ? JSON.parse(option.getAttribute("data-keywords")) : [];
const structuredKeywords = structuredKeywordString ? JSON.parse(structuredKeywordString) : {};

return { option, keywords, structuredKeywords, label: option.querySelector(".label").innerText };
});

this.#initialize();
Expand Down Expand Up @@ -256,8 +265,8 @@ export class Search extends LitElement {
});

// Check if the input value matches any of the keywords
this.#options.forEach(({ option, keywords = [] }, i) => {
keywords.forEach((keyword) => {
this.#options.forEach(({ option, keywords = [], structuredKeywords = {} }, i) => {
[...keywords, ...Object.values(structuredKeywords).flat()].forEach((keyword) => {
if (keyword.toLowerCase().includes(input.toLowerCase()) && !toShow.includes(i)) toShow.push(i);
});
});
Expand Down Expand Up @@ -317,13 +326,22 @@ export class Search extends LitElement {
listItemElement.classList.add("option");
listItemElement.setAttribute("hidden", "");
listItemElement.setAttribute("tabindex", -1);
if (option.keywords) listItemElement.setAttribute("data-keywords", JSON.stringify(option.keywords));

const { disabled, structuredKeywords, keywords } = option;

if (structuredKeywords)
listItemElement.setAttribute(
"data-structured-keywords",
JSON.stringify(option.structuredKeywords)
);
if (keywords) listItemElement.setAttribute("data-keywords", JSON.stringify(option.keywords));

listItemElement.addEventListener("click", (clickEvent) => {
clickEvent.stopPropagation();
this.#onSelect(option);
});

if (option.disabled) listItemElement.setAttribute("disabled", "");
if (disabled) listItemElement.setAttribute("disabled", "");

const container = document.createElement("div");

Expand All @@ -346,11 +364,25 @@ export class Search extends LitElement {

container.appendChild(label);

if (option.keywords) {
const keywords = document.createElement("small");
keywords.classList.add("keywords");
keywords.innerText = option.keywords.join(", ");
container.appendChild(keywords);
if (keywords) {
const keywordsElement = document.createElement("small");
keywordsElement.classList.add("keywords");
keywordsElement.innerText = option.keywords.join(", ");
container.appendChild(keywordsElement);
}

if (structuredKeywords) {
const div = document.createElement("div");
div.classList.add("structured-keywords");

Object.entries(structuredKeywords).forEach(([key, value]) => {
const keywordsElement = document.createElement("small");
const capitalizedKey = key[0].toUpperCase() + key.slice(1);
keywordsElement.innerHTML = `<b>${capitalizedKey}:</b> ${value.join(", ")}`;
div.appendChild(keywordsElement);
});

container.appendChild(div);
}

listItemElement.append(container);
Expand Down
21 changes: 15 additions & 6 deletions src/renderer/src/stories/pages/guided-mode/data/GuidedStructure.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,24 @@ export class GuidedStructurePage extends Page {
.then((res) => res.json())
.then((json) =>
Object.entries(json).map(([key, value]) => {
const category = categories.find(({ test }) => test.test(key))?.value;
const displayName = key.trim();

const interfaceName = value.name;

const category = categories.find(({ test }) => test.test(interfaceName))?.value;

const structuredKeywords = {
suffixes: value.suffixes ?? [],
};

return {
...value,
key,
value: key,
...value, // Contains label and name already (extra metadata)
key: displayName,
value: interfaceName,
structuredKeywords,
category,
disabled: !supportedInterfaces.includes(key),
}; // Has label and keywords property already
disabled: !supportedInterfaces.includes(interfaceName),
};
})
)
.catch((error) => console.error(error));
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ describe('E2E Test', () => {

await toNextPage('inspect')

}, 30 * 1000) // Wait for conversion to complete
}, 30 * 1000) // Wait for conversion preview to complete

test('Review NWB Inspector output', async () => {

Expand Down
Loading