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

chore: incoming webhook events UI #6317

Merged
merged 6 commits into from
Feb 23, 2024
Merged

Conversation

nunogois
Copy link
Member

@nunogois nunogois commented Feb 22, 2024

https://linear.app/unleash/issue/2-1937/incoming-webhook-events-ui

This PR implements the UI for incoming webhook events.

We're also introducing a new SidePanelList component that we'll be able to reuse when we tackle action set events. This PR also promotes ReactJSONEditor to a common component and adapts it slightly for this use case.

image

image

We're refreshing the events view every 5s, so if you're monitoring events for a specific incoming webhook you can see the latest ones coming in.
We load 20 (configurable through the hook) events by default. Everytime you reach the end of the list you can load 20 more events until you reach the end of the event list.

image

Copy link

vercel bot commented Feb 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 23, 2024 10:23am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Feb 23, 2024 10:23am

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

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

Code Health Quality Gates: FAILED

  • Declining Code Health: 2 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Declining Code Health (highest to lowest):

Comment on lines +53 to +54
const [eventsModalOpen, setEventsModalOpen] = useState(false);

Choose a reason for hiding this comment

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

❌ Getting worse: Large Method
IncomingWebhooksTable increases from 221 to 239 lines of code, threshold = 120

Why does this problem occur?

Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function. Read more.

To ignore this warning click here.

previousPageData: IncomingWebhookEventsResponse,
) => {
// Does not meet conditions
if (!incomingWebhookId || !isEnterprise || !incomingWebhooksEnabled)

Choose a reason for hiding this comment

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

❌ New issue: Complex Conditional
getKey:SWRInfiniteKeyLoader has 1 complex conditionals with 2 branches, threshold = 2

Why does this problem occur?

A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell. Read more.

To ignore this warning click here.

@nunogois nunogois force-pushed the chore-incoming-webhook-events-ui branch from f4093ca to e09f279 Compare February 22, 2024 14:35
Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

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

Code Health Quality Gates: FAILED

  • Declining Code Health: 2 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Declining Code Health (highest to lowest):

Comment on lines +31 to +57
...(editorStyle === 'sidePanel' && {
'&&&': {
'& .jse-main': {
minHeight: 0,
},
'--jse-main-border': 0,
'& > div': {
height: '100%',
},
'& .jse-focus': {
'--jse-main-border': 0,
},
'& .cm-gutters': {
'--jse-panel-background': 'transparent',
'--jse-panel-border': 'transparent',
},
'& .cm-gutter-lint': {
width: 0,
},
'& .jse-text-mode': {
borderBottomRightRadius: theme.shape.borderRadiusMedium,
},
'& .cm-scroller': {
'--jse-delimiter-color': theme.palette.text.primary,
},
},
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

This felt a tad noisy, but I guess this is where it belongs

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, can't think of a better way of doing this right now, as I want this specific style for this component when used on the new side panel component.

Comment on lines +13 to +15
const LazyReactJSONEditor = lazy(
() => import('component/common/ReactJSONEditor/ReactJSONEditor'),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could the component be exported this way? so it's always lazily imported? Or is that an implementation detail more than what we should do every time?

Copy link
Member Author

Choose a reason for hiding this comment

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

If I understand correctly you're asking whether we can export the lazy import, so that it is always lazy imported. I think it should always be up to the parent to decide how to import the component, but we can discuss this in the team.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes exactly. I saw it being lazily imported twice in the same PR, so figured it was worth asking if this should be the standard way of doing this

@@ -137,12 +151,16 @@ export const IncomingWebhooksModal = ({
<FormTemplate
loading={loading}
modal
title={title}
title=''
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we make this property/parameter optional? Or did you want to show that it's intentionally omitted?

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems like it's already optional so we can just omit it. Nice catch! f35add8

Copy link
Contributor

@daveleek daveleek left a comment

Choose a reason for hiding this comment

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

Couple of questions around things like potentially undefined parameters meaning we return null etc. But apart from that LGTM!

refreshInterval: 5000,
});

if (!incomingWebhook) {
Copy link
Contributor

Choose a reason for hiding this comment

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

under which circumstances would this occur?

Copy link
Member Author

Choose a reason for hiding this comment

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

incomingWebhook is optional on the props, so this saves us from adding the optional chaining operator (?.) everywhere we access incomingWebhook down the line. If there's no incomingWebhook, we simply don't render the component.

However to address your question, if we look at:
https://github.com/Unleash/unleash/pull/6317/files#diff-825b19367b6b8fc7939b8bc023222583d4778b4afef02559b16c7523a3fc68a8R263-R270
We'll see that we're passing down the selectedIncomingWebhook to this prop. Which means it is going to be undefined in case no incoming webhook has been selected, which is why the prop is optional.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, thanks for the explanation!

Copy link
Contributor

@daveleek daveleek Feb 23, 2024

Choose a reason for hiding this comment

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

What would the drawbacks of conditionally rendering the Modal be?
Edit: asking to be enlightened, not a blocking question!

Copy link
Member Author

@nunogois nunogois Feb 23, 2024

Choose a reason for hiding this comment

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

That could also work, but if we're using ConditionallyRender to accomplish that, the component should be returned in a callback, so something like this:

<ConditionallyRender
    condition={Boolean(selectedIncomingWebhook)}
    show={() => (
        <IncomingWebhooksModal
            incomingWebhook={selectedIncomingWebhook!}
            open={modalOpen}
            setOpen={setModalOpen}
            newToken={(token: string) => {
                setNewToken(token);
                setTokenDialog(true);
            }}
            onOpenEvents={() => {
                setModalOpen(false);
                setEventsModalOpen(true);
            }}
        />
    )}
/>

TypeScript also doesn't know that show only happens when the condition is true, so you also need to add the ! in selectedIncomingWebhook!. But if you do this, I believe it's safe to assume that the incomingWebhook prop is no longer optional since it's always going to be present.

While this could be a valid option and sometimes easier, the main drawbacks for me at this stage are noisy code at the parent level and less consistency with the rest of our code base.

Effectively, what we have now, checking for if (!incomingWebhook) return null inside the component, is the same as a conditional render, but shifting the responsibility of handling this gracefully to the component itself and not the parent.

previousPageData: IncomingWebhookEventsResponse,
) => {
// Does not meet conditions
if (!incomingWebhookId || !isEnterprise || !incomingWebhooksEnabled)
Copy link
Contributor

Choose a reason for hiding this comment

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

!incomingWebhookId
Is this a UI that can be opened without having an existing inc.webhook?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is related to: #6317 (comment)

The behavior we want for this hook is that you can call it whenever, but if you're not passing an incomingWebhookId, it should not fetch data.

Since you cannot conditionally call hooks in React, this matches the previous comment well, because you can just call this hook every time and it will gracefully handle undefined cases.

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

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

Code Health Quality Gates: FAILED

  • Declining Code Health: 2 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Declining Code Health (highest to lowest):

@nunogois nunogois merged commit 12ff4ab into main Feb 23, 2024
12 of 13 checks passed
@nunogois nunogois deleted the chore-incoming-webhook-events-ui branch February 23, 2024 11:01
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

Successfully merging this pull request may close these issues.

2 participants