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

Separated Alert to View / Edit / New page components #4183

Merged
merged 6 commits into from
Oct 7, 2019

Conversation

ranbena
Copy link
Contributor

@ranbena ranbena commented Sep 24, 2019

  • Refactor

Description

By request in comment for separation of mega file, now Alert.jsx renders:

<div className="container alert-page">
  {mode === MODES.NEW && <AlertNew {...commonProps} />}
  {mode === MODES.VIEW && <AlertView canEdit={canEdit} {...commonProps} />}
  {mode === MODES.EDIT && <AlertEdit {...commonProps} />}
</div>

Also, made abstracted the alert name component into:

<Title alert={alert} name={name} onChange={onNameChange} editMode />

@ranbena ranbena requested a review from arikfr September 24, 2019 17:33
@ranbena ranbena self-assigned this Sep 24, 2019
alert: AlertType.isRequired,
queryResult: PropTypes.object, // eslint-disable-line react/forbid-prop-types,
pendingRearm: PropTypes.number,
delete: PropTypes.func.isRequired,
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 keep breaking Github @kravets-levko :)

{
path: '/alerts/new',
title: 'New Alert',
mode: MODES.NEW,
Copy link
Member

Choose a reason for hiding this comment

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

Why not have each path render its own component? What's the purpose of having a single top level page component? To share the callback functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Less code duplication
Also allows alert, query and queryResult to be props instead of state, simplifying the page components.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also allows this, which imo is more elegant than redirection to view page:

// force view mode if can't edit
if (!canEdit) {
this.setState({ mode: MODES.VIEW });
}

Copy link
Member

Choose a reason for hiding this comment

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

You could use composition instead:

<AlertPage ...>
    <EditAlertPage ...>
</AlertPage>

But the ability to change states without making API request is a win. In the long run, we should find a way to do this without as this pattern isn't always applicable. But here it's fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But the ability to change states without making API request is a win.

Are you sure that's happening here? Changing Alert states mandates url changes which causes page to reload (navigateTo).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arikfr it was an easy modification e865460

@arikfr
Copy link
Member

arikfr commented Sep 26, 2019 via email

@ranbena
Copy link
Contributor Author

ranbena commented Sep 26, 2019

I don't think that just rendering the view page when you hit the edit url is the thing to do.

That's not the case. The edit button doesn't get rendered if the user can't edit the alert.
It's for the off-chance that an editing user shares an alert url with a non-editing user.

@arikfr
Copy link
Member

arikfr commented Sep 26, 2019

It's for the off-chance that an editing user shares an alert url with a non-editing user.

I know and still I think it has the potential to confuse people who did expect to edit the alert using this URL. Even showing a notification saying something like "You do not have permission to edit this Alert." is probably enough. Not a huge priority.

@ranbena
Copy link
Contributor Author

ranbena commented Sep 26, 2019

Was also an ez change eecb6d3

As long as you're ok with the prompt being a notification (cause it's easy):

Screen Shot 2019-09-26 at 15 11 23

And instead of hiding action buttons they're disabled with a tooltip:

Screen Shot 2019-09-26 at 15 32 21

@arikfr arikfr merged commit be404a4 into alert-1 Oct 7, 2019
@arikfr arikfr deleted the alert-separation branch October 7, 2019 08:46
@arikfr
Copy link
Member

arikfr commented Oct 7, 2019

Merged.

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.

2 participants