Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Truncate extension descriptions #8282

Merged
merged 4 commits into from
Jul 22, 2014
Merged

Truncate extension descriptions #8282

merged 4 commits into from
Jul 22, 2014

Conversation

le717
Copy link
Contributor

@le717 le717 commented Jun 29, 2014

This is for #8216.

  • Code to toggle between original and truncated description
  • Visual review
  • Code review

@le717
Copy link
Contributor Author

le717 commented Jun 30, 2014

Quick update: I have been working on displaying the full extension upon click, the trick has been changing only that description and not all of them. Once I get that, then I can work on toggling between the two. I'm sure I'll get it working very soon.

@le717
Copy link
Contributor Author

le717 commented Jun 30, 2014

@larz0 I've got the toggle actions you requested implemented, if you would want to look at it. I doubt this is the final code implementation, but that should not effect the look. I made a quick GIF overview for you too. :)

show-hide-desc2

description = entry.installInfo ? entry.installInfo.metadata.shortdescription : entry.registryInfo.metadata.shortdescription;
}

$(element).toggleClass("expand-desc trunc-desc");
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 was the only way I could figure out how to trigger the appropriate hide/show actions.

@larz0
Copy link
Member

larz0 commented Jun 30, 2014

Cool. Looks good! Thanks for the gif.


// To prevent awkward addition of ellipsis, try to truncate the description
// at the end of the last whole word
if (description.lastIndexOf(" ") < descriptionLimit && description.lastIndexOf(" ") > -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to set a var to description.lastIndexOf(" ") and use it instead of calling the function 3 times.

@le717
Copy link
Contributor Author

le717 commented Jul 1, 2014

@SAplayer Changes pushed. Do you still want me to move the truncate function to StringUtils for more general-purpose usage? The way I had to access the function in test/spec/ExtensionManager-test.js feels a bit hacky to me.

* @param {boolean} short true if short description should be shown, false for full length.
*/
function toggleDescription(id, element, short) {
var description, linkTitle,
Copy link
Contributor

Choose a reason for hiding this comment

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

It's usually one variable per line

Copy link
Contributor

Choose a reason for hiding this comment

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

You can use more than one in he first line. JSLint allows you to do that. I often do that so that you don't get lines with just a variable name.

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 was unsure about this, so I checked and just double checked the coding conventions, and I found nothing about single/multiple variables per line. Should I leave it or initialize them as null or something?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is fine how it is now. Those are initialized to undefined by JavaScript anyway.

@le717
Copy link
Contributor Author

le717 commented Jul 1, 2014

Changes pushed, except for the toggleClass second parameter question. :)

linkTitle = Strings.VIEW_TRUNCATED_DESCRIPTION;
}

$element.toggleClass("expand-desc trunc-desc")
Copy link
Contributor

Choose a reason for hiding this comment

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

The old comment is gone. So i'll reply here.

You are not really using the classes to style the element, so maybe you shouldn't use a class. To store data in the DOM use the data attributes. You can just have a single data-* attribute and change i'ts value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or if that doesn't work, you can use 2 toggles.

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 data-* method works. Now what to show it? data-toggle-desc?

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 know. I didn't wrote because I couldn't think of a good name for it.

@le717
Copy link
Contributor Author

le717 commented Jul 1, 2014

Changes pushed. I ended up calling it data-toggle-desc because it makes sense to what it does, at least to me.

