chain pruning

This commit is contained in:
Kaushik Narayan R 2025-03-15 00:21:17 -07:00
parent fae3c9bbf1
commit c1c4d4d45a
3 changed files with 49 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import {
opCreateLinkURL, opCreateLinkURL,
opDeleteLinkURL, opDeleteLinkURL,
opFetchGraphURL, opFetchGraphURL,
opPruneChainURL,
opPruneLinkURL, opPruneLinkURL,
opUpdateUserDataURL, opUpdateUserDataURL,
} from "./paths.ts"; } from "./paths.ts";
@ -48,11 +49,7 @@ type backfillChainBodyType = {
root: string; // playlistID root: string; // playlistID
}; };
interface backfillChainDataType extends apiRespBaseType { interface backfillChainDataType extends backfillLinkDataType {}
toAddNum: number;
addedNum: number;
localNum: number;
}
type pruneLinkBodyType = createLinkBodyType; type pruneLinkBodyType = createLinkBodyType;
@ -61,6 +58,10 @@ interface pruneLinkDataType extends apiRespBaseType {
deletedNum: number; deletedNum: number;
} }
type pruneChainBodyType = backfillChainBodyType;
interface pruneChainDataType extends pruneLinkDataType {}
export const apiFetchGraph = async (): Promise< export const apiFetchGraph = async (): Promise<
AxiosResponse<fetchGraphDataType, any> AxiosResponse<fetchGraphDataType, any>
> => { > => {
@ -137,3 +138,14 @@ export const apiPruneLink = async (
return error.response; return error.response;
} }
}; };
export const apiPruneChain = async (
data: pruneChainBodyType
): Promise<AxiosResponse<pruneChainDataType, any>> => {
try {
const response = await axiosInstance.put(opPruneChainURL, data);
return response;
} catch (error: any) {
return error.response;
}
};

View File

@ -17,3 +17,4 @@ export const opDeleteLinkURL: "api/operations/link" = opCreateLinkURL;
export const opBackfillLinkURL = "api/operations/populate/link"; export const opBackfillLinkURL = "api/operations/populate/link";
export const opBackfillChainURL = "api/operations/populate/chain"; export const opBackfillChainURL = "api/operations/populate/chain";
export const opPruneLinkURL = "api/operations/prune/link"; export const opPruneLinkURL = "api/operations/prune/link";
export const opPruneChainURL = "api/operations/prune/chain";

View File

@ -48,6 +48,7 @@ import {
apiCreateLink, apiCreateLink,
apiDeleteLink, apiDeleteLink,
apiFetchGraph, apiFetchGraph,
apiPruneChain,
apiPruneLink, apiPruneLink,
apiUpdateUserData, apiUpdateUserData,
} from "../../api/operations.ts"; } from "../../api/operations.ts";
@ -354,6 +355,34 @@ const Graph = (): React.ReactNode => {
return; return;
}; };
const pruneChain = async () => {
if (selectedNodeID === "") {
showWarnToastNotification("Select a playlist!");
return;
}
const selectedNode = playlistNodes.filter(
(nd) => nd.id === selectedNodeID
)[0];
if (!selectedNode) throw new ReferenceError("no playlist selected");
setLoading(true);
const resp = await APIWrapper({
apiFn: apiPruneChain,
data: {
root: spotifyPlaylistLinkPrefix + selectedNodeID,
},
refreshAuth,
});
setLoading(false);
if (resp?.status === 200) {
if (resp?.data.deletedNum < resp?.data.toDelNum)
showWarnToastNotification(resp?.data.message);
else showSuccessToastNotification(resp?.data.message);
return;
}
return;
};
type getLayoutedElementsOpts = { type getLayoutedElementsOpts = {
direction: rankdirType; direction: rankdirType;
}; };
@ -570,9 +599,9 @@ const Graph = (): React.ReactNode => {
<PiSubsetOf size={36} /> <PiSubsetOf size={36} />
Prune Link Prune Link
</Button> </Button>
<Button disabled={loading}> <Button disabled={loading} onClickMethod={pruneChain}>
<PiSubsetOf size={36} /> <PiSubsetOf size={36} />
Prune Link Prune Chain
</Button> </Button>
<hr className={styles.divider} /> <hr className={styles.divider} />
<Button disabled={loading} onClickMethod={() => arrangeLayout("TB")}> <Button disabled={loading} onClickMethod={() => arrangeLayout("TB")}>