Skip to content

Commit

Permalink
Merge pull request #277 from calkit/showcase
Browse files Browse the repository at this point in the history
Add project showcase and move description into title bar
  • Loading branch information
petebachant authored Jan 20, 2025
2 parents 842af61 + 8207c54 commit 6768e4a
Show file tree
Hide file tree
Showing 11 changed files with 743 additions and 419 deletions.
101 changes: 99 additions & 2 deletions backend/app/api/routes/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def create_project(
logger.warning(f"Failed to create: {resp.json()}")
try:
message = resp.json()["errors"][0]["message"].capitalize()
except:
except Exception:
message = "Failed to create GitHub repo"
raise HTTPException(resp.status_code, message)
resp_json = resp.json()
Expand Down Expand Up @@ -1227,7 +1227,31 @@ def get_project_figure(
current_user: CurrentUser,
session: SessionDep,
) -> Figure:
raise HTTPException(501)
project = app.projects.get_project(
session=session,
owner_name=owner_name,
project_name=project_name,
current_user=current_user,
min_access_level="read",
)
ck_info = get_ck_info(
project=project, user=current_user, session=session, ttl=120
)
figures = ck_info.get("figures", [])
# Get the figure content and base64 encode it
for fig in figures:
if fig.get("path") == figure_path:
item = get_project_contents(
owner_name=owner_name,
project_name=project_name,
session=session,
current_user=current_user,
path=fig["path"],
)
fig["content"] = item.content
fig["url"] = item.url
return Figure.model_validate(fig)
raise HTTPException(404, "Figure not found")


@router.post("/projects/{owner_name}/{project_name}/figures")
Expand Down Expand Up @@ -2632,3 +2656,76 @@ def get_project_app(
if project_app is None:
return
return ProjectApp.model_validate(project_app)


class ProjectShowcaseFigureInput(BaseModel):
figure: str


class ProjectShowcaseFigure(BaseModel):
figure: Figure


class ProjectShowcaseText(BaseModel):
text: str


class ProjectShowcaseInput(BaseModel):
elements: list[ProjectShowcaseFigureInput | ProjectShowcaseText]


class ProjectShowcase(BaseModel):
elements: list[ProjectShowcaseFigure | ProjectShowcaseText]


@router.get("/projects/{owner_name}/{project_name}/showcase")
def get_project_showcase(
owner_name: str,
project_name: str,
current_user: CurrentUser,
session: SessionDep,
) -> ProjectShowcase | None:
project = app.projects.get_project(
owner_name=owner_name,
project_name=project_name,
session=session,
current_user=current_user,
min_access_level="read",
)
incorrectly_defined = ProjectShowcase(
elements=[
ProjectShowcaseText(text="Showcase is not correctly defined.")
]
)
ck_info = get_ck_info(
project=project, user=current_user, session=session, ttl=120
)
showcase = ck_info.get("showcase")
if showcase is None:
return
try:
inputs = ProjectShowcaseInput.model_validate(dict(elements=showcase))
except Exception:
return incorrectly_defined
# Iterate over showcase elements, fetching the contents to return
elements_out = []
for element_in in inputs.elements:
if isinstance(element_in, ProjectShowcaseFigureInput):
try:
element_out = ProjectShowcaseFigure(
figure=get_project_figure(
owner_name=owner_name,
project_name=project_name,
session=session,
current_user=current_user,
figure_path=element_in.figure,
)
)
except Exception:
element_out = ProjectShowcaseText(
text=f"Figure at path '{element_in.figure}' not found"
)
else:
element_out = element_in
elements_out.append(element_out)
return ProjectShowcase.model_validate(dict(elements=elements_out))
20 changes: 1 addition & 19 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,9 @@ strict = true
exclude = ["venv", ".venv", "alembic"]

[tool.ruff]
target-version = "py310"
target-version = "py312"
exclude = ["alembic"]

[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"UP", # pyupgrade
"ARG001", # unused arguments in functions
]
ignore = [
"E501", # line too long, handled by black
"B008", # do not perform function calls in argument defaults
"W191", # indentation contains tabs
"B904", # Allow raising exceptions without from e, for HTTPException
]

[tool.ruff.lint.pyupgrade]
# Preserve types, even if a file imports `from __future__ import annotations`.
keep-runtime-typing = true
12 changes: 12 additions & 0 deletions frontend/src/client/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,18 @@ export type ProjectPublic = {
current_user_access?: "read" | "write" | "admin" | "owner" | null
}

export type ProjectShowcase = {
elements: Array<ProjectShowcaseFigure | ProjectShowcaseText>
}

export type ProjectShowcaseFigure = {
figure: Figure
}

export type ProjectShowcaseText = {
text: string
}

export type ProjectsPublic = {
data: Array<ProjectPublic>
count: number
Expand Down
38 changes: 38 additions & 0 deletions frontend/src/client/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,44 @@ export const $ProjectPublic = {
},
} as const

export const $ProjectShowcase = {
properties: {
elements: {
type: "array",
contains: {
type: "any-of",
contains: [
{
type: "ProjectShowcaseFigure",
},
{
type: "ProjectShowcaseText",
},
],
},
isRequired: true,
},
},
} as const

export const $ProjectShowcaseFigure = {
properties: {
figure: {
type: "Figure",
isRequired: true,
},
},
} as const

export const $ProjectShowcaseText = {
properties: {
text: {
type: "string",
isRequired: true,
},
},
} as const

export const $ProjectsPublic = {
properties: {
data: {
Expand Down
27 changes: 27 additions & 0 deletions frontend/src/client/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import type {
ProjectCreate,
ProjectPatch,
ProjectPublic,
ProjectShowcase,
ProjectsPublic,
Publication,
Question,
Expand Down Expand Up @@ -379,6 +380,10 @@ export type ProjectsData = {
ownerName: string
projectName: string
}
GetProjectShowcase: {
ownerName: string
projectName: string
}
}

export type OrgsData = {
Expand Down Expand Up @@ -2129,6 +2134,28 @@ export class ProjectsService {
},
})
}

/**
* Get Project Showcase
* @returns unknown Successful Response
* @throws ApiError
*/
public static getProjectShowcase(
data: ProjectsData["GetProjectShowcase"],
): CancelablePromise<ProjectShowcase | null> {
const { ownerName, projectName } = data
return __request(OpenAPI, {
method: "GET",
url: "/projects/{owner_name}/{project_name}/showcase",
path: {
owner_name: ownerName,
project_name: projectName,
},
errors: {
422: `Validation Error`,
},
})
}
}

export class OrgsService {
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/Common/ActionsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface ActionsMenuProps {
}

const ActionsMenu = ({ type, value, disabled }: ActionsMenuProps) => {
const editUserModal = useDisclosure()
const editEntityModal = useDisclosure()
const deleteModal = useDisclosure()

return (
Expand All @@ -35,7 +35,7 @@ const ActionsMenu = ({ type, value, disabled }: ActionsMenuProps) => {
/>
<MenuList>
<MenuItem
onClick={editUserModal.onOpen}
onClick={editEntityModal.onOpen}
icon={<FiEdit fontSize="16px" />}
>
Edit {type.toLowerCase()}
Expand All @@ -51,14 +51,14 @@ const ActionsMenu = ({ type, value, disabled }: ActionsMenuProps) => {
{type === "User" ? (
<EditUser
user={value as UserPublic}
isOpen={editUserModal.isOpen}
onClose={editUserModal.onClose}
isOpen={editEntityModal.isOpen}
onClose={editEntityModal.onClose}
/>
) : (
<EditProject
project={value as ProjectPublic}
isOpen={editUserModal.isOpen}
onClose={editUserModal.onClose}
isOpen={editEntityModal.isOpen}
onClose={editEntityModal.onClose}
/>
)}
<Delete
Expand Down
Loading

0 comments on commit 6768e4a

Please sign in to comment.