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

Page state preservation for Categorization page, Palette/Table clicking simplification, and general cleanup for landing and categorization pages #61

Merged
merged 1 commit into from
Feb 28, 2022

Conversation

jarmoza
Copy link
Contributor

@jarmoza jarmoza commented Feb 23, 2022

  1. Fix for preserving page state of categorization page - table is (re)painted on page load based on info in the store (see 3 below)
  2. Retrieval of palette on page load (see mounted() in each page) from stylesheet and placement of palette in store for later use by JS components
    • Current colors for table painting are immediately set afterward (setCurrentPaintClass(0) in categorization.vue) and placed in the store
  3. Replacement of old way(s) of table painting with simplified method
    • Table row is styled appropriately upon click
    • Row ID is placed in store upon table row click and easily identified and repainted (see paintTable() in categorization.vue)
  4. Removal of old and now-unused functions and data
  5. General streamlining of landing and categorization pages/components

…lette on page load and placement in store, general cleanup and streamlining of landing and categorization pages/components
@jarmoza jarmoza requested a review from surchs February 23, 2022 22:39
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 for the PR. I took some time to go through the changes and also tried to understand the logic for state and coloring.

My takeaway is that we really need to rethink our handling of the coloring and the categorization of column names. As in: we need to split the two problems and handle them separately. At the moment, category assignment and also the "is categorized" status of columns is tracked via their style color attributes in the DOM, and this is also reflected in the function and variable naming throughout the app ("paintTable", "paintingData"). From what I can see, routing everything through the color requires a very considerable amount of code complexity (regex parsing of our CSS stylesheet, specific lifecycle hooks, comparing colors to infer categorization status), some of it undesirable (direct editing of DOM elements to set color rather than letting Vue handle it).

Our main goal is to get users to tell us what categories each column and value belong to. The colors are just a visual guide / helper and should not force us to adopt complex design. I think if we dropped colors alltogether, we could probably build a simple mapping of column names to categories just via the row-click events of our tables in a few lines of intuitive code.

From there we can think about applying color. If I understand things right, coloring the row tables is a bit tricky because we are using bootstrap and they are opinionated about colors and themes. I saw that in the current master (before this PR), you had used :tbody-tr-class to programmatically style the table rows. If that works, I think we should figure out the categorization, have a mapping of categories to css classes (hardcoded), and then feed the appropriate array to :tbody-tr-class every time a categorization update has happened. If :tbody-tr-class is not a viable solution, then we should look into b-table-simple instead of b-table. It is a bit more complex and less adaptable, but we gain fine-grained control over all elements of the table and if that allows us to lose complexity elsewhere, I think it's still worth it.

So my suggestion is:

  • let's split categorization from coloring,
  • ignore the coloring for now,
  • figure out fundamentally the categorization and state keeping for the categorization,
  • refactor variables and function names to unambiguously identify them as about categorization
  • remove code about coloring aggressively and focus on reducing complexity
  • once the categorization is working (with or without coloring), think about how we can style the tables with color

This may make sense to do in a separate PR, in which case I'd say we close this one and have a chat. Let me know what you think.

let row = document.getElementById(rowKey);

// II. Repaint the row the corresponding colors
row.style.backgroundColor = paintingData[columnID].bColor;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is an improvement to the previous painting system via :tbody-tr-class. Now we are editing the DOM directly instead of letting vue handle that part. If there is no easy way to color a table row through vue bootstrap using b-table programmatically, then we should either stick with the row-styling via css classes or move to b-table-simple to have more control over the row styling.

@@ -9,8 +9,7 @@
:items="tableData"
primary-key="primary-key"
@row-clicked="tableRowClick"
select-mode="multi"
:tbody-tr-class="paintClass">
select-mode="multi">
Copy link
Contributor

Choose a reason for hiding this comment

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

As noted below, I don't think getting rid of :tbody-tr-class in favour of direct DOM editing is the right choice here.

// 0. Counts number of painted columns
let columnCount = 0;

for ( let columnName in paintingData ) {

if ( defaultBackgroundColor != paintingData[columnName].bColor ||
defaultForegroundColor != paintingData[columnName].fColor ) {
if ( this.defaultBackgroundColor != paintingData[columnName].bColor ||
Copy link
Contributor

Choose a reason for hiding this comment

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

I really think we need to separate the categorization (and how we store categorization information in the store) from anything related to color, styling, and CSS. At the moment, if I understand things correctly, we have a global store called pageData.categoriztion.paintingData that keeps track of tsvCategory and fColor and bColor and primaryKey for the rows that have been annotated.

And here we are counting columns that have been annotated with countPaintedColumns by comparing their color names to a default color name. But the color is just a visual guide, the important information is what category a column has been mapped to. So I really think that routing everything through the color adds a lot of hard to understand complexity here that we should think about clearing up before we merge this!

foregroundColors: foregroundColors
});
},

Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand this correctly, the entire above added section (retrievePalette) exists in order to regex parse the main.css stylesheet in order to retrieve the colors we have defined there and store them in a global store backgroundColors and foregroundColors. And if I also understand this correctly, the only reason we need to do that is because we keep track of what category a column has been assigned to by comparing it's current DOM style color attribute to the values in this list.

As I mentioned above, I really think we need to completely split colors and categorization and focus on keeping track of the categorization.

@jarmoza jarmoza merged commit 0678e30 into master Feb 28, 2022
@surchs surchs deleted the maintain-categorization-state branch March 2, 2022 22:56
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