-
Notifications
You must be signed in to change notification settings - Fork 0
[VW-128] Api Key Connector Table Views #97
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
Open
trummelhadron
wants to merge
5
commits into
main
Choose a base branch
from
connector-tables
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
|---|---|---|
| @@ -1,18 +1,18 @@ | ||
| import { | ||
| AssetsContainer, | ||
| AssetsError, | ||
| AssetsList, | ||
| AssetsLoading, | ||
| } from "@/features/assets/components/assets"; | ||
| import { assetsParamsLoader } from "@/features/assets/server/params-loader"; | ||
| import { prefetchAssets } from "@/features/assets/server/prefetch"; | ||
| AssetConnectorList, | ||
| AssetConnectorsContainer, | ||
| ConnectorsError, | ||
| ConnectorsLoading, | ||
| } from "@/features/api-key-connectors/components/connectors"; | ||
| import { connectorsParamsLoader } from "@/features/api-key-connectors/server/params-loader"; | ||
| import { prefetchAssetConnectors } from "@/features/api-key-connectors/server/prefetch"; | ||
| import { createListPage } from "@/lib/page-factory"; | ||
|
|
||
| export default createListPage({ | ||
| paramsLoader: assetsParamsLoader, | ||
| prefetch: prefetchAssets, | ||
| Container: AssetsContainer, | ||
| List: AssetsList, | ||
| Loading: AssetsLoading, | ||
| Error: AssetsError, | ||
| paramsLoader: connectorsParamsLoader, | ||
| prefetch: prefetchAssetConnectors, | ||
| Container: AssetConnectorsContainer, | ||
| List: AssetConnectorList, | ||
| Loading: ConnectorsLoading, | ||
| Error: ConnectorsError, | ||
| }); |
26 changes: 13 additions & 13 deletions
26
src/app/(dashboard)/(rest)/connectors/deviceArtifacts/page.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 |
|---|---|---|
| @@ -1,18 +1,18 @@ | ||
| import { | ||
| DeviceArtifactsContainer, | ||
| DeviceArtifactsError, | ||
| DeviceArtifactsList, | ||
| DeviceArtifactsLoading, | ||
| } from "@/features/device-artifacts/components/device-artifacts"; | ||
| import { deviceArtifactsParamsLoader } from "@/features/device-artifacts/server/params-loader"; | ||
| import { prefetchDeviceArtifacts } from "@/features/device-artifacts/server/prefetch"; | ||
| ConnectorsError, | ||
| ConnectorsLoading, | ||
| DeviceArtifactConnectorList, | ||
| DeviceArtifactConnectorsContainer, | ||
| } from "@/features/api-key-connectors/components/connectors"; | ||
| import { connectorsParamsLoader } from "@/features/api-key-connectors/server/params-loader"; | ||
| import { prefetchDeviceArtifactConnectors } from "@/features/api-key-connectors/server/prefetch"; | ||
| import { createListPage } from "@/lib/page-factory"; | ||
|
|
||
| export default createListPage({ | ||
| paramsLoader: deviceArtifactsParamsLoader, | ||
| prefetch: prefetchDeviceArtifacts, | ||
| Container: DeviceArtifactsContainer, | ||
| List: DeviceArtifactsList, | ||
| Loading: DeviceArtifactsLoading, | ||
| Error: DeviceArtifactsError, | ||
| paramsLoader: connectorsParamsLoader, | ||
| prefetch: prefetchDeviceArtifactConnectors, | ||
| Container: DeviceArtifactConnectorsContainer, | ||
| List: DeviceArtifactConnectorList, | ||
| Loading: ConnectorsLoading, | ||
| Error: ConnectorsError, | ||
| }); |
26 changes: 13 additions & 13 deletions
26
src/app/(dashboard)/(rest)/connectors/remediations/page.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 |
|---|---|---|
| @@ -1,18 +1,18 @@ | ||
| import { | ||
| RemediationsContainer, | ||
| RemediationsError, | ||
| RemediationsList, | ||
| RemediationsLoading, | ||
| } from "@/features/remediations/components/remediations"; | ||
| import { remediationsParamsLoader } from "@/features/remediations/server/params-loader"; | ||
| import { prefetchRemediations } from "@/features/remediations/server/prefetch"; | ||
| ConnectorsError, | ||
| ConnectorsLoading, | ||
| RemediationConnectorList, | ||
| RemediationConnectorsContainer, | ||
| } from "@/features/api-key-connectors/components/connectors"; | ||
| import { connectorsParamsLoader } from "@/features/api-key-connectors/server/params-loader"; | ||
| import { prefetchRemediationConnectors } from "@/features/api-key-connectors/server/prefetch"; | ||
| import { createListPage } from "@/lib/page-factory"; | ||
|
|
||
| export default createListPage({ | ||
| paramsLoader: remediationsParamsLoader, | ||
| prefetch: prefetchRemediations, | ||
| Container: RemediationsContainer, | ||
| List: RemediationsList, | ||
| Loading: RemediationsLoading, | ||
| Error: RemediationsError, | ||
| paramsLoader: connectorsParamsLoader, | ||
| prefetch: prefetchRemediationConnectors, | ||
| Container: RemediationConnectorsContainer, | ||
| List: RemediationConnectorList, | ||
| Loading: ConnectorsLoading, | ||
| Error: ConnectorsError, | ||
| }); |
26 changes: 13 additions & 13 deletions
26
src/app/(dashboard)/(rest)/connectors/vulnerabilities/page.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 |
|---|---|---|
| @@ -1,18 +1,18 @@ | ||
| import { | ||
| VulnerabilitiesContainer, | ||
| VulnerabilitiesError, | ||
| VulnerabilitiesList, | ||
| VulnerabilitiesLoading, | ||
| } from "@/features/vulnerabilities/components/vulnerabilities"; | ||
| import { vulnerabilitiesParamsLoader } from "@/features/vulnerabilities/server/params-loader"; | ||
| import { prefetchVulnerabilities } from "@/features/vulnerabilities/server/prefetch"; | ||
| ConnectorsError, | ||
| ConnectorsLoading, | ||
| VulnerabilityConnectorList, | ||
| VulnerabilityConnectorsContainer, | ||
| } from "@/features/api-key-connectors/components/connectors"; | ||
| import { connectorsParamsLoader } from "@/features/api-key-connectors/server/params-loader"; | ||
| import { prefetchVulnerabilityConnectors } from "@/features/api-key-connectors/server/prefetch"; | ||
| import { createListPage } from "@/lib/page-factory"; | ||
|
|
||
| export default createListPage({ | ||
| paramsLoader: vulnerabilitiesParamsLoader, | ||
| prefetch: prefetchVulnerabilities, | ||
| Container: VulnerabilitiesContainer, | ||
| List: VulnerabilitiesList, | ||
| Loading: VulnerabilitiesLoading, | ||
| Error: VulnerabilitiesError, | ||
| paramsLoader: connectorsParamsLoader, | ||
| prefetch: prefetchVulnerabilityConnectors, | ||
| Container: VulnerabilityConnectorsContainer, | ||
| List: VulnerabilityConnectorList, | ||
| Loading: ConnectorsLoading, | ||
| Error: ConnectorsError, | ||
| }); |
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
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,86 @@ | ||
| "use client"; | ||
|
|
||
| import type { ColumnDef } from "@tanstack/react-table"; | ||
| import { formatDistanceToNow } from "date-fns"; | ||
| import { Badge } from "@/components/ui/badge"; | ||
| import { SortableHeader } from "@/components/ui/data-table"; | ||
| import { | ||
| Tooltip, | ||
| TooltipContent, | ||
| TooltipTrigger, | ||
| } from "@/components/ui/tooltip"; | ||
| import type { ConnectorResponse } from "../types"; | ||
|
|
||
| export const columns: ColumnDef<ConnectorResponse>[] = [ | ||
| { | ||
| id: "name", | ||
| accessorKey: "name", | ||
| header: ({ column }) => ( | ||
| <SortableHeader header="Connector Name" column={column} /> | ||
| ), | ||
| }, | ||
| { | ||
| accessorKey: "Username", | ||
| meta: { title: "Username" }, | ||
| header: "Username", | ||
| accessorFn: (row) => row.user.name, | ||
| }, | ||
| { | ||
| id: "lastRequest", | ||
| accessorKey: "lastRequest", | ||
| header: ({ column }) => ( | ||
| <SortableHeader header="Last Used" column={column} /> | ||
| ), | ||
| cell: ({ row }) => { | ||
| const value = row.original.lastRequest; | ||
| return ( | ||
| <Tooltip> | ||
| <TooltipTrigger> | ||
| {value ? `${formatDistanceToNow(value)} ago` : "Never"} | ||
| </TooltipTrigger> | ||
| <TooltipContent> | ||
| {value ? value.toLocaleString() : "Never"} | ||
| </TooltipContent> | ||
| </Tooltip> | ||
| ); | ||
| }, | ||
| }, | ||
| { | ||
| id: "status", | ||
| accessorKey: "status", | ||
| header: "Status", | ||
| cell: ({ row }) => { | ||
| let text = "Expired"; | ||
| let color = "bg-red-400"; | ||
| if (row.original.apiKeyId || row.original.integrationId) { | ||
| text = "Active"; | ||
| color = "bg-green-300"; | ||
| } | ||
|
|
||
| return ( | ||
| <Badge variant="outline" className={color}> | ||
| {text} | ||
| </Badge> | ||
| ); | ||
| }, | ||
| }, | ||
| { | ||
| id: "type", | ||
| accessorKey: "type", | ||
| header: "Type", | ||
| cell: ({ row }) => { | ||
| let text = "API Key"; | ||
| let color = "bg-blue-300"; | ||
| if (row.original.integrationId) { | ||
| text = "Integration"; | ||
| color = "bg-yellow-300"; | ||
| } | ||
|
|
||
| return ( | ||
| <Badge variant="outline" className={color}> | ||
| {text} | ||
| </Badge> | ||
| ); | ||
| }, | ||
| }, | ||
| ]; |
159 changes: 159 additions & 0 deletions
159
src/features/api-key-connectors/components/connectors.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,159 @@ | ||
| "use client"; | ||
|
|
||
| import { | ||
| EmptyView, | ||
| EntityContainer, | ||
| EntityHeader, | ||
| EntitySearch, | ||
| ErrorView, | ||
| LoadingView, | ||
| } from "@/components/entity-components"; | ||
| import { DataTable } from "@/components/ui/data-table"; | ||
| import { ResourceType } from "@/generated/prisma"; | ||
| import { useEntitySearch } from "@/hooks/use-entity-search"; | ||
| import { | ||
| useConnectorParams, | ||
| useSuspenseConnectorsByResourceType, | ||
| } from "../hooks/use-connectors"; | ||
| import { columns } from "./columns"; | ||
|
|
||
| export const ConnectorsLoading = () => { | ||
| return <LoadingView message="Loading connectors..." />; | ||
| }; | ||
|
|
||
| export const ConnectorsError = () => { | ||
| return <ErrorView message="Error loading connectors" />; | ||
| }; | ||
|
|
||
| export const ConnectorsEmpty = () => { | ||
| return ( | ||
| <EmptyView message="No connectors found. Connectors are typically seeded using the database seed script." /> | ||
| ); | ||
| }; | ||
|
|
||
| const ConnectorsHeader = ({ | ||
| disabled, | ||
| resourceType, | ||
| }: { | ||
| disabled?: boolean; | ||
| resourceType: string; | ||
| }) => { | ||
| return ( | ||
| <EntityHeader | ||
| title={`${resourceType} Connectors`} | ||
| description={`View connectors that others are using`} | ||
| disabled={disabled} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| const ConnectorsContainer = ({ | ||
| children, | ||
| resourceType, | ||
| }: { | ||
| children: React.ReactNode; | ||
| resourceType: ResourceType | string; | ||
| }) => { | ||
| return ( | ||
| <EntityContainer header={<ConnectorsHeader resourceType={resourceType} />}> | ||
| {children} | ||
| </EntityContainer> | ||
| ); | ||
| }; | ||
|
|
||
| const ConnectorsSearch = () => { | ||
| const [params, setParams] = useConnectorParams(); | ||
| const { searchValue, onSearchChange } = useEntitySearch({ | ||
| params, | ||
| setParams, | ||
| }); | ||
|
|
||
| return ( | ||
| <EntitySearch | ||
| value={searchValue} | ||
| onChange={onSearchChange} | ||
| placeholder="Search connectors" | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| const ConnectorsList = ({ resourceType }: { resourceType: ResourceType }) => { | ||
| const { data: connectors, isFetching } = useSuspenseConnectorsByResourceType({ | ||
| resourceType, | ||
| }); | ||
|
|
||
| console.log("useSuspenseConnectorsByResourceType:", connectors); | ||
|
|
||
| return ( | ||
| <DataTable | ||
| paginatedData={connectors} | ||
| columns={columns} | ||
| isLoading={isFetching} | ||
| search={<ConnectorsSearch />} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export const AssetConnectorsContainer = ({ | ||
| children, | ||
| }: { | ||
| children: React.ReactNode; | ||
| }) => { | ||
| return ( | ||
| <ConnectorsContainer resourceType={ResourceType.Asset}> | ||
| {children} | ||
| </ConnectorsContainer> | ||
| ); | ||
| }; | ||
|
|
||
| export const DeviceArtifactConnectorsContainer = ({ | ||
| children, | ||
| }: { | ||
| children: React.ReactNode; | ||
| }) => { | ||
| return ( | ||
| <ConnectorsContainer resourceType={"Device Artifact"}> | ||
| {children} | ||
| </ConnectorsContainer> | ||
| ); | ||
| }; | ||
|
|
||
| export const RemediationConnectorsContainer = ({ | ||
| children, | ||
| }: { | ||
| children: React.ReactNode; | ||
| }) => { | ||
| return ( | ||
| <ConnectorsContainer resourceType={ResourceType.Remediation}> | ||
| {children} | ||
| </ConnectorsContainer> | ||
| ); | ||
| }; | ||
|
|
||
| export const VulnerabilityConnectorsContainer = ({ | ||
| children, | ||
| }: { | ||
| children: React.ReactNode; | ||
| }) => { | ||
| return ( | ||
| <ConnectorsContainer resourceType={ResourceType.Vulnerability}> | ||
| {children} | ||
| </ConnectorsContainer> | ||
| ); | ||
| }; | ||
|
|
||
| export const AssetConnectorList = () => { | ||
| return <ConnectorsList resourceType={ResourceType.Asset} />; | ||
| }; | ||
|
|
||
| export const DeviceArtifactConnectorList = () => { | ||
| return <ConnectorsList resourceType={ResourceType.DeviceArtifact} />; | ||
| }; | ||
|
|
||
| export const RemediationConnectorList = () => { | ||
| return <ConnectorsList resourceType={ResourceType.Remediation} />; | ||
| }; | ||
|
|
||
| export const VulnerabilityConnectorList = () => { | ||
| return <ConnectorsList resourceType={ResourceType.Vulnerability} />; | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Remove connector payload debug logging before merge.
Line 85 logs fetched connector data in the browser console. This is a production data-exposure/noise risk and should be removed.
Suggested fix
- console.log("useSuspenseConnectorsByResourceType:", connectors);📝 Committable suggestion
🤖 Prompt for AI Agents