-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugin: add log file downloading (#193)
* sketch out fetching logs * make npm start do a build to make sure the latest is there * set up wp env to use 8.1 and named plugin and theme paths * add ui for download logs block * add dowload handling to the form handler also stub out the log download data * allow clicking header to toggle if it has the right className * make input renderer more general * update download template and add timestamp defaults * remove some error logs * fix how the post title is collected * refactor the client log endpoint * clean up log filtering * remove error log * fix site size * add download block to the site template
- Loading branch information
Showing
14 changed files
with
751 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
{ | ||
"core": "WordPress/WordPress", | ||
"plugins": [ "./plugin" ], | ||
"themes": [ "./theme" ], | ||
"phpVersion": "8.1", | ||
|
||
"config": { | ||
"WP_DEBUG": true, | ||
"WP_DEBUG_LOG": true, | ||
"WP_DEBUG_DISPLAY": true, | ||
"SCRIPT_DEBUG": true, | ||
"WP_DEVELOPMENT_MODE": "all", | ||
"WP_ENVIRONMENT_TYPE": "local" | ||
} | ||
}, | ||
"mappings": { | ||
"wp-content/plugins/wpcloud-station-plugin": "./plugin", | ||
"wp-content/themes/wpcloud-station-theme": "./theme" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 3, | ||
"name": "wpcloud/log-download", | ||
"version": "0.1.0", | ||
"title": "Download Log File", | ||
"category": "wpcloud", | ||
"icon": "feedback", | ||
"description": "A block to download the log file", | ||
"example": {}, | ||
"supports": { | ||
"html": false | ||
}, | ||
"textdomain": "wpcloud", | ||
"editorScript": "file:./index.js", | ||
"viewScript": "file:./view.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
import { InnerBlocks } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import metadata from './block.json'; | ||
import { inputTemplate } from '../utils/templates'; | ||
|
||
const required = [ | ||
{ name: 'type', label: __('Type'), required: true, hint: '', type: 'select', options: { site: __('Site'), error: __('Error') } }, | ||
{ name: 'log_start', label: __('Start Time'),required: true, hint: __( 'Logs are only guaranteed for 28 days. A start date before that may return incomplete data.' ), type: 'datetime' }, | ||
{ name: 'log_end', label: __('End Time'), required: true, hint: '', type: 'datetime', value: '2024-08-29T14:40' }, | ||
] | ||
const filters = [ | ||
{ name: 'page_size', label: __('Page Size'), hint: __('The maximum number of records to retrieve in a single request. Defaults to 500. Max of 10000.'), type: 'number', placeholder: __('Enter page size') }, | ||
{ name: 'scroll_id', label: __('Scroll ID'), hint: __( 'String used to specify the next page of data for large queries; the same query arguments as the initial query must be provided with the scroll_id on each subsequent request.' ), type: 'text', placeholder: __('Enter scroll ID') }, | ||
{ name: 'sort_order', label: __('Sort Order'), hint: '', type: 'select', options: { asc: __('Ascending'), desc: __('Descending') } }, | ||
|
||
// error filters | ||
{ name: 'filter-error__severity', label: __('Log Level'), hint: 'Comma separated log levels. Example: User, Warning ,Deprecated, Fatal error', type: 'text', placeholder: __('Enter log level'), className: 'wpcloud_form_input__optional_log_filter'}, | ||
// site filters | ||
{ name: 'filter-site__cached', label: __('Cached'), hint: '', type: 'text', className: 'wpcloud_form_input__option_log_filter' } , | ||
{ name: 'filter-site__renderer', label: __('Renderer'), hint: '', type: 'text', className: 'wpcloud_form_input__optional_log_filter' }, | ||
{ name: 'filter-site__request_type', label: __('Request Type'), hint: '', type: 'text', className: 'wpcloud_form_input__optional_log_filter' }, | ||
{ name: 'filter-site__status', label: __('Status'), hint: '', type: 'text', placeholder: '200,404', className: 'wpcloud_form_input__optional_log_filter' }, | ||
{ name: 'filter-site__user_ip', label: __('User IP'), hint: '', type: 'text', placeholder: __('127.0.0.0'), className: 'wpcloud_form_input__optional_log_filter' }, | ||
]; | ||
|
||
const template = [ | ||
[ 'wpcloud/site-details', { metadata: { name: 'Download logs form' } }, | ||
[ | ||
[ 'core/heading', { level: 2, content: __('Download Logs') } ], | ||
[ | ||
'wpcloud/form', | ||
{ | ||
ajax: true, | ||
wpcloudAction: 'log_download', | ||
className: 'wpcloud_block_form__log_download', | ||
}, | ||
[ | ||
...required.map(inputTemplate), | ||
[ 'wpcloud/expanding-section', { metadata: { name: 'Log Filters' }, clickToToggle: false, hideHeader: false }, | ||
[ | ||
[ 'wpcloud/expanding-header', { className: 'click-to-toggle' }, | ||
[ | ||
['core/heading', { level: 3, content: __('Filters'), }], | ||
], | ||
], | ||
[ 'wpcloud/expanding-content', {}, | ||
[ | ||
...filters.map(inputTemplate) | ||
] | ||
], | ||
] | ||
], | ||
[ 'wpcloud/button', { label: __('Download'), type: 'submit' } ], | ||
] | ||
], | ||
] | ||
] | ||
]; | ||
|
||
registerBlockType(metadata.name, { | ||
edit: () => <InnerBlocks template={template} />, | ||
save: () => <InnerBlocks.Content />, | ||
}); |
Oops, something went wrong.