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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add link to selected default-snippet in SnippetAreas view #5392

Merged
merged 6 commits into from Sep 9, 2020

Conversation

niklasnatter
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related issues/PRs related to #5143
License MIT

What's in this PR?

This PR adjusts the SnippetAreas view to provide a link to to the selected snippet. The SnippetAreas view is used to set default snippets for a webspace.

Why?

Because the Selection, SingleSelection, SmartContent and TeaserSelection provide a similar link feature. Also, it is quite annoying to search for the name of the selected snippet in the snippet list if there are a lot of snippets 馃檪

@alexander-schranz
Copy link
Member

For me this should target 2.1 branch as a bugfix, as it was just forgot there :)

@niklasnatter niklasnatter changed the base branch from master to release/2.1 July 3, 2020 17:30
@alexander-schranz alexander-schranz added the UX Affecting the end user label Jul 5, 2020
@alexander-schranz
Copy link
Member

I did test it and it did work as expected but it would be great if @danrot could have a look at the code also as he is most familiar with the deep links.

@@ -1,7 +1,8 @@
// @flow
import React from 'react';
import {shallow, mount, render} from 'enzyme';
import {Router} from 'sulu-admin-bundle/services';
import Router from 'sulu-admin-bundle/services/Router';
import Route from 'sulu-admin-bundle/services/Router/Route';
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't import {Route, Router} from 'sulu-admin-bundle/services'; also work?

<Button
className={snippetAreasStyles.titleButton}
onClick={this.handleSnippetClick}
skin="link"
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 that this results in the desired design, since the other deep links are also shown differently (i.e. without an underline). The other deep links are simply div elements with a button role, would keep it the same way here for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the reason i implemented this using a Button is that the react/jsx-no-bind eslint rule forces me to extract this "simple <div> into a separate component.

this is the second time in a short timespan that this rule complicates the implementation of a simple component. i would really like to enable the allowArrowFunctions of it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Personally I don't think that this makes it a lot more complicated, and extracting separate components is most of the time not such a bad idea. Also, as described in the rule documentation, that should speed up rendering. I tend to believe that, unless I see a benchmark proofing the opposite. I think we already have talked about this, and this rule would indeed not work anymore with hooks, but since we are not using them yet I would keep this rule for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you think its a good idea to extract a component in this case?

regarding performance, i tend to dont believe that, unless I see a benchmark proofing the opposite 馃槈
see https://cdb.reacttraining.com/react-inline-functions-and-performance-bdff784f5578

Copy link
Contributor

Choose a reason for hiding this comment

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

TBH, although it is an unpopular opinion, I would do it, because MobX advises to use small components (which is MobX specific, so that's for sure not mentioned in that article) and because the rule also avoids code like this:

<div
    onClick={() =>{
        methodCall1();
        methodCall2();
        if (someValue == 5) {
            methodCall3();
        } else {
            methodCall4();
            methodCall5();
        }
    }}
/>

This code should IMO definitely be extracted into a separate function, and the rule also enforces this.

These two reasons alone would be enough for me to accept the minor inconvenience creating a separate component causes. But if we still decide to not do that anymore I would change that in the eslint config instead of disabling it using comments, because it has about the same effect (I do not want to think or argue at every PR if that is a valid edge case for disabling this rule).

Copy link
Contributor

Choose a reason for hiding this comment

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

After some thinking this discussion took maybe a bit an unnecessary turn... I didn't dislike the Button solution very much, the only real concern for me was that the styling did not match. But this could be solved by introducing another skin (maybe "text"?) that would display it in the way we want it to be displayed. This way we could keep the rule, and the issue you have mentioned would be solved in many cases. What do you think?

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, a text skin for the Button component sounds okay to me. It will also prevent the issues with the react/jsx-no-bind for the most simple cases in the future, so thats nice 馃檪

const router = new Router({});
router.attributes = {
webspace: 'sulu',
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are the attributes removed in all these tests? Haven't they been necessary before as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the sulu-admin-bundle/services/Router is mocked to check the calls to the navigate method. the attributes are already set in the mock: https://github.com/sulu/sulu/pull/5392/files#diff-1d96f77c6059525b08c9dfc4dabee33aR22-R27

Copy link
Contributor

@danrot danrot left a comment

Choose a reason for hiding this comment

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

Not really sure why, but your PR also changed the text color of the primary button:

Screenshot from 2020-09-09 10-46-08

@danrot danrot merged commit 6df5665 into sulu:release/2.1 Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
UX Affecting the end user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants