Skip to content

Commit 8821961

Browse files
authored
1 parent a6b6734 commit 8821961

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

src/containers/not-found/dispatch.tsx

+49-8
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ const SectionTitle = ({ children }: { children: ReactNode }) => (
2828
<h2 className='pf-c-title'>{children}</h2>
2929
);
3030

31-
export const Dispatch = (props: RouteProps) => {
31+
export const Dispatch = ({ location, navigate }: RouteProps) => {
3232
const { featureFlags } = useContext();
3333

34-
const { pathname } = ParamHelper.parseParamString(props.location.search) as {
34+
const { pathname } = ParamHelper.parseParamString(location.search) as {
3535
pathname: string;
3636
};
3737

@@ -41,15 +41,56 @@ export const Dispatch = (props: RouteProps) => {
4141
const [roles, setRoles] = useState(null);
4242

4343
useEffect(() => {
44-
CollectionVersionAPI.list({ namespace, name, is_highest: true })
45-
.then(({ data: { data } }) => setCollections(data || []))
46-
.catch(() => setCollections([]));
44+
const wait = [];
45+
46+
wait.push(
47+
CollectionVersionAPI.list({ namespace, name, is_highest: true })
48+
.then(({ data: { data } }) => data || [])
49+
.catch(() => [])
50+
.then((c) => (setCollections(c), c)),
51+
);
4752

4853
if (featureFlags.legacy_roles) {
49-
LegacyRoleAPI.list({ github_user: namespace, name })
50-
.then(({ data: { results } }) => setRoles(results || []))
51-
.catch(() => setRoles([]));
54+
wait.push(
55+
LegacyRoleAPI.list({ github_user: namespace, name })
56+
.then(({ data: { results } }) => results || [])
57+
.catch(() => [])
58+
.then((r) => (setRoles(r), r)),
59+
);
5260
}
61+
62+
Promise.all(wait).then(([collections, roles]) => {
63+
if (collections.length === 1 && !roles?.length) {
64+
const {
65+
collection_version: { name: collection, namespace },
66+
repository: { name: repo },
67+
} = collections[0];
68+
69+
navigate(
70+
formatPath(Paths.collectionByRepo, {
71+
collection,
72+
namespace,
73+
repo,
74+
}),
75+
);
76+
}
77+
78+
if (roles.length === 1 && !collections.length) {
79+
const {
80+
name,
81+
summary_fields: {
82+
namespace: { name: username },
83+
},
84+
} = roles[0];
85+
86+
navigate(
87+
formatPath(Paths.legacyRole, {
88+
username,
89+
name,
90+
}),
91+
);
92+
}
93+
});
5394
}, [pathname]);
5495

5596
return (

0 commit comments

Comments
 (0)