discourse/app
Alan Guo Xiang Tan 4da2e3fef4
DEV: Group and nest routes in `userPrivateMessages` into child routes (#19190)
Currently this is how the navigation structure looks like on the messages page: 

#### When personal inbox route is active

```
Inbox
  sent
  new
  unread
  archive
Group 1 Inbox
Group 2 Inbox
Tags
<Plugin Outlet>
```

#### When group inbox route is active

```
Inbox
Group 1 Inbox
  sent
  new
  unread
  archive
Group 2 Inbox
Tags
<Plugin Outlet>
```

With the existing structure, it is very easy for plugins to add additional navigation links by using the plugin outlet. In the redesigned user page navigation, the navigation structure on the messages page has been changed to look like this: 

#### When personal inbox route is active

```
---dropdown-------
| Inbox          |   Latest | Sent | New | Unread | Archive
------------------
```

#### When group inbox route is active 

```
---dropdown------
| Group 1 Inbox |   Latest | New | Unread | Archive
-----------------
```

With the new navigation structure, we can no longer rely on a simple plugin outlet to extend the navigation structure. Instead, we will need to introduce a plugin API for plugins to extend the navigation structure. The API needs to allow two things to happen: 

1. The plugin API needs to allow the plugin to register an item in the drop down and for the registered item to be "selected" whenever the plugin's routes are active. 

1. The plugin API needs to allow the plugin to register items into the secondary horizontal navigation menu beside the drop down. 

While trying to design the API, I struggle with trying to determine the "context" of the current route. In order words, it was hard to figure out if the current user is viewing the personal inbox, group inbox or tags. This is attributed to the fact that our current routing structure looks like this:

```
this.route(
  "userPrivateMessages",
  { path: "/messages", resetNamespace: true },
  function () {
    this.route("new");
    this.route("unread");
    this.route("archive");
    this.route("sent");
    this.route("warnings");
    this.route("group", { path: "group/:name" });
    this.route("groupArchive", { path: "group/:name/archive" });
    this.route("groupNew", { path: "group/:name/new" });
    this.route("groupUnread", { path: "group/:name/unread" });
    this.route("tags");
    this.route("tagsShow", { path: "tags/:id" });
  }
);
```

In order to provide context of the current route, we currently require all child routes under the `userPrivateMessages` route to set a `pmView` property on the `userPrivateMessages` controller. If the route requires additional context like the group currently active on the group inbox routes, the child routes would then have to set the `group` property on the `userPrivateMessages` controller. The problems with this approach is that we end up with many permutations of state on the `userPrivateMessages` controller and have to always clean up the state when navigating between the child routes. Basically, data is flowing upwards from the child routes into the parent controller which is not an ideal approach because we cannot easily determine where the "data" setup happens. Instead, we want to follow something similar to the "Data down, actions up" pattern where data flows downwards. In this commit, the `userPrivateMessages` routes have been changed to look like this: 

```
this.route(
  "userPrivateMessages",
  { path: "/messages", resetNamespace: true },
  function () {
    this.route("user", { path: "/" }, function () {
      this.route("new");
      this.route("unread");
      this.route("archive");
      this.route("sent");
      this.route("warnings");
    });

    this.route("group", { path: "group/:name" }, function () {
      this.route("archive");
      this.route("new");
      this.route("unread");
    });

    this.route("tags", { path: "/tags" }, function () {
      this.route("show", { path: ":id" });
    });
  }
);
```

Basically, we group the child routes based on the purpose each route servers. User inbox routes are grouped together while group inbox routes are grouped together. A big benefit of this is that now have a different Ember router and controller for each grouping of child routes. The context of the current route is then tied directly to the route name instead of requiring each child route to set an attribute on the parent controller. 

The second reason for why we needed to group the child routes together is because it allows us to pass the responsibility of rendering the secondary navigation links to the child routes. In this commit, we use the `{{in-element}}` modifier in the child route to render the secondary navigation links.

```
---dropdown--------
| Group 1 Inbox   |     Latest | New | Unread | Archive
------------------------
<parent template>    <horizontal secondary navigation links element>
```

This means that each child route with its own model and context can then handle the responsibility of rendering the secondary navigation links without having to pass its context up to the `userPrivateMessages` controller. While this should have simplified by the `userPrivateMessages` controller, we can't do that in this commit because our current navigation structure requires all links for all message inboxes to remain on screen at all times. Once we fully transition to the redesigned user menu navigation, we will be able to greatly simplify things around the routes and controllers for `userPrivateMessages`. 

In an ideal world, we would deprecate the old routes but I have done a quick search through all known plugins and no plugins are currently relying on those routes. There is a chance we could break plugins here but I'll like to see some smoke first before committing to the effort of deprecating client side routes.
2022-12-01 09:21:12 +08:00
..
assets DEV: Group and nest routes in `userPrivateMessages` into child routes (#19190) 2022-12-01 09:21:12 +08:00
controllers FIX: Exclude claimed reviewables from user menu (#19179) 2022-12-01 07:09:57 +08:00
helpers Meta topic: https://meta.discourse.org/t/meta-theme-color-is-not-respecting-current-color-scheme/239815 (#18832) 2022-11-07 10:06:26 +03:00
jobs FIX: Exclude claimed reviewables from user menu (#19179) 2022-12-01 07:09:57 +08:00
mailers SECURITY: Filter tags in user notifications for visibility (#19239) 2022-11-29 10:35:41 -06:00
models FIX: Exclude claimed reviewables from user menu (#19179) 2022-12-01 07:09:57 +08:00
serializers FIX: Exclude claimed reviewables from user menu (#19179) 2022-12-01 07:09:57 +08:00
services FEATURE: Deleting a user with their posts also deletes chat messages. (#19194) 2022-11-28 13:32:57 -03:00
views FIX: Validate unsubscribe key has an associated user (#19262) 2022-11-30 14:29:07 -03:00