Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/trunk' into add/ci-php-8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
anomiex committed Nov 19, 2024
2 parents ecce6b6 + 42ddde5 commit 7a5b460
Show file tree
Hide file tree
Showing 121 changed files with 1,504 additions and 445 deletions.
2 changes: 1 addition & 1 deletion .github/versions.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Versions of tools to use in CI.
PHP_VERSION=8.2
COMPOSER_VERSION=2.7.7
COMPOSER_VERSION=2.8.3
NODE_VERSION=22.9.0
PNPM_VERSION=9.3.0

Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions projects/js-packages/charts/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Files not needed to be distributed in the package.
.gitattributes export-ignore
node_modules export-ignore

# Files to exclude from the mirror repo
/changelog/** production-exclude
/.eslintrc.cjs production-exclude
2 changes: 2 additions & 0 deletions projects/js-packages/charts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor/
node_modules/
7 changes: 7 additions & 0 deletions projects/js-packages/charts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

24 changes: 24 additions & 0 deletions projects/js-packages/charts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# charts

Display charts within Automattic products.

## How to install charts

### Installation From Git Repo

## Contribute

## Get Help

## Using this package in your WordPress plugin

If you plan on using this package in your WordPress plugin, we would recommend that you use [Jetpack Autoloader](https://packagist.org/packages/automattic/jetpack-autoloader) as your autoloader. This will allow for maximum interoperability with other plugins that use this package as well.

## Security

Need to report a security vulnerability? Go to [https://automattic.com/security/](https://automattic.com/security/) or directly to our security bug bounty site [https://hackerone.com/automattic](https://hackerone.com/automattic).

## License

charts is licensed under [GNU General Public License v2 (or later)](./LICENSE.txt)

Empty file.
4 changes: 4 additions & 0 deletions projects/js-packages/charts/changelog/initial-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Initial version.
42 changes: 42 additions & 0 deletions projects/js-packages/charts/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "automattic/charts",
"description": "Display charts within Automattic products.",
"type": "library",
"license": "GPL-2.0-or-later",
"require": {},
"require-dev": {
"automattic/jetpack-changelogger": "@dev"
},
"autoload": {
"classmap": [
"src/"
]
},
"scripts": {
"test-coverage": [
"pnpm run test-coverage"
],
"test-js": [
"pnpm run test"
]
},
"repositories": [
{
"type": "path",
"url": "../../packages/*",
"options": {
"monorepo": true
}
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"autotagger": true,
"npmjs-autopublish": true,
"changelogger": {
"link-template": "https://github.com/Automattic/charts/compare/v${old}...v${new}"
},
"mirror-repo": "Automattic/charts"
}
}
31 changes: 31 additions & 0 deletions projects/js-packages/charts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@automattic/charts",
"version": "0.1.0-alpha",
"description": "Display charts within Automattic products.",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/charts/#readme",
"bugs": {
"url": "https://github.com/Automattic/jetpack/labels/[JS Package] Charts"
},
"repository": {
"type": "git",
"url": "https://github.com/Automattic/jetpack.git",
"directory": "projects/js-packages/charts"
},
"license": "GPL-2.0-or-later",
"author": "Automattic",
"scripts": {
"test": "jest --config=tests/jest.config.cjs",
"test-coverage": "pnpm run test --coverage"
},
"devDependencies": {
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"jest-extended": "4.0.2",
"typescript": "5.0.4"
},
"exports": {
".": "./src/index.ts",
"./state": "./src/state",
"./action-types": "./src/state/action-types"
}
}
2 changes: 2 additions & 0 deletions projects/js-packages/charts/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Put your code in this `src/` folder!
// Feel free to delete or rename this file.
18 changes: 18 additions & 0 deletions projects/js-packages/charts/tests/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// We recommend using `jest` for testing. If you're testing React code, we recommend `@testing-library/react` and related packages.
// Please match the versions used elsewhere in the monorepo.
//
// Please don't add new uses of `mocha`, `chai`, `sinon`, `enzyme`, and so on. We're trying to standardize on one testing framework.
//
// The default setup is to have files named like "name.test.js" (or .jsx, .ts, or .tsx) in this `tests/` directory.
// But you could instead put them in `src/`, or put files like "name.js" (or .jsx, .ts, or .tsx) in `test` or `__tests__` directories somewhere.

// This is a placeholder test, new tests will be added soon
const placeholderFunction = () => {
return true;
};

describe( 'placeholderTest', () => {
it( 'should be a function', () => {
expect( typeof placeholderFunction ).toBe( 'function' );
} );
} );
7 changes: 7 additions & 0 deletions projects/js-packages/charts/tests/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require( 'path' );
const baseConfig = require( 'jetpack-js-tools/jest/config.base.js' );

module.exports = {
...baseConfig,
rootDir: path.join( __dirname, '..' ),
};
9 changes: 9 additions & 0 deletions projects/js-packages/charts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "jetpack-js-tools/tsconfig.base.json",
"compilerOptions": {
"typeRoots": [ "./node_modules/@types/", "src/*" ],
"outDir": "./build/"
},
// List all sources and source-containing subdirs.
"include": [ "./src" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Adds ThreatModal component and stories
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
display: flex;
font-family: "Courier 10 Pitch", Courier, monospace;
flex-direction: row;
overflow-x: scroll;
overflow-x: auto;
white-space: pre;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
font-family: monospace;
display: flex;
flex-direction: row;
overflow-x: scroll;
overflow-x: auto;
}

.marked-lines__marked-line {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Button } from '@automattic/jetpack-components';
import {
type Threat,
fixerIsInError,
fixerIsInProgress,
fixerStatusIsStale,
getFixerState,
getFixerAction,
getFixerMessage,
} from '@automattic/jetpack-scan';
import { Tooltip } from '@wordpress/components';
import { useCallback, useMemo } from '@wordpress/element';
Expand All @@ -30,10 +30,7 @@ export default function ThreatFixerButton( {
className?: string;
} ): JSX.Element {
const fixerState = useMemo( () => {
const inProgress = threat.fixer && fixerIsInProgress( threat.fixer );
const error = threat.fixer && fixerIsInError( threat.fixer );
const stale = threat.fixer && fixerStatusIsStale( threat.fixer );
return { inProgress, error, stale };
return getFixerState( threat.fixer );
}, [ threat.fixer ] );

const tooltipText = useMemo( () => {
Expand All @@ -53,54 +50,7 @@ export default function ThreatFixerButton( {
return __( 'An auto-fixer is in progress.', 'jetpack' );
}

switch ( threat.fixable.fixer ) {
case 'delete':
if ( threat.filename ) {
if ( threat.filename.endsWith( '/' ) ) {
return __( 'Deletes the directory that the infected file is in.', 'jetpack' );
}

if ( threat.signature === 'Core.File.Modification' ) {
return __( 'Deletes the unexpected file in a core WordPress directory.', 'jetpack' );
}

return __( 'Deletes the infected file.', 'jetpack' );
}

if ( threat.extension?.type === 'plugin' ) {
return __( 'Deletes the plugin directory to fix the threat.', 'jetpack' );
}

if ( threat.extension?.type === 'theme' ) {
return __( 'Deletes the theme directory to fix the threat.', 'jetpack' );
}
break;
case 'update':
return __( 'Upgrades the plugin or theme to a newer version.', 'jetpack' );
case 'replace':
case 'rollback':
if ( threat.filename ) {
return threat.signature === 'Core.File.Modification'
? __(
'Replaces the modified core WordPress file with the original clean version from the WordPress source code.',
'jetpack'
)
: __(
'Replaces the infected file with a previously backed up version that is clean.',
'jetpack'
);
}

if ( threat.signature === 'php_hardening_WP_Config_NoSalts_001' ) {
return __(
'Replaces the default salt keys in wp-config.php with unique ones.',
'jetpack'
);
}
break;
default:
return __( 'An auto-fixer is available.', 'jetpack' );
}
return getFixerMessage( threat );
}, [ threat, fixerState ] );

const buttonText = useMemo( () => {
Expand All @@ -112,18 +62,8 @@ export default function ThreatFixerButton( {
return __( 'Error', 'jetpack' );
}

switch ( threat.fixable.fixer ) {
case 'delete':
return __( 'Delete', 'jetpack' );
case 'update':
return __( 'Update', 'jetpack' );
case 'replace':
case 'rollback':
return __( 'Replace', 'jetpack' );
default:
return __( 'Fix', 'jetpack' );
}
}, [ threat.fixable, fixerState.error ] );
return getFixerAction( threat );
}, [ threat, fixerState.error ] );

const handleClick = useCallback(
( event: React.MouseEvent ) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Text, Button } from '@automattic/jetpack-components';
import { Notice } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import React, { ReactElement } from 'react';
import styles from './styles.module.scss';

const CredentialsGate = ( {
siteCredentialsNeeded,
credentialsIsFetching,
credentialsRedirectUrl,
children,
}: {
siteCredentialsNeeded: boolean;
credentialsIsFetching: boolean;
credentialsRedirectUrl: string;
children: ReactElement;
} ): JSX.Element => {
if ( ! siteCredentialsNeeded ) {
return children;
}

return (
<>
<Notice
status="warning"
isDismissible={ false }
children={
<Text>
{ __(
'Before Jetpack can auto-fix threats on your site, it needs your server credentials.',
'jetpack'
) }
</Text>
}
/>

<Text>
{ __(
'Your server credentials allow Jetpack to access the server that’s powering your website. This information is securely saved and only used to perform fix threats detected on your site.',
'jetpack'
) }
</Text>

<Text>
{ __(
'Once you’ve entered server credentials, Jetpack will be fixing the selected threats.',
'jetpack'
) }
</Text>

<div className={ styles[ 'modal-actions' ] }>
<Button
isExternalLink={ true }
weight="regular"
href={ credentialsRedirectUrl }
isLoading={ credentialsIsFetching }
>
{ __( 'Enter server credentials', 'jetpack' ) }
</Button>
</div>
</>
);
};

export default CredentialsGate;
Loading

0 comments on commit 7a5b460

Please sign in to comment.