-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
283 additions
and
53 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
apps/webservice/src/app/[workspaceSlug]/SidebarContext.tsx
This file contains 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,15 @@ | ||
"use client"; | ||
|
||
import { createContext, useContext } from "react"; | ||
|
||
type SidebarContextType = { | ||
activeSidebarItem: string | null; | ||
setActiveSidebarItem: (item: string | null) => void; | ||
}; | ||
|
||
export const SidebarContext = createContext<SidebarContextType>({ | ||
activeSidebarItem: null, | ||
setActiveSidebarItem: () => {}, | ||
}); | ||
|
||
export const useSidebar = () => useContext(SidebarContext); |
This file contains 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
This file contains 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
This file contains 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
51 changes: 51 additions & 0 deletions
51
apps/webservice/src/app/[workspaceSlug]/SidebarPopoverSystem.tsx
This file contains 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,51 @@ | ||
"use client"; | ||
|
||
import type { Workspace } from "@ctrlplane/db/schema"; | ||
|
||
import { api } from "~/trpc/react"; | ||
import { SidebarLink } from "./SidebarLink"; | ||
|
||
export const SidebarPopoverSystem: React.FC<{ | ||
systemId: string; | ||
workspace: Workspace; | ||
}> = ({ workspace, systemId }) => { | ||
const system = api.system.byId.useQuery(systemId); | ||
const environments = api.environment.bySystemId.useQuery(systemId); | ||
const deployments = api.deployment.bySystemId.useQuery(systemId); | ||
return ( | ||
<div className="space-y-4 text-sm"> | ||
<div className="text-lg font-semibold">{system.data?.name}</div> | ||
|
||
<div className="space-y-1.5"> | ||
<div className="text-xs font-semibold uppercase text-muted-foreground"> | ||
Environments | ||
</div> | ||
<div> | ||
{environments.data?.map(({ name }) => ( | ||
<SidebarLink | ||
href={`/${workspace.slug}/systems/${system.data?.slug}/environments`} | ||
> | ||
{name} | ||
</SidebarLink> | ||
))} | ||
</div> | ||
</div> | ||
|
||
<div className="space-y-1.5"> | ||
<div className="text-xs font-semibold uppercase text-muted-foreground"> | ||
Deployments | ||
</div> | ||
<div> | ||
{deployments.data?.map(({ id, name, slug }) => ( | ||
<SidebarLink | ||
key={id} | ||
href={`/${workspace.slug}/systems/${system.data?.slug}/deployments/${slug}`} | ||
> | ||
{name} | ||
</SidebarLink> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
93 changes: 93 additions & 0 deletions
93
apps/webservice/src/app/[workspaceSlug]/SidebarPopoverTargets.tsx
This file contains 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,93 @@ | ||
"use client"; | ||
|
||
import type { Workspace } from "@ctrlplane/db/schema"; | ||
import { IconBookmark } from "@tabler/icons-react"; | ||
import LZString from "lz-string"; | ||
|
||
import { Badge } from "@ctrlplane/ui/badge"; | ||
import { | ||
ComparisonOperator, | ||
FilterType, | ||
} from "@ctrlplane/validators/conditions"; | ||
import { ResourceFilterType } from "@ctrlplane/validators/resources"; | ||
|
||
import { api } from "~/trpc/react"; | ||
import { TargetIcon } from "./_components/TargetIcon"; | ||
import { SidebarLink } from "./SidebarLink"; | ||
|
||
export const SidebarPopoverTargets: React.FC<{ workspace: Workspace }> = ({ | ||
workspace, | ||
}) => { | ||
const kinds = api.workspace.resourceKinds.useQuery(workspace.id); | ||
|
||
const views = api.resource.view.list.useQuery(workspace.id); | ||
const viewsWithHash = views.data?.map((view) => ({ | ||
...view, | ||
hash: LZString.compressToEncodedURIComponent(JSON.stringify(view.filter)), | ||
})); | ||
|
||
return ( | ||
<div className="space-y-4 text-sm"> | ||
<div className="text-lg font-semibold">Targets</div> | ||
|
||
<div className="space-y-1.5"> | ||
<div className="text-xs font-semibold uppercase text-muted-foreground"> | ||
Saved Views | ||
</div> | ||
<div> | ||
<div className="rounded-md text-xs text-neutral-600"> | ||
No saved filters found. | ||
</div> | ||
{viewsWithHash != null && viewsWithHash.length > 0 && ( | ||
<> | ||
{viewsWithHash.map(({ id, name, hash }) => ( | ||
<SidebarLink | ||
href={`/${workspace.slug}/targets?filter=${hash}`} | ||
key={id} | ||
> | ||
<IconBookmark className="h-4 w-4 text-muted-foreground" /> | ||
{name} | ||
</SidebarLink> | ||
))} | ||
</> | ||
)} | ||
</div> | ||
</div> | ||
|
||
<div className="space-y-1.5"> | ||
<div className="text-xs font-semibold uppercase text-muted-foreground"> | ||
Kinds | ||
</div> | ||
<div> | ||
{kinds.data?.map(({ version, kind, count }) => ( | ||
<SidebarLink | ||
href={`/${workspace.slug}/targets?filter=${LZString.compressToEncodedURIComponent( | ||
JSON.stringify({ | ||
type: FilterType.Comparison, | ||
operator: ComparisonOperator.And, | ||
conditions: [ | ||
{ | ||
type: ResourceFilterType.Kind, | ||
value: kind, | ||
operator: "equals", | ||
}, | ||
], | ||
}), | ||
)}`} | ||
key={`${version}/${kind}`} | ||
> | ||
<TargetIcon version={version} kind={kind} /> | ||
<span className="flex-grow">{kind}</span> | ||
<Badge | ||
variant="secondary" | ||
className="rounded-full bg-neutral-500/10 text-xs text-muted-foreground" | ||
> | ||
{count} | ||
</Badge> | ||
</SidebarLink> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains 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.