Skip to content
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

Add user survey to wp-admin #3235

Draft
wants to merge 21 commits into
base: develop
Choose a base branch
from
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 4 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"presets": [ "@wordpress/default" ]
}
"presets": [
"@calderajs/babel-preset-calderajs"
]
}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ wp-test-case
/vendor/**/.git

!assets/build/

# Avoid committing webpack dev client assets
dist/*
!dist/asset-manifest.json
!dist/README.json
!dist/react.min.js
!dist/react-dom.min.js
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ This is the new stuff, built with webpack. Eventually everything UI will be here
* viewer - The entry viewer. Work not in progress, not used in plugin.
* editor - Theoretical.

* Build for development and start watcher.
- `npm run dev`
* Build for production
- `npm run build:webpack`



#### `/assets/`
This is the old stuff, built with grunt.

Expand All @@ -81,11 +78,16 @@ This is the old stuff, built with grunt.
* `composer test:delete` - Delete test forms and pages the are on.
* `composer nuke` - Deletes dependencies, including lock files -- NPM and Composer.

##### npm
* `npm test` - Run JavaScript test watcher
* `npm run test:once` - Run JavaScript unit tests once
* `npm run test:e2e` - Start Cypress e2e test runner.
* `npm run test:e2e:ci` - Trigger Cypress.io test record.
##### yarn
* `yarn test` - Run JavaScript test watcher
* `yarn build` - Build all JavaScript and CSS for production
* `yarn build:blocks` - Build blocks JavaScript and CSS for production
* `yarn build:clients` - Build other JavaScript and CSS for production.
* `yarn start` - Start dev server for clients that are not blocks and run watcher.
* `yarn start:blocks` - Start dev server for blocks and run watcher.
* `yarn test:once` - Run JavaScript unit tests once
* `yarn test:e2e` - Start Cypress e2e test runner.
* `yarn test:e2e:ci` - Trigger Cypress.io test record.

##### wp-cli
Probably don't use these directly. They will change. Must be prefaced with `docker-compose run --rm cli`
Expand Down
2 changes: 1 addition & 1 deletion assets/build/css/caldera-forms-front.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/css/caldera-forms-front.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/caldera-forms-front.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! GENERATED SOURCE FILE caldera-forms - v1.8.5 - 2019-05-29 */var resBaldrickTriggers;
/*! GENERATED SOURCE FILE caldera-forms - v1.8.6-a.1 - 2019-05-30 */var resBaldrickTriggers;

