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

Post demo cleanup - Annotation page component overhaul and formatting #108

Merged
merged 11 commits into from
Apr 26, 2022

Conversation

jarmoza
Copy link
Contributor

@jarmoza jarmoza commented Apr 14, 2022

General

  1. All UI text has been placed in a uiText object in the data of their respective component
  2. Fields from the store are given to annotation components and subcomponents via provide/inject mechanism. Other fields are passed as props.
  3. All props now use the object notation with type and required. If a prop is given to a component but is not used, it is listed but not marked as required: true.
  4. All entries in the script section of Vue template files have been arranged according to the Vue style guide: props, provide/inject, data, computed, Vue lifecycle hooks, methods. Within each group all fields, methods, etc. are alphabetized.
  5. Functional programming solutions (e.g. Object.fromEntries(), entries(), map(), etc.) remain where useful. However, instances of multiple-levels-deep functional programming were reevaluated with two concerns in mind. 1) Readability and 2) efficiency - with the latter taking precedence over the former. Cases where both readability and computational efficiency could be improved were changed to an imperative approach.
  6. Formatting consistency with four space indents and line spacing has been added. A few other bits of tidying - like capitalizing the beginning of comments and the addition of a p_ hungarian notation to distinguish parameters from local variables. Some of this is just for consistency's sake for the time being until we introduce a prettifier - which will be coming up very soon.
  7. All instances of '==' and '!=' have been replaced with '===' and '!==' respectively.

index.js

  1. Corresponding action/mutation functions for the new annotationDetails field have been added to the store. This field contains information for generating the individual annotation tabs. This field holds the same purpose as the former pages field in annotation.vue, but is now moved to the more central place of the store where it can be properly initialized via config (in the future). Each page object also contains a new options field for any specialized parameters needed for any of the tabs. The field is initialized in the nuxtServerInit action just like the categories.
  2. Corresponding action/mutation functions to revert annotation changes if a column unlinked from its category post-annotation has been added to the store,revertColumnToOriginal. This is currently called when a remove button is clicked in the annot-columns component.
  3. New getters have been added to the store to retrieve column and value descriptions from the data dictionary: columnDescription and valueDescription.
  4. Function convertTsvLinesToDict in the store has been renamed to convertTsvLinesToTableData in order to better reflect its purpose. But more importantly, a bug in this function was fixed that was still allowing
    blank lines in files to enter the data table.

category-*

  1. category-*.vue files have all been removed. They have been replaced with the more general annot-tab component.

annot-tab

  1. annot-tab contains the annot-explanation and annot-columns components of the previous category-* components but now includes a component representing the data type specialized components for each category on the annotation page. The information to generate these tabs is now found in the store in the annotationDetails field which is initialized in the nuxtServerInit action.
  2. Three computed properties that were previously in the specialized annotation components have been moved up into the annot-tab component: filteredTable (now filteredDataTable), relevantColumns, and uniqueValues

annot-age-values, annot-discrete-choices, and annot-vocabulary

  1. Save annotation buttons remain in the specialized components of the annotation tabs. This is because decoupling them without messy event handling or refs to child methods was not possible. The small redundancy of each component having its own save button is preferable.
  2. Function names and fields not moved to the annot-tab component that remain in the specialized annotation components have been standardized (i.e. saveButtonDisabled, saveButtonColor, applyAnnotation, transformedValue, initializeMapping, updateMapping, etc.)
  3. applyTransformation has been renamed to applyAnnotation and a new helper function has been introduced for the sake of uniformity: transformedValue. This latter function is the place where an annotation component can go to get the new value given a column and raw value. The hope was that applyAnnotation could be raised up to the annot-tab level but given some slight differences, it made sense to keep it here. In the very least, applyAnnotation and transformedValue can give these components consistent function naming.
  4. Similarly, 'mapping' function names have all been standardized - initializeMapping, updateMapping, and uploadMapping (future functionality withstanding).
  5. As the checkAnnotationState functions just have the purpose of setting the disabled status of the save annotation button, that statement has been pulled out of the function. The disabled status is now more explicitly set via the new boolean return value of checkAnnotationState instead.

annot-columns

  1. retrieveColumnDescription has been implemented to display the data dictionary description of the column next to its name in this component. (Can always be dropped if the screen appears to be too cluttered because of it.) This uses the new columnDescription retrieval method in the store
  2. The v-for key warning has been removed by adding the key as columnName

