backstage-plugin-announcements icon indicating copy to clipboard operation
backstage-plugin-announcements copied to clipboard

🚀 Feature: Take signals into use

Open drodil opened this issue 1 year ago • 4 comments

🔖 Feature description

The signals plugin is coming in the Backstage 1.23.0 release. This allows to send push messages from backend to frontend plugins. Announcements plugin could also utilize this to show new announcements without need for polling or user to refresh the page.

🎤 Context

See backend integration: https://github.com/backstage/backstage/blob/master/plugins/signals-node/README.md And frontend: https://github.com/backstage/backstage/blob/master/plugins/signals-react/README.md

✌️ Possible Implementation

  1. Create signal announcements and publish to that whenever there is new announcement created
  2. In the frontend use useSignal('announcements') to get info about the changes
  3. When the signal is received, re-fetch and re-render the announcements

👀 Have you spent some time to check if this feature request has been raised before?

  • [X] I checked and didn't find similar issue

Are you willing to submit PR?

None

drodil avatar Jan 23 '24 10:01 drodil

@drodil I just read your medium post about Backstage notification, I think that announcements plugin is good candidate for using NotificationService

gaelgoth avatar May 07 '24 20:05 gaelgoth

@gaelgoth, there is a bit more context around the use of signals in this discord thread.

I've also been thinking about ways the notifications plugins may make the announcements plugins obsolete. We could contribute a few components that render the output of the broadcast feature to announcement-styled components.

So users would receive a notification, but you could also broadcast as an announcement. Something along those lines.

kurtaking avatar May 10 '24 19:05 kurtaking

I've also been thinking about ways the notifications plugins may make the announcements plugins obsolete. We could contribute a few components that render the output of the broadcast feature to announcement-styled components.

So users would receive a notification, but you could also broadcast as an announcement. Something along those lines.

Hi @kurtaking,

did you come to any conclusion regarding this integration? We would like to integrate announcements into our dev portal (with a possibility to notify with external tools like mattermost). In that matter we could contribute here to either an integration or the "announcement" components.

jjwedemyer avatar Jul 02 '24 10:07 jjwedemyer

I've also been thinking about ways the notifications plugins may make the announcements plugins obsolete. We could contribute a few components that render the output of the broadcast feature to announcement-styled components. So users would receive a notification, but you could also broadcast as an announcement. Something along those lines.

Hi @kurtaking,

did you come to any conclusion regarding this integration? We would like to integrate announcements into our dev portal (with a possibility to notify with external tools like mattermost). In that matter we could contribute here to either an integration or the "announcement" components.

I haven't had the time lately to think through this. Others have asked for similar functionality to what you want, so the change is definitely welcome.

kurtaking avatar Jul 08 '24 22:07 kurtaking

Wanted to chime in here before I look into contributing. We're using the Announcements plugin and the Notifications plugin. Would love to see posting an Announcement also send a broadcast notification or some sort of integration. I don't think Notifications supersedes Announcements as a UI for creating one and browsing past announcements is necessary. But it would be helpful to have a richer way of notifying users.

kunickiaj avatar Sep 26 '24 22:09 kunickiaj

IMO, this plugin might not need to integrate to notifications but instead only signals. This allows users to see new announcements without refreshing the page or navigating to the announcements page. Of course this does not mean it could not integrate to notifications as well but it should be done in a different PR and also make it configurable.

I've done both signals and notifications integration to my Q&A plugin that makes the UI update every time someone posts question/answer or votes and also sends a notification. For reference you might check it out here: https://github.com/drodil/backstage-plugin-qeta

drodil avatar Sep 27 '24 04:09 drodil

hey @drodil, spent some time on this, but I am missing something you are doing in qeta. I cannot get a response on the frontend. I pushed up some sandbox code, but the gist is below.

// backend - router.ts

router.post(
    '/announcements',
    async (req: Request<{}, {}, AnnouncementRequest, {}>, res) => {
      if (!(await isRequestAuthorized(req, announcementCreatePermission))) {
        throw new NotAllowedError('Unauthorized');
      }

      const { publisher, category, title, excerpt, body } = req.body;

      const announcement =
        await persistenceContext.announcementsStore.insertAnnouncement({
          id: uuid(),
          publisher,
          category,
          title,
          excerpt,
          body,
          created_at: DateTime.now(),
        });

      await signalAnnouncement(announcement, signals);

      return res.status(201).json(announcement);
    },
  );

export const signalAnnouncement = async (
  announcement: AnnouncementModel,
  signalService: SignalsService,
) => {
  if (!announcement) {
    return;
  }

  await signalService.publish<AnnouncementSignal>({
    recipients: { type: 'broadcast' },
    channel: 'announcement:new',
    message: {
      data: {
        ...announcement,
        created_at: announcement.created_at.toString(),
      },
    },
  });
  console.log('Broadcasted announcement');
};
// frontend - banner component

export const SignalAnnouncementBanner = (props: NewAnnouncementBannerProps) => {
  const [announcement, setAnnouncement] = useState<
    AnnouncementSignal['data'] | undefined
  >();
  
  // I've tried a few different channel strings
  const { lastSignal } = useSignal<AnnouncementSignal>('announcements:announcements:new');

  useEffect(() => {
    if (!lastSignal) {
      console.log('is null', lastSignal);
      return;
    }

    setAnnouncement(lastSignal?.data);
  }, [lastSignal]);

  if (!announcement) {
    return null;
  }

  return (
    <AnnouncementBanner
      key={announcement.id}
      announcement={announcement}
      variant={props.variant}
    />
  );
};

Does the signals plugin require the events plugin?

kurtaking avatar Sep 28 '24 15:09 kurtaking

Hi, yes it does and have you also installed the plugin on the frontend?

drodil avatar Sep 28 '24 15:09 drodil

Hi, yes it does and have you also installed the plugin on the frontend?

Pretty sure I have the correct signals plugins installed, but I do not support events right now. Will need to do that first. I might be able to get to that tonight, but will be gone all day spending time with the family.

kurtaking avatar Sep 28 '24 15:09 kurtaking

@drodil, do you have time to take a look at https://github.com/procore-oss/backstage-plugin-announcements/pull/436? The banner is still not appearing after creating a new announcement. lastSignal remains undefined regardless of what I try.


Implemented events system in https://github.com/procore-oss/backstage-plugin-announcements/pull/437.

kurtaking avatar Sep 29 '24 05:09 kurtaking

https://github.com/procore-oss/backstage-plugin-announcements/blob/main/plugins%2Fannouncements%2Fdev%2Findex.tsx should include and initialize the signals-plugin and dependency should be changed to be devDependency.

drodil avatar Sep 29 '24 06:09 drodil

Example here: https://github.com/drodil/backstage-plugin-qeta/blob/main/plugins%2Fqeta%2Fdev%2Findex.tsx#L42

drodil avatar Sep 29 '24 06:09 drodil

Is there a release coming with this support?

drodil avatar Sep 30 '24 07:09 drodil

Is there a release coming with this support?

I'm under the impression it's live. I had issues with the release job recently. I thought it's fixed but I'll double check when I get to a computer.

kurtaking avatar Sep 30 '24 12:09 kurtaking

Thanks! Was just wondering as Github doesn't have any releases 🙂

drodil avatar Sep 30 '24 14:09 drodil

Thanks! Was just wondering as Github doesn't have any releases 🙂

Sad day. That needs to be fixed. 😢

kurtaking avatar Sep 30 '24 14:09 kurtaking

💭 ugh, another possible benefit of migrating to @backstage/community-plugins would be to leverage their release process.

kurtaking avatar Sep 30 '24 14:09 kurtaking