Skip to content

Commit

Permalink
Updates beginning section default based on log target
Browse files Browse the repository at this point in the history
  • Loading branch information
CGoodwin90 committed Dec 27, 2023
1 parent d1f08ba commit 045b7d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/components/LogViewer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import LogAccordion from 'components/LogViewer/LogAccordion';

import { StyledLogs } from './StyledLogViewer';

const LogViewer = ({ logs, status = 'NA', checkedParseState, changeState, forceLastSectionOpen = true }) => (
const LogViewer = ({ logs, status = 'NA', checkedParseState, changeState, forceLastSectionOpen = true, logsTarget = "Deployments" }) => (
<React.Fragment>
<StyledLogs className="logs">
{logs !== null ? (
checkedParseState ? (
<div className="log-viewer">{logPreprocessor(logs, status, forceLastSectionOpen)}</div>
<div className="log-viewer">{logPreprocessor(logs, status, forceLastSectionOpen, logsTarget)}</div>
) : (
<div className="log-viewer with-padding">{logs}</div>
)
Expand Down Expand Up @@ -37,13 +37,13 @@ const isLogStateBad = status => {
* @param {*} status a status for the build - if not complete, we open the very last item
* @returns
*/
const logPreprocessor = (logs, status, forceLastSectionOpen = true) => {
const logPreprocessor = (logs, status, forceLastSectionOpen = true, logsTarget) => {
let ret = null;
let statusBad = isLogStateBad(status);
let openLastSection = forceLastSectionOpen || shouldLastSectionBeOpen(status);

try {
let tokens = logPreprocessorTokenize(logs);
let tokens = logPreprocessorTokenize(logs, logsTarget);
let sectionMetadata = logPreprocessorExtractSectionEndDetails(logs);
let AST = logPreprocessorProcessParse(tokens, sectionMetadata);
return logPreprocessorProcessASTToReact(AST, openLastSection, statusBad);
Expand Down Expand Up @@ -183,12 +183,11 @@ const logPreprocessorExtractSectionEndDetails = logs => {
return ret;
};

const logPreprocessorTokenize = logs => {
const logPreprocessorTokenize = (logs, logsTarget) => {
// tokenize
const regexp =
/##############################################\n(BEGIN) (.+)\n##############################################/;
const beginningSectionDefaultDetails = 'Build Setup';

const beginningSectionDefaultDetails = logsTarget === "Deployments" ? 'Build Setup' : 'Task Setup';
// The regex above will split the logs into three separate token types
// 1. standard blocks of text
// 2. markers for section starts containing "SECTION" only
Expand Down
2 changes: 1 addition & 1 deletion src/components/Task/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const Task: FC<TaskProps> = ({ task, projectId, environmentId }) => {
</div>
)}
</div>
<LogViewer logs={task.logs} status={task.status} changeState={null} checkedParseState={true} forceLastSectionOpen={true} />
<LogViewer logs={task.logs} status={task.status} changeState={null} checkedParseState={true} forceLastSectionOpen={true} logsTarget={"tasks"} />
</StyledTask>
);
};
Expand Down

0 comments on commit 045b7d2

Please sign in to comment.