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

fix(ui): sort out table state #15944

Merged
merged 7 commits into from
Nov 18, 2019
Merged

fix(ui): sort out table state #15944

merged 7 commits into from
Nov 18, 2019

Conversation

drdelambre
Copy link
Contributor

Closes #15889

Right now there are multiple places within the app that are trying to convert the fields coming back from a query. All of these attempts tried to merge the multiple sources of truth (in turn becoming their own source of truth) from with the view layer. This has the drawback of being lost or needing replication when application state is required in a different part of the app, and resulting in a state that is hard to reason about. From the blame log, it looks like there have been a handful of bugs over the past 10mo or so circling this issue.
In this PR, I pull that logic closer towards its storage (into the reducer layer) to ensure that it is decoupled from any view, and is applied on any future transformation of the data. This simplified things a bit. All of this code still desperately needs to be normalized (see: https://egghead.io/lessons/javascript-redux-normalizing-the-state-shape) to reduce pass-by-reference errors and simplify the object assembly (in which most of this code is shuffled into a selector that builds the correct object instead of deciphering how to convert objects), but i wanted to shake this out in production for awhile to make sure I didn't introduce more bugs first.

@@ -117,6 +111,7 @@ export const getViewForTimeMachine = (
}

dispatch(setActiveTimeMachine(timeMachineID, {view}))
dispatch(executeQueries(dashboardID))
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 intended this to mean "whenever a timemachine loads a view, run the queries to populate its data"

@@ -142,6 +135,40 @@ export const initialState = (): TimeMachinesState => ({
},
})

const getTableProperties = (view, 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.

this is mostly a csv parser for now. since the csv can be very large, we dont want to make a lot of copies of it in memory, so we move a pointer around in place and try to extract only the line that has the meta data in it that we want

csv
.slice(pointer, csv.indexOf('\r\n', pointer))
.split(',')
.filter(o => !existing.hasOwnProperty(o))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

now that we have a hashmap of the existing column names and a list of ones we got from... where ever.. we can forget about the existing ones and have a default fill for the new ones

return {...state, view}
}

case 'UPDATE_FIELD_OPTION': {
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 seemed less heavy handed than replacing the entire array... as a side effect, it should be more resilient to data inconsistencies across the app. imagine one component updating the 3rd element of the array, while another one swaps the 3rd and 6th element.

@drdelambre
Copy link
Contributor Author

I forgot that I can't effectively test this without goller's changes to the db flush mechanism as the meat of this code is dependent on transforming data from the resolution of backend calls, so.... i promise to write them later? 🤷‍♂

@drdelambre drdelambre changed the title WIP fix(ui): sort out table state fix(ui): sort out table state Nov 16, 2019
@drdelambre drdelambre requested review from asalem1 and desa November 16, 2019 01:00
@@ -71,7 +71,7 @@ describe('Dashboards.Actions.getViewForTimeMachine', () => {
)

expect(mocked(getView)).toHaveBeenCalledTimes(1)
expect(mockedDispatch).toHaveBeenCalledTimes(2)
expect(mockedDispatch).toHaveBeenCalledTimes(3)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

because now we populate the queries

Copy link
Contributor

@desa desa left a comment

Choose a reason for hiding this comment

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

This was really informative! Great work.

Copy link
Contributor

@zoesteinkamp zoesteinkamp left a comment

Choose a reason for hiding this comment

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

It makes sense to remove these inconsistencies and have all the data stream in from one source so we stop having different views of data

@drdelambre drdelambre merged commit 612a898 into master Nov 18, 2019
@drdelambre drdelambre deleted the alex_fix_tables branch November 18, 2019 17:49
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.

Visualization Configuration for Table: Cannot unhide columns in column settings
3 participants