-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[POR-2202] allow users to link apps to their datastore from the dashb…
…oard (#4170)
- Loading branch information
Feroze Mohideen
authored
Jan 19, 2024
1 parent
1b97469
commit 1b897d3
Showing
19 changed files
with
553 additions
and
348 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { z } from "zod"; | ||
|
||
import { | ||
appRevisionWithSourceValidator, | ||
type AppRevisionWithSource, | ||
} from "main/home/app-dashboard/apps/types"; | ||
|
||
import api from "shared/api"; | ||
|
||
// use this hook to get the latest revision of every app in the project/cluster | ||
export const useLatestAppRevisions = ({ | ||
projectId, | ||
clusterId, | ||
}: { | ||
projectId: number; | ||
clusterId: number; | ||
}): { | ||
revisions: AppRevisionWithSource[]; | ||
} => { | ||
const { data: apps = [] } = useQuery( | ||
[ | ||
"getLatestAppRevisions", | ||
{ | ||
cluster_id: clusterId, | ||
project_id: projectId, | ||
}, | ||
], | ||
async () => { | ||
if (clusterId === -1 || projectId === -1) { | ||
return; | ||
} | ||
|
||
const res = await api.getLatestAppRevisions( | ||
"<token>", | ||
{ | ||
deployment_target_id: undefined, | ||
ignore_preview_apps: true, | ||
}, | ||
{ cluster_id: clusterId, project_id: projectId } | ||
); | ||
|
||
const apps = await z | ||
.object({ | ||
app_revisions: z.array(appRevisionWithSourceValidator), | ||
}) | ||
.parseAsync(res.data); | ||
|
||
return apps.app_revisions; | ||
}, | ||
{ | ||
refetchOnWindowFocus: false, | ||
enabled: clusterId !== 0 && projectId !== 0, | ||
} | ||
); | ||
return { | ||
revisions: apps, | ||
}; | ||
}; |
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
122 changes: 122 additions & 0 deletions
122
dashboard/src/main/home/app-dashboard/apps/SelectableAppList.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,122 @@ | ||
import React, { useMemo } from "react"; | ||
import { PorterApp } from "@porter-dev/api-contracts"; | ||
import styled, { css } from "styled-components"; | ||
|
||
import Container from "components/porter/Container"; | ||
import Icon from "components/porter/Icon"; | ||
import Spacer from "components/porter/Spacer"; | ||
import Text from "components/porter/Text"; | ||
import { AppIcon, AppSource } from "main/home/app-dashboard/apps/AppMeta"; | ||
|
||
import healthy from "assets/status-healthy.png"; | ||
|
||
import { type AppRevisionWithSource } from "./types"; | ||
|
||
type SelectableAppRowProps = { | ||
app: AppRevisionWithSource; | ||
onSelect?: () => void; | ||
onDeselect?: () => void; | ||
selected?: boolean; | ||
}; | ||
|
||
const SelectableAppRow: React.FC<SelectableAppRowProps> = ({ | ||
app, | ||
selected, | ||
onSelect, | ||
onDeselect, | ||
}) => { | ||
const proto = useMemo(() => { | ||
return PorterApp.fromJsonString(atob(app.app_revision.b64_app_proto), { | ||
ignoreUnknownFields: true, | ||
}); | ||
}, [app.app_revision.b64_app_proto]); | ||
|
||
return ( | ||
<ResourceOption | ||
selected={selected} | ||
onClick={() => { | ||
if (selected) { | ||
onDeselect?.(); | ||
} else { | ||
onSelect?.(); | ||
} | ||
}} | ||
isHoverable={onSelect != null || onDeselect != null} | ||
> | ||
<div> | ||
<Container row> | ||
<Spacer inline width="1px" /> | ||
<AppIcon buildpacks={proto.build?.buildpacks ?? []} /> | ||
<Spacer inline width="12px" /> | ||
<Text size={14}>{proto.name}</Text> | ||
<Spacer inline x={1} /> | ||
</Container> | ||
<Spacer height="15px" /> | ||
<Container row> | ||
<AppSource source={app.source} /> | ||
<Spacer inline x={1} /> | ||
</Container> | ||
</div> | ||
{selected && <Icon height="18px" src={healthy} />} | ||
</ResourceOption> | ||
); | ||
}; | ||
|
||
type AppListProps = { | ||
appListItems: Array<{ | ||
app: AppRevisionWithSource; | ||
key: string; | ||
onSelect?: () => void; | ||
onDeselect?: () => void; | ||
isSelected?: boolean; | ||
}>; | ||
}; | ||
|
||
const SelectableAppList: React.FC<AppListProps> = ({ appListItems }) => { | ||
return ( | ||
<StyledSelectableAppList> | ||
{appListItems.map((ali) => { | ||
return ( | ||
<SelectableAppRow | ||
key={ali.key} | ||
app={ali.app} | ||
selected={ali.isSelected} | ||
onSelect={ali.onSelect} | ||
onDeselect={ali.onDeselect} | ||
/> | ||
); | ||
})} | ||
</StyledSelectableAppList> | ||
); | ||
}; | ||
|
||
export default SelectableAppList; | ||
|
||
const StyledSelectableAppList = styled.div` | ||
display: flex; | ||
row-gap: 10px; | ||
flex-direction: column; | ||
max-height: 400px; | ||
overflow-y: scroll; | ||
`; | ||
|
||
const ResourceOption = styled.div<{ selected?: boolean; isHoverable: boolean }>` | ||
background: ${(props) => props.theme.clickable.bg}; | ||
border: 1px solid | ||
${(props) => (props.selected ? "#ffffff" : props.theme.border)}; | ||
width: 100%; | ||
padding: 10px 15px; | ||
border-radius: 5px; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
${(props) => props.isHoverable && "cursor: pointer;"} | ||
${(props) => | ||
props.isHoverable && | ||
!props.selected && | ||
css` | ||
&:hover { | ||
border: 1px solid #7a7b80; | ||
} | ||
`} | ||
`; |
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.