annot-vocabulary

  1. getDescription has been split into two functions and moved to the store since it contained general, reusable data dictionary functionality. These are the new columnDescription and valueDescription functions

@jarmoza jarmoza requested a review from surchs April 14, 2022 20:28
Copy link
Contributor

@surchs surchs left a comment

Choose a reason for hiding this comment

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

Thanks @jarmoza, this is a really excellent PR! The code got immensely more readable and clear. This is great, and great work!

I made some small comments, the main thing would probably be the eslint config to make sure we have consistent whitespace.

.eslintrc.js Outdated
// "airbnb", // TODO: activate this styleset
"eslint:recommended",
"plugin:vue/strongly-recommended",
// "plugin:prettier/recommended", // TODO: consider activating
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say let's get rid of prettier and have eslint handle formatting when called.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me at this point. I'll remove the commented out lines.

.eslintrc.js Outdated

rules: {

"no-unused-vars": [ "error", {
Copy link
Contributor

Choose a reason for hiding this comment

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

in our discussion we said we'll turn this into a warning instead so that unused variables are flagged.

return [colName, value]
export default {

props: {
Copy link
Contributor

Choose a reason for hiding this comment

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

cool, I like the consistent ordering!

// (Currently just used for unused variables in v-for statements)
"ignorePattern": "^_"
}]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

My only comment here is that I don't think these rules enforce / fix indentation and trailing whitespaces. Apart from the actual code linting, this is one major improvement for us because we will avoid these messy git diffs that are mostly white-space differences.

So I would say let's make sure here that we get rid of trailing whitespace and that there is some opinionated rule about indentation - otherwise we'll continue having whitespace diffs and make our history hard to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@surchs I've changed these to warnings and added some specific rules about indent, vue script-indent, comma spacing, and trailing commas.

The idea here is to explicit about the rules we want to enforce even though they might be default in eslint and vue-eslint rules?

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. No, my comment was about the fact that when I run eslint with this config locally, I don't get yelled at for trailing whitespace and I can chose what level of indentation I want for each line as I see fit. I think we should pick some indentation style and remove trailing whitespaces so that its consistent in the code and we don't get diffs because one of us accidentally added or removed some whitespace.

overflow-y: scroll;
}

</style>
Copy link
Contributor

Choose a reason for hiding this comment

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

This is excellent! Short, clear purpose, super legible!


for ( let index = 0; index < this.columnToCategoryTable.length; index++ ) {
// A. Determine if category-column linking or unlinking has occurred
const linking = !( this.selectedCategory === this.columnToCategoryMap[p_clickData.column] );
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this just be

Suggested change
const linking = !( this.selectedCategory === this.columnToCategoryMap[p_clickData.column] );
const linking = this.selectedCategory !== this.columnToCategoryMap[p_clickData.column] ;

? If so, I'd find that easier to read

store/index.js Outdated
{
id: 1,
category: "Sex",
explanation: "This is an explanation for how to annotate sex.",
Copy link
Contributor

Choose a reason for hiding this comment

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

indent seems off

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Somehow tabs remain in this file. Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. But we should check why your eslint run didn't catch that.

store/index.js Outdated
// 0. This annotation information is default but we can swap out and reinitialize
// annotation data structures by calling 'initializeAnnotationDetails' with a new
// object containing annotation information for each category
const annotationDetails = [
Copy link
Contributor

Choose a reason for hiding this comment

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

cool, I like this!

store/index.js Outdated
},

// Tool navigation

enablePage(p_context, p_navData) {
Copy link
Contributor

Choose a reason for hiding this comment

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

how about initializePage? Maybe not quite the right name, but this method seems to do more than just make the link clickable, particularly in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perfect. 👌

store/index.js Outdated

p_context.commit("removeColumnCategorization", p_linkingData.column);
},

// Annotation page actions

revertColumnToOriginal(p_context, p_columnName) {
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 add a docstring comment to explain what this method does and when it would be called? I assume this is when someone wants to reset an annotation?

@jarmoza jarmoza merged commit 18ab0aa into master Apr 26, 2022
Copy link
Contributor

@surchs surchs left a comment

Choose a reason for hiding this comment

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

I think you need to run one more eslint --fix to get the remaining errors (annotation component and some js config files). Otherwise this is good to go 🎉 !

@jarmoza
Copy link
Contributor Author

jarmoza commented Apr 26, 2022

@surchs Yup! I noticed. Pushed the eslint changes for the pages in a separate commit outside the PR right afterward.

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.

None yet

2 participants