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

Allow to expand the build logs section when skipped #4

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/hooks/timers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@ export function useDebouncedValue<T>(value: T, ms: number): T {

return debounced;
}

export function useNow() {
const [now, setNow] = useState(new Date());

useEffect(() => {
const interval = setInterval(() => {
setNow(new Date());
}, 1000);

return () => clearInterval(interval);
}, []);

return now;
}
1 change: 1 addition & 0 deletions src/intl/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"build": {
"title": "Build",
"buildSkipped": "This deployment uses a previous build originally created during deployment <link>{deploymentId}</link>",
"duration": "<dim>Duration: {duration}s</dim>",
"completed": "<dim>Completed in</dim> {elapsed}s",
"waitingForLogs": {
"title": "Getting ready to build your service",
Expand Down
55 changes: 43 additions & 12 deletions src/modules/deployment/deployment-logs/deployment-logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import { hasBuild } from 'src/application/service-functions';
import { useObserve } from 'src/hooks/lifecycle';
import { useLogs } from 'src/hooks/logs';
import { useNow } from 'src/hooks/timers';
import { Translate } from 'src/intl/translate';

import { BuildLogs } from './build-logs';
Expand Down Expand Up @@ -118,15 +119,15 @@ function canToggleBuild(deployment: ComputeDeployment) {
return false;
}

return deployment.build !== undefined;
return deployment.buildSkipped || deployment.build !== undefined;
}

function canToggleRuntime(deployment: ComputeDeployment) {
if (deployment.status === 'canceled') {
return false;
}

return !hasBuild(deployment) || deployment.build?.status === 'completed';
return !hasBuild(deployment) || deployment.buildSkipped || deployment.build?.status === 'completed';
}

function connectToBuildLogs(deployment: ComputeDeployment, expanded: boolean) {
Expand Down Expand Up @@ -168,7 +169,6 @@ type BuildSectionHeaderProps = {
};

function BuildSectionHeader({ expanded, setExpanded, deployment, lines }: BuildSectionHeaderProps) {
const build = deployment.build;
const status = getBuildStatus(deployment);
const [StatusIcon, statusColorClassName] = buildStatusMap[status];

Expand All @@ -181,22 +181,52 @@ function BuildSectionHeader({ expanded, setExpanded, deployment, lines }: BuildS
StatusIcon={StatusIcon}
statusColorClassName={statusColorClassName}
lastLogLine={status === 'running' ? lines[lines.length - 1] : undefined}
end={
status === 'completed' &&
build !== undefined && (
<div>
<T id="build.completed" values={{ elapsed: elapsed(build) }} />
</div>
)
}
end={<BuildSectionHeaderEnd expanded={expanded} deployment={deployment} />}
/>
);
}

type BuildSectionHeaderEndProps = {
expanded: boolean;
deployment: ComputeDeployment;
};

function BuildSectionHeaderEnd({ expanded, deployment }: BuildSectionHeaderEndProps) {
const build = deployment.build;
const status = getBuildStatus(deployment);
const now = useNow();

if (build === undefined) {
return;
}

if (status === 'running' && expanded) {
const duration = Math.floor((now.getTime() - new Date(build.startedAt).getTime()) / 1000);

return (
<div>
<T id="build.duration" values={{ duration }} />
</div>
);
}

if (status === 'completed') {
return (
<div>
<T id="build.completed" values={{ elapsed: elapsed(build) }} />
</div>
);
}
}

function getBuildStatus(deployment: ComputeDeployment): DeploymentBuildStatus | 'pending' {
const { build } = deployment;

if (build === undefined) {
if (deployment.buildSkipped) {
return 'completed';
}

if (deployment.status == 'pending') {
return 'pending';
}
Expand All @@ -223,7 +253,8 @@ type RuntimeSectionHeaderProps = {
};

function RuntimeSectionHeader({ expanded, setExpanded, deployment, lines }: RuntimeSectionHeaderProps) {
const notStarted = hasBuild(deployment) && deployment.build?.status !== 'completed';
const notStarted =
hasBuild(deployment) && !deployment.buildSkipped && deployment.build?.status !== 'completed';

const [StatusIcon, statusColorClassName] = notStarted
? statuses.pending
Expand Down