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

Manage students tab: show data with new UI under experiment #19948

Merged
merged 6 commits into from
Jan 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions apps/src/sites/code.org/pages/public/teacher-dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import {
renderSyncOauthSectionControl,
unmountSyncOauthSectionControl,
renderLoginTypeAndSharingControls,
unmountLoginTypeAndSharingControls
} from './sections';
unmountLoginTypeAndSharingControls,
renderSectionTable,
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a little strange that some of our tab render functions we have inlined (renderSectionProjects, renderSectionProgress), and this one we import. Seems like it would be good for us to be consistent. Not something that needs to be fixed in this PR, but something to keep in mind.

FWIW, I think your approach of having it be imported might be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was following how some react buttons get loaded onto the page already. I think it makes a little more sense than defining it in index.

} from '@cdo/apps/templates/teacherDashboard/sections';
import logToCloud from '@cdo/apps/logToCloud';

const script = document.querySelector('script[data-teacherdashboard]');
Expand All @@ -28,6 +29,7 @@ main(scriptData);
// disableExperiments url params will cause a persistent setting to be stored
// from any page in teacher dashboard.
const showProjectThumbnails = experiments.isEnabled('showProjectThumbnails');
const showManageStudentsReact = experiments.isEnabled(experiments.MANAGE_STUDENTS);

function renderSectionProjects(sectionId) {
const dataUrl = `/dashboardapi/v1/projects/section/${sectionId}`;
Expand Down Expand Up @@ -395,6 +397,12 @@ function main() {
$scope.section.$promise.then(section => renderLoginTypeAndSharingControls(section.id));
});

if (showManageStudentsReact) {
$scope.$on('student-table-react-rendered', () => {
$scope.section.$promise.then(section => renderSectionTable(section.id, section.login_type));
});
}

$scope.$on('$destroy', () => {
unmountSyncOauthSectionControl();
unmountLoginTypeAndSharingControls();
Expand Down
3 changes: 1 addition & 2 deletions apps/src/templates/manageStudents/ManageStudentsTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ export const studentSectionDataPropType = PropTypes.shape({
id: PropTypes.number.isRequired,
name: PropTypes.string,
username: PropTypes.string,
userType: PropTypes.string,
age: PropTypes.number,
gender: PropTypes.string,
secretWords: PropTypes.string,
secretPictureName: PropTypes.string,
secretPicturePath: PropTypes.string,
sectionId: PropTypes.number,
loginType: PropTypes.string,
});

/** @enum {number} */
Expand Down
6 changes: 3 additions & 3 deletions apps/src/templates/manageStudents/ShowSecret.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const styles = {
class ShowSecret extends Component {
static propTypes = {
initialIsShowing: PropTypes.bool,
secretWord: PropTypes.string.isRequired,
secretPicture: PropTypes.string.isRequired,
secretWord: PropTypes.string,
secretPicture: PropTypes.string,
resetSecret: PropTypes.func.isRequired,
loginType: PropTypes.string.isRequired,
};
Expand Down Expand Up @@ -56,7 +56,7 @@ class ShowSecret extends Component {
<p>{this.props.secretWord}</p>
}
{this.props.loginType === SectionLoginType.picture &&
<img src={this.props.secretPicture} style={styles.image} />
<img src={'/images/' + this.props.secretPicture} style={styles.image} />
}
<Button onClick={this.reset} color={Button.ButtonColor.blue} text={i18n.reset()} style={styles.reset} />
<Button onClick={this.hide} color={Button.ButtonColor.white} text={i18n.hideSecret()} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import teacherSections, {
import SyncOmniAuthSectionControl from '@cdo/apps/lib/ui/SyncOmniAuthSectionControl';
import LoginTypeParagraph from '@cdo/apps/templates/teacherDashboard/LoginTypeParagraph';
import SectionsSharingButton from '@cdo/apps/templates/teacherDashboard/SectionsSharingButton';
import ManageStudentsTable from '@cdo/apps/templates/manageStudents/ManageStudentsTable';

/**
* On the manage students tab of an oauth section, use React to render a button
Expand Down Expand Up @@ -69,6 +70,38 @@ export function renderLoginTypeAndSharingControls(sectionId) {
);
}

export function renderSectionTable(sectionId, loginType) {
const dataUrl = `/v2/sections/${sectionId}/students`;
const element = document.getElementById('student-table-react');

$.ajax({
method: 'GET',
url: dataUrl,
dataType: 'json'
}).done(studentData => {
studentData = studentData.map((student) => {
return {
id: student.id,
name: student.name,
username: student.username,
age: student.age,
gender: student.gender,
secretWords: student.secret_words,
secretPicturePath: student.secret_picture_path,
sectionId: sectionId,
loginType: loginType,
};
});
ReactDOM.render(
<ManageStudentsTable
studentData={studentData}
id={sectionId}
loginType={loginType}
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are going to be embedding loginType onto each student, should we just have ManageStudentsTable extract it from studentData (i.e. studentData[0].loginType) rather than also passing it in separately?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

then when we have zero students, we won't have information we need to display the table headers properly

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahhh. I wonder if the better option would be to have ManageStudentsTable own sticking loginType onto studentData?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about I only do a mapping once, and I just be really explicit about everything I need and what I want the names to be? See above

/>,
element);
});
}

export function unmountLoginTypeAndSharingControls() {
ReactDOM.unmountComponentAtNode(loginTypeControlsMountPoint());
ReactDOM.unmountComponentAtNode(shareSettingMountPoint());
Expand Down
2 changes: 2 additions & 0 deletions apps/src/util/experiments.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const STORAGE_KEY = 'experimentsList';
const GA_EVENT = 'experiments';
const EXPERIMENT_LIFESPAN_HOURS = 12;

experiments.MANAGE_STUDENTS = 'manageStudents';

/**
* Get our query string. Provided as a method so that tests can mock this.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
layout: none
theme: none
Expand Down Expand Up @@ -148,6 +147,8 @@ content-type: text/ng-template
%th.manage-th{style: "padding-top:5px;padding-bottom:5px; height:45px"}
%button.btn.btn-primary{"ng-click" => "save(section.students)", "ng-show" => "editingAny(section.students)", style: "float:left", "ng-disabled" => "allForm.$invalid"}= I18n.t('dashboard_action_save_all')

#student-table-react{'ng-init' => '$emit("student-table-react-rendered");'}

%div{"ng-if" => "section.login_type === 'picture' || section.login_type === 'word'"}
%h3{"ng-show" => 'section.students.length > 0'}
= I18n.t 'dashboard_students_share_section', section_code: '{{section.code}}', join_url: CDO.code_org_url('/join', 'http:')
Expand Down