-
Notifications
You must be signed in to change notification settings - Fork 881
fix: ui: workspace bumpers now honour template max_ttl #3532
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
Conversation
export const deadlineMinusDisabled = (workspace: Workspace, now: dayjs.Dayjs): boolean => { | ||
const delta = dayjs(workspace.latest_build.deadline).diff(now) | ||
return delta <= 30 * 60 * 1000 // 30 minutes | ||
} | ||
|
||
export const deadlinePlusDisabled = (workspace: Workspace, now: dayjs.Dayjs): boolean => { | ||
const delta = dayjs(workspace.latest_build.deadline).diff(now) | ||
return delta >= 24 * 60 * 60 * 1000 // 24 hours | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
review: moved to util/workspace.ts
EDIT: actually moved to util/schedule.ts
which is a more sensible place for it
{checkPermissionsError && <ErrorSummary error={checkPermissionsError} />} | ||
</div> | ||
) | ||
} else if (!workspace) { | ||
return <FullScreenLoader /> | ||
} else if (!template) { | ||
return <div className={styles.error}>Loading template</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be treated as a loading state like !workspace
. I'm assuming that if fetching it failed, we'll have an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair. Although I'd really like to be able to add information to FullScreenLoader
on what's currently happening (e.g. Reticulating Splines)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add a prop to FullScreenLoader
that can take that info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a good idea. I'll open a separate issue for that.
@@ -181,6 +183,7 @@ describe("Workspace Page", () => { | |||
|
|||
describe("Resources", () => { | |||
it("shows the status of each agent in each resource", async () => { | |||
const getTemplateMock = jest.spyOn(api, "getTemplate").mockResolvedValueOnce(MockTemplate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's generally better to test things that are apparent to the user than internals like whether a function was called, but sometimes it's necessary. Is this one of the cases where testing user-apparent effects is too hard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure -- I'll try seeing if I can make some assertions about child components here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it seems like testing properties of child components is considered somewhat of an anti-pattern. I'll factor some more stuff out to a util file and test it separately.
@@ -85,7 +91,7 @@ export const WorkspacePage: React.FC = () => { | |||
bannerSend({ | |||
type: "UPDATE_DEADLINE", | |||
workspaceId: workspace.id, | |||
newDeadline: dayjs(workspace.latest_build.deadline).utc().add(4, "hours"), | |||
newDeadline: dayjs.min(deadline.add(4, "hours"), maxDeadline(workspace, template)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to change this here, but I'm wondering if we want to try to push logic like this into XState. Instead of one UPDATE_DEADLINE
event, we could have multiple events that do calculations within them. The idea would be to try to get more logic out of components. Maybe a topic for Frontend Variety.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was wondering that but didn't want to over-complicate the machine. :-)
@@ -1,10 +1,14 @@ | |||
import { Theme } from "@material-ui/core/styles" | |||
import dayjs from "dayjs" | |||
import duration from "dayjs/plugin/duration" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love that you put util functions in their own spot and tested them! I noticed when I was working on the schedule form that there are a lot of different places for schedule-related util functions. Any thoughts on that? I don't want to make you figure it all out in this PR but I might at least call this util file something about the schedule instead of just the workspace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO I think it makes sense to keep it in the workspace util file, as workspaces and schedules are tightly coupled. If we eventually move schedules into more of a separate entity of their own, then maybe I could see it making more sense.
EDIT: Silly me, I forgot about util/schedule.ts
. Moving things in there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! The loading state is the only thing I feel strongly about.
3a16557
to
e69ff7f
Compare
util/schedule.ts
and unit test separatelyVerification Steps:
Fixes #2764.