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

Second step : Category hierarchy & article visibility - [merged] #44

Closed
cswendrowski opened this issue Sep 24, 2021 · 40 comments
Closed

Comments

@cswendrowski
Copy link

In GitLab by @adrien.schiehle on Sep 24, 2021, 12:17

Merges categories -> categories

A little bigger one. It has some recursive code to go through the whole category tree.

But that shouldn't pose any problem as long as there is no infinite loop in what we retrieve for World Anvil.

By saying that... I may need to add a security and the categoryBranchLevel 👼

This is what it does :

README_visibilityManagement

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 24, 2021, 12:24

added 1 commit

Compare with previous version

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 24, 2021, 12:26

Security has been added to avoid infinite loops

I think the browser would have kill the process anyway. But now, we see why it crashed 😄

@cswendrowski
Copy link
Author

requested review from @aaclayton

@cswendrowski
Copy link
Author

Are there parameters that are supported aside from limit and offset? I might prefer seeing the function signature here be more explicit:

async getCategories({limit=50, offset=0}={}) {
  ...
}

@cswendrowski
Copy link
Author

We should request with Dimitris that the API explicitly return a key for whether more results exist or not. As it stands it can be the case that there are exactly 50 categories, and so we don't know whether there are more to fetch or not. This applies to the articles API also.

@cswendrowski
Copy link
Author

Should this be batch.categories?

@cswendrowski
Copy link
Author

Rather than documenting as type * can be we be a bit more explicit, at the very least I assume they are objects?

@cswendrowski
Copy link
Author

Prefer using foundry.utils.mergeObject to namespace the helper. It may (eventually) be removed from the global scope.

@cswendrowski
Copy link
Author

Please declare all functions as function buildCategoryBranch(...args) rather than as const arrow functions.

@cswendrowski
Copy link
Author

I would like the journal.js file to only include the Application definition used to display the journal view. For some of the data processing I think we should create a separate module file, something like utilities.js

@cswendrowski
Copy link
Author

We should refactor these control buttons to have a shared handler that delegates actions. The pattern I would like to use is this:

HTML:*

<button type="button" class="world-anvil-control" data-action="toggle-wip"></button>

JS:

// In activateListeners
html.find(".world-anvil-control").click(this._onClickControlButton.bind(this));

// Below
_onClickControlButton(event) {
  event.preventDefault();
  const button = event.currentTarget;
  const action = button.dataset.action;
  switch ( action ) {
    case "toggle-wip"
      break;
    // other actions
  }
}

@cswendrowski
Copy link
Author

Hey Adrien, there is a lot here, so my first round of feedback is focused on the overall code structure and design. Once you get a chance to iterate on these comments I'll do a subsequent round(s) of feedback on the internal logic.

@cswendrowski
Copy link
Author

removed review request for @aaclayton

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:03

Commented on module/api.js line 146

We directly pass them to the WA api. Currently we only use the default values.

I agree with you on saying default parameters is better. I will also change it for getArticles(). (Which is what I copied from 👼 )

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:03

Commented on module/api.js line 146

changed this line in version 3 of the diff

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:03

Commented on module/api.js line 149

changed this line in version 3 of the diff

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:03

added 1 commit

Compare with previous version

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:07

Commented on module/api.js line 149

I didn't dwell too much in this. I just used the same method which was used for getArticles().

Maybe there already is some data on the batch object, I will look into it.

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:09

Commented on module/api.js line 152

changed this line in version 4 of the diff

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:09

added 1 commit

  • b929cdb - Bugfix for 50+ categories

Compare with previous version

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:09

Commented on module/api.js line 152

Bug spotted! well done.

I didn't have 50 categories for my tests, didn't see it.

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:20

Commented on module/journal.js line 8

changed this line in version 5 of the diff

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:20

added 1 commit

Compare with previous version

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:20

Commented on module/journal.js line 8

I have been a little lenient on those ones...

I will add basic type for them. I come from the backend side, with strong types. I was a little lost in the beginning when discovering javascript.

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:27

Commented on module/journal.js line 28

changed this line in version 6 of the diff

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:27

added 1 commit

  • 0df0015 - mergeObject => foundry.utils.mergeObject

Compare with previous version

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:27

Commented on module/journal.js line 28

