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: Unedited markdown widgets not persisting #2019

Merged

Conversation

AkshatJawne
Copy link
Contributor

Resolves #1777

Changes Implemented:

  • Removed check to return null if the content is the default content (meaning it is unedited), which was resulting in the window disappearing on refresh

@AkshatJawne AkshatJawne self-assigned this May 15, 2024
@AkshatJawne AkshatJawne requested a review from mofojed May 16, 2024 17:25
Comment on lines 34 to 50
if (panelState.content === '') {
// If the content is empty, display markdown panel with default content
const configNew = {
type: 'react-component' as const,
component: MarkdownPanel.COMPONENT,
props: {
id: configProps.id,
metaData: {},
panelState: {
content: MarkdownUtils.DEFAULT_CONTENT,
},
},
localDashboardId: configProps.id,
title: MarkdownUtils.DEFAULT_TITLE,
};
return hydrate(configNew);
}
Copy link
Member

Choose a reason for hiding this comment

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

We should never be calling hydrate from within a dehydration function.

Dehydration is taking a panel and outputting a serializable object such that we can serialize the layout and save it; hydration is the opposite, where we take a serialized layout, and hydrate it into objects (such as a grid model).

When we're dehydrating the layout, we check if the returned dehydration is null, and if it is, we omit the component from the layout completely:

const dehydratedComponent = dehydrateComponent(component, itemConfig);

In this case though, we do want to save the panel to the layout, we just don't want to save the actual content with it. I don't think there's a case where we would want to drop it completely from the layout (which returning null does).

Digging into it a bit ... I think you should actually remove this custom dehydrateMarkdown function completely, and just use the default hydrate/dehydrate functions (omitting the last two parameters from the call to registerComponent below). Then need to change MarkdownPanel.getClosedMarkdowns to filter out any panel that doesn't have a markdown set.

Actually found another bug too - if we return null from the dehydration function (as we're doing above), PanelManager throws an error:

Error while emitting event: TypeError: Cannot set properties of null (setting 'parentStackId')
    at PanelManager.addClosedPanel (PanelManager.ts:365:54)
    at PanelManager.handleClosed (PanelManager.ts:347:10)
    at EventHub.emit (EventEmitter.ts:69:22)

You can see this by just opening and closing a markdown panel before your changes. We should have a check there for if the dehydrated component is null, and if it is, skip pushing it onto the closed array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the information on hydration, it was very helpful! Will make the changes and will take a look at the other bug you mentioned

@AkshatJawne AkshatJawne requested a review from mofojed May 17, 2024 16:45
packages/dashboard/src/PanelManager.ts Outdated Show resolved Hide resolved
const usedTitles = openedMarkdowns.map(markdown => markdown.title ?? '');
const panelTitle =
title != null && title !== ''
? title
: MarkdownUtils.getNewMarkdownTitle(usedTitles);
const content =
closedMarkdowns.length > 0 ? null : MarkdownUtils.DEFAULT_CONTENT;
const content = MarkdownUtils.DEFAULT_CONTENT;
Copy link
Member

Choose a reason for hiding this comment

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

We don't want to do this - right now this change is causing a regression, which is re-opening closed markdown widgets.

If you open a markdown panel, edit it to add some text, then close it, and then open a new markdown panel, you get a starting page prompting you to re-open one of the previously closed markdown panels or to just create a new one:
image

I think what you should do is just set null for content from here, then in MarkdownPanel is where it will actually decide whether to show the starting page or the default content (when it calls getClosedMarkdowns).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just pushed changes, if I understood correctly when you said

then in MarkdownPanel is where it will actually decide whether to show the starting page or the default content (when it calls getClosedMarkdowns).

It now works such that on initial opening of a Markdown, you get this panel, given that when getClosedMarkdowns is called in MarkdownPanel, the condition for the starting page appearing is whether the state isStatePageShown is set to true:
image

However, after refreshing after editing, we see the default content:

image

@AkshatJawne AkshatJawne marked this pull request as draft May 22, 2024 13:43
@AkshatJawne AkshatJawne marked this pull request as ready for review May 22, 2024 13:51
@AkshatJawne AkshatJawne requested a review from mofojed May 22, 2024 13:55
@AkshatJawne
Copy link
Contributor Author

Looking into e2e failures

@AkshatJawne
Copy link
Contributor Author

Still failing on e2e with Mathjax, investigating why

mofojed
mofojed previously approved these changes May 24, 2024
@AkshatJawne
Copy link
Contributor Author

@mofojed changed the getClosedMarkdowns, but the approving review has gone stale, so if you could approve it again after reviewing, that would be great!

@AkshatJawne AkshatJawne requested a review from mofojed May 24, 2024 14:02
mofojed
mofojed previously approved these changes May 24, 2024
@AkshatJawne AkshatJawne merged commit c17f136 into deephaven:main May 24, 2024
9 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators May 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Markdown widgets do not persist refresh if they were not edited
2 participants