Skip to content
This repository was archived by the owner on Jan 16, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": [
"@verdaccio",
"prettier",
"plugin:react/recommended",
"plugin:jest/recommended",
"plugin:prettier/recommended",
Expand Down
1 change: 1 addition & 0 deletions jest/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = {
// note: this section has to be on sync with webpack configuration
'verdaccio-ui/components/(.*)': '<rootDir>/src/components/$1',
'verdaccio-ui/utils/(.*)': '<rootDir>/src/utils/$1',
'verdaccio-ui/providers/(.*)': '<rootDir>/src/providers/$1',
'verdaccio-ui/design-tokens/(.*)': '<rootDir>/src/design-tokens/$1',
},
};
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@
"emotion": "10.0.27",
"emotion-theming": "10.0.27",
"eslint": "7.15.0",
"eslint-config-prettier": "7.2.0",
"eslint-loader": "^4.0.2",
"eslint-plugin-codeceptjs": "1.3.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jsx-a11y": "6.4.1",
"eslint-plugin-prettier": "3.2.0",
"eslint-plugin-react": "7.21.5",
"eslint-plugin-react-hooks": "4.2.0",
"eslint-plugin-verdaccio": "9.6.1",
Expand Down Expand Up @@ -212,11 +212,9 @@
},
"lint-staged": {
"*.{js,tsx,ts}": [
"eslint . --ext .js,.ts,.tsx",
"prettier --write"
"eslint . --ext .js,.ts,.tsx"
],
"*": [
"detect-secrets-launcher --baseline .secrets-baseline --word-list",
"git add"
]
},
Expand Down
4 changes: 2 additions & 2 deletions partials/storage/jquery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4981,7 +4981,7 @@
"shasum": "958ce29e81c9790f31be7792df5d4d95fc57fbca"
}
},
"_rev": "61-e6be890a78963127",
"_rev": "62-040142a7508cf597",
"readme": "# jQuery\n\n> jQuery is a fast, small, and feature-rich JavaScript library.\n\nFor information on how to get started and how to use jQuery, please see [jQuery's documentation](http://api.jquery.com/).\nFor source files and issues, please visit the [jQuery repo](https://github.com/jquery/jquery).\n\nIf upgrading, please see the [blog post for 3.3.1](https://blog.jquery.com/2017/03/20/jquery-3.3.1-now-available/). This includes notable differences from the previous version and a more readable changelog.\n\n## Including jQuery\n\nBelow are some of the most common ways to include jQuery.\n\n### Browser\n\n#### Script tag\n\n```html\n<script src=\"https://code.jquery.com/jquery-3.3.1.min.js\"></script>\n```\n\n#### Babel\n\n[Babel](http://babeljs.io/) is a next generation JavaScript compiler. One of the features is the ability to use ES6/ES2015 modules now, even though browsers do not yet support this feature natively.\n\n```js\nimport $ from \"jquery\";\n```\n\n#### Browserify/Webpack\n\nThere are several ways to use [Browserify](http://browserify.org/) and [Webpack](https://webpack.github.io/). For more information on using these tools, please refer to the corresponding project's documention. In the script, including jQuery will usually look like this...\n\n```js\nvar $ = require(\"jquery\");\n```\n\n#### AMD (Asynchronous Module Definition)\n\nAMD is a module format built for the browser. For more information, we recommend [require.js' documentation](http://requirejs.org/docs/whyamd.html).\n\n```js\ndefine([\"jquery\"], function($) {\n\n});\n```\n\n### Node\n\nTo include jQuery in [Node](nodejs.org), first install with npm.\n\n```sh\nnpm install jquery\n```\n\nFor jQuery to work in Node, a window with a document is required. Since no such window exists natively in Node, one can be mocked by tools such as [jsdom](https://github.com/tmpvar/jsdom). This can be useful for testing purposes.\n\n```js\nrequire(\"jsdom\").env(\"\", function(err, window) {\n\tif (err) {\n\t\tconsole.error(err);\n\t\treturn;\n\t}\n\n\tvar $ = require(\"jquery\")(window);\n});\n```",
"_id": "jquery"
}
}
2 changes: 1 addition & 1 deletion src/App/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jest.mock('verdaccio-ui/utils/storage', () => {
return new LocalStorageMock();
});

