Skip to content

Commit

Permalink
Merge pull request #1300 from thunderstore-io/01-20-disable_package_a…
Browse files Browse the repository at this point in the history
…dmin_tools_and_route_some_package_tabs_to_old_website

Disable package admin tools and route some package tabs to old website
  • Loading branch information
Oksamies authored Jan 20, 2025
2 parents d49748a + 80c1781 commit 7190edd
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 75 deletions.
174 changes: 100 additions & 74 deletions apps/cyberstorm-remix/app/p/packageListing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {
useLoaderData,
useLocation,
useOutletContext,
useRevalidator,
// useRevalidator,
} from "@remix-run/react";
import {
CopyButton,
Heading,
Image,
Modal,
// Modal,
NewBreadCrumbs,
NewButton,
NewIcon,
Expand All @@ -23,7 +23,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { ApiError } from "@thunderstore/thunderstore-api";
import { ThunderstoreLogo } from "@thunderstore/cyberstorm/src/svg/svg";
import {
faCog,
// faCog,
faUsers,
faHandHoldingHeart,
faDownload,
Expand All @@ -35,8 +35,8 @@ import TeamMembers from "./components/TeamMembers/TeamMembers";
import { useEffect, useRef, useState } from "react";
import { useHydrated } from "remix-utils/use-hydrated";
import {
PackageDeprecateAction,
PackageEditForm,
// PackageDeprecateAction,
// PackageEditForm,
PackageLikeAction,
} from "@thunderstore/cyberstorm-forms";
import { PageHeader } from "~/commonComponents/PageHeader/PageHeader";
Expand Down Expand Up @@ -120,14 +120,17 @@ export async function loader({ params }: LoaderFunctionArgs) {
// }

export default function Community() {
const { community, communityFilters, listing, team } =
useLoaderData<typeof loader>();
// TODO: Enable when APIs are available
// const { community, communityFilters, listing, team } =
// useLoaderData<typeof loader>();
const { community, listing, team } = useLoaderData<typeof loader>();

const location = useLocation();

const outletContext = useOutletContext() as OutletContextShape;
const currentUser = outletContext.currentUser;
const config = outletContext.requestConfig;
const domain = outletContext.domain;

const [isLiked, setIsLiked] = useState(false);

Expand All @@ -139,13 +142,13 @@ export default function Community() {
);
};

const revalidator = useRevalidator();

const revalidateLoaderData = async () => {
if (revalidator.state === "idle") {
revalidator.revalidate();
}
};
// TODO: Enable when APIs are available
// const revalidator = useRevalidator();
// const revalidateLoaderData = async () => {
// if (revalidator.state === "idle") {
// revalidator.revalidate();
// }
// };

useEffect(() => {
if (currentUser?.username) {
Expand Down Expand Up @@ -199,53 +202,54 @@ export default function Community() {
? "source"
: "details";

const managementTools = (
<Modal
popoverId="packageManagementTools"
trigger={
<NewButton
csVariant="primary"
{...{
popovertarget: "packageManagementTools",
popovertargetaction: "open",
}}
>
<NewIcon csMode="inline" noWrapper>
<FontAwesomeIcon icon={faCog} />
</NewIcon>
Manage
</NewButton>
}
>
<PackageEditForm
options={communityFilters.package_categories.map((cat) => {
return { label: cat.name, value: cat.slug };
})}
community={listing.community_identifier}
namespace={listing.namespace}
package={listing.name}
current_categories={listing.categories}
isDeprecated={listing.is_deprecated}
dataUpdateTrigger={revalidateLoaderData}
deprecationButton={
<NewButton
primitiveType="button"
onClick={PackageDeprecateAction({
packageName: listing.name,
namespace: listing.namespace,
isDeprecated: listing.is_deprecated,
dataUpdateTrigger: revalidateLoaderData,
config: config,
})}
csVariant={listing.is_deprecated ? "warning" : "primary"}
>
{listing.is_deprecated ? "Undeprecate" : "Deprecate"}
</NewButton>
}
config={config}
/>
</Modal>
);
// TODO: Enable when APIs are available
// const managementTools = (
// <Modal
// popoverId="packageManagementTools"
// trigger={
// <NewButton
// csVariant="primary"
// {...{
// popovertarget: "packageManagementTools",
// popovertargetaction: "open",
// }}
// >
// <NewIcon csMode="inline" noWrapper>
// <FontAwesomeIcon icon={faCog} />
// </NewIcon>
// Manage
// </NewButton>
// }
// >
// <PackageEditForm
// options={communityFilters.package_categories.map((cat) => {
// return { label: cat.name, value: cat.slug };
// })}
// community={listing.community_identifier}
// namespace={listing.namespace}
// package={listing.name}
// current_categories={listing.categories}
// isDeprecated={listing.is_deprecated}
// dataUpdateTrigger={revalidateLoaderData}
// deprecationButton={
// <NewButton
// primitiveType="button"
// onClick={PackageDeprecateAction({
// packageName: listing.name,
// namespace: listing.namespace,
// isDeprecated: listing.is_deprecated,
// dataUpdateTrigger: revalidateLoaderData,
// config: config,
// })}
// csVariant={listing.is_deprecated ? "warning" : "primary"}
// >
// {listing.is_deprecated ? "Undeprecate" : "Deprecate"}
// </NewButton>
// }
// config={config}
// />
// </Modal>
// );

return (
<>
Expand Down Expand Up @@ -333,12 +337,12 @@ export default function Community() {
}
/>
<div className="headerActions">
{/* TODO: Admin tools */}
{currentUser?.teams.some(function (cuTeam) {
{/* TODO: Admin tools // TODO: Enable when APIs are available*/}
{/* {currentUser?.teams.some(function (cuTeam) {
return cuTeam?.name === listing.team.name;
})
? managementTools
: null}
: null} */}
</div>
</div>
</header>
Expand Down Expand Up @@ -372,14 +376,25 @@ export default function Community() {
},
current: currentTab === "required",
},
// TODO: Once Analysis page is ready, enable it
// {
// itemProps: {
// key: "wiki",
// primitiveType: "cyberstormLink",
// linkId: "PackageWiki",
// community: listing.community_identifier,
// namespace: listing.namespace,
// package: listing.name,
// "aria-current": currentTab === "wiki",
// children: <>Wiki</>,
// },
// current: currentTab === "wiki",
// },
{
itemProps: {
key: "wiki",
primitiveType: "cyberstormLink",
linkId: "PackageWiki",
community: listing.community_identifier,
namespace: listing.namespace,
package: listing.name,
primitiveType: "link",
href: `${domain}/c/${listing.community_identifier}/p/${listing.namespace}/${listing.name}/wiki`,
"aria-current": currentTab === "wiki",
children: <>Wiki</>,
},
Expand Down Expand Up @@ -414,14 +429,25 @@ export default function Community() {
// TODO: Version count field needs to be added to the endpoint
// numberSlateValue: listing.versionCount,
},
// TODO: Once Analysis page is ready, enable it
// {
// itemProps: {
// key: "source",
// primitiveType: "cyberstormLink",
// linkId: "PackageSource",
// community: listing.community_identifier,
// namespace: listing.namespace,
// package: listing.name,
// "aria-current": currentTab === "source",
// children: <>Analysis</>,
// },
// current: currentTab === "source",
// },
{
itemProps: {
key: "source",
primitiveType: "cyberstormLink",
linkId: "PackageSource",
community: listing.community_identifier,
namespace: listing.namespace,
package: listing.name,
href: `${domain}/c/${listing.community_identifier}/p/${listing.namespace}/${listing.name}/source`,
primitiveType: "link",
"aria-current": currentTab === "source",
children: <>Analysis</>,
},
Expand Down
14 changes: 13 additions & 1 deletion apps/cyberstorm-remix/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ declare global {
export type OutletContextShape = {
currentUser: CurrentUser | undefined;
requestConfig: () => RequestConfig;
domain: string;
};

export const meta: MetaFunction = () => {
Expand Down Expand Up @@ -190,6 +191,11 @@ export function Layout({ children }: { children: React.ReactNode }) {
}

function App() {
// TODO: Remove this customization when legacy site is removed
const domain =
getPublicEnvVariables(["PUBLIC_SITE_URL"]).PUBLIC_SITE_URL ??
"https://thunderstore.io";

const [currentUser, setCurrentUser] = useState<CurrentUser | undefined>(
undefined
);
Expand All @@ -208,7 +214,13 @@ function App() {
}, []);

return (
<Outlet context={{ currentUser: currentUser, requestConfig: rcCallable }} />
<Outlet
context={{
currentUser: currentUser,
requestConfig: rcCallable,
domain: domain,
}}
/>
);
}

Expand Down

0 comments on commit 7190edd

Please sign in to comment.