Skip to content

Commit

Permalink
auto populate the agent submission form
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiftyos committed Dec 19, 2024
1 parent ed7c937 commit 3852741
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions autogpt_platform/backend/backend/server/v2/store/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ async def get_my_agents(
agent_version=agent.version,
agent_name=agent.name or "",
last_edited=agent.updatedAt or agent.createdAt,
description=agent.description or "",
)
for agent in agents
]
Expand Down
1 change: 1 addition & 0 deletions autogpt_platform/backend/backend/server/v2/store/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class MyAgent(pydantic.BaseModel):
agent_id: str
agent_version: int
agent_name: str
description: str
last_edited: datetime.datetime


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ export const PublishAgentInfo: React.FC<PublishAgentInfoProps> = ({
const [slug, setSlug] = React.useState(initialData?.slug || "");
const thumbnailsContainerRef = React.useRef<HTMLDivElement | null>(null);

React.useEffect(() => {
if (initialData) {
setImages(
initialData.additionalImages
? [initialData.thumbnailSrc, ...initialData.additionalImages]
: initialData.thumbnailSrc
? [initialData.thumbnailSrc]
: [],
);
setSelectedImage(initialData.thumbnailSrc || null);
setTitle(initialData.title);
setSubheader(initialData.subheader);
setYoutubeLink(initialData.youtubeLink);
setCategory(initialData.category);
setDescription(initialData.description);
setSlug(initialData.slug);
}
}, [initialData]);

const handleRemoveImage = (indexToRemove: number) => {
const newImages = [...images];
newImages.splice(indexToRemove, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ export const PublishAgentPopout: React.FC<PublishAgentPopoutProps> = ({
);
const [myAgents, setMyAgents] = React.useState<MyAgentsResponse | null>(null);
const [selectedAgent, setSelectedAgent] = React.useState<string | null>(null);
const [initialData, setInitialData] = React.useState<{
title: string;
subheader: string;
slug: string;
thumbnailSrc: string;
youtubeLink: string;
category: string;
description: string;
additionalImages?: string[];
} | null>(null);
const [publishData, setPublishData] =
React.useState<StoreSubmissionRequest>(submissionData);
const [selectedAgentId, setSelectedAgentId] = React.useState<string | null>(
Expand Down Expand Up @@ -102,6 +112,23 @@ export const PublishAgentPopout: React.FC<PublishAgentPopoutProps> = ({
};

const handleNextFromSelect = (agentId: string, agentVersion: number) => {
const selectedAgentData = myAgents?.agents.find(
(agent) => agent.agent_id === agentId,
);

const name = selectedAgentData?.agent_name || "";
const description = selectedAgentData?.description || "";
setInitialData({
title: name,
subheader: "",
description: description,
thumbnailSrc: "",
youtubeLink: "",
category: "",
slug: name.replace(/ /g, "-"),
additionalImages: [],
});

setStep("info");
setSelectedAgentId(agentId);
setSelectedAgentVersion(agentVersion);
Expand Down Expand Up @@ -203,6 +230,7 @@ export const PublishAgentPopout: React.FC<PublishAgentPopoutProps> = ({
onBack={handleBack}
onSubmit={handleNextFromInfo}
onClose={handleClose}
initialData={initialData}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ export type MyAgent = {
agent_version: number;
agent_name: string;
last_edited: string;
description: string;
};

export type MyAgentsResponse = {
Expand Down

0 comments on commit 3852741

Please sign in to comment.