Skip to content

Commit cabfcc2

Browse files
committed
[WIP] PR-in-a-box ansible#4523
1 parent 4dae654 commit cabfcc2

22 files changed

+55
-79
lines changed

config/community.dev.webpack.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports = webpackBase({
2626
// Determines if the app should be compiled to run on insights or on
2727
// another platform. Options: insights, standalone
2828
DEPLOYMENT_MODE: 'standalone',
29+
IS_COMMUNITY: true,
2930

3031
NAMESPACE_TERM: 'namespaces',
3132

config/community.prod.webpack.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = webpackBase({
77
API_BASE_PATH: '/api/',
88
UI_BASE_PATH: '/ui/',
99
DEPLOYMENT_MODE: 'standalone',
10+
IS_COMMUNITY: true,
1011
NAMESPACE_TERM: 'namespaces',
1112
UI_USE_HTTPS: false,
1213
UI_DEBUG: false,

config/insights.dev.webpack.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module.exports = webpackBase({
2727
// Determines if the app should be compiled to run on insights or on
2828
// another platform. Options: insights, standalone
2929
DEPLOYMENT_MODE: 'insights',
30+
IS_INSIGHTS: true,
3031

3132
// Determines the title of the "namespaces" page
3233
NAMESPACE_TERM: 'partners',

config/insights.prod.webpack.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = webpackBase({
1111
? '/preview/ansible/automation-hub/'
1212
: '/ansible/automation-hub/',
1313
DEPLOYMENT_MODE: 'insights',
14+
IS_INSIGHTS: true,
1415
NAMESPACE_TERM: 'partners',
1516
UI_USE_HTTPS: false,
1617
UI_DEBUG: false,

config/standalone.dev.webpack.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ module.exports = webpackBase({
2525
// Determines if the app should be compiled to run on insights or on
2626
// another platform. Options: insights, standalone
2727
DEPLOYMENT_MODE: 'standalone',
28+
// dev-mode only, support `IS_COMMUNITY=1 npm run start-standalone` in addition to `npm run start-community`
29+
IS_COMMUNITY: !!process.env.IS_COMMUNITY,
2830

2931
NAMESPACE_TERM: 'namespaces',
3032

config/webpack.base.config.js

+15-16
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,32 @@ const gitCommit =
2222
process.env.HUB_UI_VERSION ||
2323
execSync('git rev-parse HEAD', { encoding: 'utf-8' }).trim();
2424

25+
const docsURL =
26+
'https://access.redhat.com/documentation/en-us/red_hat_ansible_automation_platform/';
27+
2528
// Default user defined settings
2629
const defaultConfigs = [
2730
// Global scope means that the variable will be available to the app itself
2831
// as a constant after it is compiled
29-
{ name: 'API_HOST', default: '', scope: 'global' },
3032
{ name: 'API_BASE_PATH', default: '', scope: 'global' },
31-
{ name: 'UI_BASE_PATH', default: '', scope: 'global' },
32-
{ name: 'DEPLOYMENT_MODE', default: 'standalone', scope: 'global' },
33-
{ name: 'NAMESPACE_TERM', default: 'namespaces', scope: 'global' },
33+
{ name: 'API_HOST', default: '', scope: 'global' },
3434
{ name: 'APPLICATION_NAME', default: 'Galaxy NG', scope: 'global' },
35-
{ name: 'UI_EXTERNAL_LOGIN_URI', default: '/login', scope: 'global' },
35+
{ name: 'IS_COMMUNITY', default: false, scope: 'global' },
36+
{ name: 'IS_INSIGHTS', default: false, scope: 'global' },
37+
{ name: 'NAMESPACE_TERM', default: 'namespaces', scope: 'global' },
38+
{ name: 'UI_BASE_PATH', default: '', scope: 'global' },
3639
{ name: 'UI_COMMIT_HASH', default: gitCommit, scope: 'global' },
37-
{
38-
name: 'UI_DOCS_URL',
39-
default:
40-
'https://access.redhat.com/documentation/en-us/red_hat_ansible_automation_platform/',
41-
scope: 'global',
42-
},
43-
44-
// Webpack scope means the variable will only be available to webpack at
45-
// build time
46-
{ name: 'UI_USE_HTTPS', default: false, scope: 'webpack' },
40+
{ name: 'UI_DOCS_URL', default: docsURL, scope: 'global' },
41+
{ name: 'UI_EXTERNAL_LOGIN_URI', default: '/login', scope: 'global' },
42+
43+
// Webpack scope: only available in customConfigs here, not exposed to the UI
44+
{ name: 'API_PROXY_TARGET', default: undefined, scope: 'webpack' },
45+
{ name: 'DEPLOYMENT_MODE', default: 'standalone', scope: 'webpack' },
4746
{ name: 'UI_DEBUG', default: false, scope: 'webpack' },
4847
{ name: 'UI_PORT', default: 8002, scope: 'webpack' },
48+
{ name: 'UI_USE_HTTPS', default: false, scope: 'webpack' },
4949
{ name: 'WEBPACK_PROXY', default: undefined, scope: 'webpack' },
5050
{ name: 'WEBPACK_PUBLIC_PATH', default: undefined, scope: 'webpack' },
51-
{ name: 'API_PROXY_TARGET', default: undefined, scope: 'webpack' },
5251
];
5352

5453
const insightsMockAPIs = ({ app }) => {

src/api/active-user.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Constants } from 'src/constants';
21
import { HubAPI } from './hub';
32
import { UserType } from './response-types/user';
43

@@ -17,7 +16,7 @@ class API extends HubAPI {
1716
// page to refresh before loading the token that can't be done witha single
1817
// API request.
1918
getToken(): Promise<{ data: { token: string } }> {
20-
if (DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE) {
19+
if (IS_INSIGHTS) {
2120
return Promise.reject(
2221
'Use window.insights.chrome.auth to get tokens for insights deployments',
2322
);

src/api/base.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@ export class BaseAPI {
7575
// This runs before every API request and ensures that the user is
7676
// authenticated before the request is executed. On most calls it appears
7777
// to only add ~10ms of latency.
78-
if (DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE) {
78+
if (IS_INSIGHTS) {
7979
await window.insights.chrome.auth.getUser();
80-
}
81-
if (DEPLOYMENT_MODE === Constants.STANDALONE_DEPLOYMENT_MODE) {
80+
} else {
8281
request.headers['X-CSRFToken'] = Cookies.get('csrftoken');
8382
}
8483
return request;

src/components/cards/namespace-card.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import ArrowRightIcon from '@patternfly/react-icons/dist/esm/icons/arrow-right-i
1212
import React from 'react';
1313
import { Link } from 'react-router-dom';
1414
import { Logo, Tooltip } from 'src/components';
15-
import { Constants } from 'src/constants';
1615
import { namespaceTitle } from 'src/utilities';
1716
import './cards.scss';
1817

@@ -33,10 +32,7 @@ export const NamespaceNextPageCard = ({ onClick }: { onClick: () => void }) => {
3332
<div
3433
style={{
3534
display: 'flex',
36-
height:
37-
DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE
38-
? '216px'
39-
: '168px',
35+
height: IS_INSIGHTS ? '216px' : '168px',
4036
justifyContent: 'center',
4137
}}
4238
>

src/components/headers/collection-header.tsx

+4-8
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,8 @@ export class CollectionHeader extends React.Component<IProps, IState> {
202202
{ key: 'origin_repository', name: t`Repo` },
203203
];
204204

205-
const {
206-
display_signatures,
207-
can_upload_signatures,
208-
display_repositories,
209-
ai_deny_index,
210-
} = this.context.featureFlags;
205+
const { can_upload_signatures, display_signatures, display_repositories } =
206+
this.context.featureFlags;
211207

212208
const {
213209
collection_version,
@@ -248,7 +244,7 @@ export class CollectionHeader extends React.Component<IProps, IState> {
248244
namespace?.related_fields?.my_permissions?.includes?.(permission);
249245

250246
const canDeleteCommunityCollection =
251-
ai_deny_index &&
247+
IS_COMMUNITY &&
252248
hasObjectPermission('galaxy.change_namespace', this.state.namespace);
253249

254250
const dropdownItems = [
@@ -577,7 +573,7 @@ export class CollectionHeader extends React.Component<IProps, IState> {
577573
}
578574
pageControls={
579575
<Flex>
580-
{DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE ? (
576+
{IS_INSIGHTS ? (
581577
<FlexItem>
582578
<ExternalLink href={issueUrl}>{t`Create issue`}</ExternalLink>
583579
</FlexItem>

src/components/repo-selector/repo-selector.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
InputGroupText,
77
} from '@patternfly/react-core';
88
import React from 'react';
9-
import { Constants } from 'src/constants';
109
import { useContext } from 'src/loaders/app-context';
1110

1211
interface IProps {
@@ -16,7 +15,7 @@ interface IProps {
1615
export const RepoSelector = ({ selectedRepo }: IProps) => {
1716
const { featureFlags } = useContext();
1817

19-
if (DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE) {
18+
if (IS_INSIGHTS) {
2019
return null;
2120
}
2221
if (!featureFlags.display_repositories) {

src/components/shared/alert-list.tsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
AlertProps,
55
} from '@patternfly/react-core';
66
import React, { ReactNode } from 'react';
7-
import { Constants } from 'src/constants';
87

98
interface IProps {
109
/** List of alerts to display */
@@ -26,10 +25,9 @@ export const AlertList = ({ alerts, closeAlert }: IProps) => (
2625
style={{
2726
position: 'fixed',
2827
right: '5px',
29-
top:
30-
DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE
31-
? '124px' // 70 + 50 + 4
32-
: '80px', // 76 + 4
28+
top: IS_INSIGHTS
29+
? '124px' // 70 + 50 + 4
30+
: '80px', // 76 + 4
3331
zIndex: 300,
3432
display: 'flex',
3533
flexDirection: 'column',

src/components/shared/download-count.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import { Trans, t } from '@lingui/macro';
22
import DownloadIcon from '@patternfly/react-icons/dist/esm/icons/download-icon';
33
import React from 'react';
44
import { Tooltip } from 'src/components';
5-
import { Constants } from 'src/constants';
65
import { language } from 'src/l10n';
76

87
interface IProps {
98
item?: { download_count?: number };
109
}
1110

1211
export const DownloadCount = ({ item }: IProps) => {
13-
if (DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE) {
12+
if (IS_INSIGHTS) {
1413
return null;
1514
}
1615
if (!item?.download_count) {

src/constants.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ export class Constants {
66
static readonly DEFAULT_PAGE_SIZE = 10;
77
static readonly DEFAULT_PAGINATION_OPTIONS = [10, 20, 50, 100];
88

9-
static readonly INSIGHTS_DEPLOYMENT_MODE = 'insights';
10-
static readonly STANDALONE_DEPLOYMENT_MODE = 'standalone';
11-
12-
static CERTIFIED_REPO =
13-
DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE
14-
? 'published'
15-
: 'rh-certified';
9+
static CERTIFIED_REPO = IS_INSIGHTS ? 'published' : 'rh-certified';
1610

1711
static USER_GROUP_MGMT_PERMISSIONS = [
1812
'galaxy.delete_user',

src/containers/landing/landing-page.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
MultiSearchSearch,
1313
closeAlertMixin,
1414
} from 'src/components';
15-
import { AppContext } from 'src/loaders/app-context';
1615
import { Paths, formatPath } from 'src/paths';
1716
import { RouteProps, withRouter } from 'src/utilities';
1817
import './landing-page.scss';
@@ -33,8 +32,7 @@ export class LandingPage extends React.Component<RouteProps, IState> {
3332
}
3433

3534
componentDidMount() {
36-
const { ai_deny_index } = this.context.featureFlags;
37-
if (!ai_deny_index) {
35+
if (!IS_COMMUNITY) {
3836
this.setState({ redirect: true });
3937
}
4038
}
@@ -210,5 +208,3 @@ export class LandingPage extends React.Component<RouteProps, IState> {
210208
}
211209

212210
export default withRouter(LandingPage);
213-
214-
LandingPage.contextType = AppContext;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1013,9 +1013,9 @@ export class NamespaceDetail extends React.Component<RouteProps, IState> {
10131013
const hasObjectPermission = (permission, namespace) =>
10141014
namespace?.related_fields?.my_permissions?.includes?.(permission);
10151015
const { showControls } = this.state;
1016-
const { display_repositories, ai_deny_index } = this.context.featureFlags;
1016+
const { display_repositories } = this.context.featureFlags;
10171017
const canDeleteCommunityCollection =
1018-
ai_deny_index &&
1018+
IS_COMMUNITY &&
10191019
hasObjectPermission('galaxy.change_namespace', this.state.namespace);
10201020

10211021
if (!showControls) {

src/containers/search/search.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class Search extends React.Component<RouteProps, IState> {
117117
private load() {
118118
this.queryCollections();
119119

120-
if (DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE) {
120+
if (IS_INSIGHTS) {
121121
this.getSynclist();
122122
}
123123
}
@@ -389,9 +389,9 @@ class Search extends React.Component<RouteProps, IState> {
389389
const { hasPermission } = this.context;
390390
const hasObjectPermission = (permission, namespace) =>
391391
namespace?.related_fields?.my_permissions?.includes?.(permission);
392-
const { display_repositories, ai_deny_index } = this.context.featureFlags;
392+
const { display_repositories } = this.context.featureFlags;
393393
const canDeleteCommunityCollection =
394-
ai_deny_index &&
394+
IS_COMMUNITY &&
395395
hasObjectPermission(
396396
'galaxy.change_namespace',
397397
collection.collection_version.namespace,

src/index.d.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ declare module '*.svg';
88
declare var API_BASE_PATH;
99
declare var API_HOST;
1010
declare var APPLICATION_NAME;
11-
declare var DEPLOYMENT_MODE;
11+
declare var IS_COMMUNITY: boolean;
12+
declare var IS_INSIGHTS: boolean;
1213
declare var NAMESPACE_TERM;
1314
declare var PULP_API_BASE_PATH;
1415
declare var UI_BASE_PATH;
1516
declare var UI_COMMIT_HASH;
1617
declare var UI_DOCS_URL;
1718
declare var UI_EXTERNAL_LOGIN_URI;
1819

19-
// when DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE only
20+
// when IS_INSIGHTS only
2021
interface Window {
2122
insights: {
2223
chrome: {

src/loaders/standalone/layout.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export const StandaloneLayout = ({
168168

169169
return (
170170
<Page isManagedSidebar={true} header={Header} sidebar={Sidebar}>
171-
{featureFlags?.ai_deny_index ? (
171+
{IS_COMMUNITY ? (
172172
<Banner>
173173
<Trans>
174174
Thanks for trying out the new and improved Galaxy, please share your

src/loaders/standalone/menu.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,16 @@ function standaloneMenu() {
122122
menuItem(t`Documentation`, {
123123
url: UI_DOCS_URL,
124124
external: true,
125-
condition: ({ featureFlags, settings, user }) =>
126-
!featureFlags.ai_deny_index &&
125+
condition: ({ settings, user }) =>
126+
!IS_COMMUNITY &&
127127
(settings.GALAXY_ENABLE_UNAUTHENTICATED_COLLECTION_ACCESS ||
128128
!user.is_anonymous),
129129
}),
130130
menuItem(t`Documentation`, {
131131
url: 'https://ansible.readthedocs.io/projects/galaxy-ng/en/latest/community/userguide/',
132132
external: true,
133-
condition: ({ featureFlags, settings, user }) =>
134-
featureFlags.ai_deny_index &&
133+
condition: ({ settings, user }) =>
134+
IS_COMMUNITY &&
135135
(settings.GALAXY_ENABLE_UNAUTHENTICATED_COLLECTION_ACCESS ||
136136
!user.is_anonymous),
137137
}),

src/paths.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import { t } from '@lingui/macro';
2-
import { Constants } from 'src/constants';
32
import { ParamHelper, ParamType } from 'src/utilities';
43

54
export function formatPath(path: Paths, data = {}, params?: ParamType) {
65
// insights router has basename="/", "/beta/" or "/preview/", with hub under a nested "ansible/automation-hub" route - our urls are relative to that
7-
let url =
8-
DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE
9-
? UI_BASE_PATH.replace('/preview/', '/')
10-
.replace('/beta/', '/')
11-
.replace(/\/$/, '')
12-
: '';
6+
let url = IS_INSIGHTS
7+
? UI_BASE_PATH.replace('/preview/', '/')
8+
.replace('/beta/', '/')
9+
.replace(/\/$/, '')
10+
: '';
1311
url += (path as string) + '/';
1412
url = url.replaceAll('//', '/');
1513

src/utilities/namespace-title.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import { Constants } from 'src/constants';
2-
31
export function namespaceTitle({
42
name,
53
company,
64
}: {
75
name: string;
86
company?: string;
97
}): string {
10-
return DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE
11-
? company || name
12-
: name;
8+
return IS_INSIGHTS ? company || name : name;
139
}

0 commit comments

Comments
 (0)