@@ -156,6 +189,10 @@ define(function (require, exports, module) {
ExtensionManager.markForRemoval($target.attr("data-extension-id"), true);
} else if ($target.hasClass("undo-update")) {
ExtensionManager.removeUpdate($target.attr("data-extension-id"));
} else if ($target.attr("data-toggle-desc") === "expand-desc") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to let you know, jQuery has a .data() method to get the data attributes, which makes the code look a bit cleaner.

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, but all the other code in that same if-else-if block uses .attr() to access the data- attributes. So I guess the question of which one to use comes down to consistency with the rest of the code around it for better method.

Also, I can't seem to get .data() to work correctly. It will pick up the expand-desc value but not the trunc-desc value, so the description expands but never contracts.

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't saw the use of .attr() in this file. I've been using .data() for data attributes. Maybe to make it work you need to also add the data attributes with .data()? Anyway it was a minor nit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alrighty then. I'll leave it as-is.

@le717
Copy link
Contributor Author

le717 commented Jul 2, 2014

Thanks for reviewing this, everyone. The only questions I have now are

  1. If ExtensionManagerView._truncateDescription() should be slightly refactored to have the limit set via argument and move it to StringUtils (as @SAplayer mentioned)
  2. Do need to be unit tests for the short/full description displaying?

That first one is important, as right now in order to fix the current unit test for description view (test/spec/ExtensionManager-test.js, line 776) makes a new instance of ExtensionManagerView just to access the function. I feel funny about doing that, not to mention it is probably not the most ideal thing in the world, considering all that ExtensionManagerView does.

@TomMalbran
Copy link
Contributor

@le717 If you want you can do that but since no other module uses it, I am not sure if is required.

My concern is about having the description duplicated for almost every extension, since shortDescription is actually the description for almost all the extensions. With that said, hasShortDescription has kind of the wrong meaning if you don't read how it is implemented, since every extension has a shortDescription and you want to expand the ones where the short description is actually shorter than the description. But I am not quite sure what is the best solution.

@le717
Copy link
Contributor Author

le717 commented Jul 2, 2014

I'm just thinking about efficiency and good practice, as ExtensionManagerView is what initializes the entire registry manager... I'll leave it there for now, and maybe someone from the Adobe team will know what to do.

I could change it to where it shortened the description, check if it is different, and only if it is different will it be added to the extension details. This way, for most of the extensions only one copy of the description will be present.

{{^metadata.description}}
<p class="muted"><em>{{Strings.EXTENSION_NO_DESCRIPTION}}</em></p>
{{/metadata.description}}
<span class="ext-full-description">
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 looked up the Mustache syntax, and I think this how all this should work.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine, but maybe a some indentation will make the code look better like:

            {{#hasShortDescription}}
                {{metadata.shortdescription}}
            {{/hasShortDescription}}
            {{^hasShortDescription}}
                {{#metadata.description}}
                    {{metadata.description}}
                {{/metadata.description}}
                {{^metadata.description}}
                    <p class="muted"><em>{{Strings.EXTENSION_NO_DESCRIPTION}}</em></p>
                {{/metadata.description}}
            {{/hasShortDescription}}

@TomMalbran
Copy link
Contributor

@le717 Sorry for not getting back to you earlier. This is looking good, I think that we can do those few changes and then merge it. You also need to merge with master.

@le717
Copy link
Contributor Author

le717 commented Jul 16, 2014

@TomMalbran No problem. I understand not being able to do this stuff all the time. :)

Changes for all but the test pushed. I will fix that ASAP, can't code anymore today.

So, my updated TODO for the code review now looks like:

  • Fix test
  • Any other review changes
  • Rebase
  • Merge with master

if (lastSpaceChar < len && lastSpaceChar > -1) {
str = str.substr(0, lastSpaceChar);
}
return str;
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrong indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@le717
Copy link
Contributor Author

le717 commented Jul 21, 2014

@TomMalbran Changes pushed, ready for rereview. The original description unit test is broken for some reason, not sure how to to fix it quite yet.

EDIT And for some reason Travis does not build my PR at all anymore...

@le717
Copy link
Contributor Author

le717 commented Jul 21, 2014

@TomMalbran Unit tests fixed, ready for review. I'm doing my best to get this in for Release 42 so the extension manager doesn't so odd now that #7995 is merged. :)



if (info.metadata.description !== undefined) {
context.hasShortDescription = StringUtils.truncate(info.metadata.description, 140);
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't look like we need hasShortDescription. We could just have info.metadata.shortdescription = StringUtils.truncate(info.metadata.description, 140);

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 did this so an info.metadata.shortdescription key would not be created for every extension (like you wanted). Without it, most of the info.metadata.shortdescription keys will have a value of undefined.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but right now it works different from before. So it can be changed again. Before shortDesc and desc where the same for most, which meant duplicated strings. But now it is undefined, so that is 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.

Fixed and pushed.

@TomMalbran
Copy link
Contributor

You still need to fix the merge issue. You can merge with master and then fix it.

@@ -1 +1 @@
Subproject commit 6c0cd2b56b50837a010bd27f322a57edfbe9fee9
Subproject commit 64bee5830b6f838c2c9be6dded98a5dac794dbcd
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be there. You need to update the submodules

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yikes. I was watching for that but it seems I missed it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@TomMalbran
Copy link
Contributor

I think this is almost ready besides those last comments. But I noticed that most short descriptions are just a few chars shorter. Maybe we could allow more chars before using a short description.

@TomMalbran
Copy link
Contributor

We are about to branch to release, so I am not sure if it can fit into release 41. We have to be sure that is bug-free and that it does not causes any other bug if we want to merge it right now.

@le717
Copy link
Contributor Author

le717 commented Jul 22, 2014

@TomMalbran How much longer should it be? @larz0 suggested it be the 140 character limit. I've been using this branch as my Brackets version since I started the PR with no issues.

@TomMalbran
Copy link
Contributor

@le717 Figuring the best length might be an issue too. I tried with 200 and it feels a bit better. The descriptions are still short enough, and there are less with a short description.

@le717
Copy link
Contributor Author

le717 commented Jul 22, 2014

@TomMalbran 200 looks good and knocks out mainly the overly long descriptions now. I think @larz0 liked 140 because I mentioned that is the Twitter character limit and devs can (usually) describe their extension within that limit. @larz0 Do you have any further input on this?

@dangoor
Copy link
Contributor

dangoor commented Jul 22, 2014

I personally find 140 characters to be painfully limited. 200 seems reasonable.

@TomMalbran
Copy link
Contributor

I see. 140 is a good limit, but since is a recent thing, I see several extensions that extend just a little bit more than that, so 200 seems to fit better with us at this point.

@le717
Copy link
Contributor Author

le717 commented Jul 22, 2014

@TomMalbran @dangoor Limit increased to 200 characters and change pushed.

TomMalbran added a commit that referenced this pull request Jul 22, 2014
Truncate extension descriptions
@TomMalbran TomMalbran merged commit 8ce9221 into adobe:master Jul 22, 2014
@TomMalbran
Copy link
Contributor

Thanks. Merged :)

@le717
Copy link
Contributor Author

le717 commented Jul 22, 2014

I have such a huge smile on my face right now I probably look silly. :D

@TomMalbran
Copy link
Contributor

Hehe :)

@larz0
Copy link
Member

larz0 commented Jul 22, 2014

reaction9

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants