Skip to content

Commit

Permalink
Merge branch 'feat--demo-page' of github.com:hatchet-dev/hatchet into…
Browse files Browse the repository at this point in the history
… feat--demo-page
  • Loading branch information
abelanger5 committed Jun 27, 2024
2 parents af03ccc + 85e3b64 commit 43097c9
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 126 deletions.
59 changes: 2 additions & 57 deletions api/v1/server/handlers/tenants/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,10 @@ package tenants
import (
"github.com/labstack/echo/v4"

"github.com/hatchet-dev/hatchet/api/v1/server/oas/apierrors"
"github.com/hatchet-dev/hatchet/api/v1/server/oas/gen"
"github.com/hatchet-dev/hatchet/api/v1/server/oas/transformers"
"github.com/hatchet-dev/hatchet/pkg/repository"
"github.com/hatchet-dev/hatchet/pkg/repository/prisma/db"
)

func (t *TenantService) TenantUpdate(ctx echo.Context, request gen.TenantUpdateRequestObject) (gen.TenantUpdateResponseObject, error) {
tenant := ctx.Get("tenant").(*db.TenantModel)

// validate the request
if apiErrors, err := t.config.Validator.ValidateAPI(request.Body); err != nil {
return nil, err
} else if apiErrors != nil {
return gen.TenantUpdate400JSONResponse(*apiErrors), nil
}

// construct the database query
updateOpts := &repository.UpdateTenantOpts{}

if request.Body.AnalyticsOptOut != nil {
updateOpts.AnalyticsOptOut = request.Body.AnalyticsOptOut
}

if request.Body.AlertMemberEmails != nil {
updateOpts.AlertMemberEmails = request.Body.AlertMemberEmails
}

if request.Body.Name != nil {
updateOpts.Name = request.Body.Name
}

// update the tenant
tenant, err := t.config.APIRepository.Tenant().UpdateTenant(tenant.ID, updateOpts)

if err != nil {
return nil, err
}

if request.Body.MaxAlertingFrequency != nil ||
request.Body.EnableExpiringTokenAlerts != nil ||
request.Body.EnableTenantResourceLimitAlerts != nil ||
request.Body.EnableWorkflowRunFailureAlerts != nil {

_, err = t.config.APIRepository.TenantAlertingSettings().UpsertTenantAlertingSettings(
tenant.ID,
&repository.UpsertTenantAlertingSettingsOpts{
MaxFrequency: request.Body.MaxAlertingFrequency,
EnableExpiringTokenAlerts: request.Body.EnableExpiringTokenAlerts,
EnableWorkflowRunFailureAlerts: request.Body.EnableWorkflowRunFailureAlerts,
EnableTenantResourceLimitAlerts: request.Body.EnableTenantResourceLimitAlerts,
},
)

if err != nil {
return nil, err
}
}

return gen.TenantUpdate200JSONResponse(
*transformers.ToTenant(tenant),
), nil
return gen.TenantUpdate400JSONResponse(apierrors.NewAPIErrors("this is disabled for the demo")), nil
}
36 changes: 11 additions & 25 deletions frontend/app/src/pages/auth/login/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Link, useNavigate } from 'react-router-dom';
import { UserLoginForm } from './components/user-login-form';
import { cn } from '@/lib/utils';
import { Button, buttonVariants } from '@/components/ui/button';
import { Button } from '@/components/ui/button';
import { useMutation } from '@tanstack/react-query';
import api, { UserLoginRequest } from '@/lib/api';
import { useState } from 'react';
Expand Down Expand Up @@ -45,21 +44,10 @@ export default function Login() {
].filter(Boolean);

