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

refactor/interpretations component [DHIS2-5470] #370

Merged
merged 109 commits into from
Feb 26, 2019

Conversation

joakimia
Copy link
Contributor

@joakimia joakimia commented Dec 7, 2018

This PR includes refactoring of the interpretations component, changes:

  • Added d2 as context on all components requiring access to the object, instead of passing it down as props. I've also removed imports on helper functions / models and are passing it through th fn parameter.

  • Added RichText and RichTextParser wrapper to the textareas.

  • Added Cancel Button permanently instead of only when editing an existing one.

  • Removed the InterpretationsDialog, instead the textarea is rendered at the bottom of the panel.

  • Reduced the renderfunctions by creating renderX fn.

  • Removed the misc.js file and utils/ folder and created folders for each function (So it wont become a dumping ground for all sorts of "generic" fn's / components.

  • I have removed the maxWidth on CollapsibleCard and added flex: '1 1 100% to the root container such that the component can use the available space in DV / Maps / Dashboard.

  • The Date, Likes and replies are rendered below the text of the interpretation/comment card.

  • If the created date is more than 24 hours old, the formatted relative date will be rendered instead of "x days/months/years ago".

  • Removed some unused code.

  • Re-structured/ Moved some test cases to new components that i have created.

  • Added Read/Write checks for interpretations.

  • Added prop Item and appName for the dashboard, in order to render the redirect button.

  • Added InputFields instead of Dialogs for original interpretations.

  • Added Toolbar with markdown functionality.

  • I did not put in the (edited) label, since the lastUpdated value changes when a user replies to the interpretation, or if the sharing properties are changed. Meaning that the (edited) label will eventually appear and might confuse the user (as it was supposed to indicate whether or not the specific text have been changed).

  • Bold / Italic is reset by the UI component in the new DV (I spoke with Viktor and he informed me that this component will be removed in the next release)

Quick Summary of the render structure:

InterpretationsCard:

  • Renders Either the interpretationsList, Or the specific Interpretation if View/Interpretaion is clicked
  • Renders the InputField, if the current interpretation have not been cliced/viewed and the user have write access to the analytic object.

InterpretationsList:

  • Renders all interpretations that the viewer have read access to. Renders 5 Interpretations along with a Show / Hide previous interpretations if the amount is higher than 5.

Interpretation:

  • Renders the Interpretation, its replies, (Sharing Dialog if "Manage Sharing" button is clicked, or Delete Dialog if Delete is Clicked).

ActionButtonContainer:

  • Renders the buttons depending on the user is either the owner, or have write access (There is no manage sharing dialog on comments, so it inherits the Interpretations sharing properties. If The user do not have write access, the person can not reply to the interpretations or comments, but can still read them).

ActionButton / Likes / Replies:

  • Render Icons / likes/ replies labels with 200ms onHover delay on tooltips

CommentsList:

  • Renders "View/Hide More replies" if the amount of comments is higher than 5.
  • Render the comments (Or NewCommentField if edit button is clicked).
  • Renders a NewCommentField at the bottom of the list if the user has write access

Comment:

  • Renders the comment, cardInfo and Buttons (if the user have write access / is owner of the comment)
  • Renders the Delete Dialog

NewInterpretationField/NewCommentField:

  • Renders the InputField with 3 states (initial, focused, focused with text present).
  • Renders the Toolbar with markdown and RichText wrapper.
  • Posts/Updates an Interpretation/Comment based on prop comment/interpretation
  • NewInterpretationField will render the sharing dialog when the "Manage Sharing" link have been added.

Toolbar:

  • Renders the button and Emoticon menu.
  • Uses markdown (I've mirrored the slack behavior in addition to the specification of the design document) file to insert markdown.
  • meta key + b/i triggers * or _

…leCard, replace Link text with InterpretationIcons, exporting Icons through misc.js, adding styles into styles file
…nd CommentTextArea.js, adding styles folder for components within interpretations/ folder. adding style file for CommentTextArea
…js wrapped with withStyles, removing unused className rules, adding PropType classes
… file for InterpretationComments.js changin in-line style to className, exporting and wrapping Component in withStyles
…='md' and will recieve rules from d2-ui-theme
…ggestion, removing unnecesarry divs, replacing with fragments
…ncrease available space and mirror original interpretation structure
…r than 24 hours old, rendering specific date if evaluation returns true
… renders the tooltip above the icon when there's only 1 valid action rendered, minor adjustments after linking package locally and testing in DV
…ck-suggestion (momentarily) add new file NewInterpretation.js with boilerplate to replace the interpretation dialog that covers the whole screen, in order to not block the data you want to interpret
…lacing interpretations dialog, additional re-factoring
//TODO length > 5 && showPreviousComments
// "Show previous comments ( x of < interpretations.length - rendered comments> )"
return (
interpretations.length ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't seem like this check is necessary, since interpretations.length was already checked on line 16

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 file is not complete, the TODO comment might not be that clear as well. Currently i have a early return if there's no interpretation.
If there's more than 5 interpretations (lets say 15 of them), the component will mount with 10 hidden interpretations (with a "show previous comments" button), and render the 5 newest (mirroring the facebook/other social media behavior)

this.props.onClose();
});

_saveInterpretation() {
Copy link
Contributor

@jenniferarnesen jenniferarnesen Dec 10, 2018

Choose a reason for hiding this comment

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

What does the leading "_" indicate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of this file is copy pasted from InterpretationsDialog, i assume the underscore indicates that this function performs a network request.
I'll change the name to postInterpretation instead.

@@ -0,0 +1,38 @@
export const styles = theme => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

mispelled filename:
CollapsibelCard -> CollapsibleCard

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected filename and import name of CollapsibleCard.

expandOpen: {
transform: 'rotate(180deg)',
},
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you fix the missing newline on all the files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added newline on all the .style files. Checked the .style files in DV and I cant say that we are normally doing this, but the lines do get more clear. I think eslint/prettier removes it with the message "remove unnecessary newline"

import i18n from '@dhis2/d2-i18n';
import SharingDialog from '@dhis2/d2-ui-sharing-dialog';
import { withStyles } from '@material-ui/core/styles';
import some from 'lodash/fp/some';
import InterpretationComments from './InterpretationComments';
import InterpretationDialog from './InterpretationDialog';
Copy link
Contributor

Choose a reason for hiding this comment

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

InterpretationDialog file has been deleted.

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 re-created that file and added it back. I assume the symlink were still present and pointed to the inode which resided in my trash folder, so i didnt get any errors.

this.state = { tooltipIsOpen: false };
}

componentWillUnmount() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems to be some alignment issues in this file?

onCurrentInterpretationChange={onCurrentInterpretationChange}
/>
</div>
<MuiThemeProvider muiTheme={getMuiTheme()}>
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if we don't include this Provider?

@@ -60,7 +60,7 @@ export class Details extends React.Component {
const SubscriptionButton = this.renderSubscriptionButton();

return (
<CollapsibleCard title={i18n.t('Favorite details')}>
<CollapsibleCard title={i18n.t('Chart details')}>
Copy link
Contributor

Choose a reason for hiding this comment

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

It won't always be a chart. Is it possible to pass in the type (Map, Pivot table, chart...), or maybe it should just say "Details"? (double check with Joe).

@joakimia joakimia merged commit 57e3633 into master Feb 26, 2019
@joakimia joakimia deleted the refactor/interpretations-component branch February 26, 2019 09:12
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.

4 participants