MCPcopy Index your code
hub / github.com/coder/coder / autostopDisplay

Function autostopDisplay

site/src/utils/schedule.tsx:82–176  ·  view source on GitHub ↗
(
	workspace: Workspace,
	activityStatus: WorkspaceActivityStatus,
	template: Template,
)

Source from the content-addressed store, hash-verified

80};
81
82export const autostopDisplay = (
83 workspace: Workspace,
84 activityStatus: WorkspaceActivityStatus,
85 template: Template,
86): {
87 message: ReactNode;
88 tooltip?: ReactNode;
89 danger?: boolean;
90} => {
91 const ttl = workspace.ttl_ms;
92
93 if (isWorkspaceOn(workspace) && workspace.latest_build.deadline) {
94 // Workspace is on --> derive from latest_build.deadline. Note that the
95 // user may modify their workspace object (ttl) while the workspace is
96 // running and depending on system semantics, the deadline may still
97 // represent the previously defined ttl. Thus, we always derive from the
98 // deadline as the source of truth.
99
100 const deadline = dayjs(workspace.latest_build.deadline).tz(
101 dayjs.tz.guess(),
102 );
103 const now = dayjs(workspace.latest_build.deadline);
104
105 if (activityStatus === "connected") {
106 const hasMaxDeadline = Boolean(workspace.latest_build.max_deadline);
107 const maxDeadline = dayjs(workspace.latest_build.max_deadline);
108 if (hasMaxDeadline && maxDeadline.isBefore(now.add(2, "hour"))) {
109 return {
110 message: "Required to stop soon",
111 tooltip: (
112 <>
113 <HelpPopoverTitle>Upcoming stop required</HelpPopoverTitle>
114 This workspace will be required to stop by{" "}
115 {dayjs(workspace.latest_build.max_deadline).format(
116 "MMMM D [at] h:mm A",
117 )}
118 . You can restart your workspace before then to avoid
119 interruption.
120 </>
121 ),
122 danger: true,
123 };
124 }
125 }
126
127 if (isShuttingDown(workspace, deadline)) {
128 return {
129 message: "Workspace is shutting down",
130 };
131 }
132 let title = (
133 <HelpPopoverTitle>Template Autostop requirement</HelpPopoverTitle>
134 );
135 let reason: ReactNode = ` because the ${template.display_name} template has an autostop requirement.`;
136 if (template.autostop_requirement && template.allow_user_autostop) {
137 title = <HelpPopoverTitle>Autostop schedule</HelpPopoverTitle>;
138 reason = (
139 <span data-chromatic="ignore">

Callers 1

AutostopDisplayFunction · 0.90

Calls 4

isWorkspaceOnFunction · 0.90
isShuttingDownFunction · 0.85
isShutdownSoonFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected