Skip to content

Commit 53cd9dd

Browse files
authored
Roles: prefer namespace over github_user (#4440)
* Role: use namespace instead of github_user where applicable Follow-up to #4423 No-Issue * standalone routes: rename username to namespace * role-detail: specify types
1 parent ceb269d commit 53cd9dd

File tree

9 files changed

+64
-58
lines changed

9 files changed

+64
-58
lines changed

src/components/legacy-namespace-list/legacy-namespace-item.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function LegacyNamespaceListItem({
2929
} = useContext();
3030
const { id, avatar_url, name, summary_fields } = namespace;
3131

32-
const namespace_url = formatPath(Paths.legacyNamespace, {
32+
const namespace_url = formatPath(Paths.standaloneNamespace, {
3333
namespaceid: id,
3434
});
3535

src/components/legacy-role-list/legacy-role-item.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@ interface LegacyRoleProps {
2929
export function LegacyRoleListItem({ role, show_thumbnail }: LegacyRoleProps) {
3030
const {
3131
description,
32-
github_user,
3332
modified,
3433
name,
3534
summary_fields: { namespace, versions, tags },
3635
} = role;
3736
const latest = versions[0];
3837

39-
const role_url = formatPath(Paths.legacyRole, {
40-
username: namespace.name,
38+
const role_url = formatPath(Paths.standaloneRole, {
39+
namespace: namespace.name,
4140
name,
4241
});
4342
const release_date = latest?.release_date || modified;
@@ -49,7 +48,7 @@ export function LegacyRoleListItem({ role, show_thumbnail }: LegacyRoleProps) {
4948
cells.push(
5049
<DataListCell isFilled={false} alignRight={false} key='ns'>
5150
<Logo
52-
alt={t`${github_user} logo`}
51+
alt={t`${namespace.name} logo`}
5352
image={namespace.avatar_url}
5453
size='70px'
5554
unlockWidth

src/containers/ansible-role/namespace-detail.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class NamespaceRoles extends React.Component<
102102
this.setState({ loading: true });
103103
LegacyRoleAPI.list({
104104
...params,
105-
github_user: namespace.name,
105+
namespace: namespace.name,
106106
})
107107
.then(({ data: { count, results } }) =>
108108
this.setState({
@@ -237,7 +237,7 @@ class AnsibleRoleNamespaceDetail extends React.Component<
237237
> {
238238
static contextType = AppContext;
239239

240-
// This is the details page for a legacy namespace
240+
// This is the details page for a standalone namespace
241241

242242
constructor(props) {
243243
super(props);
@@ -261,8 +261,7 @@ class AnsibleRoleNamespaceDetail extends React.Component<
261261
}
262262

263263
componentDidMount() {
264-
const namespaceid = this.props.routeParams.namespaceid;
265-
LegacyNamespaceAPI.get(namespaceid)
264+
LegacyNamespaceAPI.get(this.props.routeParams.namespaceid)
266265
.then((response) =>
267266
this.setState({
268267
loading: false,
@@ -299,7 +298,7 @@ class AnsibleRoleNamespaceDetail extends React.Component<
299298
);
300299
}
301300

302-
const namespace_url = formatPath(Paths.legacyNamespace, {
301+
const namespace_url = formatPath(Paths.standaloneNamespace, {
303302
namespaceid: namespace.id,
304303
});
305304

src/containers/ansible-role/role-detail.tsx

+28-23
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ import { NotFound } from 'src/containers/not-found/not-found';
4141
import { Paths, formatPath } from 'src/paths';
4242
import { RouteProps, handleHttpError, withRouter } from 'src/utilities';
4343

44-
interface RoleMeta {
44+
interface RoleMetaProps {
4545
addAlert: (alert: AlertType) => void;
46-
github_user: string;
4746
name: string;
47+
namespace: string;
4848
role: LegacyRoleDetailType;
4949
}
5050

51-
interface RoleMetaReadme {
51+
interface RoleMetaReadmeState {
5252
readme_html: string;
5353
}
5454

55-
class RoleInstall extends React.Component<RoleMeta> {
55+
class RoleInstall extends React.Component<RoleMetaProps> {
5656
render() {
57-
const installCMD = `ansible-galaxy role install ${this.props.github_user}.${this.props.name}`;
57+
const installCMD = `ansible-galaxy role install ${this.props.namespace}.${this.props.name}`;
5858
return (
5959
<>
6060
<h1>
@@ -68,7 +68,7 @@ class RoleInstall extends React.Component<RoleMeta> {
6868
}
6969
}
7070

71-
class RoleDocs extends React.Component<RoleMeta, RoleMetaReadme> {
71+
class RoleDocs extends React.Component<RoleMetaProps, RoleMetaReadmeState> {
7272
constructor(props) {
7373
super(props);
7474
this.state = {
@@ -138,7 +138,7 @@ interface RoleVersionsState {
138138
loading: boolean;
139139
}
140140

141-
class RoleVersions extends React.Component<RoleMeta, RoleVersionsState> {
141+
class RoleVersions extends React.Component<RoleMetaProps, RoleVersionsState> {
142142
constructor(props) {
143143
super(props);
144144
this.state = {
@@ -191,31 +191,33 @@ class RoleVersions extends React.Component<RoleMeta, RoleVersionsState> {
191191
interface RoleState {
192192
activeItem: string;
193193
alerts: AlertType[];
194-
github_user: string;
195194
loading: boolean;
196195
name: string;
196+
namespace: string;
197197
role: LegacyRoleDetailType;
198198
}
199199

200200
class AnsibleRoleDetail extends React.Component<RouteProps, RoleState> {
201201
constructor(props) {
202202
super(props);
203203

204-
const { username, name } = props.routeParams;
204+
const { namespace, name } = props.routeParams;
205205
this.state = {
206206
activeItem: 'install',
207207
alerts: [],
208-
github_user: username,
209208
loading: true,
210209
name,
210+
namespace,
211211
role: null,
212212
};
213213
}
214214

215215
componentDidMount() {
216+
const { name, namespace } = this.state;
217+
216218
LegacyRoleAPI.list({
217-
github_user: this.state.github_user,
218-
name: this.state.name,
219+
name,
220+
namespace,
219221
page_size: 1,
220222
})
221223
.then(({ data: { results } }) =>
@@ -241,7 +243,8 @@ class AnsibleRoleDetail extends React.Component<RouteProps, RoleState> {
241243
}
242244

243245
render() {
244-
const { activeItem, alerts, github_user, loading, name, role } = this.state;
246+
const { activeItem, alerts, loading, name, role } = this.state;
247+
245248
if (loading) {
246249
return <LoadingPageWithHeader />;
247250
}
@@ -261,7 +264,7 @@ class AnsibleRoleDetail extends React.Component<RouteProps, RoleState> {
261264
'/' +
262265
encodeURIComponent(role.github_repo);
263266
const namespace = role.summary_fields.namespace;
264-
const namespace_url = formatPath(Paths.legacyNamespace, {
267+
const namespace_url = formatPath(Paths.standaloneNamespace, {
265268
namespaceid: namespace.id,
266269
});
267270
let release_date = null;
@@ -281,7 +284,7 @@ class AnsibleRoleDetail extends React.Component<RouteProps, RoleState> {
281284
const header_cells = [
282285
<DataListCell isFilled={false} alignRight={false} key='ns'>
283286
<Logo
284-
alt={t`${role.github_user} logo`}
287+
alt={t`${namespace.name} logo`}
285288
fallbackToDefault
286289
image={role.summary_fields.namespace.avatar_url}
287290
size='70px'
@@ -339,26 +342,26 @@ class AnsibleRoleDetail extends React.Component<RouteProps, RoleState> {
339342
return (
340343
<RoleInstall
341344
addAlert={addAlert}
342-
github_user={github_user}
343345
name={name}
346+
namespace={namespace.name}
344347
role={role}
345348
/>
346349
);
347350
} else if (activeItem === 'documentation') {
348351
return (
349352
<RoleDocs
350353
addAlert={addAlert}
351-
github_user={github_user}
352354
name={name}
355+
namespace={namespace.name}
353356
role={role}
354357
/>
355358
);
356359
} else if (activeItem === 'versions') {
357360
return (
358361
<RoleVersions
359362
addAlert={addAlert}
360-
github_user={github_user}
361363
name={name}
364+
namespace={namespace.name}
362365
role={role}
363366
/>
364367
);
@@ -370,16 +373,18 @@ class AnsibleRoleDetail extends React.Component<RouteProps, RoleState> {
370373
const breadcrumbs = [
371374
{
372375
name: t`Roles`,
373-
url: formatPath(Paths.legacyRoles),
376+
url: formatPath(Paths.standaloneRoles),
374377
},
375378
{
376-
name: github_user,
377-
url: formatPath(Paths.legacyNamespace, { namespaceid: namespace.id }),
379+
name: namespace.name,
380+
url: formatPath(Paths.standaloneNamespace, {
381+
namespaceid: namespace.id,
382+
}),
378383
},
379384
{
380385
name,
381-
url: formatPath(Paths.legacyRole, {
382-
username: github_user,
386+
url: formatPath(Paths.standaloneRole, {
387+
namespace: namespace.name,
383388
name,
384389
}),
385390
},

src/containers/not-found/dispatch.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const Dispatch = ({ location, navigate }: RouteProps) => {
5252

5353
if (featureFlags.legacy_roles) {
5454
wait.push(
55-
LegacyRoleAPI.list({ github_user: namespace, name })
55+
LegacyRoleAPI.list({ name, namespace })
5656
.then(({ data: { results } }) => results || [])
5757
.catch(() => [])
5858
.then((r) => (setRoles(r), r)),
@@ -79,13 +79,13 @@ export const Dispatch = ({ location, navigate }: RouteProps) => {
7979
const {
8080
name,
8181
summary_fields: {
82-
namespace: { name: username },
82+
namespace: { name: namespace },
8383
},
8484
} = roles[0];
8585

8686
navigate(
87-
formatPath(Paths.legacyRole, {
88-
username,
87+
formatPath(Paths.standaloneRole, {
88+
namespace,
8989
name,
9090
}),
9191
);
@@ -161,7 +161,7 @@ export const Dispatch = ({ location, navigate }: RouteProps) => {
161161
title={t`No matching roles found.`}
162162
description={
163163
<Link
164-
to={formatPath(Paths.legacyRoles)}
164+
to={formatPath(Paths.standaloneRoles)}
165165
>{t`Show all roles`}</Link>
166166
}
167167
/>
@@ -177,7 +177,7 @@ export const Dispatch = ({ location, navigate }: RouteProps) => {
177177
))}
178178
</DataList>
179179
<Link
180-
to={formatPath(Paths.legacyRoles)}
180+
to={formatPath(Paths.standaloneRoles)}
181181
>{t`Show all roles`}</Link>
182182
</>
183183
)}

src/containers/search/multi-search.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,12 @@ export const MultiSearch = (props: RouteProps) => {
283283
title={t`Roles`}
284284
showAllLink={
285285
<Link
286-
to={formatPath(Paths.legacyRoles)}
286+
to={formatPath(Paths.standaloneRoles)}
287287
>{t`Show all roles`}</Link>
288288
}
289289
showMoreLink={
290290
<Link
291-
to={formatPath(Paths.legacyRoles, {}, { keywords })}
291+
to={formatPath(Paths.standaloneRoles, {}, { keywords })}
292292
>{t`Show more roles`}</Link>
293293
}
294294
>
@@ -306,12 +306,12 @@ export const MultiSearch = (props: RouteProps) => {
306306
title={t`Role namespaces`}
307307
showAllLink={
308308
<Link
309-
to={formatPath(Paths.legacyNamespaces)}
309+
to={formatPath(Paths.standaloneNamespaces)}
310310
>{t`Show all role namespaces`}</Link>
311311
}
312312
showMoreLink={
313313
<Link
314-
to={formatPath(Paths.legacyNamespaces, {}, { keywords })}
314+
to={formatPath(Paths.standaloneNamespaces, {}, { keywords })}
315315
>{t`Show more role namespaces`}</Link>
316316
}
317317
>
@@ -408,7 +408,7 @@ export const MultiSearch = (props: RouteProps) => {
408408
emptyStateTitle={t`No matching roles found.`}
409409
showAllLink={
410410
<Link
411-
to={formatPath(Paths.legacyRoles)}
411+
to={formatPath(Paths.standaloneRoles)}
412412
>{t`Show all roles`}</Link>
413413
}
414414
/>
@@ -421,7 +421,7 @@ export const MultiSearch = (props: RouteProps) => {
421421
emptyStateTitle={t`No matching role namespaces found.`}
422422
showAllLink={
423423
<Link
424-
to={formatPath(Paths.legacyNamespaces)}
424+
to={formatPath(Paths.standaloneNamespaces)}
425425
>{t`Show all role namespaces`}</Link>
426426
}
427427
/>

src/loaders/standalone/menu.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ function standaloneMenu() {
9999
},
100100
[
101101
menuItem(t`Roles`, {
102-
url: formatPath(Paths.legacyRoles),
102+
url: formatPath(Paths.standaloneRoles),
103103
alternativeUrls: [formatPath(Paths.compatLegacyRoles)],
104104
}),
105105
menuItem(t`Role Namespaces`, {
106-
url: formatPath(Paths.legacyNamespaces),
106+
url: formatPath(Paths.standaloneNamespaces),
107107
alternativeUrls: [formatPath(Paths.compatLegacyNamespaces)],
108108
}),
109109
],

src/loaders/standalone/routes.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,13 @@ export class StandaloneRoutes extends React.Component<IRoutesProps> {
212212
},
213213

214214
// roles ...
215-
{ component: AnsibleRoleNamespaceDetail, path: Paths.legacyNamespace },
216-
{ component: AnsibleRoleNamespaceList, path: Paths.legacyNamespaces },
217-
{ component: AnsibleRoleDetail, path: Paths.legacyRole },
218-
{ component: AnsibleRoleList, path: Paths.legacyRoles },
215+
{
216+
component: AnsibleRoleNamespaceDetail,
217+
path: Paths.standaloneNamespace,
218+
},
219+
{ component: AnsibleRoleNamespaceList, path: Paths.standaloneNamespaces },
220+
{ component: AnsibleRoleDetail, path: Paths.standaloneRole },
221+
{ component: AnsibleRoleList, path: Paths.standaloneRoles },
219222
// ... but still support legacy urls
220223
{
221224
component: AnsibleRoleNamespaceDetail,

src/paths.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ export enum Paths {
9090
login = '/login',
9191
logout = '/logout',
9292
landingPage = '/',
93-
legacyRole = '/standalone/roles/:username/:name',
94-
legacyRoles = '/standalone/roles/',
95-
legacyNamespace = '/standalone/namespaces/:namespaceid',
96-
legacyNamespaces = '/standalone/namespaces/',
93+
standaloneRole = '/standalone/roles/:namespace/:name',
94+
standaloneRoles = '/standalone/roles',
95+
standaloneNamespace = '/standalone/namespaces/:namespaceid',
96+
standaloneNamespaces = '/standalone/namespaces',
9797
searchByRepo = '/repo/:repo',
9898
myCollectionsByRepo = '/repo/:repo/my-namespaces/:namespace',
9999
collectionByRepo = '/repo/:repo/:namespace/:collection',
@@ -127,10 +127,10 @@ export enum Paths {
127127
collections = '/collections',
128128

129129
// for compatibility with old beta routes, remove later
130-
compatLegacyRole = '/legacy/roles/:username/:name',
131-
compatLegacyRoles = '/legacy/roles/',
130+
compatLegacyRole = '/legacy/roles/:namespace/:name',
131+
compatLegacyRoles = '/legacy/roles',
132132
compatLegacyNamespace = '/legacy/namespaces/:namespaceid',
133-
compatLegacyNamespaces = '/legacy/namespaces/',
133+
compatLegacyNamespaces = '/legacy/namespaces',
134134
}
135135

136136
export const namespaceBreadcrumb = () =>

0 commit comments

Comments
 (0)