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

Desktop: Fixes #4891: Solve "Resource Id not provided" error #4943

Merged
merged 2 commits into from
May 13, 2021

Conversation

Subhra264
Copy link
Contributor

Fixes: #4891

A function openItemById is created inside app-desktop/gui/NoteEditor/utils/contextMenu.ts just to avoid duplicate code. The useMessageHandler hook and menuItems both use the openItemById function so that the user gets the same experience on ctrl+click or right-click+open a link.

Testing

Manual Testing

Manually tested both on markdown editor and the TinyMCE editor( with note-links, resource-links; performing both the operations: ctrl+click and right-click+open ).

Unit testing

Sorry ( again ), I couldn't find a way to write a unit test for it. Maybe it is possible to add a test, but I think it would be very ( very) complex ( so need some guide ).

@@ -53,17 +55,52 @@ function handleCopyToClipboard(options: ContextMenuOptions) {
}
}

export function menuItems(): ContextMenuItems {
export async function openItemById(options: any, dispatch: Function) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the code, you only need an ID and an optional hash, so pass this to the function explicitely: itemId: string, dispatch:Function, hash:string = '' Please do not use "any" as it disables type checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

if (!item) throw new Error(`No item with ID ${itemId}`);

if (item.type_ === BaseModel.TYPE_RESOURCE) {
const localState = await Resource.localState(item);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declare the resource here, with type checking: const resource = item as ResourceEntity and use that resource variable for this block of code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

bridge().showErrorMessageBox(error.message);
}
} else if (item.type_ === BaseModel.TYPE_NOTE) {
let noteItem: any = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a "noteItem", it's an action so please call it that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And type checking on the note: const note = item as NoteEntity

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a "noteItem", it's an action so please call it that.

Removed it as options parameter is no longer needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And type checking on the note const note = item as NoteEntity

Done

Comment on lines 88 to 90
if (options.hash) {
noteItem = { ...noteItem, hash: options.hash };
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make no sense to recreate the object. Just pass the hash directly to the action, as in the original code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@laurent22
Copy link
Owner

All good now, thank you for the update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resource ID not provided error when click link with markdown pane closed
2 participants