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

Fixed bug with VM detail leading after refresh #497

Merged
merged 1 commit into from
Feb 28, 2018

Conversation

bond95
Copy link
Contributor

@bond95 bond95 commented Feb 21, 2018

Bug: If open detail of VM that is not on first page, and refresh it, it'll leads to main page.
Fixes: #491


This change is Reviewable

@@ -1,6 +1,7 @@
import {
CHANGE_VM_ICON,
CHANGE_VM_ICON_BY_ID,
CHECK_VM_AVIABILITY,
Copy link
Contributor

Choose a reason for hiding this comment

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

spelling?

@@ -110,6 +110,7 @@ const VmDetailPageConnected = connect(
}),
(dispatch) => ({
getVms: ({ vmId }) => dispatch(selectVmDetail({ vmId })),
checkVMAviability: ({ vmId }) => dispatch(checkVMAviability({ vmId })),
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not like this collision of names, it might be source of dummy bugs in the future or decreases readability at least.

@@ -345,3 +346,12 @@ export function changeVmIconById ({ vmId, iconId }) {
},
}
}

export function checkVMAviability ({ vmId }) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we follow the convention that only first letter in an abbreviation is capitalized? Like: checkVmAvailability.

We already use that in e.g. VmDialog, VmDetail, and others. Similarly we use CHECK_VM_AVIABILITY, not CHECK_V_M_AVIABILITY

src/sagas.js Outdated
@@ -581,6 +582,16 @@ function* fetchUSBFilter (action) {
}
}

function* checkVmAviability (action) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this can be simplified:

yield fetchSingleVm({ payload: { vmId: action.payload.vmId } })
const vm = yield select(state => state.getIn(['vms', 'vms', action.payload.vmId])
if (!vm) {
  yield put(redirectRoute({ route: '/' }))
}

It could save one request.

src/sagas.js Outdated
@@ -581,6 +582,16 @@ function* fetchUSBFilter (action) {
}
}

function* checkVmAvailability (action) {
Copy link
Contributor

Choose a reason for hiding this comment

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

copy from previous pull request version

Maybe this can be simplified:

yield fetchSingleVm({ payload: { vmId: action.payload.vmId } })
const vm = yield select(state => state.getIn(['vms', 'vms', action.payload.vmId])
if (!vm) {
  yield put(redirectRoute({ route: '/' }))
}

It could save one request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, because if we call fetchSingleVm it update state vms, before adding fetched VM to state, thus VmDetailPage will update and call check again, and again, and again... Thus my version is more simplified. Otherwise it need to add more lines for take care of this recursion.

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. So how about (pseudo-code):

const vmFromStore = yield select(state => state.getIn(['vms', 'vms', action.payload.vmId])
if (vmFromStore) {
  return
}
yield fetchSingleVm({ payload: { vmId: action.payload.vmId } })
const loadedVm = yield select(state => state.getIn(['vms', 'vms', action.payload.vmId])
if (!loadedVm) {
  yield put(redirectRoute({ route: '/' }))
}

I agree that originally posted version is easy to read. I find network requests expensive and requesting the same entity twice in this case not necessary.

Copy link
Contributor Author

@bond95 bond95 Feb 26, 2018

Choose a reason for hiding this comment

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

It doing the same thing, and we already check availability of VM in current vms state, in VmDetailPage component.

@bond95
Copy link
Contributor Author

bond95 commented Feb 26, 2018

@jniederm @mareklibra Done.

Copy link
Contributor

@jniederm jniederm left a comment

Choose a reason for hiding this comment

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

except that new line LGTM

@@ -103,6 +103,7 @@ class PageRouter extends React.Component {

render () {
let { route, location, history, routeReducer } = this.props

Copy link
Contributor

Choose a reason for hiding this comment

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

Now this seems pretty unrelated.

@bond95
Copy link
Contributor Author

bond95 commented Feb 27, 2018

@jniederm Done.

@mareklibra
Copy link
Contributor

Review status: 0 of 1 files reviewed at latest revision, 7 unresolved discussions.


src/components/Pages/index.js, line 22 at r4 (raw file):

    const vmInStore = this.props.vms.getIn(['vms', this.props.match.params.id])
    if (!vmInStore && Selectors.isFilterChecked()) {
      this.props.getVms({ vmId: this.props.match.params.id })

This can cause firing of multiple same API requests at the app init.

I would move that to componentWillMount()


Comments from Reviewable

@bond95
Copy link
Contributor Author

bond95 commented Feb 28, 2018

@mareklibra it already in componentWillMount, otherwise it wouldn't work. Because component will mount only one time, if internet speed gonna be too slow then it don't get filterChecked in time.

@mareklibra
Copy link
Contributor

I'm sorry, I don't understand following sentence:

it already in componentWillMount, otherwise it wouldn't work.

In recent implementation, I can see the call within componentWillUpdate() , which is not called for first (initial) rendering but for every other, means whenever props or state change. This can cause multiple API requests until the very first one finishes.
This can be fixed in multiple ways, the simplest one seems to be just moving the call to the componentWillMount or similar to ensure, it is called just once.

If availability of state.config.isFilterChecked is an issue at the time of componentWillUpdate() calling, it can be fixed i.e. either by

  • saga (not preferred)
  • a wait function performing up to N sleeps of 50ms (or so) until state.config.isFilterChecked === true, then calling a callback function which is the dispatch in our case

@bond95
Copy link
Contributor Author

bond95 commented Feb 28, 2018

@mareklibra

I'm sorry, I don't understand following sentence:

Here you can see almost the same functionality https://github.com/bond95/ovirt-web-ui/blob/d972d0d2a9dfbec9909239e7cdabba678aa174ba/src/components/Pages/index.js#L13

This can cause multiple API requests until the very first one finishes.

It wouldn't, because if VM already in redux state, then it don't gonna send request again, you can see it here in vmInStore:

if (!vmInStore && Selectors.isFilterChecked()) {

@mareklibra
Copy link
Contributor

It wouldn't, because if VM already in redux state,

It will. The componentWillUpdate() is called whenever props or state are changed. And at the app initialization, there are multiple changes occurring, so this might be called multiple times shen the VM is still not in the store (means untile the first getVm() finishes, consider scenario with overloaded server).

@bond95
Copy link
Contributor Author

bond95 commented Feb 28, 2018

@mareklibra what do you think now?

Bug: If open detail of VM that is not on first page, and refresh it, it'll leads to main page.
Fixes: oVirt#491
@mareklibra mareklibra merged commit f9bfe46 into oVirt:master Feb 28, 2018
@mareklibra mareklibra mentioned this pull request Feb 28, 2018
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.

3 participants