هل من الممكن تمرير معلمات إلى واجهة برمجة التطبيقات التي تنشئ روابط المجتمع؟

e.g.

       api.addCommunitySectionLink({
         name: "intersection-navigator",
         route:"tags.intersection",
         title: I18n.t("tag_intersection_navigator.link.title"),
         text: I18n.t("tag_intersection_navigator.link.text")
       })

… will fail because that route requires a tag_id.

I’ve tried adding:

        params: { tag_id:  siteSettings.discourse_tag_intersection_navigator_all_word },
        model: { tag_id: siteSettings.discourse_tag_intersection_navigator_all_word },

… but I strongly suspect this isn’t processed as necessary by the api …

4 إعجابات

Ah, I’ve made progress!

It involves this:

3 إعجابات

Specifically, I think it’s here: discourse/app/assets/javascripts/discourse/app/lib/sidebar/custom-community-section-links.js at d0c3f3b8fe6905e7e33ae4944cdf44c11ccc0df6 · discourse/discourse · GitHub

if we add this it should work:

get models() {
 return args.models;
}
3 إعجابات

Oh thanks for opening!

إعجاب واحد (1)

Oh and since there’s a typeof args === "function" condition, you could do something like this immediately:

api.addCommunitySectionLink((Base) =>
  class CustomLink extends Base {
    get name() {
      return "intersection-navigator";
    }

    get route() {
      return "tag.show";
    }

    get models() {
      return ["tagid"];
    }

    get title() {
      return I18n.t("tag_intersection_navigator.link.title");
    }

    get text() {
      return I18n.t("tag_intersection_navigator.link.text");
    }

  }
);
إعجاب واحد (1)

yes, that’s what I’m already doing … but there’s some funny later in the process

إعجاب واحد (1)

For some reason, this isn’t quite it and I’m getting some complaint about lack of postStream upon click:

api.addCommunitySectionLink((baseSectionLink) => {
        return class CustomSectionLink extends baseSectionLink {
          get name() {
            return "intersection-navigator";
          }

          get route() {
            return "tags.intersection";
          }

          get models() {
            return [{tag_id: siteSettings.discourse_tag_intersection_navigator_all_word}];
          }

          get title() {
            return I18n.t("tag_intersection_navigator.link.title")
          }

          get text() {
            return I18n.t("tag_intersection_navigator.link.text");
          }
        };
      });

It’s almost as if you need to include the model for the current route, which is weird!

إعجاب واحد (1)

what’s the output of that setting? it seems to work ok when I manually do:

get models() {
  return ["featured", "tv"];
}
إعجابَين (2)

yes, that works, that’s really helpful, thanks!

the setting is just a string. I was over-thinking it I think.

the name “models” for the query params isn’t 100% intuitive though?

Your PR will make this much neater, cheers!

إعجابَين (2)

yeah it wasn’t clear to me at first either, but it’s because in the end it uses Ember’s LinkTo component, which expects a model argument…

إعجاب واحد (1)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.