8000 webpack config - add IS_COMMUNITY & IS_INSIGHTS flags by himdel · Pull Request #4523 · ansible/ansible-hub-ui · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

webpack config - add IS_COMMUNITY & IS_INSIGHTS flags #4523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/community.dev.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = webpackBase({
// Determines if the app should be compiled to run on insights or on
// another platform. Options: insights, standalone
DEPLOYMENT_MODE: 'standalone',
IS_COMMUNITY: true,

NAMESPACE_TERM: 'namespaces',

Expand Down
1 change: 1 addition & 0 deletions config/community.prod.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = webpackBase({
API_BASE_PATH: '/api/',
UI_BASE_PATH: '/ui/',
DEPLOYMENT_MODE: 'standalone',
IS_COMMUNITY: true,
NAMESPACE_TERM: 'namespaces',
UI_USE_HTTPS: false,
UI_DEBUG: false,
Expand Down
1 change: 1 addition & 0 deletions config/insights.dev.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = webpackBase({
// Determines if the app should be compiled to run on insights or on
// another platform. Options: insights, standalone
DEPLOYMENT_MODE: 'insights',
IS_INSIGHTS: true,

// Determines the title of the "namespaces" page
NAMESPACE_TERM: 'partners',
Expand Down
1 change: 1 addition & 0 deletions config/insights.prod.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = webpackBase({
? '/preview/ansible/automation-hub/'
: '/ansible/automation-hub/',
DEPLOYMENT_MODE: 'insights',
IS_INSIGHTS: true,
NAMESPACE_TERM: 'partners',
UI_USE_HTTPS: false,
UI_DEBUG: false,
Expand Down
2 changes: 2 additions & 0 deletions config/standalone.dev.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ module.exports = webpackBase({
// Determines if the app should be compiled to run on insights or on
// another platform. Options: insights, standalone
DEPLOYMENT_MODE: 'standalone',
// dev-mode only, support `IS_COMMUNITY=1 npm run start-standalone` in addition to `npm run start-community`
IS_COMMUNITY: !!process.env.IS_COMMUNITY,

NAMESPACE_TERM: 'namespaces',

Expand Down
31 changes: 15 additions & 16 deletions config/webpack.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,32 @@ const gitCommit =
process.env.HUB_UI_VERSION ||
execSync('git rev-parse HEAD', { encoding: 'utf-8' }).trim();

const docsURL =
'https://access.redhat.com/documentation/en-us/red_hat_ansible_automation_platform/';

// Default user defined settings
const defaultConfigs = [
// Global scope means that the variable will be available to the app itself
// as a constant after it is compiled
{ name: 'API_HOST', default: '', scope: 'global' },
{ name: 'API_BASE_PATH', default: '', scope: 'global' },
{ name: 'UI_BASE_PATH', default: '', scope: 'global' },
{ name: 'DEPLOYMENT_MODE 6D4E 9;, default: 'standalone', scope: 'global' },
{ name: 'NAMESPACE_TERM', default: 'namespaces', scope: 'global' },
{ name: 'API_HOST', default: '', scope: 'global' },
{ name: 'APPLICATION_NAME', default: 'Galaxy NG', scope: 'global' },
{ name: 'UI_EXTERNAL_LOGIN_URI', default: '/login', scope: 'global' },
{ name: 'IS_COMMUNITY', default: false, scope: 'global' },
{ name: 'IS_INSIGHTS', default: false, scope: 'global' },
{ name: 'NAMESPACE_TERM', default: 'namespaces', scope: 'global' },
{ name: 'UI_BASE_PATH', default: '', scope: 'global' },
{ name: 'UI_COMMIT_HASH', default: gitCommit, scope: 'global' },
{
name: 'UI_DOCS_URL',
default:
'https://access.redhat.com/documentation/en-us/red_hat_ansible_automation_platform/',
scope: 'global',
},

// Webpack scope means the variable will only be available to webpack at
// build time
{ name: 'UI_USE_HTTPS', default: false, scope: 'webpack' },
{ name: 'UI_DOCS_URL', default: docsURL, scope: 'global' },
{ name: 'UI_EXTERNAL_LOGIN_URI', default: '/login', scope: 'global' },

// Webpack scope: only available in customConfigs here, not exposed to the UI
{ name: 'API_PROXY_TARGET', default: undefined, scope: 'webpack' },
{ name: 'DEPLOYMENT_MODE', default: 'standalone', scope: 'webpack' },
{ name: 'UI_DEBUG', default: false, scope: 'webpack' },
{ name: 'UI_PORT', default: 8002, scope: 'webpack' },
{ name: 'UI_USE_HTTPS', default: false, scope: 'webpack' },
{ name: 'WEBPACK_PROXY', default: undefined, scope: 'webpack' },
{ name: 'WEBPACK_PUBLIC_PATH', default: undefined, scope: 'webpack' },
{ name: 'API_PROXY_TARGET', default: undefined, scope: 'webpack' },
];

const insightsMockAPIs = ({ app }) => {
Expand Down
3 changes: 1 addition & 2 deletions src/api/active-user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Constants } from 'src/constants';
import { HubAPI } from './hub';
import { UserType } from './response-types/user';

Expand All @@ -17,7 +16,7 @@ class API extends HubAPI {
// page to refresh before loading the token that can't be done witha single
// API request.
getToken(): Promise<{ data: { token: string } }> {
if (DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE) {
if (IS_INSIGHTS) {
return Promise.reject(
'Use window.insights.chrome.auth to get tokens for insights deployments',
);
Expand Down
5 changes: 2 additions & 3 deletions src/api/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ export class BaseAPI {
// This runs before every API request and ensures that the user is
// authenticated before the request is executed. On most calls it appears
// to only add ~10ms of latency.
if (DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE) {
if (IS_INSIGHTS) {
await window.insights.chrome.auth.getUser();
}
if (DEPLOYMENT_MODE === Constants.STANDALONE_DEPLOYMENT_MODE) {
} else {
request.headers['X-CSRFToken'] = Cookies.get('csrftoken');
}
return request;
Expand Down
6 changes: 1 addition & 5 deletions src/components/cards/namespace-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import ArrowRightIcon from '@patternfly/react-icons/dist/esm/icons/arrow-right-i
import React from 'react';
import { Link } from 'react-router-dom';
import { Logo, Tooltip } from 'src/components';
import { Constants } from 'src/constants';
import { namespaceTitle } from 'src/utilities';
import './cards.scss';

Expand All @@ -33,10 +32,7 @@ export const NamespaceNextPageCard = ({ onClick }: { onClick: () => void }) => {
<div
style={{
display: 'flex',
height:
DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE
? '216px'
: '168px',
height: IS_INSIGHTS ? '216px' : '168px',
justifyContent: 'center',
}}
>
Expand Down
12 changes: 4 additions & 8 deletions src/components/headers/collection-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,8 @@ export class CollectionHeader extends React.Component<IProps, IState> {
{ key: 'origin_repository', name: t`Repo` },
];

const {
display_signatures,
can_upload_signatures,
display_repositories,
ai_deny_index,
} = this.context.featureFlags;
const { can_upload_signatures, display_signatures, display_repositories } =
this.context.featureFlags;

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

const canDeleteCommunityCollection =
ai_deny_index &&
IS_COMMUNITY &&
hasObjectPermission('galaxy.change_namespace', this.state.namespace);

const dropdownItems = [
Expand Down Expand Up @@ -577,7 +573,7 @@ export class CollectionHeader extends React.Component<IProps, IState> {
}
pageControls={
<Flex>
{DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE ? (
{IS_INSIGHTS ? (
<FlexItem>
<ExternalLink href={issueUrl}>{t`Create issue`}</ExternalLink>
</FlexItem>
Expand Down
3 changes: 1 addition & 2 deletions src/components/repo-selector/repo-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
InputGroupText,
} from '@patternfly/react-core';
import React from 'react';
import { Constants } from 'src/constants';
import { useContext } from 'src/loaders/app-context';

interface IProps {
Expand All @@ -16,7 +15,7 @@ interface IProps {
export const RepoSelector = ({ selectedRepo }: IProps) => {
const { featureFlags } = useContext();

if (DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE) {
if (IS_INSIGHTS) {
return null;
}
if (!featureFlags.display_repositories) {
Expand Down
8 changes: 3 additions & 5 deletions src/components/shared/alert-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
AlertProps,
} from '@patternfly/react-core';
import React, { ReactNode } from 'react';
import { Constants } from 'src/constants';

interface IProps {
/** List of alerts to display */
Expand All @@ -26,10 +25,9 @@ export const AlertList = ({ alerts, closeAlert }: IProps) => (
style={{
position: 'fixed',
right: '5px',
top:
DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE
? '124px' // 70 + 50 + 4
: '80px', // 76 + 4
top: IS_INSIGHTS
? '124px' // 70 + 50 + 4
: '80px', // 76 + 4
zIndex: 300,
display: 'flex',
flexDirection: 'column',
Expand Down
3 changes: 1 addition & 2 deletions src/components/shared/download-count.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import { Trans, t } from '@lingui/macro';
import DownloadIcon from '@patternfly/react-icons/dist/esm/icons/download-icon';
import React from 'react';
import { Tooltip } from 'src/components';
import { Constants } from 'src/constants';
import { language } from 'src/l10n';

interface IProps {
item?: { download_count?: number };
}

export const DownloadCount = ({ item }: IProps) => {
if (DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE) {
if (IS_INSIGHTS) {
return null;
}
if (!item?.download_count) {
Expand Down
8 changes: 1 addition & 7 deletions src/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ export class Constants {
static readonly DEFAULT_PAGE_SIZE = 10;
static readonly DEFAULT_PAGINATION_OPTIONS = [10, 20, 50, 100];

static readonly INSIGHTS_DEPLOYMENT_MODE = 'insights';
static readonly STANDALONE_DEPLOYMENT_MODE = 'standalone';

2851
static CERTIFIED_REPO =
DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE
? 'published'
: 'rh-certified';
static CERTIFIED_REPO = IS_INSIGHTS ? 'published' : 'rh-certified';

static USER_GROUP_MGMT_PERMISSIONS = [
'galaxy.delete_user',
Expand Down
6 changes: 1 addition & 5 deletions src/containers/landing/landing-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
MultiSearchSearch,
closeAlertMixin,
} from 'src/components';
import { AppContext } from 'src/loaders/app-context';
import { Paths, formatPath } from 'src/paths';
import { RouteProps, withRouter } from 'src/utilities';
import './landing-page.scss';
Expand All @@ -33,8 +32,7 @@ export class LandingPage extends React.Component<RouteProps, IState> {
}

componentDidMount() {
const { ai_deny_index } = this.context.featureFlags;
if (!ai_deny_index) {
if (!IS_COMMUNITY) {
this.setState({ redirect: true });
}
}
Expand Down Expand Up @@ -210,5 +208,3 @@ export class LandingPage extends React.Component<RouteProps, IState> {
}

export default withRouter(LandingPage);

LandingPage.contextType = AppContext;
4 changes: 2 additions & 2 deletions src/containers/namespace-detail/namespace-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1013,9 +1013,9 @@ export class NamespaceDetail extends React.Component<RouteProps, IState> {
const hasObjectPermission = (permission, namespace) =>
namespace?.related_fields?.my_permissions?.includes?.(permission);
const { showControls } = this.state;
const { display_repositories, ai_deny_index } = this.context.featureFlags;
const { display_repositories } = this.context.featureFlags;
const canDeleteCommunityCollection =
ai_deny_index &&
IS_COMMUNITY &&
hasObjectPermission('galaxy.change_namespace', this.state.namespace);

if (!showControls) {
Expand Down
6 changes: 3 additions & 3 deletions src/containers/search/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Search extends React.Component<RouteProps, IState> {
private load() {
this.queryCollections();

if (DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE) {
if (IS_INSIGHTS) {
this.getSynclist();
}
}
Expand Down Expand Up @@ -389,9 +389,9 @@ class Search extends React.Component<RouteProps, IState> {
const { hasPermission } = this.context;
const hasObjectPermission = (permission, namespace) =>
namespace?.related_fields?.my_permissions?.includes?.(permission);
const { display_repositories, ai_deny_index } = this.context.featureFlags;
const { display_repositories } = this.context.featureFlags;
const canDeleteCommunityCollection =
ai_deny_index &&
IS_COMMUNITY &&
hasObjectPermission(
'galaxy.change_namespace',
collection.collection_version.namespace,
Expand Down
5 changes: 3 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ declare module '*.svg';
declare var API_BASE_PATH;
declare var API_HOST;
declare var APPLICATION_NAME;
declare var DEPLOYMENT_MODE;
declare var IS_COMMUNITY: boolean;
declare var IS_INSIGHTS: boolean;
declare var NAMESPACE_TERM;
declare var PULP_API_BASE_PATH;
declare var UI_BASE_PATH;
declare var UI_COMMIT_HASH;
declare var UI_DOCS_URL;
declare var UI_EXTERNAL_LOGIN_URI;

// when DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE only
// when IS_INSIGHTS only
interface Window {
insights: {
chrome: {
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/standalone/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export const StandaloneLayout = ({

return (
<Page isManagedSidebar={true} header={Header} sidebar={Sidebar}>
{featureFlags?.ai_deny_index ? (
{IS_COMMUNITY ? (
<Banner>
<Trans>
Thanks for trying out the new and improved Galaxy, please share your
Expand Down
8 changes: 4 additions & 4 deletions src/loaders/standalone/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ function standaloneMenu() {
menuItem(t`Documentation`, {
url: UI_DOCS_URL,
external: true,
condition: ({ featureFlags, settings, user }) =>
!featureFlags.ai_deny_index &&
condition: ({ settings, user }) =>
!IS_COMMUNITY &&
(settings.GALAXY_ENABLE_UNAUTHENTICATED_COLLECTION_ACCESS ||
!user.is_anonymous),
}),
menuItem(t`Documentation`, {
url: 'https://ansible.readthedocs.io/projects/galaxy-ng/en/latest/community/userguide/',
external: true,
condition: ({ featureFlags, settings, user }) =>
featureFlags.ai_deny_index &&
condition: ({ settings, user }) =>
IS_COMMUNITY &&
(settings.GALAXY_ENABLE_UNAUTHENTICATED_COLLECTION_ACCESS ||
!user.is_anonymous),
}),
Expand Down
12 changes: 5 additions & 7 deletions src/paths.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { t } from '@lingui/macro';
import { Constants } from 'src/constants';
import { ParamHelper, ParamType } from 'src/utilities';

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

Expand Down
6 changes: 1 addition & 5 deletions src/utilities/namespace-title.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { Constants } from 'src/constants';

export function namespaceTitle({
name,
company,
}: {
name: string;
company?: string;
}): string {
return DEPLOYMENT_MODE === Constants.INSIGHTS_DEPLOYMENT_MODE
? company || name
: name;
return IS_INSIGHTS ? company || name : name;
}
0