edit button in docs section
This commit is contained in:
parent
bb37638a16
commit
193bd88446
2 changed files with 66 additions and 9 deletions
|
|
@ -1,6 +1,8 @@
|
|||
import { ConfigYaml } from "@continuedev/config-yaml";
|
||||
import {
|
||||
ArrowPathIcon,
|
||||
ArrowTopRightOnSquareIcon,
|
||||
PencilIcon,
|
||||
StopIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { SiteIndexingConfig } from "core";
|
||||
|
|
@ -19,9 +21,17 @@ import { StatusIndicator } from "./StatusIndicator";
|
|||
|
||||
interface IndexingStatusViewerProps {
|
||||
docConfig: SiteIndexingConfig;
|
||||
docFromYaml?: NonNullable<ConfigYaml["docs"]>[number];
|
||||
}
|
||||
|
||||
function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) {
|
||||
function isUsesBlock(block: any): block is { uses: string } {
|
||||
return typeof block !== "string" && "uses" in block;
|
||||
}
|
||||
|
||||
function DocsIndexingStatus({
|
||||
docConfig,
|
||||
docFromYaml,
|
||||
}: IndexingStatusViewerProps) {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const { selectedProfile } = useAuth();
|
||||
const dispatch = useAppDispatch();
|
||||
|
|
@ -69,6 +79,25 @@ function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) {
|
|||
dispatch(setShowDialog(true));
|
||||
};
|
||||
|
||||
const openUrl = (path: string) =>
|
||||
ideMessenger.request("controlPlane/openUrl", {
|
||||
path,
|
||||
orgSlug: undefined,
|
||||
});
|
||||
|
||||
const handleEdit = () => {
|
||||
console.log("edit", docFromYaml);
|
||||
if (selectedProfile?.profileType === "local") {
|
||||
ideMessenger.post("config/openProfile", {
|
||||
profileId: undefined,
|
||||
});
|
||||
} else if (docFromYaml && isUsesBlock(docFromYaml)) {
|
||||
openUrl(`${docFromYaml.uses}/new-version`);
|
||||
} else if (selectedProfile?.fullSlug) {
|
||||
const slug = `${selectedProfile.fullSlug.ownerSlug}/${selectedProfile.fullSlug.packageSlug}`;
|
||||
openUrl(`${slug}/new-version`);
|
||||
}
|
||||
};
|
||||
const progressPercentage = useMemo(() => {
|
||||
if (!status) {
|
||||
return 0;
|
||||
|
|
@ -138,6 +167,11 @@ function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) {
|
|||
/>
|
||||
)}
|
||||
|
||||
<PencilIcon
|
||||
className="h-3 w-3 cursor-pointer text-gray-400 hover:brightness-125"
|
||||
onClick={handleEdit}
|
||||
/>
|
||||
|
||||
{/* Commenting out until we have ability to edit local YAML for the user to remove the docs */}
|
||||
{/* {selectedProfile?.profileType === "local" &&
|
||||
status?.status !== "indexing" ? (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { parseConfigYaml } from "@continuedev/config-yaml";
|
||||
import { PlusIcon } from "@heroicons/react/24/outline";
|
||||
import { IndexingStatus } from "core";
|
||||
import { useContext, useMemo } from "react";
|
||||
|
|
@ -22,6 +23,16 @@ function DocsIndexingStatuses() {
|
|||
const { selectedProfile } = useAuth();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
const mergedDocs = useMemo(() => {
|
||||
const parsed = selectedProfile?.rawYaml
|
||||
? parseConfigYaml(selectedProfile?.rawYaml ?? "")
|
||||
: undefined;
|
||||
return (config.docs ?? []).map((doc, index) => ({
|
||||
doc,
|
||||
docFromYaml: parsed?.docs?.[index],
|
||||
}));
|
||||
}, [config.docs, selectedProfile?.rawYaml]);
|
||||
|
||||
const handleAddDocs = () => {
|
||||
if (selectedProfile?.profileType === "local") {
|
||||
dispatch(setShowDialog(true));
|
||||
|
|
@ -43,22 +54,22 @@ function DocsIndexingStatuses() {
|
|||
return 4;
|
||||
};
|
||||
|
||||
const docs = [...(config.docs ?? [])];
|
||||
const docs = [...mergedDocs];
|
||||
docs.sort((a, b) => {
|
||||
const statusA = indexingStatuses[a.startUrl]?.status ?? "pending";
|
||||
const statusB = indexingStatuses[b.startUrl]?.status ?? "pending";
|
||||
const statusA = indexingStatuses[a.doc.startUrl]?.status ?? "pending";
|
||||
const statusB = indexingStatuses[b.doc.startUrl]?.status ?? "pending";
|
||||
|
||||
// First, compare by status
|
||||
const statusCompare = sorter(statusA) - sorter(statusB);
|
||||
if (statusCompare !== 0) return statusCompare;
|
||||
|
||||
// If status is the same, sort by presence of icon
|
||||
const hasIconA = !!a.faviconUrl;
|
||||
const hasIconB = !!b.faviconUrl;
|
||||
const hasIconA = !!a.doc.faviconUrl;
|
||||
const hasIconB = !!b.doc.faviconUrl;
|
||||
return hasIconB === hasIconA ? 0 : hasIconB ? 1 : -1;
|
||||
});
|
||||
return docs;
|
||||
}, [config, indexingStatuses]);
|
||||
}, [mergedDocs, indexingStatuses]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-1">
|
||||
|
|
@ -77,8 +88,20 @@ function DocsIndexingStatuses() {
|
|||
</a>
|
||||
)}
|
||||
</div>
|
||||
{sortedConfigDocs.map((doc) => {
|
||||
return <DocsIndexingStatus key={doc.startUrl} docConfig={doc} />;
|
||||
{sortedConfigDocs.map((docConfig) => {
|
||||
return (
|
||||
<div
|
||||
key={docConfig.doc.startUrl}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
<div className="flex-grow">
|
||||
<DocsIndexingStatus
|
||||
docFromYaml={docConfig.docFromYaml}
|
||||
docConfig={docConfig.doc}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{sortedConfigDocs.length > 0 && (
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue