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

fix: Add message explaining that build logs are deleted after 180 days. #4402

Merged
merged 1 commit into from
Mar 12, 2024

Conversation

svenaas
Copy link
Contributor

@svenaas svenaas commented Mar 4, 2024

Fixes #4379

Changes proposed in this pull request:

  • Adds a message to the build logs page which is displayed when a build is older than 180 days, after which build logs are no longer available for display
  • Adds a loading indicator on the build logs page
  • Refactors CommitSummary to take buildDetails instead of buildID, requiring parents to retrieve the build
  • Refactors build details fetch into hooks
  • Adds tests for CommitSummary

security considerations

None. Adds explanatory and status information to the user interface regarding details already present.

sknep
sknep previously approved these changes Mar 6, 2024
Copy link
Contributor

@sknep sknep left a comment

Choose a reason for hiding this comment

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

this looks awesome :)

sknep
sknep previously approved these changes Mar 6, 2024
@svenaas svenaas requested a review from a team March 6, 2024 20:44
@svenaas
Copy link
Contributor Author

svenaas commented Mar 6, 2024

If you want to try this out locally the easiest route is probably to hardcode a completedAt on line 17 of siteBuildLogs.jsx. Or you could edit a build in the DB to prematurely age it.

Comment on lines 55 to 62
{buildTooOld(buildDetails) && (
<div>
<SiteBuildLogTable buildLogs={['Builds more than 180 days old are deleted according to platform policy.']} />
</div>
)}
{(!logs || logs?.length === 0) && (
<div>
<SiteBuildLogTable buildLogs={['This build does not have any build logs.']} />
Copy link
Contributor

@sknep sknep Mar 6, 2024

Choose a reason for hiding this comment

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

This should work, but I haven't run it locally

Suggested change
{buildTooOld(buildDetails) && (
<div>
<SiteBuildLogTable buildLogs={['Builds more than 180 days old are deleted according to platform policy.']} />
</div>
)}
{(!logs || logs?.length === 0) && (
<div>
<SiteBuildLogTable buildLogs={['This build does not have any build logs.']} />
{(!logs || logs?.length === 0) && (
<div>
{buildTooOld(buildDetails) && (
<SiteBuildLogTable buildLogs={['Builds more than 180 days old are deleted according to platform policy.']} />
)}
{!buildTooOld(buildDetails) && (
<SiteBuildLogTable buildLogs={['This build does not have any build logs.']} />
)}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It just needs a little more to work:

Suggested change
{buildTooOld(buildDetails) && (
<div>
<SiteBuildLogTable buildLogs={['Builds more than 180 days old are deleted according to platform policy.']} />
</div>
)}
{(!logs || logs?.length === 0) && (
<div>
<SiteBuildLogTable buildLogs={['This build does not have any build logs.']} />
{(!logs || logs?.length === 0) && (
<div>
{buildTooOld(buildDetails) && (
<SiteBuildLogTable buildLogs={['Builds more than 180 days old are deleted according to platform policy.']} />
)}
{!buildTooOld(buildDetails) && (
<SiteBuildLogTable buildLogs={['This build does not have any build logs.']} />
)}
</div>
)}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I may have just snipped that in a different place from you. Never mind.

Here's the approach I came up with though:

      {(() => {
        if (!logs || logs?.length === 0) {
          if (buildTooOld(buildDetails)) {
            return (
              <div>
                <SiteBuildLogTable buildLogs={['Builds more than 180 days old are deleted according to platform policy.']} />
              </div>
            );
          }
          return (
            <div>
              <SiteBuildLogTable buildLogs={['This build does not have any build logs.']} />
            </div>
          );
        }
        return null;
      })()}

Which do you think is more readable?

Copy link
Contributor

@sknep sknep Mar 7, 2024

Choose a reason for hiding this comment

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

oh i like this one just fine! you don't have to wrap the <SiteBuildLogTable> in a <div> if you don't need to for layout purposes. It's just that the return () statement can only have one parent node, so if you have two or more elements, you wrap them in a div or <>. Each of these is in their own return, and only one element, so you could save yourself 4 lines if you like :)

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, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

What about?

      {buildTooOld(buildDetails) ? (
        <SiteBuildLogTable
          buildLogs={[
            'Builds more than 180 days old are deleted according to platform policy.',
          ]}
        />
      ) : (
        <>
          {logs && logs?.length > 0 ? (
            <SiteBuildLogTable buildLogs={logs} buildState={state} />
          ) : (
            <SiteBuildLogTable
              buildLogs={['This build does not have any build logs.']}
            />
          )}
        </>
      )}

Copy link
Contributor Author

@svenaas svenaas Mar 7, 2024

Choose a reason for hiding this comment

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

Do you prefer this to what I pushed, @apburnes?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering if a ternary operator would 1) work, 2) be easy to read. I could see a case for either approach; they're basically indistinguishable. I think ternaries are cool, but they're sometimes hard to read. I'm neutral on this :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Giving this a gentle bump, @apburnes. I think I'd already pushed my approach to this when you suggested another way here, but I don't know whether you'd like me to switch to your version or were just in the process of suggesting it when I applied mine.

tl/dr: Am I waiting for you to re-review or are you waiting for me to switch to your suggested implementation?

</div>
)}
{(() => {
if (!logs || logs?.length === 0) {
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 scenario where there are build logs and the build is over 180 days?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the scenario you found on dev where the build log was still being shown on an old build that still had build logs: https://pages-dev.cloud.gov/sites/2/builds/5/logs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's why we made this change.

Copy link
Contributor

Choose a reason for hiding this comment

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

The logic still shows both the 180 day message and the build logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It only checks buildTooOld if there are no build logs.

<SiteBuildLogTable buildLogs={['This build does not have any build logs.']} />
</div>
)}
{(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the only place in the frontend we use the closure syntax to display components. We don't have solid conventions for writing UI components but It is introducing another pattern for logic control. Should we settle on a convention and document it?

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'm newest to React JSX, so I defer to y'all on which convention is wisest.

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 what the immediately invoked function does here so I'd remove if it isn't necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored into a separate function at Andrew's suggestion.

});
const { isLoading, buildDetails } = build;

useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we use this hook in two places, what do you think about creating a new build details hook in the hooks directory and importing it to the paces we use it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I'll see what I can do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored into hooks

@svenaas svenaas force-pushed the 4379-explain-that-build-logs-are-gone-after-180-days branch from 962526d to f0a1847 Compare March 12, 2024 16:40
@svenaas svenaas requested a review from apburnes March 12, 2024 17:23
@@ -55,8 +55,19 @@ const SiteBuildTasks = () => {
const buildId = parseInt(buildIdStr, 10);
const [buildTasks, setBuildTasks] = useState([]);

const [build, setBuild] = useState({
Copy link
Contributor

Choose a reason for hiding this comment

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

You can replace this useState and useEffect with the new buildDetails hook.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aw shoot I forgot about build tasks. On it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How 'bout now?

@svenaas svenaas requested a review from apburnes March 12, 2024 19:32
Copy link
Contributor

@apburnes apburnes left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

@svenaas svenaas force-pushed the 4379-explain-that-build-logs-are-gone-after-180-days branch from 64c93be to 8facede Compare March 12, 2024 19:46
@svenaas svenaas merged commit b3a1f6e into main Mar 12, 2024
7 of 8 checks passed
@svenaas svenaas deleted the 4379-explain-that-build-logs-are-gone-after-180-days branch March 12, 2024 19:57
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.

Update Build Logs view to show alert when build logs are over 180 days
4 participants