Skip to content

Commit

Permalink
fix: disable info registry section with pkg manager config (verdaccio…
Browse files Browse the repository at this point in the history
  • Loading branch information
juanpicado authored Jun 13, 2021
1 parent 73d34bf commit 8ca5fe6
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 210 deletions.
6 changes: 0 additions & 6 deletions packages/plugins/ui-theme/htmllinter.config.js

This file was deleted.

2 changes: 2 additions & 0 deletions packages/plugins/ui-theme/i18n/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"header": {
"documentation": "Documentation",
"registry-info": "Registry Information",
"registry-info-link": "Learn more",
"registry-no-conf": "No configurations available",
"greetings": "Hi "
},
"search": {
Expand Down
5 changes: 1 addition & 4 deletions packages/plugins/ui-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
"@emotion/jest": "^11.3.0",
"@emotion/styled": "10.0.27",
"@emotion/styled-base": "^10.0.31",
"@htmllinter/basic-config": "^0.5.1",
"@htmllinter/core": "^0.5.1",
"@material-ui/core": "4.11.2",
"@material-ui/core": "4.11.4",
"@material-ui/icons": "4.11.2",
"@material-ui/styles": "^4.11.4",
"@testing-library/dom": "7.31.2",
Expand Down Expand Up @@ -135,7 +133,6 @@
"test:size": "bundlesize",
"lint": "pnpm lint:js && pnpm lint:css",
"lint:css": "yarn stylelint \"src/**/styles.ts\"",
"lint:html": "yarn htmllinter src/template/index.html",
"verdaccio:server": "node tools/verdaccio.js",
"build": "webpack --config tools/webpack.prod.config.babel.js",
"build:stats": "webpack --config tools/webpack.prod.config.babel.js --json > stats.json",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { render, cleanup, fireEvent } from 'verdaccio-ui/utils/test-react-testing-library';
import { screen, render, cleanup } from 'verdaccio-ui/utils/test-react-testing-library';

import RegistryInfoContent from './RegistryInfoContent';

Expand All @@ -10,27 +10,19 @@ describe('<RegistryInfoContent /> component', () => {
});

test('should load the component with no data', () => {
const { getByTestId } = render(<RegistryInfoContent registryUrl={''} scope={''} />);
const unorderedListOfTodos = getByTestId('tabs-el');
expect(unorderedListOfTodos.children.length).toBe(1);
render(<RegistryInfoContent registryUrl={''} scope={''} />);
expect(screen.getByText('No configurations available')).toBeInTheDocument();
});

test('should load the appropiate tab content when the tab is clicked', () => {
const props = { registryUrl: 'http://localhost:4872', scope: '@' };
const pnpmTabTextContent = `pnpm adduser --registry ${props.registryUrl}`;

// Render the component.
const { container, getByTestId } = render(
<RegistryInfoContent registryUrl={props.registryUrl} scope={props.scope} />
);

// Assert the text content for pnpm tab is not present intially
expect(container.textContent).not.toContain(pnpmTabTextContent);

const pnpmTab = getByTestId('pnpm-tab');
fireEvent.click(pnpmTab);

// Assert the text content is correct after clicking on the tab.
expect(container.textContent).toContain(pnpmTabTextContent);
render(<RegistryInfoContent registryUrl={props.registryUrl} scope={props.scope} />);

screen.debug();
expect(screen.getByText('pnpm set @:registry http://localhost:4872')).toBeInTheDocument();
expect(screen.getByText('pnpm adduser --registry http://localhost:4872')).toBeInTheDocument();
expect(
screen.getByText('pnpm profile set password --registry http://localhost:4872')
).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -1,91 +1,155 @@
import React, { useState } from 'react';
import styled from '@emotion/styled';
import Accordion from '@material-ui/core/Accordion';
import AccordionDetails from '@material-ui/core/AccordionDetails';
import AccordionSummary from '@material-ui/core/AccordionSummary';
import Box from '@material-ui/core/Box';
import Link from '@material-ui/core/Link';
import { makeStyles } from '@material-ui/core/styles';
import Typography from '@material-ui/core/Typography';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
import React, { FC } from 'react';
import { useTranslation } from 'react-i18next';

import CopyToClipBoard from 'verdaccio-ui/components/CopyToClipBoard';
import { default as Typography } from 'verdaccio-ui/components/Heading';
import Tab from 'verdaccio-ui/components/Tab';
import Tabs from 'verdaccio-ui/components/Tabs';
import { useConfig } from 'verdaccio-ui/providers/config';
import {
getCLISetRegistry,
getCLIChangePassword,
getCLISetConfigRegistry,
} from 'verdaccio-ui/utils/cli-utils';
import { NODE_MANAGER } from 'verdaccio-ui/utils/constants';

import { CommandContainer } from './styles';
import { Props, State } from './types';

const RegistryInfoContent: React.FC<Props> = (props) => {
const [tabPosition, setTabPosition] = useState<State['tabPosition']>(0);
const handleChange = (event: React.ChangeEvent<{}>, tabPosition: number): void => {
event.preventDefault();
setTabPosition(tabPosition);
};

const renderNpmTab = (scope: string, registryUrl: string): JSX.Element => {
return (
<>
<CopyToClipBoard
text={getCLISetConfigRegistry(`${NODE_MANAGER.npm} set`, scope, registryUrl)}
/>
<CopyToClipBoard text={getCLISetRegistry(`${NODE_MANAGER.npm} adduser`, registryUrl)} />
<CopyToClipBoard text={getCLIChangePassword(NODE_MANAGER.npm, registryUrl)} />
</>
);
};
const renderNpmTab = (scope: string, registryUrl: string): JSX.Element => {
return (
<Box display="flex" flexDirection="column" p={1}>
<CopyToClipBoard
text={getCLISetConfigRegistry(`${NODE_MANAGER.npm} set`, scope, registryUrl)}
/>
<CopyToClipBoard text={getCLISetRegistry(`${NODE_MANAGER.npm} adduser`, registryUrl)} />
<CopyToClipBoard text={getCLIChangePassword(NODE_MANAGER.npm, registryUrl)} />
</Box>
);
};

const renderPnpmTab = (scope: string, registryUrl: string): JSX.Element => {
return (
<>
<CopyToClipBoard
text={getCLISetConfigRegistry(`${NODE_MANAGER.pnpm} set`, scope, registryUrl)}
/>
<CopyToClipBoard text={getCLISetRegistry(`${NODE_MANAGER.pnpm} adduser`, registryUrl)} />
<CopyToClipBoard text={getCLIChangePassword(NODE_MANAGER.pnpm, registryUrl)} />
</>
);
};
const renderPnpmTab = (scope: string, registryUrl: string): JSX.Element => {
return (
<Box display="flex" flexDirection="column" p={1}>
<CopyToClipBoard
text={getCLISetConfigRegistry(`${NODE_MANAGER.pnpm} set`, scope, registryUrl)}
/>
<CopyToClipBoard text={getCLISetRegistry(`${NODE_MANAGER.pnpm} adduser`, registryUrl)} />
<CopyToClipBoard text={getCLIChangePassword(NODE_MANAGER.pnpm, registryUrl)} />
</Box>
);
};

const renderYarnTab = (scope: string, registryUrl: string): JSX.Element => {
return (
const renderYarnTab = (scope: string, registryUrl: string): JSX.Element => {
return (
<Box display="flex" flexDirection="column" p={1}>
<CopyToClipBoard
text={getCLISetConfigRegistry(`${NODE_MANAGER.yarn} config set`, scope, registryUrl)}
/>
);
};
</Box>
);
};

const useStyles = makeStyles((theme) => ({
root: {
width: '100%',
},
heading: {
fontSize: theme.typography.pxToRem(15),
fontWeight: theme.typography.fontWeightBold,
},
}));

export const AccordionContainer = styled('div')({
padding: 30,
paddingLeft: 0,
paddingRight: 0,
});

const renderTabs = (): JSX.Element => {
const { scope, registryUrl } = props;
export const CommandContainer = styled('div')({
padding: 5,
});

export const LinkContainer = styled('div')({
margin: 10,
marginLeft: 0,
});

export type Props = {
registryUrl: string;
scope: string;
};

return (
<>
<Tabs
color={'primary'}
data-testid={'tabs-el'}
indicatorColor={'primary'}
onChange={handleChange}
value={tabPosition}
variant="fullWidth">
<Tab data-testid={'npm-tab'} label={NODE_MANAGER.npm} />
<Tab data-testid={'pnpm-tab'} label={NODE_MANAGER.pnpm} />
<Tab data-testid={'yarn-tab'} label={NODE_MANAGER.yarn} />
</Tabs>
{tabPosition === 0 && <TabContainer>{renderNpmTab(scope, registryUrl)}</TabContainer>}
{tabPosition === 1 && <TabContainer>{renderPnpmTab(scope, registryUrl)}</TabContainer>}
{tabPosition === 2 && <TabContainer>{renderYarnTab(scope, registryUrl)}</TabContainer>}
</>
);
};
const RegistryInfoContent: FC<Props> = ({ scope, registryUrl }) => {
const { t } = useTranslation();
const classes = useStyles();
const { configOptions } = useConfig();

/* eslint react/prop-types:0 */
const TabContainer: React.FC = ({ children }): JSX.Element => {
return (
<CommandContainer data-testid={'tab-content'}>
<Typography>{children}</Typography>
</CommandContainer>
);
};
const hasNpm = configOptions?.pkgManagers?.includes('npm');
const hasYarn = configOptions?.pkgManagers?.includes('yarn');
const hasPnpm = configOptions?.pkgManagers?.includes('pnpm');
const hasPkgManagers = hasNpm | hasPnpm | hasYarn;
if (!hasPkgManagers || !scope || !registryUrl) {
return <AccordionContainer>{t('header.registry-no-conf')}</AccordionContainer>;
}

return <div>{renderTabs()}</div>;
return hasPkgManagers ? (
<AccordionContainer>
{hasNpm && (
<Accordion>
<AccordionSummary
aria-controls="panel1a-content"
expandIcon={<ExpandMoreIcon />}
id="panel1a-header">
<Typography className={classes.heading}>{'npm'}</Typography>
</AccordionSummary>
<AccordionDetails>
<CommandContainer data-testid={'tab-content'}>
{renderNpmTab(scope, registryUrl)}
</CommandContainer>
</AccordionDetails>
</Accordion>
)}
{hasYarn && (
<Accordion>
<AccordionSummary
aria-controls="panel2a-content"
expandIcon={<ExpandMoreIcon />}
id="panel2a-header">
<Typography className={classes.heading}>{'yarn'}</Typography>
</AccordionSummary>
<AccordionDetails>
<CommandContainer data-testid={'tab-content'}>
{renderYarnTab(scope, registryUrl)}
</CommandContainer>
</AccordionDetails>
</Accordion>
)}
{hasPnpm && (
<Accordion>
<AccordionSummary
aria-controls="panel3a-content"
expandIcon={<ExpandMoreIcon />}
id="panel3a-header">
{'pnpm'}
</AccordionSummary>
<AccordionDetails>
<CommandContainer data-testid={'tab-content'}>
{renderPnpmTab(scope, registryUrl)}
</CommandContainer>
</AccordionDetails>
</Accordion>
)}
<LinkContainer>
<Link href="https://verdaccio.org/docs/en/cli-registry" target="_blank">
<Typography>{t('header.registry-info-link')}</Typography>
</Link>
</LinkContainer>
</AccordionContainer>
) : null;
};

export default RegistryInfoContent;

This file was deleted.

This file was deleted.

3 changes: 1 addition & 2 deletions packages/web/src/renderHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export default function renderHTML(config, manifest, manifestFiles, req, res) {
const title = config?.web?.title ?? WEB_TITLE;
const login = hasLogin(config);
const scope = config?.web?.scope ?? '';
// FIXME: logo URI is incomplete
let logoURI = config?.web?.logo ?? '';
const logoURI = config?.web?.logo ?? '';
const pkgManagers = config?.web?.pkgManagers ?? ['yarn', 'pnpm', 'npm'];
const version = pkgJSON.version;
const primaryColor = validatePrimaryColor(config?.web?.primary_color) ?? '#4b5e40';
Expand Down
Loading

0 comments on commit 8ca5fe6

Please sign in to comment.