I changed it.

May I ask it to appear in release note if you chose to remove it on 0.9 or 0.10 ? I find this method really useful, and I tend to use it almost everywhere in my custom code...

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:33

Commented on module/journal.js line 14

changed this line in version 7 of the diff

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:33

added 1 commit

  • f730534 - function instead of const

Compare with previous version

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:33

Commented on module/journal.js line 14

I never really understood the differences between the two of them (even after reading post on it)

If you want to only use function inside module, that's ok for me. I will do the change.

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:40

Commented on module/journal.js line 4

Hmmm... I think framework.js already do the work of your utilities.js file.

importArticle is in fact currently the only public method of the framework.js file.

We could perhaps put the function importOrRefreshArticle( articleId, {renderSheet=false} = {} ) inside it, but that would be all.

(This is a two lines function that call importArticle after trying to retrieve it from the Journal entries)

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 12:55

Commented on module/journal.js line 324

I'm really curious for this one.

I'm mostly self taught in frontend dev, and I may have picked really bad habits.

When I have buttons with similar display but different behavior, I tend to use something like that :

<button type="button" class="css-class action-class"></button>

And after that

.wy-world .my-sheet .css-class {
  /*stuff here */
}
html.find(".action-class").click(this._onClickDoSomething.bind(this));

It allows me to have :

  • 1 endpoint = 1 function

I find it more easy to read, and to describe inside comments

Is there some performance issue, or some other risky things by doing that ?

You previously put a one somewhat big method in journal.js that was handling all the clicks.

It was manageable with the number of clicks you had. But now with the visibility buttons (and later, the secrets one), it became far too big.

That's why I splitted it, and put action-classes instead of data-action.

If the problems comes from the '.world-anvil-control' which come on each line, I think I can simply remove it. action-classes should be enough to catch the click 👼 .

    html.find("button.link-folder").click(this._onClickLinkFolder.bind(this));
    html.find("button.display-folder").click(this._onClickDisplayFolder.bind(this));
    html.find("button.hide-folder").click(this._onClickHideFolder.bind(this));
    html.find("button.sync-folder").click(this._onClickSyncFolder.bind(this));
    html.find("button.link-entry").click(this._onClickLinkEntry.bind(this));
    html.find("button.browse-entry").click(this._onClickBrowseEntry.bind(this));
    html.find("button.display-entry").click(this._onClickDisplayEntry.bind(this));
    html.find("button.hide-entry").click(this._onClickHideEntry.bind(this));
    html.find("button.toggle-drafts").click(this._onClickToggleDrafts.bind(this));
    html.find("button.toggle-wip").click(this._onClickToggleWIP.bind(this));

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Sep 27, 2021, 13:06

Commented on module/api.js line 149

Unfortunately, nothing on the batch object. I tried to limit it to five element, so that I can check if there were something new retrieved, but no 😓

{
    "world": { "id": "d219435f...", [...]},
    "term": null,
    "offset": 0,
    "limit": "5",
    "order_by": "id",
    "trajectory": "ASC",
    "categories": [ {...}, {...}, {...}, {...}, {...} ]
}

It's the same structure as the one used from getArticles().

You think Dimitris will add something here? It's not the best, but its pretty standard and works.

I vote for letting it as it is.

@cswendrowski
Copy link
Author

requested review from @aaclayton

@cswendrowski
Copy link
Author

Thanks for your patience here, haven't forgotten about this one - just a bit overwhelmed right now with other work.

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Oct 12, 2021, 13:01

Commented on module/journal.js line 324

changed this line in version 8 of the diff

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Oct 12, 2021, 13:01

added 4 commits

  • f730534...ef08cb3 - 2 commits from branch foundrynet:master
  • e7a6d6c - Merge branch 'master' into categories
  • 536e323 - Trying to clean and remove unecessary modifs

Compare with previous version

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Oct 12, 2021, 13:03

Commented on module/journal.js line 324

I put it back as it was since you don't have much time for now to do a big review

@cswendrowski
Copy link
Author

In GitLab by @adrien.schiehle on Oct 12, 2021, 13:07

added 1 commit

Compare with previous version

@cswendrowski
Copy link
Author

changed target branch from master to categories

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

No branches or pull requests

1 participant