jest.mock('verdaccio-ui/utils/api', () => ({
jest.mock('verdaccio-ui/providers/API/api', () => ({
// eslint-disable-next-line jest/no-mocks-import
request: require('../../jest/unit/components/__mocks__/api').default.request,
}));
Expand Down
2 changes: 1 addition & 1 deletion src/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const StyledBoxContent = styled(Box)<{ theme?: Theme }>(({ theme }) => ({
/* eslint-disable react/jsx-no-bind */
/* eslint-disable react-hooks/exhaustive-deps */
const App: React.FC = () => {
const [user, setUser] = useState<undefined | { username: string }>();
const [user, setUser] = useState<undefined | { username: string | null }>();
/**
* Logout user
* Required by: <Header />
Expand Down
2 changes: 1 addition & 1 deletion src/App/AppContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface AppProps {
}

export interface User {
username: string;
username: string | null;
}

export interface AppContextProps extends AppProps {
Expand Down
4 changes: 2 additions & 2 deletions src/App/AppRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ enum Route {

export const history = createBrowserHistory({
// @ts-ignore
basename: window.__VERDACCIO_BASENAME_UI_OPTIONS && window.__VERDACCIO_BASENAME_UI_OPTIONS.url_prefix,
basename: window?.__VERDACCIO_BASENAME_UI_OPTIONS?.url_prefix,
});

const AppRoute: React.FC = () => {
Expand All @@ -36,7 +36,7 @@ const AppRoute: React.FC = () => {

const { user } = appContext;

const isUserLoggedIn = user && user.username;
const isUserLoggedIn = user?.username;

return (
<Router history={history}>
Expand Down
2 changes: 1 addition & 1 deletion src/App/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Header: React.FC<Props> = ({ withoutSearch }) => {
onOpenRegistryInfoDialog={() => setOpenInfoDialog(true)}
onToggleLogin={() => setShowLoginModal(!showLoginModal)}
onToggleMobileNav={() => setShowMobileNavBar(!showMobileNavBar)}
username={user && user.username}
username={user?.username}
withoutSearch={withoutSearch}
/>
</InnerNavBar>
Expand Down
2 changes: 1 addition & 1 deletion src/App/Header/HeaderRight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { RightSide } from './styles';

interface Props {
withoutSearch?: boolean;
username?: string;
username?: string | null;
onToggleLogin: () => void;
onOpenRegistryInfoDialog: () => void;
onToggleMobileNav: () => void;
Expand Down
2 changes: 1 addition & 1 deletion src/App/Header/LoginDialog/LoginDialog.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import api from 'verdaccio-ui/utils/api';
import api from 'verdaccio-ui/providers/API/api';
import { render, waitFor, fireEvent } from 'verdaccio-ui/utils/test-react-testing-library';

import AppContext, { AppContextProps } from '../../AppContext';
Expand Down
36 changes: 34 additions & 2 deletions src/App/Header/LoginDialog/LoginDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import i18next from 'i18next';
import isEmpty from 'lodash/isEmpty';
import React, { useState, useContext, useCallback } from 'react';
import { useTranslation } from 'react-i18next';

import Dialog from 'verdaccio-ui/components/Dialog';
import DialogContent from 'verdaccio-ui/components/DialogContent';
import { makeLogin, LoginError } from 'verdaccio-ui/utils/login';
import { useAPI, LoginBody } from 'verdaccio-ui/providers/API/APIProvider';
import { LoginError } from 'verdaccio-ui/utils/login';
import storage from 'verdaccio-ui/utils/storage';

import AppContext from '../../../App/AppContext';
Expand All @@ -20,6 +23,35 @@ interface Props {
const LoginDialog: React.FC<Props> = ({ onClose, open = false }) => {
const { t } = useTranslation();
const appContext = useContext(AppContext);
const { doLogin } = useAPI();

// eslint-disable-next-line react-hooks/exhaustive-deps
const makeLogin = useCallback(
async (username?: string, password?: string): Promise<LoginBody> => {
// checks isEmpty
if (isEmpty(username) || isEmpty(password)) {
const error = {
type: 'error',
description: i18next.t('form-validation.username-or-password-cant-be-empty'),
};
return { error };
}

try {
const response: LoginBody = await doLogin(username as string, password as string);

return response;
} catch (e) {
console.error('login error', e.message);
const error = {
type: 'error',
description: i18next.t('form-validation.unable-to-sign-in'),
};
return { error };
}
},
[doLogin]
);

if (!appContext) {
throw Error(t('app-context-not-correct-used'));
Expand All @@ -42,7 +74,7 @@ const LoginDialog: React.FC<Props> = ({ onClose, open = false }) => {
onClose();
}
},
[appContext, onClose]
[appContext, onClose, makeLogin]
);

return (
Expand Down
18 changes: 16 additions & 2 deletions src/App/Header/Search/Search.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,29 @@ import React from 'react';
import { BrowserRouter as Router } from 'react-router-dom';

import '@testing-library/jest-dom/extend-expect';
import api from 'verdaccio-ui/utils/api';

import api from 'verdaccio-ui/providers/API/api';
import APIProvider from 'verdaccio-ui/providers/API/APIProvider';
import AppConfigurationProvider from 'verdaccio-ui/providers/config';
import { render, fireEvent, waitFor } from 'verdaccio-ui/utils/test-react-testing-library';

jest.mock('lodash/debounce', () =>
jest.fn(fn => {
fn.cancel = jest.fn();
return fn;
})
);

import Search from './Search';

/* eslint-disable verdaccio/jsx-spread */
const ComponentToBeRendered: React.FC = () => (
<Router>
<Search />
<AppConfigurationProvider>
<APIProvider>
<Search />
</APIProvider>
</AppConfigurationProvider>
</Router>
);

Expand Down
5 changes: 3 additions & 2 deletions src/App/Header/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
import { RouteComponentProps, withRouter } from 'react-router';

import AutoComplete from 'verdaccio-ui/components/AutoComplete';
import { callSearch } from 'verdaccio-ui/utils/calls';
import { useAPI } from 'verdaccio-ui/providers/API/APIProvider';

import SearchAdornment from './SearchAdornment';

Expand All @@ -23,6 +23,7 @@ const Search: React.FC<RouteComponentProps> = ({ history }) => {
const [loading, setLoading] = useState(false);
const mountedRef = useRef(true);
const [requestList, setRequestList] = useState<Array<{ abort: () => void }>>([]);
const { callSearch } = useAPI();

/**
* Cancel all the requests which are in pending state.
Expand Down Expand Up @@ -138,7 +139,7 @@ const Search: React.FC<RouteComponentProps> = ({ history }) => {
}
}
},
[requestList, setRequestList, setSuggestions, setLoaded, setError, setLoading]
[requestList, setRequestList, setSuggestions, setLoaded, setError, setLoading, callSearch]
);

useEffect(() => {
Expand Down
16 changes: 12 additions & 4 deletions src/components/ActionBar/ActionBarAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import styled from '@emotion/styled';
import BugReportIcon from '@material-ui/icons/BugReport';
import DownloadIcon from '@material-ui/icons/CloudDownload';
import HomeIcon from '@material-ui/icons/Home';
import React from 'react';
import React, { useCallback } from 'react';
import { useTranslation } from 'react-i18next';

import { Theme } from 'verdaccio-ui/design-tokens/theme';
import { useAPI } from 'verdaccio-ui/providers/API/APIProvider';
import { extractFileName, downloadFile } from 'verdaccio-ui/utils/url';

import FloatingActionButton from '../FloatingActionButton';
import Link from '../Link';
import Tooltip from '../Tooltip';

import downloadTarball from './download-tarball';

export const Fab = styled(FloatingActionButton)<{ theme?: Theme }>(({ theme }) => ({
backgroundColor: theme?.palette.type === 'light' ? theme?.palette.primary.main : theme?.palette.cyanBlue,
color: theme?.palette.white,
Expand All @@ -33,6 +33,14 @@ export interface ActionBarActionProps {
/* eslint-disable react/jsx-no-bind */
const ActionBarAction: React.FC<ActionBarActionProps> = ({ type, link }) => {
const { t } = useTranslation();
const { getResource } = useAPI();

const handleDownload = useCallback(async () => {
const fileStream = await getResource(link);
const fileName = extractFileName(link);
downloadFile(fileStream, fileName);
}, [getResource, link]);

switch (type) {
case 'VISIT_HOMEPAGE':
return (
Expand All @@ -57,7 +65,7 @@ const ActionBarAction: React.FC<ActionBarActionProps> = ({ type, link }) => {
case 'DOWNLOAD_TARBALL':
return (
<Tooltip title={t('action-bar-action.download-tarball')}>
<Fab data-testid="download-tarball-btn" onClick={downloadTarball(link)} size="small">
<Fab data-testid="download-tarball-btn" onClick={handleDownload} size="small">
<DownloadIcon />
</Fab>
</Tooltip>
Expand Down
18 changes: 0 additions & 18 deletions src/components/ActionBar/download-tarball.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/components/ActionBar/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { default } from './ActionBar';
export { default as downloadTarball } from './download-tarball';
10 changes: 8 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { AppContainer } from 'react-hot-loader';

import APIProvider from 'verdaccio-ui/providers/API/APIProvider';
import AppConfigurationContext from 'verdaccio-ui/providers/config';

import App from './App';
import StyleBaseline from './design-tokens/StyleBaseline';
import ThemeProvider from './design-tokens/ThemeProvider';

const rootNode = document.getElementById('root');

const renderApp = (Component: React.ElementType): void => {
ReactDOM.render(
<AppContainer>
<ThemeProvider>
<StyleBaseline />
<Component />
<AppConfigurationContext>
<APIProvider>
<Component />
</APIProvider>
</AppConfigurationContext>
</ThemeProvider>
</AppContainer>,
rootNode
Expand Down
18 changes: 0 additions & 18 deletions src/pages/Version/DetailSidebar/ActionBar/download-tarball.ts

This file was deleted.

Loading