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

feat: Pages and Resources components [BD-38] [TNL-8101] [BB-3972] #63

Merged
merged 1 commit into from Jul 1, 2021

Conversation

xitij2000
Copy link
Contributor

@xitij2000 xitij2000 commented Mar 30, 2021

TNL-8101 / TNL-8450
Hooks up the course apps API so that the data returned by the server is being used.
Adds the base components and infrastructure to enable adding pages for configuring each app.

This PR adds the foundation to the UI for adding settings components for individual pages in future PRs.

course-apps-calculator.mp4

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. labels Mar 30, 2021
@openedx-webhooks
Copy link

openedx-webhooks commented Mar 30, 2021

Thanks for the pull request, @xitij2000! I've created BLENDED-810 to keep track of it in Jira.

When this pull request is ready, tag your edX technical lead.

@davidjoy davidjoy changed the title Pages and Resources components feat: Pages and Resources components Mar 30, 2021
@davidjoy
Copy link
Contributor

(tweaked the PR title to use conventional commits, as per the new OEP: https://github.com/edx/open-edx-proposals/blob/master/oeps/oep-0051-bp-conventional-commits.rst)

@xitij2000
Copy link
Contributor Author

@davidjoy This is stil WIP, and I plan to squash the commits with a proper message before this is ready.

@xitij2000 xitij2000 changed the title feat: Pages and Resources components feat: Pages and Resources components [BD-03] Mar 31, 2021
@openedx-webhooks openedx-webhooks added blended PR is managed through 2U's blended developmnt program and removed open-source-contribution PR author is not from Axim or 2U labels Mar 31, 2021
src/index.jsx Outdated Show resolved Hide resolved
@xitij2000 xitij2000 force-pushed the kshitij/pages-and-resources branch 2 times, most recently from e1bb64f to 42e637b Compare April 12, 2021 05:06
@xitij2000 xitij2000 force-pushed the kshitij/pages-and-resources branch from 42e637b to 0518865 Compare May 25, 2021 10:57
src/index.scss Outdated Show resolved Hide resolved
@asadazam93
Copy link
Contributor

@xitij2000 Can you also add screenshots of how the pages look like?

Copy link
Contributor

@mehaknasir mehaknasir left a comment

Choose a reason for hiding this comment

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

Some Logical and Console Errors are there which may be because this work is in progress. other things we have reviewed and have listed our findings for your reference.

src/pages-and-resources/teams/Settings.jsx Outdated Show resolved Hide resolved
>
<h3>{title}</h3>
<AppConfigFormDivider />
<Form onSubmit={onApply}>
Copy link
Contributor

Choose a reason for hiding this comment

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

why are not we using the Formik library for form management? by convention we are using Formik forms in codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR started before that became convention :-)

I'll update this code to use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I think in this case Formik might not work as well since the the base form doesn't know about the form elements injected in the child component.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can use Formik in AppSettingsModal I see no reason why we can’t.

The structure of form does not look good to me and the modal is not closing on submit.
The type=submit will also work if you place this button inside form closing tag. I think this needs to be revisited.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@awaisdar001

We can use Formik in AppSettingsModal I see no reason why we can’t.
The reason using Formik here is harder is that the form is crated in AppSettingsModal, but the contents of the form will be created elsewhere. So Formik here will not know what all form elements the child components have added.

The fact that we can't use it here, doesn't mean we can't use it at all. We can use it in individual components, so I'll update those and share.

The structure of form does not look good to me and the modal is not closing on submit.
Could you highlight what doesn't look about the structure of the form?

The modal is not closing on submit on purpose for a couple of reasons:

  • The apply operation is a remote operation, so we'd want to convey the saving state, possibly via a stateful apply button, or some other UI element. So the form shouldn't close till the data is saved and we've confirmed to the use that the data is saved.
  • If the saving fails, and the form closes, it could be irritating for users so have to reopen the page, apply all the changes again (it could be a lot of teamsets) and then try saving again.
  • A user might want to make a couple of changes, apply them, and continue editing.

The type=submit will also work if you place this button inside form closing tag. I think this needs to be revisited.

I'll see if I can do something to restructure this to allow that to work.

