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

FIX Create campaign success message #37

Merged
merged 14 commits into from
Aug 3, 2017

Conversation

phalkunz
Copy link
Contributor

@phalkunz phalkunz commented Jul 21, 2017

@phalkunz phalkunz changed the title Change "Add campaign" to "Add new" FIX Create campaign success message Jul 21, 2017
@phalkunz phalkunz force-pushed the pulls/1.0/create-success-msg branch from 0840b53 to ec321c7 Compare July 21, 2017 02:16
@@ -352,6 +436,7 @@ function mapStateToProps(state, ownProps) {
record: record || {},
campaign: state.campaign,
treeClass,
newItemCreated: state.campaign.newItemCreated,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proptypes definition for this

if (this.props.record.State === 'open') {
if (!items || items.length === 0) {
actionProps = Object.assign(actionProps, {
title: i18n._t('CampaignAdmin.PUBLISHCAMPAIGN'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add translation default fallback

className="flexbox-area-grow
fill-height
preview
campaign-admin__campaign-preview
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't have new lines in double quoted strings...
move these to a variable or classnames object

@@ -6,6 +6,7 @@ const initialState = deepFreeze({
changeSetItemId: null,
isPublishing: false,
view: null,
newItemCreated: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name for this is quite confusing, since this is a boolean type, it should describe the question like isNewItem or hasNewItem.
newItemCreated implies it's an object that was just created.

* @param {boolean}
* @return {Object}
*/
export function setNewCampaignCreated(newItemCreated) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming is inconsistent with what it's doing, maybe setIsNewItem or markHasCreatedItem

having both New and Created is double up on meaning.

@@ -119,7 +120,8 @@ class CampaignAdmin extends SilverStripeComponent {
// open the new campaign in edit mode after save completes
const sectionUrl = this.props.sectionConfig.url;
const id = response.record.id;
this.props.router.push(`${sectionUrl}/set/${id}/edit`);
this.props.campaignActions.setNewCampaignCreated(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the id is available, it would be more extensible to include the record or even just the id in the record, rather than just a boolean.
In this case, you could ignore the is or has prefix I mentioned below. But try to keep the naming consistent still setNewItem is perfectly fine.

@phalkunz phalkunz force-pushed the pulls/1.0/create-success-msg branch from 7af190b to 280d637 Compare July 27, 2017 04:51
@phalkunz phalkunz force-pushed the pulls/1.0/create-success-msg branch from 280d637 to 65e66c2 Compare July 27, 2017 23:35
);
const newItemInfo = newItem ?
(<p className="alert alert-success alert--no-border" role="alert">
Nice one! You have successfully created a campaign.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i18n this please.

<div className={previewClasses}>
<h2 className="campaign-admin__empty-heading">Getting started</h2>
<p className="campaign-admin__empty-info">
Select <strong>Add to Campaign</strong> from pages, files, and other content types

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i18n this please

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be careful with adding html to translation strings, it's heavily discouraged because you need to use dangerouslySetInnerHTML in react... (or castStringToElement())
Can we use quotes instead?
I've raised this about the "Nice one!" being bold above as well, and it was agreed that we could remove the bold for that.

/**
* Set new campaign
*
* @param {?number}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalid JSDoc @param {Number|null}

@@ -29,6 +28,16 @@ class CampaignAdminList extends SilverStripeComponent {
this.handleItemSelected = this.handleItemSelected.bind(this);
this.setBreadcrumbs = this.setBreadcrumbs.bind(this);
this.handleCloseItem = this.handleCloseItem.bind(this);

if (!this.isRecordLoaded()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is in the constructor, would be a good idea to pass through props to isRecordLoaded it can default to this.props if not provided

@@ -550,7 +590,7 @@ public function getCampaignCreateForm()
'campaignCreateForm',
$fields,
FieldList::create(
FormAction::create('save', _t(__CLASS__.'.SAVE', 'Save'))
FormAction::create('save', _t(__CLASS__.'.SAVE', 'Create'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't good practice, please create a new translation key entry... the fallback doesn't even take effect.

<div className={previewClasses}>
<h2 className="campaign-admin__empty-heading">Getting started</h2>
<p className="campaign-admin__empty-info">
Select <strong>Add to Campaign</strong> from pages, files, and other content types
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be careful with adding html to translation strings, it's heavily discouraged because you need to use dangerouslySetInnerHTML in react... (or castStringToElement())
Can we use quotes instead?
I've raised this about the "Nice one!" being bold above as well, and it was agreed that we could remove the bold for that.

'noItemText' => 'Add from ' . $class->i18n_plural_name() . ' area',
'items' => []
];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not comfortable with the idea of cross-module references like this...
Can these be added by an extension hook, rather than hardcoded in to campaign admin?
It could even be an array of classes in a config.

Either extension hook or config will be fine, both could be a best of both worlds.

'baseClass' => DataObject::getSchema()->baseDataClass('SilverStripe\Assets\File'),
'singular' => $class->i18n_singular_name(),
'plural' => $class->i18n_plural_name(),
'noItemText' => 'Add from ' . $class->i18n_plural_name() . ' area',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops and this could be i18n translated

{
listGroupItems.length > 0
? listGroupItems
: <p className="list-group-item">{group.noItemsText}</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phalkunz please note, we're following airbnb formatting standards (to an extent) so ternary conditions should break like this:

condition
  ? item
  : null

ref: https://github.com/airbnb/javascript/#comparison--nested-ternaries the better section

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -155,6 +159,34 @@ public function readCampaigns()
return $response;
}

protected function getPlaceholderGroups()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPDoc please.

{
$groups = [];

$classes = Config::inst()->get(self::class, 'placeholder_group_classes');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplication of ChangeSet::important_classes config.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by this? Should we be using ChangeSet.important_classes instead?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I see your comment below.

@@ -315,6 +374,19 @@ class CampaignAdminList extends SilverStripeComponent {
return groups;
}

getPlaceholderGroups() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we need this api; doesn't groupItemsForSet() build the groups automatically?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, @phalkunz has explained why this is necessary. The only change I'd request is the switch to using the existing config for important_classes instead.

'data' => [
'pristineTitle' => _t(__CLASS__.'SAVED', 'Saved'),
'pristineIcon' => 'tick',
'dirtyTitle' => _t(__CLASS__.'SAVECHANGES', 'Save changes'),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@unclecheese Looks like this render the title set above (line 521) redundant.


foreach ($classes as $class) {
/** @var DataObject $item */
$item = Injector::inst()->get($class);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get() won't return null if the class doesn't exist, it'll throw an exception. Can you use class_exists() instead please?

@flamerohr flamerohr dismissed tractorcow’s stale review August 3, 2017 06:10

All feedback addressed :)

@flamerohr flamerohr merged commit fe5768f into silverstripe:1 Aug 3, 2017
@flamerohr flamerohr deleted the pulls/1.0/create-success-msg branch August 3, 2017 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants