- Notifications
You must be signed in to change notification settings - Fork929
chore: refactor schedule banner#4274
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
11 commits Select commitHold shift + click to select a range
88dd059
Start refactor
presleypdd6b914
Fix color of auto stop switch
presleyp7ccabaf
Format
presleyp16e5fd4
Use helper functions for min/max check
presleyp744aeeb
Fix type
presleypffedaef
Put new component in own file
presleyp70ff45f
Merge branch 'main' into bump/presleyp/3566
presleyp7d2f618
Fix decrease deadline bug
presleyp9c3db83
Simplify functions
presleyp56553f6
Use ChooseOne
presleypfe7ba4e
Remove commented code
presleypFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletionssite/src/components/WorkspaceScheduleForm/WorkspaceScheduleForm.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
149 changes: 23 additions & 126 deletionssite/src/pages/WorkspacePage/WorkspacePage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletionssite/src/pages/WorkspacePage/WorkspaceReadyPage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { useActor, useSelector } from "@xstate/react" | ||
import { FeatureNames } from "api/types" | ||
import dayjs from "dayjs" | ||
import { useContext } from "react" | ||
import { Helmet } from "react-helmet-async" | ||
import { useTranslation } from "react-i18next" | ||
import { selectFeatureVisibility } from "xServices/entitlements/entitlementsSelectors" | ||
import { StateFrom } from "xstate" | ||
import { DeleteDialog } from "../../components/Dialogs/DeleteDialog/DeleteDialog" | ||
import { Workspace, WorkspaceErrors } from "../../components/Workspace/Workspace" | ||
import { pageTitle } from "../../util/page" | ||
import { getFaviconByStatus } from "../../util/workspace" | ||
import { XServiceContext } from "../../xServices/StateContext" | ||
import { WorkspaceEvent, workspaceMachine } from "../../xServices/workspace/workspaceXService" | ||
interface WorkspaceReadyPageProps { | ||
workspaceState: StateFrom<typeof workspaceMachine> | ||
workspaceSend: (event: WorkspaceEvent) => void | ||
} | ||
export const WorkspaceReadyPage = ({ | ||
workspaceState, | ||
workspaceSend, | ||
}: WorkspaceReadyPageProps): JSX.Element => { | ||
const [bannerState, bannerSend] = useActor(workspaceState.children["scheduleBannerMachine"]) | ||
const xServices = useContext(XServiceContext) | ||
const featureVisibility = useSelector(xServices.entitlementsXService, selectFeatureVisibility) | ||
const [buildInfoState] = useActor(xServices.buildInfoXService) | ||
const { | ||
workspace, | ||
refreshWorkspaceWarning, | ||
builds, | ||
getBuildsError, | ||
buildError, | ||
cancellationError, | ||
applicationsHost, | ||
permissions, | ||
} = workspaceState.context | ||
if (workspace === undefined) { | ||
throw Error("Workspace is undefined") | ||
} | ||
const canUpdateWorkspace = Boolean(permissions?.updateWorkspace) | ||
const { t } = useTranslation("workspacePage") | ||
const favicon = getFaviconByStatus(workspace.latest_build) | ||
return ( | ||
<> | ||
<Helmet> | ||
<title>{pageTitle(`${workspace.owner_name}/${workspace.name}`)}</title> | ||
<link rel="alternate icon" type="image/png" href={`/favicons/${favicon}.png`} /> | ||
<link rel="icon" type="image/svg+xml" href={`/favicons/${favicon}.svg`} /> | ||
</Helmet> | ||
<Workspace | ||
bannerProps={{ | ||
isLoading: bannerState.hasTag("loading"), | ||
onExtend: () => { | ||
bannerSend({ | ||
type: "INCREASE_DEADLINE", | ||
hours: 4, | ||
}) | ||
}, | ||
}} | ||
scheduleProps={{ | ||
onDeadlineMinus: () => { | ||
bannerSend({ | ||
type: "DECREASE_DEADLINE", | ||
hours: 1, | ||
}) | ||
}, | ||
onDeadlinePlus: () => { | ||
bannerSend({ | ||
type: "INCREASE_DEADLINE", | ||
hours: 1, | ||
}) | ||
}, | ||
deadlineMinusEnabled: () => !bannerState.matches("atMinDeadline"), | ||
deadlinePlusEnabled: () => !bannerState.matches("atMaxDeadline"), | ||
}} | ||
isUpdating={workspaceState.hasTag("updating")} | ||
workspace={workspace} | ||
handleStart={() => workspaceSend({ type: "START" })} | ||
handleStop={() => workspaceSend({ type: "STOP" })} | ||
handleDelete={() => workspaceSend({ type: "ASK_DELETE" })} | ||
handleUpdate={() => workspaceSend({ type: "UPDATE" })} | ||
handleCancel={() => workspaceSend({ type: "CANCEL" })} | ||
resources={workspace.latest_build.resources} | ||
builds={builds} | ||
canUpdateWorkspace={canUpdateWorkspace} | ||
hideSSHButton={featureVisibility[FeatureNames.BrowserOnly]} | ||
workspaceErrors={{ | ||
[WorkspaceErrors.GET_RESOURCES_ERROR]: refreshWorkspaceWarning, | ||
[WorkspaceErrors.GET_BUILDS_ERROR]: getBuildsError, | ||
[WorkspaceErrors.BUILD_ERROR]: buildError, | ||
[WorkspaceErrors.CANCELLATION_ERROR]: cancellationError, | ||
}} | ||
buildInfo={buildInfoState.context.buildInfo} | ||
applicationsHost={applicationsHost} | ||
/> | ||
<DeleteDialog | ||
entity="workspace" | ||
name={workspace.name} | ||
info={t("deleteDialog.info", { timeAgo: dayjs(workspace.created_at).fromNow() })} | ||
isOpen={workspaceState.matches({ ready: { build: "askingDelete" } })} | ||
onCancel={() => workspaceSend({ type: "CANCEL_DELETE" })} | ||
onConfirm={() => { | ||
workspaceSend({ type: "DELETE" }) | ||
}} | ||
/> | ||
</> | ||
) | ||
} |
10 changes: 5 additions & 5 deletionssite/src/util/schedule.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
25 changes: 21 additions & 4 deletionssite/src/util/schedule.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.