jQuery(function($){
function fieldErrors(fields, $form, $notice) {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/entry-viewer-2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! GENERATED SOURCE FILE caldera-forms - v1.8.5 - 2019-05-29 *//**
/*! GENERATED SOURCE FILE caldera-forms - v1.8.6-a.1 - 2019-05-30 *//**
* API Client for Caldera Forms API for a single form
*
* @since 1.5.0
Expand Down
2 changes: 1 addition & 1 deletion assets/js/parsley.min.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! GENERATED SOURCE FILE caldera-forms - v1.8.5 - 2019-05-29 *//*!
/*! GENERATED SOURCE FILE caldera-forms - v1.8.6-a.1 - 2019-05-30 *//*!
* Parsley.js
* Version 2.8.1 - built Sat, Feb 3rd 2018, 2:27 pm
* http://parsleyjs.org
Expand Down
2 changes: 1 addition & 1 deletion assets/js/vue.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! GENERATED SOURCE FILE caldera-forms - v1.8.5 - 2019-05-29 *//*!
/*! GENERATED SOURCE FILE caldera-forms - v1.8.6-a.1 - 2019-05-30 *//*!
* Vue.js v2.1.6
* (c) 2014-2016 Evan You
* Released under the MIT License.
Expand Down
7 changes: 3 additions & 4 deletions caldera-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

add_action( 'init', function(){
//hack to make code splitting work.
if( false !== strpos( $_SERVER['REQUEST_URI'], 'wp-admin/clients/') ){
cf_redirect(plugin_dir_url(__FILE__).str_replace( '/wp-admin/', '',$_SERVER['REQUEST_URI']));exit;
if( false !== strpos( $_SERVER['REQUEST_URI'], 'clients/') ){

cf_redirect(untrailingslashit( plugin_dir_url(__FILE__) ).$_SERVER['REQUEST_URI'] );exit;
}

});
Expand Down Expand Up @@ -152,8 +153,6 @@ function caldera_forms_load()
//@see https://github.com/CalderaWP/Caldera-Forms/issues/2855
add_filter( 'caldera_forms_pro_log_mode', '__return_false' );
add_filter( 'caldera_forms_pro_mail_debug', '__return_false' );


}

/**
Expand Down
2 changes: 0 additions & 2 deletions cf2/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ function caldera_forms_get_v2_container()
}

/**
<<<<<<< HEAD
* Setup Cf2 container
*
* @since 1.8.0
Expand Down Expand Up @@ -68,4 +67,3 @@ function caldera_forms_schedule_job(\calderawp\calderaforms\cf2\Jobs\Job $job, $
->getService(\calderawp\calderaforms\cf2\Services\QueueSchedulerService::class)
->schedule($job, $delay);
}

2 changes: 1 addition & 1 deletion classes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2119,7 +2119,7 @@ public static function init_privacy_settings()
'scripts' => [
'privacy',
'admin',

Caldera_Forms_Render_Assets::make_slug('cf-react')
],
'styles' => [
'editor-grid'
Expand Down
14 changes: 3 additions & 11 deletions classes/admin/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,7 @@ public static function register_scripts()

wp_register_script(self::slug('baldrick'), Caldera_Forms_Render_Assets::make_url('wp-baldrick-full'), array('jquery'), $version);


$admin_client_dependencies = [
'wp-element',
'wp-components'
];
global $wp_version;
if (!version_compare($wp_version, '5.0.0', '>=')) {
$admin_client_dependencies[] = Caldera_Forms_Render_Assets::make_slug('legacy-bundle');
}
wp_register_script(Caldera_Forms_Render_Assets::make_slug('admin-client'), Caldera_Forms_Render_Assets::make_url('admin-client'), $admin_client_dependencies, $version);
wp_register_script(Caldera_Forms_Render_Assets::make_slug('admin-client'), Caldera_Forms_Render_Assets::make_url('admin-client'), Caldera_Forms_Render_Assets::cf_dependencies('admin-client' ), $version);

wp_register_script(self::slug('admin'), Caldera_Forms_Render_Assets::make_url('admin'), array(
self::slug('baldrick'),
Expand Down Expand Up @@ -349,6 +340,7 @@ protected static function data_to_localize()
'nonce' => Caldera_Forms_API_Util::get_core_nonce()
),
'isProConnected' => (bool) caldera_forms_pro_is_active(),
'showSurveyFirst' => true,
);
$api_config = new Caldera_Forms_API_JsConfig;
$data = array_merge($data, $api_config->toArray());
Expand All @@ -375,4 +367,4 @@ public static function set_cf_admin($slug)
wp_localize_script($slug, 'CF_ADMIN', $data);
}

}
}
1 change: 1 addition & 0 deletions classes/admin/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public function render()
public function enqueue_assets()
{

Caldera_Forms_Render_Assets::maybe_register();
if (!empty($this->assets['scripts'])) {
foreach ($this->assets['scripts'] as $handle) {
Caldera_Forms_Render_Assets::enqueue_script($handle);
Expand Down
145 changes: 121 additions & 24 deletions classes/render/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ class Caldera_Forms_Render_Assets
*/
protected static $client_modified_time;


/**
* The array from webpack manifest
*
* @sicne 1.8.6
*
* @var array
*/
protected static $webpack_asset_manifest;

/**
* Enqueue styles for field type
*
Expand Down Expand Up @@ -312,6 +322,8 @@ public static function get_core_scripts()
'privacy' => self::make_url('privacy'),
'render' => self::make_url('render'),
'legacy-bundle' => self::make_url('legacy-bundle'),
'cf-react' => trailingslashit( CFCORE_URL ) . 'dist/react.min.js',
'cf-react-dom' => trailingslashit( CFCORE_URL ) . 'dist/react-dom.min.js',
];

return $script_urls;
Expand Down Expand Up @@ -485,6 +497,11 @@ public static function enqueue_style($style)
*/
public static function enqueue_script($script, $depts = ['jquery'])
{

if( 'cf-react' === $script ){
wp_enqueue_script($script);
return;
}
if( 'render' === $script ||$script === self::make_slug('render') ){
if (is_admin() ) {
$load_render = false;
Expand Down Expand Up @@ -579,11 +596,38 @@ public static function make_url($name, $script = true)
$name = 'admin';
}

$version = absint(self::get_client_modified_time());
$manifest = self::get_webpack_manifest();
if ($script) {
return "{$root_url}clients/{$name}/build/index.min.js?h={$version}";
} else {
return "{$root_url}clients/{$name}/build/style.min.css?h={$version}";
if (
in_array($name, [
'blocks',
'pro',
'privacy',
'legacy-bundle'
])
|| empty($manifest)
|| ! array_key_exists("{$name}.js",$manifest)
) {
return "{$root_url}clients/{$name}/build/index.min.js";
} else {
return $manifest["{$name}.js"];
}
} else {
if (
in_array($name, [
'blocks',
'pro',
'privacy',
'legacy-bundle'
])
|| empty($manifest)
|| ! array_key_exists("{$name}.css",$manifest)
) {
return "{$root_url}clients/{$name}/build/style.min.css";

}else{
return $manifest["{$name}.css"];
}
}
}

Expand All @@ -603,24 +647,6 @@ public static function make_url($name, $script = true)

}

/**
* Get the time the clients directory was modified at.
*
* - Used to hash the file URLs for client entry points.
* - This avoids running filetime or md5 hash on all 10 files.
*
* @since 1.8.6
*
* @return int
*/
protected static function get_client_modified_time(){
return rand();
if( ! self::$client_modified_time ){
$dir = dirname(__FILE__,3). '/clients/admin/build/index.min.js' ;
self::$client_modified_time = filemtime($dir);
}
return self::$client_modified_time;
}

/**
* Is this the slug of a webpack entry point
Expand Down Expand Up @@ -683,10 +709,41 @@ public static function cf_dependencies($tag){
if ($tag === "blocks") {
$tags = ["wp-blocks"];
} else if($tag === "render") {
$tags = ["wp-element","wp-data"];
}
if (! Caldera_Forms_Admin::is_main_page()) {
$tags = [
'wp-data',
'wp-dom',
'wp-element',
'react',

];
}
//this should not be needed, but it seams to be only way to get react on the page
foreach ($tags as $t ){
wp_enqueue_script($t);
}
}elseif( 'admin-client' === $tag ){
$tags = [
'lodash',
'cf-react',
'cf-react-dom',
'wp-polyfill',
'wp-keycodes'
];
wp_enqueue_script('lodash' );
}

}

foreach ( $tags as $_tag ){
if( ! wp_script_is($_tag, 'registered')){
global $wp_scripts;
wp_default_packages_vendor( $wp_scripts );
wp_default_packages_scripts( $wp_scripts );
break;
}
}

return $tags;
}

Expand Down Expand Up @@ -827,6 +884,8 @@ protected static function register_script($script_key, $script_url, $depts = ['j
return;
} elseif ('editor' == $script_key) {
$depts = ['jquery', 'wp-color-picker'];
} elseif( 'privacy' === $script_key ) {
$depts = ['cf-react','cf-react-dom'];
} else {
//no needd...
}
Expand Down Expand Up @@ -1112,4 +1171,42 @@ protected static function is_beaver_builder_editor(){
return isset($_GET, $_GET[ 'fl_builder']);
}


/**
* Get the generated asset-mainfiest.json
*
* @since 1.8.6
*
* @return array
*/
protected static function get_webpack_manifest()
{
if( ! is_array( self::$webpack_asset_manifest ) ){
$path = CFCORE_PATH .'/dist/asset-manifest.json';
if (!file_exists($path)) {
return [];
}
$contents = file_get_contents($path);
if (empty($contents)) {
return [];
}
$assets = json_decode($contents, true);
if( ! empty($assets) ){

self::$webpack_asset_manifest = [];
foreach ($assets as $asset => $url) {
if (false === strpos($asset, '.map')) {
self::$webpack_asset_manifest[$asset] = $url;
}
}

}else{
self::$webpack_asset_manifest = [];
}
}
return self::$webpack_asset_manifest;

}


}
7 changes: 4 additions & 3 deletions clients/admin/MainDashboard/DashboardPanels/ProDashboard.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React,{Fragment,useEffect,useState} from 'react';
import {TabPanel} from "@wordpress/components";
import {ProWhatIs} from "../../../components/ProSettings";
import {Addons} from "../components/AddOns/Addons";

const onSelect = () => {
};
import {Addons} from "../components/AddOns/Addons";
import {Fragment} from "react";

export default function ProDashboard({isProConnected,apiRoot}) {

return (
<Fragment>
<ProWhatIs />
Expand Down Expand Up @@ -53,4 +54,4 @@ export default function ProDashboard({isProConnected,apiRoot}) {
ProDashboard.defaultProps = {
apiRoot: 'https://calderaforms.com/wp-json',
isProConnected: false,
};
};
Loading