Skip to content

Commit

Permalink
Merge pull request #44905 from code-dot-org/dtl_candidate_0dbd8797
Browse files Browse the repository at this point in the history
  • Loading branch information
deploy-code-org committed Feb 17, 2022
2 parents 357fb85 + 0dbd879 commit 3c24a21
Show file tree
Hide file tree
Showing 78 changed files with 5,658 additions and 4,168 deletions.
1 change: 1 addition & 0 deletions apps/src/dance/Dance.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ Dance.prototype.displayFeedback_ = function() {
: ['HourOfCode'];

let feedbackOptions = {
doNothingOnHidden: true,
feedbackType: this.testResults,
message: this.message,
response: this.response,
Expand Down
33 changes: 21 additions & 12 deletions apps/src/feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ FeedbackUtils.prototype.displayFeedback = function(
) {
options.level = options.level || {};

const {onContinue, shareLink} = options;
const {onContinue, shareLink, doNothingOnHidden} = options;
const hadShareFailure = options.response && options.response.share_failure;
const showingSharing =
options.showingSharing && !hadShareFailure && shareLink;
Expand Down Expand Up @@ -229,17 +229,25 @@ FeedbackUtils.prototype.displayFeedback = function(
project.saveIfSourcesChanged();
}

var onHidden = onlyContinue
? onContinue
: function() {
if (!continueButton || feedbackDialog.hideButDontContinue) {
this.studioApp_.displayMissingBlockHints(
missingRecommendedBlockHints
);
} else {
onContinue();
}
}.bind(this);
let onHidden;
if (doNothingOnHidden) {
// No additional onHidden functionality upon closing the dialog
} else {
/*
hideButDontContinue toggles when the again button is pressed, so its value
may change after this definition
*/
onHidden = function() {
if (
!continueButton ||
(feedbackDialog && feedbackDialog.hideButDontContinue)
) {
this.studioApp_.displayMissingBlockHints(missingRecommendedBlockHints);
} else {
onContinue();
}
}.bind(this);
}

var icon;
if (!options.hideIcon) {
Expand Down Expand Up @@ -422,6 +430,7 @@ FeedbackUtils.prototype.displayFeedback = function(
level_id: options.response.level_id
});
}
options.onContinue();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const BOARD_EVENT_ALIASES = {
doubleTap: 'tap:double'
};

export const SONG_SINGLE_NOTE = ['G3'];

// For use with Piezo.play()
// Preferred tempo: 104
export const SONG_CHARGE = [
Expand All @@ -50,8 +52,6 @@ export const SONG_CHARGE = [
['G4', 1]
];

export const SONG_1D = ['B4', null, 'B4', null, 'G#4', 'F#4', 'E4', null, 'E4'];

// Preferred tempo: 80
export const SONG_LEVEL_COMPLETE = [
['G#4', 1 / 8],
Expand Down
12 changes: 5 additions & 7 deletions apps/src/lib/kits/maker/dropletConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
CP_BUTTON_VARS,
CP_COMPONENT_EVENTS,
SONG_CHARGE,
SONG_1D
SONG_SINGLE_NOTE
} from './boards/circuitPlayground/PlaygroundConstants';

import {
Expand All @@ -31,9 +31,7 @@ const colorPixelVariables = _.range(N_COLOR_LEDS).map(
const colorLedBlockPrefix = `${colorPixelVariables[0]}.`;

function stringifySong(song) {
return (
'[\n' + song.map(note => ` ${JSON.stringify(note)}`).join(',\n') + '\n]'
);
return '[' + song.map(note => `${JSON.stringify(note)}`).join(', ') + ']';
}
config.stringifySong = stringifySong;

Expand Down Expand Up @@ -168,7 +166,7 @@ const circuitPlaygroundBlocks = [
parent: api,
category: CIRCUIT_CATEGORY,
paletteParams: ['component', 'event', 'callback'],
params: ['buttonL', '"down"', 'function(event) {\n \n}'],
params: ['buttonL', '"down"', 'function() {\n \n}'],
allowFunctionDrop: {2: true},
dropdown: {
0: Object.keys(CP_COMPONENT_EVENTS),
Expand Down Expand Up @@ -304,14 +302,14 @@ const circuitPlaygroundBlocks = [
func: 'buzzer.playNotes',
category: CIRCUIT_CATEGORY,
paletteParams: ['notes', 'tempo'],
params: [stringifySong(SONG_1D), 120],
params: [stringifySong(SONG_SINGLE_NOTE), 120],
paramButtons: {minArgs: 1, maxArgs: 2}
},
{
func: 'buzzer.playSong',
category: CIRCUIT_CATEGORY,
paletteParams: ['notes', 'tempo'],
params: [stringifySong(SONG_CHARGE), 120],
params: [`[${stringifySong(SONG_CHARGE[0])}]`, 120],
paramButtons: {minArgs: 1, maxArgs: 2}
},
{
Expand Down
13 changes: 11 additions & 2 deletions apps/src/sites/studio/pages/certificates/show.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import React from 'react';
import ReactDOM from 'react-dom';
import {Provider} from 'react-redux';
import getScriptData from '@cdo/apps/util/getScriptData';
import CertificateShare from '@cdo/apps/templates/CertificateShare';
import {getStore} from '@cdo/apps/redux';

$(document).ready(function() {
const store = getStore();
const certificateData = getScriptData('certificate');
const {imageUrl, printUrl} = certificateData;
const {imageUrl, printUrl, announcement} = certificateData;
ReactDOM.render(
<CertificateShare imageUrl={imageUrl} printUrl={printUrl} />,
<Provider store={store}>
<CertificateShare
imageUrl={imageUrl}
printUrl={printUrl}
announcement={announcement}
/>
</Provider>,
document.getElementById('certificate-share')
);
});
51 changes: 42 additions & 9 deletions apps/src/templates/CertificateShare.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,53 @@
import React from 'react';
import PropTypes from 'prop-types';
import i18n from '@cdo/locale';
import {pegasus} from '@cdo/apps/lib/util/urlHelpers';
import {TwoColumnActionBlock} from '@cdo/apps/templates/studioHomepages/TwoColumnActionBlock';
import styleConstants from '../styleConstants';

export default function CertificateShare(props) {
export default function CertificateShare({announcement, printUrl, imageUrl}) {
return (
<a href={props.printUrl}>
<img
src={props.imageUrl}
alt={i18n.certificateForCompletion()}
width="100%"
/>
</a>
<div style={styles.wrapper}>
<a href={printUrl}>
<img
src={imageUrl}
alt={i18n.certificateForCompletion()}
width="100%"
style={styles.certificate}
/>
</a>
{announcement && (
<TwoColumnActionBlock
imageUrl={pegasus(announcement.image)}
subHeading={announcement.title}
description={announcement.body}
buttons={[
{
id: announcement.buttonId,
url: announcement.buttonUrl,
text: announcement.buttonText
}
]}
/>
)}
</div>
);
}

const styles = {
wrapper: {
with: '100%',
maxWidth: styleConstants['content-width'],
marginLeft: 'auto',
marginRight: 'auto'
},
certificate: {
marginBottom: 20
}
};

CertificateShare.propTypes = {
imageUrl: PropTypes.string.isRequired,
printUrl: PropTypes.string.isRequired
printUrl: PropTypes.string.isRequired,
announcement: PropTypes.object
};
4 changes: 1 addition & 3 deletions apps/test/unit/lib/kits/maker/dropletConfigTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ describe('maker/dropletConfig.js', () => {
['B2', 1 / 4],
['C3', 1 / 2]
])
).to.equal(
'[\n' + ' ["A1",0.25],\n' + ' ["B2",0.25],\n' + ' ["C3",0.5]\n' + ']'
);
).to.equal('[' + '["A1",0.25], ' + '["B2",0.25], ' + '["C3",0.5]' + ']');
});
});

Expand Down
58 changes: 58 additions & 0 deletions apps/test/unit/templates/CertificateShareTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';
import {shallow} from 'enzyme';
import {expect} from '../../util/reconfiguredChai';
import CertificateShare from '@cdo/apps/templates/CertificateShare';

const defaultProps = {
imageUrl: '/certificate-image',
printUrl: '/certificate-print',
announcement: {
image: '/announcement-image',
title: 'Title Text',
body: 'body text',
buttonId: 'button-id',
buttonUrl: '/button-url',
buttonText: 'button text'
}
};

describe('CertificateShare', () => {
let storedWindowDashboard;

beforeEach(() => {
storedWindowDashboard = window.dashboard;
window.dashboard = {
CODE_ORG_URL: '//code.org'
};
});

afterEach(() => {
window.dashboard = storedWindowDashboard;
});

it('renders announcement image url relative to pegasus', () => {
const wrapper = shallow(<CertificateShare {...defaultProps} />);

const printLink = wrapper.find('a');
expect(printLink.prop('href')).to.equal('/certificate-print');
const image = printLink.find('img');
expect(image.prop('src')).to.equal('/certificate-image');

const block = wrapper.find('Connect(UnconnectedTwoColumnActionBlock)');
expect(block.prop('imageUrl')).to.equal('//code.org/announcement-image');
});

it('renders no announcement without announcement prop', () => {
const props = {
...defaultProps,
announcement: null
};
const wrapper = shallow(<CertificateShare {...props} />);

const printLink = wrapper.find('a');
expect(printLink.length).to.equal(1);

const block = wrapper.find('Connect(UnconnectedTwoColumnActionBlock)');
expect(block.length).to.equal(0);
});
});

0 comments on commit 3c24a21

Please sign in to comment.