-
Notifications
You must be signed in to change notification settings - Fork 80
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
chore: [FC-0070] Remove backend redirects (use SPA functionality) #1372
chore: [FC-0070] Remove backend redirects (use SPA functionality) #1372
Conversation
Thanks for the pull request, @PKulkoRaccoonGang! What's next?Please work through the following steps to get your changes ready for engineering review: 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. 🔘 Let us know that your PR is ready for review:Who will review my changes?This repository is currently maintained by Where can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:
When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1372 +/- ##
==========================================
+ Coverage 93.27% 93.32% +0.05%
==========================================
Files 1052 1052
Lines 20462 20559 +97
Branches 4298 4419 +121
==========================================
+ Hits 19086 19187 +101
+ Misses 1316 1303 -13
- Partials 60 69 +9 ☔ View full report in Codecov by Sentry. |
106fc03
to
f4124f0
Compare
a650da7
to
d757a99
Compare
54ac07f
to
4ed52ac
Compare
17e9b11
to
56e49c6
Compare
Sandbox deployment successful 🚀 |
Sandbox deployment successful 🚀 |
console.error({ courseId, status: RequestStatus.NOT_FOUND }); | ||
} | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: since these waffle flags are a totally new API, I would recommend you load them with React Query instead of storing them in the global redux state.
Example of similar code:
frontend-app-authoring/src/library-authoring/data/apiHooks.ts
Lines 116 to 125 in 841aede
/** | |
* Hook to fetch a content library by its ID. | |
*/ | |
export const useContentLibrary = (libraryId: string | undefined) => ( | |
useQuery({ | |
queryKey: libraryAuthoringQueryKeys.contentLibrary(libraryId), | |
queryFn: () => getContentLibrary(libraryId!), | |
enabled: libraryId !== undefined, | |
}) | |
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if you do it this way, and you define types on your getWaffleFlags()
function in api.js
, then any place you use the new useCourseWaffleFlags()
hook, you'll have a typed response that properly validates all of the waffle flag names available in the response.
const { data: waffleFlags, isLoading: isLoadingFlags } = useCourseWaffleFlags();
data?.useNewGradingPage; // <- will have type boolean
data?.useOtherFlag; // <- will show an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great idea, and I really like it! However, at this stage, we’re already managing quite a few changes in the current PR. Implementing this suggestion would require additional time for development and testing, which we can’t accommodate right now. I suggest we proceed with the current solution for now, but I would definitely consider this improvement for future iterations 💯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK but in the future, please always prefer using React Query and TypeScript instead of Redux and JavaScript when building new things. It's a lot simpler and nicer.
Or, ideally, you could open a follow-up refactor PR after this one merges.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I'm very much in favor of moving off of Redux to React Query (and Typescript), I have very mixed feelings about a codebase that is inconsistent in its stack. It makes for a very confusing developer experience.
Which is to say, we should start talking about how we'll finish this move, since we seem to have already started it.
Anyway, as far as this PR is concerned, I'm fine with it staying on Redux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JS and TS can be "mixed and matched" without any problems, and without too much developer confusion.
Redux and React Context+Query is definitely another matter. But I really don't want to keep adding things to the Redux state, making it even bigger and harder to refactor, just because it's there. I'm not sure what other approach we can take besides making wholly new things in React Query and slowly transitioning other chunks of the state from Redux to Context+Query ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the other possible approach would be to embark on a full refactor, at least on a per-repo basis. I've started talking to people about the feasibility of doing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be great and I'd love to support that / work on it.
src/course-checklist/ChecklistSection/ChecklistSection.test.jsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for those refactors! I haven't tested this thoroughly but everything I tried seems good - and much faster.
This is a conditional approval, assuming that you:
- Remove the
run-build-for-gh-deps.sh
script - Finish and merge the PRs this one depends on, and
- Get the build green
run-build-for-gh-deps.sh
Outdated
@@ -0,0 +1,39 @@ | |||
#!/bin/bash | |||
|
|||
# TODO: This file is temporary and will be removed after testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Please remember to remove this file before merging.
src/course-checklist/ChecklistSection/ChecklistSection.test.jsx
Outdated
Show resolved
Hide resolved
src/course-checklist/ChecklistSection/ChecklistSection.test.jsx
Outdated
Show resolved
Hide resolved
d507d68
to
30f0933
Compare
Sandbox deployment successful 🚀 |
Sandbox deployment successful 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this and it works very well. However, I requested some changes to the code.
run-build-for-gh-deps.sh
Outdated
@@ -0,0 +1,39 @@ | |||
#!/bin/bash | |||
|
|||
# TODO: This file is temporary and will be removed after testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please go ahead and remove this workaround. I'm reviewing and testing this locally, and things are working well enough that we're almost ready to merge the frontend-component-header change, anyway.
src/course-outline/hooks.jsx
Outdated
@@ -112,15 +114,15 @@ const useCourseOutline = ({ courseId }) => { | |||
}; | |||
|
|||
const getUnitUrl = (locator) => { | |||
if (getConfig().ENABLE_UNIT_PAGE === 'true') { | |||
if (getConfig().ENABLE_UNIT_PAGE === 'true' || waffleFlags.useNewUnitPage) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much as I dislike env vars, if we're keeping them, this should be an &&
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[inform] Implemented in follow-up commit: 5f19746
(#1372)
src/course-outline/hooks.jsx
Outdated
return `/course/${courseId}/container/${locator}`; | ||
} | ||
return `${getConfig().STUDIO_BASE_URL}/container/${locator}`; | ||
}; | ||
|
||
const openUnitPage = (locator) => { | ||
const url = getUnitUrl(locator); | ||
if (getConfig().ENABLE_UNIT_PAGE === 'true') { | ||
if (getConfig().ENABLE_UNIT_PAGE === 'true' || waffleFlags.useNewUnitPage) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another &&
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[inform] Implemented in follow-up commit: 5f19746
(#1372)
src/data/slice.js
Outdated
useNewExportPage: true, | ||
useNewFilesUploadsPage: true, | ||
useNewVideoUploadsPage: true, | ||
useNewCourseOutlinePage: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default for this one should be true
, as far as I can tell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[inform] Implemented in follow-up commit: 5f19746
(#1372)
src/data/thunks.js
Outdated
// If fetching the waffle flags is unsuccessful, | ||
// the pages will still be accessible and display without any issues. | ||
// eslint-disable-next-line no-console | ||
console.error({ courseId, status: RequestStatus.NOT_FOUND }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please remove the console log? First because it should only ever be used for debugging.
Second, we probably shouldn't treat this API endpoint as optional, so we should probably just remove the try..catch
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[inform] Implemented in follow-up commit: 5f19746
(#1372)
console.error({ courseId, status: RequestStatus.NOT_FOUND }); | ||
} | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I'm very much in favor of moving off of Redux to React Query (and Typescript), I have very mixed feelings about a codebase that is inconsistent in its stack. It makes for a very confusing developer experience.
Which is to say, we should start talking about how we'll finish this move, since we seem to have already started it.
Anyway, as far as this PR is concerned, I'm fine with it staying on Redux.
src/studio-home/card-item/index.tsx
Outdated
const destinationUrl: string = waffleFlags.useNewCourseOutlinePage | ||
? path ?? url | ||
: path ?? new URL(url, getConfig().STUDIO_BASE_URL).toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not very readable. It seems to me that the waffle flag should be checked only if path
is null
or undefined
. So maybe pivot the outer conditional around that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[inform] Implemented in follow-up commit: 5f19746
(#1372)
src/utils.js
Outdated
if (!checkPath.startsWith(basePath)) { | ||
return `${basePath}${checkPath}`; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you remove this, then createCorrectInternalRoute
becomes a NOOP. If this is intentional, then the whole function should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! Reverted this function to the unchanged version, now it is used only for EditorContainer component
af762fa
to
6b0bb58
Compare
Sandbox deployment successful 🚀 |
6b0bb58
to
d723cb8
Compare
Sandbox deployment successful 🚀 |
d723cb8
to
4982d95
Compare
Sandbox deployment successful 🚀 |
Sandbox deployment successful 🚀 |
4982d95
to
b79c148
Compare
Sandbox deployment successful 🚀 |
b79c148
to
5f19746
Compare
Sandbox deployment successful 🚀 |
@arbrandes thanks for checking out this PR! Added some fixes to the commit after review and updated the header version. |
Sandbox deployment successful 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the reviews! Approved, nice work!
🚨 Dependencies:
Settings
Description
This PR introduces the ability to utilize SPA functionality when the relevant waffle flags are enabled for current MFE pages. When any new MFE page is loaded, a request is made to retrieve the waffle flags. This includes both global waffle flags related to MFE Authoring pages, as well as waffle flags specific to the current course.
These changes enhance the flexibility and functionality of the course authoring and checklist features by leveraging waffle flags for feature toggles and improving navigation logic.
Testing instruction