return (
<div className="flex flex-row flex-1 w-full h-full">
<div className="container relative hidden flex-col items-center justify-center md:grid lg:max-w-none lg:grid-cols-2 lg:px-0">
{meta?.data?.data.allowSignup && (
<Link
to="/auth/register"
className={cn(
buttonVariants({ variant: 'ghost' }),
'absolute right-4 top-4 md:right-8 md:top-8',
)}
>
Sign Up
</Link>
)}
<div className="lg:p-8 mx-auto w-screen">
<div className="mx-auto flex w-full flex-col justify-center space-y-6 sm:w-[350px]">
<div className="flex flex-1 flex-col items-center justify-center w-full h-full lg:flex-row">
<div className="container relative flex-col items-center justify-center w-full md:grid lg:max-w-none lg:grid-cols-2 lg:px-0">
<div className="mx-auto flex w-full max-w-md lg:p-8">
<div className="flex w-full flex-col justify-center space-y-6">
<div className="flex flex-col space-y-2 text-center">
<h1 className="text-2xl font-semibold tracking-tight">
Log in to Hatchet
Expand All @@ -71,7 +59,7 @@ export default function Login() {
{forms.map((form, index) => (
<React.Fragment key={index}>
{form}
{index < schemes.length - 1 && <OrContinueWith />}
{index < forms.length - 1 && <OrContinueWith />}
</React.Fragment>
))}
<p className="text-left text-sm text-gray-700 dark:text-gray-300 w-full">
Expand Down Expand Up @@ -100,12 +88,12 @@ export default function Login() {

export function OrContinueWith() {
return (
<div className="relative">
<div className="relative my-4">
<div className="absolute inset-0 flex items-center">
<span className="w-full border-t" />
</div>
<div className="relative flex justify-center text-xs uppercase">
<span className="bg-background px-2 text-gray-700 dark:text-gray-300">
<span className="bg-white px-2 text-gray-700 dark:bg-gray-800 dark:text-gray-300">
Or continue with
</span>
</div>
Expand All @@ -116,9 +104,7 @@ export function OrContinueWith() {
function BasicLogin() {
const navigate = useNavigate();
const [fieldErrors, setFieldErrors] = useState<Record<string, string>>({});
const { handleApiError } = useApiError({
setFieldErrors: setFieldErrors,
});
const { handleApiError } = useApiError({ setFieldErrors });

const loginMutation = useMutation({
mutationKey: ['user:update:login'],
Expand All @@ -142,7 +128,7 @@ function BasicLogin() {

export function GoogleLogin() {
return (
<a href="/api/v1/users/google/start">
<a href="/api/v1/users/google/start" className="w-full">
<Button variant="outline" type="button" className="w-full py-2">
<Icons.google className="mr-2 h-4 w-4" />
Google
Expand All @@ -153,7 +139,7 @@ export function GoogleLogin() {

export function GithubLogin() {
return (
<a href="/api/v1/users/github/start">
<a href="/api/v1/users/github/start" className="w-full">
<Button variant="outline" type="button" className="w-full py-2">
<Icons.gitHub className="mr-2 h-4 w-4" />
Github
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ export function StepRunPlayground({
return {};
}

// HACK this is a temporary solution to get the parent data from the previous run
// this should be handled by the backend
const parents = Object.keys(input.parents);
if (!workflowRun.jobRuns || !workflowRun.jobRuns[0]) {
return input;
Expand Down Expand Up @@ -231,31 +229,28 @@ export function StepRunPlayground({

const disabled = rerunStepMutation.isPending || isLoading;

// Function to detect the operating system
const getOS = () => {
const userAgent = window.navigator.userAgent;
// Simple checks for platform; these could be extended as needed
if (userAgent.includes('Mac')) {
return 'MacOS';
} else if (userAgent.includes('Win')) {
return 'Windows';
} else {
// Default or other OS
return 'unknown';
}
};
// Determine the appropriate shortcut based on the OS

const shortcut = getOS() === 'MacOS' ? 'Cmd + Enter' : 'Ctrl + Enter';

return (
<div className="">
<div className="p-4 sm:p-6 lg:p-8">
{stepRun && (
<>
<div className="flex flex-row gap-2 justify-between items-center sticky top-0 z-50">
<div className="text-2xl font-semibold tracking-tight">
<div className="flex flex-col sm:flex-row gap-2 justify-between items-center sticky top-0 z-50 bg-white p-4 sm:p-6 lg:p-8">
<div className="text-xl sm:text-2xl font-semibold tracking-tight">
{stepRun?.step?.readableId}
</div>
<div className="flex flex-row gap-2 justify-end items-center">
<div className="flex flex-col sm:flex-row gap-2 justify-end items-center">
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
Expand Down Expand Up @@ -301,14 +296,14 @@ export function StepRunPlayground({
</TooltipProvider>
</div>
</div>
<div className="flex flex-row gap-4 mt-4">
<div className="flex-grow w-1/2">
<div className="flex flex-col lg:flex-row gap-4 mt-4">
<div className="flex-grow lg:w-1/2">
<div className="text-lg font-semibold tracking-tight mb-4">
Input
</div>
{demo && (
<Alert variant="default" className="my-4">
<AlertTitle className="font-semibold mb-2">
<AlertTitle className="font-semibold">
<span className="mr-1">🪓</span> Here's your input.
</AlertTitle>
<AlertDescription>
Expand Down Expand Up @@ -346,16 +341,16 @@ export function StepRunPlayground({
)}
</p>
<Tabs defaultValue="output" className="flex flex-col">
<div className="flex flex-row justify-between items-center">
<div className="flex flex-row justify-start items-center gap-6 mb-2">
<div className="flex flex-col sm:flex-row justify-between items-center mb-2">
<div className="flex flex-row justify-start items-center gap-6">
<TabsList>
<TabsTrigger value="output" className="px-8">
<TabsTrigger value="output" className="px-4 sm:px-8">
Output
</TabsTrigger>
<TabsTrigger value="logs" className="px-8">
<TabsTrigger value="logs" className="px-4 sm:px-8">
Logs
</TabsTrigger>
<TabsTrigger value="events" className="px-8">
<TabsTrigger value="events" className="px-4 sm:px-8">
Events
</TabsTrigger>
</TabsList>
Expand Down
53 changes: 28 additions & 25 deletions frontend/app/src/pages/main/demo-workflow-runs/$run/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ export default function ExpandedWorkflowRun() {
<div className="flex flex-col mx-auto gap-2 max-w-7xl px-4 sm:px-6 lg:px-8">
{/* TODO the triggeredBy parent id is itself */}
{/* {run?.triggeredBy?.parentId && <ParentLink parentId={run.triggeredBy.parentId} />} */}
<div className="flex flex-row justify-between items-center">
<div className="flex flex-col sm:flex-row justify-between items-center">
<div className="flex flex-row gap-4 items-center">
<h2 className="text-2xl font-bold leading-tight text-foreground flex flex-row items-center">
<h2 className="text-lg sm:text-2xl font-bold leading-tight text-foreground flex flex-row items-center">
<Link
to={`/workflows/${run?.workflowVersion?.workflow?.metadata.id}`}
>
Expand All @@ -151,33 +151,36 @@ export default function ExpandedWorkflowRun() {
/{selectedStepRun?.step?.readableId || '*'}
</h2>
</div>
<div className="flex flex-row gap-2 items-center">
<div className="flex flex-row gap-2 items-center justify-between">
<RunStatus
status={run.status}
className="text-sm mt-1 px-4 shrink"
/>

<DropdownMenu>
<DropdownMenuTrigger>
<Button
aria-label="Workflow Actions"
size="icon"
variant="outline"
>
<BiDotsVertical />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem
disabled={WORKFLOW_RUN_TERMINAL_STATUSES.includes(run.status)}
onClick={() => {
cancelWorkflowRunMutation.mutate();
}}
>
Cancel all running steps
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<span className="hidden sm:block">
<DropdownMenu>
<DropdownMenuTrigger>
<Button
aria-label="Workflow Actions"
size="icon"
variant="outline"
>
<BiDotsVertical />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem
disabled={WORKFLOW_RUN_TERMINAL_STATUSES.includes(
run.status,
)}
onClick={() => {
cancelWorkflowRunMutation.mutate();
}}
>
Cancel all running steps
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</span>
</div>
</div>
<div className="flex flex-row justify-start items-center gap-2">
Expand Down
3 changes: 2 additions & 1 deletion frontend/app/src/pages/main/demo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type WorkflowWithVersion = {
};

export async function loader(): Promise<WorkflowWithVersion | null> {
const workflowId = 'bb0e4710-85cd-4e0e-9bd5-022b3d8142b2';
const workflowId = '432bee47-6963-4c57-bf50-bba6bb87d53e';

invariant(workflowId);

Expand Down Expand Up @@ -121,6 +121,7 @@ export default function ExpandedWorkflow() {
href="hhttps://github.com/hatchet-dev/hatchet-python-quickstart/blob/65d81c46a394818aceaa7e328bd526950e2dfa68/simple-examples/src/demo/worker.py"
target="_blank"
className="text-indigo-500 dark:text-indigo-400 underline"
rel="noreferrer"
>
source here
</a>
Expand Down
1 change: 1 addition & 0 deletions hatchet-security-checks
Submodule hatchet-security-checks added at eed774

0 comments on commit 43097c9

Please sign in to comment.