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

DEVPROD-9626: Allow rendering command sections outside of function sections #325

Merged
merged 25 commits into from
Aug 27, 2024

Conversation

SupaJoon
Copy link
Contributor

@SupaJoon SupaJoon commented Aug 20, 2024

DEVPROD-9626

Description

These code changes allow rendering a command outside of a function. During section parsing, function entries will be generated for top-level commands and they will be tagged with containsTopLevelCommand. This way, log searching and section toggling can make calculations based on the property that all functions have at least 1 command and during render time, function headers that contain a top-level command will be skipped.
Reach out to me for a log URL to test in beta.

@SupaJoon SupaJoon requested a review from a team as a code owner August 20, 2024 15:24
Comment on lines 83 to 86
const isFuncOpen =
(sectionState[func?.functionID]?.isOpen ||
func?.containsTopLevelCommand) ??
false;
Copy link
Contributor

Choose a reason for hiding this comment

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

if there a reason we can't just automatically set the section to be open during processing if the function contains top level command?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I rather handle this during processedLogLine construction (the render prop) so I can treat functions that contain top level commands the same as any other function when it comes to toggling all sections or any other open/close state logic we might add in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it seems confusing because if the command is visible, doesn't that mean that the invisible parent function is technically open all of the time? but the SectionState says that the function is not open -- wouldn't that deviate logically from the pattern that we have now?

I didn't really investigate that hard but it seems like it'd might be possible to add isOpen: containsTopLevelCommand || isOpen in the sections code somewhere

Copy link
Contributor Author

@SupaJoon SupaJoon Aug 26, 2024

Choose a reason for hiding this comment

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

I refactored the code so the open state that's pushed to ProcessedLogLines is not related to containsTopLevelCommand. I also made this refactor ticket: https://jira.mongodb.org/browse/DEVPROD-10149

Copy link
Contributor

Choose a reason for hiding this comment

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

I still think functions should be open if the command is visible and that the state should reflect that, but if the refactor will address that, then I'm fine with this for now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, that PR will address how top-level commands are represented in SectionState and SectionData by removing any function placeholders.

@SupaJoon SupaJoon requested a review from minnakt August 22, 2024 17:15
Comment on lines 106 to 109
expectError(
() => screen.getByLabelText("Checkmark With Circle Icon"),
"Unable to find a label with the text of: Checkmark With Circle Icon",
);
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason we're using expectError rather than expecting it to not be in the document (like we do elsewhere)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The screen query throws an error in this assertion and will automatically fail:
expect(screen.getByLabelText("Checkmark with Circle Icon")).not.toBeInTheDocument();
I tried this also and and the same error blocks the assertion from completing:
expect(screen.getByLabelText("Checkmark with Circle Icon")).toThrow()
That's how I decided to check the error itself with a try/catch.

Copy link
Contributor

Choose a reason for hiding this comment

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

it's probably because you want to use queryByLabelText. I think we can keep the expectError function, but we should update this to match the rest of the tests

Comment on lines +95 to +99
if (processedLogLine.isTopLevelCommand) {
status = includesLineNumber(processedLogLine, failingLine)
? SectionStatus.Fail
: SectionStatus.Pass;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I know I said this before, but do we want to reconsider moving the status calculation up higher in the code? This component would end up looking really clean because it would just use processedLogLine.status

Copy link
Contributor Author

@SupaJoon SupaJoon Aug 23, 2024

Choose a reason for hiding this comment

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

We can do the calculation earlier on achieve the refactor you're mentioning but I don't think it will necessarily be cleaner at this point in time. Currently, the status calculation only happens in this file and is only important for render purposes.
To get the value to propagate through, useSections would have to accept a separate failingLineNumber prop, and FunctionEntry, CommandEntry, SubsectionHeader and SectionHeader would all need to push along the value.

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 file a non-release blocking ticket to do the refactor? I think it makes sense for a section to inherently know its own status and could be useful to have in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@minnakt I think we should make this ticket when we need the SectionStatus to do operations on ProcessedLogLines. I don't think the refactor will have a great benefit until then since includesLineNumber is a constant time operation.

Copy link
Contributor

Choose a reason for hiding this comment

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

it's less about the performance benefits (I assume there are none) and more that I think it makes sense to have all of this information in one place. I can make a ticket since I feel pretty strongly about it

@SupaJoon SupaJoon requested a review from minnakt August 23, 2024 15:41
Copy link
Contributor

@minnakt minnakt left a comment

Choose a reason for hiding this comment

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

not sure why it didn't register my re-review so leaving another comment 👀 (I left comments in the threads above)

@SupaJoon SupaJoon requested a review from minnakt August 26, 2024 14:43
Comment on lines 102 to 103
if (!renderCommands) {
// The function is closed. Skip all log lines until the end of the function.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if this comment is clear after the updates (i.e. why does !renderCommands mean the function is closed?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I updated the comment.

Comment on lines 83 to 86
const isFuncOpen =
(sectionState[func?.functionID]?.isOpen ||
func?.containsTopLevelCommand) ??
false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I still think functions should be open if the command is visible and that the state should reflect that, but if the refactor will address that, then I'm fine with this for now

Comment on lines +95 to +99
if (processedLogLine.isTopLevelCommand) {
status = includesLineNumber(processedLogLine, failingLine)
? SectionStatus.Fail
: SectionStatus.Pass;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

it's less about the performance benefits (I assume there are none) and more that I think it makes sense to have all of this information in one place. I can make a ticket since I feel pretty strongly about it

@SupaJoon SupaJoon merged commit e3a9f5e into evergreen-ci:main Aug 27, 2024
1 of 2 checks passed
@SupaJoon SupaJoon deleted the DEVPROD-9626 branch August 27, 2024 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants