Skip to content

Commit 317bc75

Browse files
authored
fix: refresh xblock inline after accepting/rejecting library sync (#2022) (#2028)
Instead of reloading the entire Unit after syncing changes from the library, just reload the xblock that was changed. (cherry picked from commit ac5574d)
1 parent 212a54f commit 317bc75

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/course-unit/preview-changes/index.test.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ describe('<IframePreviewLibraryXBlockChanges />', () => {
8585
const acceptBtn = await screen.findByRole('button', { name: 'Accept changes' });
8686
userEvent.click(acceptBtn);
8787
await waitFor(() => {
88-
expect(mockSendMessageToIframe).toHaveBeenCalledWith(messageTypes.refreshXBlock, null);
88+
expect(mockSendMessageToIframe).toHaveBeenCalledWith(
89+
messageTypes.completeXBlockEditing,
90+
{ locator: usageKey },
91+
);
8992
expect(axiosMock.history.post.length).toEqual(1);
9093
expect(axiosMock.history.post[0].url).toEqual(libraryBlockChangesUrl(usageKey));
9194
});
@@ -100,7 +103,6 @@ describe('<IframePreviewLibraryXBlockChanges />', () => {
100103
const acceptBtn = await screen.findByRole('button', { name: 'Accept changes' });
101104
userEvent.click(acceptBtn);
102105
await waitFor(() => {
103-
expect(mockSendMessageToIframe).not.toHaveBeenCalledWith(messageTypes.refreshXBlock, null);
104106
expect(axiosMock.history.post.length).toEqual(1);
105107
expect(axiosMock.history.post[0].url).toEqual(libraryBlockChangesUrl(usageKey));
106108
});
@@ -118,7 +120,10 @@ describe('<IframePreviewLibraryXBlockChanges />', () => {
118120
const ignoreConfirmBtn = await screen.findByRole('button', { name: 'Ignore' });
119121
userEvent.click(ignoreConfirmBtn);
120122
await waitFor(() => {
121-
expect(mockSendMessageToIframe).toHaveBeenCalledWith(messageTypes.refreshXBlock, null);
123+
expect(mockSendMessageToIframe).toHaveBeenCalledWith(
124+
messageTypes.completeXBlockEditing,
125+
{ locator: usageKey },
126+
);
122127
expect(axiosMock.history.delete.length).toEqual(1);
123128
expect(axiosMock.history.delete[0].url).toEqual(libraryBlockChangesUrl(usageKey));
124129
});

src/course-unit/preview-changes/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,14 @@ const IframePreviewLibraryXBlockChanges = () => {
180180
return null;
181181
}
182182

183+
const blockPayload = { locator: blockData.downstreamBlockId };
184+
183185
return (
184186
<PreviewLibraryXBlockChanges
185187
blockData={blockData}
186188
isModalOpen={isModalOpen}
187189
closeModal={closeModal}
188-
postChange={() => sendMessageToIframe(messageTypes.refreshXBlock, null)}
190+
postChange={() => sendMessageToIframe(messageTypes.completeXBlockEditing, blockPayload)}
189191
/>
190192
);
191193
};

0 commit comments

Comments
 (0)