src/pages-and-resources/teams/Settings.jsx Outdated Show resolved Hide resolved
src/pages-and-resources/pages/PageCard.jsx Outdated Show resolved Hide resolved
src/pages-and-resources/pages/PageCard.jsx Outdated Show resolved Hide resolved
src/pages-and-resources/data/slice.js Outdated Show resolved Hide resolved
src/pages-and-resources/notes/messages.js Outdated Show resolved Hide resolved
Comment on lines 46 to 60
{isDeleting
? (
<div className="d-flex flex-column m-4" key="isDeleting">
<h3>{intl.formatMessage(messages.team_set_delete_heading)}</h3>
<p>{intl.formatMessage(messages.team_set_delete_body)}</p>
<div className="d-flex flex-row justify-content-end">
<Button variant="muted" size="sm" onClick={() => onDelete(teamSet)}>
{intl.formatMessage(messages.delete)}
</Button>
<Button variant="muted" size="sm" onClick={cancelDeletion}>
{intl.formatMessage(messages.cancel)}
</Button>
</div>
</div>
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: this should be in generics to be used in other components as well. this is already in use at other places in the application.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what exactly you're referring to here?

@xitij2000 xitij2000 changed the title feat: Pages and Resources components [BD-03] feat: Pages and Resources components [BD-38] Jun 10, 2021
@xitij2000 xitij2000 force-pushed the kshitij/pages-and-resources branch 3 times, most recently from 91106ba to 3832f35 Compare June 24, 2021 14:26
@codecov-commenter
Copy link

codecov-commenter commented Jun 24, 2021

Codecov Report

Merging #63 (5ad7f43) into master (44d8cfb) will decrease coverage by 4.75%.
The diff coverage is 2.97%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #63      +/-   ##
==========================================
- Coverage   73.31%   68.56%   -4.76%     
==========================================
  Files          67       75       +8     
  Lines        1023     1091      +68     
  Branches      192      211      +19     
==========================================
- Hits          750      748       -2     
- Misses        268      338      +70     
  Partials        5        5              
Impacted Files Coverage Δ
src/generic/FormSwitchGroup.jsx 100.00% <ø> (ø)
src/generic/status-badge/StatusBadge.jsx 0.00% <0.00%> (ø)
src/generic/status-badge/messages.js 0.00% <0.00%> (ø)
src/index.jsx 0.00% <0.00%> (ø)
src/pages-and-resources/PagesAndResources.jsx 0.00% <0.00%> (ø)
.../pages-and-resources/PagesAndResourcesProvider.jsx 100.00% <ø> (ø)
...-resources/app-settings-modal/AppSettingsModal.jsx 0.00% <0.00%> (ø)
...pages-and-resources/app-settings-modal/messages.js 0.00% <0.00%> (ø)
src/pages-and-resources/calculator/Settings.jsx 0.00% <0.00%> (ø)
src/pages-and-resources/calculator/messages.js 0.00% <0.00%> (ø)
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 44d8cfb...5ad7f43. Read the comment docs.

@xitij2000 xitij2000 marked this pull request as ready for review June 24, 2021 14:42
@xitij2000
Copy link
Contributor Author

I've added a video to the PR description.

thanks - can you update update the description as well regarding it is expected that this PR is going to serve as a base for upcoming PRs? Thank you :)

Done.

src/index.jsx Show resolved Hide resolved
src/pages-and-resources/PagesAndResources.jsx Show resolved Hide resolved
Comment on lines 46 to 57
return useFormik({
initialValues: {
enabled: !!appInfo?.enabled,
...initialValues,
},
validationSchema: Yup.object()
.shape({
enabled: Yup.boolean(),
...validationSchema,
}),
onSubmit: handleSubmit,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

useFormik limits us sometimes we are restricted in many features e.g
Field, FastField, ErrorMessage, connect(), and FieldArray will NOT work with useFormik() as they all require React Context you can learn more here
Considering future perspective its best to use <Formik /> component instead which is more powerful.

As you can see in figma when you will need to work on team settings you will need to work with <FieldArray> then useFormik will not work. for help you can take help from this already implemented example

Copy link
Contributor

Choose a reason for hiding this comment

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

any thought on this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will investigate this and update the PR accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the code to use Formik as you suggested.

src/pages-and-resources/calculator/Settings.jsx Outdated Show resolved Hide resolved
@xitij2000 xitij2000 changed the title feat: Pages and Resources components [BD-38] feat: Pages and Resources components [BD-38] [TNL-8101] Jun 28, 2021
Copy link
Contributor

@mehaknasir mehaknasir left a comment

Choose a reason for hiding this comment

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

there are two pending things on this PR, I think if we can agree on some point on this we will be able to close it soon.

<div>
{page.showStatus && <span>{intl.formatMessage(messages[pageStatusMsgId])}</span>}
<div className="my-1">
<StatusBadge status={page.enabled} />
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the padding of the status badge is also needed to be fixed. The dividers used not part of the Figma design and are going out from both sides of the modal. you can see that in the attached video as well. if that is needed to be fixed in this PR. then you might need to look at it again.

Comment on lines 46 to 57
return useFormik({
initialValues: {
enabled: !!appInfo?.enabled,
...initialValues,
},
validationSchema: Yup.object()
.shape({
enabled: Yup.boolean(),
...validationSchema,
}),
onSubmit: handleSubmit,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

any thought on this one?

@xitij2000 xitij2000 changed the title feat: Pages and Resources components [BD-38] [TNL-8101] feat: Pages and Resources components [BD-38] [TNL-8101] [BB-3972] Jun 28, 2021
@xitij2000 xitij2000 force-pushed the kshitij/pages-and-resources branch 2 times, most recently from 22fe883 to ddc937f Compare June 30, 2021 04:08

export function enableDisableApp(courseId, appId, state, syncChange = false) {
return async (dispatch) => {
if (!syncChange) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this piece of if condition needed here? When we only need to update store and not make an API call? Can you elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's used to persist state to the store without changing the state on the server.

Copy link
Contributor

Choose a reason for hiding this comment

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

Whats' the use case for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I think it was used in a previous version of the code that got refactored out.

But generally the idea was, that if a user is applying complex changes to something like teams, you keep all those changes in the store, and save then so if the page accidentally closes, you don't lose those changes. You can then pick up where you left off and sync.

showStatus: PropTypes.bool.isRequired,
showEnable: PropTypes.bool.isRequired,
enabled: PropTypes.bool.isRequired,
allowed_operations: PropTypes.shape({
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be =>allowedOperations

<h3>{title}</h3>
<AppConfigFormDivider />
<FormSwitchGroup
id={`enable-${appId}-toggle`}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking why this ID is needed? The general perception for addingids is to things if we need to use the ID somewhere e.g. tests or referencing. I can't see any usage of this.

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 is required by the FormSwitchGroup so I added it. I will update the component to make it optional.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, reading through the comments in FormSwitchGroup it seems that currently you need to attach a label to the switch component.

@xitij2000 xitij2000 force-pushed the kshitij/pages-and-resources branch 2 times, most recently from 16e22a5 to b8da9e9 Compare July 1, 2021 05:13
Copy link
Contributor

@awaisdar001 awaisdar001 left a comment

Choose a reason for hiding this comment

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

The changes looks good now, thanks for addressing them @xitij2000 :)

@mehaknasir
Copy link
Contributor

This PR looks good to me. can you please rebase your commits in 1 commit and insert a commit message following commit conventions. Also, Let me know when you need to merge it. I will do that.

…ration

Hooks up the course apps API so that the data returned by the server is being used.
Adds the base components and infrastructure to enable adding pages for configuring
each app.
@xitij2000 xitij2000 force-pushed the kshitij/pages-and-resources branch from b8da9e9 to 5ad7f43 Compare July 1, 2021 11:55
@xitij2000
Copy link
Contributor Author

I've squashed down to a single commit.
@mehaknasir I don't have commit/merge access so you will need to merge for me :-)

@awaisdar001 awaisdar001 merged commit 0e7340b into openedx:master Jul 1, 2021
@awaisdar001
Copy link
Contributor

Pr merged.

@xitij2000 xitij2000 deleted the kshitij/pages-and-resources branch July 2, 2021 05:40
@xitij2000
Copy link
Contributor Author

@awaisdar001 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blended PR is managed through 2U's blended developmnt program merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants