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

chore: switch to hashrouter for go filesystem routing #56

Merged
merged 2 commits into from
Nov 21, 2024
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
2 changes: 1 addition & 1 deletion pkg/config/testdata/git/custom/glu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ sources:
credential: vault
interval: 1m
path: v1
default_branch: release-v1
default_branch: release-v1
2 changes: 1 addition & 1 deletion pkg/config/testdata/git/default/glu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ sources:
default:
remote:
name: upstream
url: https://corp-repos/default.git
url: https://corp-repos/default.git
1 change: 1 addition & 0 deletions pkg/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Phase interface {
Source() Metadata
Get(context.Context) (Resource, error)
Promote(context.Context) error
Synced(context.Context) (bool, error)
}

// AddPhaseOptions are used to configure the addition of a ResourcePhase to a Pipeline
Expand Down
35 changes: 34 additions & 1 deletion pkg/phases/phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func (i *Phase[R]) Promote(ctx context.Context) (err error) {

if fromDigest == toDigest {
i.logger.Debug("skipping promotion", "reason", "UpToDate")

return nil
}

Expand All @@ -132,3 +131,37 @@ func (i *Phase[R]) Promote(ctx context.Context) (err error) {

return nil
}

func (i *Phase[R]) Synced(ctx context.Context) (bool, error) {
from := i.pipeline.New()
if err := i.source.View(ctx, i.pipeline.Metadata(), i.meta, from); err != nil {
return false, err
}

dep, ok := i.pipeline.PromotedFrom(i)
if !ok {
return true, nil
}

to, err := dep.GetResource(ctx)
if err != nil {
return false, err
}

fromDigest, err := from.Digest()
if err != nil {
return false, err
}

toDigest, err := to.Digest()
if err != nil {
return false, err
}

if fromDigest == toDigest {

return true, nil
}

return false, nil
}
7 changes: 7 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type phaseResponse struct {
Source core.Metadata `json:"source,omitempty"`
Digest string `json:"digest,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Synced bool `json:"synced,omitempty"`
}

func (s *Server) createPhaseResponse(ctx context.Context, phase core.Phase, dependencies map[core.Phase]core.Phase) (phaseResponse, error) {
Expand Down Expand Up @@ -125,12 +126,18 @@ func (s *Server) createPhaseResponse(ctx context.Context, phase core.Phase, depe
return phaseResponse{}, err
}

synced, err := phase.Synced(ctx)
if err != nil {
return phaseResponse{}, err
}

return phaseResponse{
Name: phase.Metadata().Name,
DependsOn: dependsOn,
Labels: labels,
Source: phase.Source(),
Digest: digest,
Synced: synced,
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { useEffect } from 'react';
import { useAppDispatch, useAppSelector } from './store/hooks';
import { fetchPipelines } from './store/pipelinesSlice';
import { fetchSystem } from './store/systemSlice';
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import { createHashRouter, RouterProvider } from 'react-router-dom';
import Pipeline from './app/pipeline';
import { RootState } from './store';
import { Helmet } from 'react-helmet';

const router = createBrowserRouter([
const router = createHashRouter([
{
path: '/',
element: <Layout />,
Expand Down
53 changes: 30 additions & 23 deletions ui/src/components/node.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Handle, NodeProps, Position } from '@xyflow/react';
import { Package, GitBranch, CircleArrowUp } from 'lucide-react';
import { Badge } from '@/components/ui/badge';
import { Package, GitBranch, CircleArrowUp, CheckCircle } from 'lucide-react';
import { PhaseNode as PhaseNodeType } from '@/types/flow';
import * as Tooltip from '@radix-ui/react-tooltip';
import { promotePhase } from '@/services/api';
import {
Dialog,
Expand All @@ -15,8 +13,8 @@ import {
import { Button } from '@/components/ui/button';
import { useState } from 'react';
import { ANNOTATION_OCI_IMAGE_URL } from '@/types/metadata';
import { getLabelColor } from '@/lib/utils';
import { Label } from './label';
import { TooltipProvider, TooltipTrigger, TooltipContent, Tooltip } from '@/components/ui/tooltip';

const PhaseNode = ({ data }: NodeProps<PhaseNodeType>) => {
const getIcon = () => {
Expand Down Expand Up @@ -45,25 +43,34 @@ const PhaseNode = ({ data }: NodeProps<PhaseNodeType>) => {
<span className="truncate text-sm font-medium">{data.name}</span>
</div>
{data.depends_on && data.depends_on !== '' && (
<Tooltip.Provider>
<Tooltip.Root>
<Tooltip.Trigger asChild>
<CircleArrowUp
className="ml-2 h-4 w-4 flex-shrink-0 cursor-pointer transition-transform hover:rotate-90 hover:text-green-600"
onClick={() => setDialogOpen(true)}
/>
</Tooltip.Trigger>
<Tooltip.Portal>
<Tooltip.Content
className="data-[state=delayed-open]:data-[side=bottom]:animate-slideUpAndFade data-[state=delayed-open]:data-[side=left]:animate-slideRightAndFade data-[state=delayed-open]:data-[side=right]:animate-slideLeftAndFade data-[state=delayed-open]:data-[side=top]:animate-slideDownAndFadet select-none rounded bg-white px-[15px] py-2.5 text-sm leading-none shadow-[hsl(206_22%_7%_/_35%)_0px_10px_38px_-10px,_hsl(206_22%_7%_/_20%)_0px_10px_20px_-15px] will-change-[transform,opacity]"
sideOffset={5}
>
Promote
<Tooltip.Arrow className="fill-white" />
</Tooltip.Content>
</Tooltip.Portal>
</Tooltip.Root>
</Tooltip.Provider>
<>
{data.synced ? (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<CheckCircle className="ml-2 h-4 w-4 flex-shrink-0 text-green-600" />
</TooltipTrigger>
<TooltipContent sideOffset={5} className="text-xs">
Up to Date
</TooltipContent>
</Tooltip>
</TooltipProvider>
) : (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<CircleArrowUp
className="ml-2 h-4 w-4 flex-shrink-0 cursor-pointer transition-transform hover:rotate-90 hover:text-green-600"
onClick={() => setDialogOpen(true)}
/>
</TooltipTrigger>
<TooltipContent sideOffset={5} className="text-xs">
Promote
</TooltipContent>
</Tooltip>
</TooltipProvider>
)}
</>
)}
</div>

Expand Down
3 changes: 2 additions & 1 deletion ui/src/components/pipeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ function getElements(pipeline: PipelineType): FlowPipeline {
labels: phase.labels || {},
depends_on: phase.depends_on,
source: phase.source,
digest: phase.digest
digest: phase.digest,
synced: phase.synced
},
extent: 'parent'
};
Expand Down
1 change: 1 addition & 0 deletions ui/src/types/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type PhaseNodeData = {
depends_on?: string;
source: Metadata;
digest?: string;
synced?: boolean;
};

export type PhaseNode = Node<PhaseNodeData, 'phase'>;
Expand Down
6 changes: 1 addition & 5 deletions ui/src/types/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,5 @@ export interface Phase {
source: Metadata;
digest?: string;
labels?: Record<string, string>;
}

export interface PipelineGroup {
id: string;
name: string;
synced?: boolean;
}