StudentContextCardTrigger.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (C) 2016 - present Instructure, Inc.
  3. *
  4. * This file is part of Canvas.
  5. *
  6. * Canvas is free software: you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License as published by the Free
  8. * Software Foundation, version 3 of the License.
  9. *
  10. * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. * details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. import $ from 'jquery'
  19. import React from 'react'
  20. import ReactDOM from 'react-dom'
  21. import GraphQLStudentContextTray from 'jsx/context_cards/GraphQLStudentContextTray'
  22. import RestStudentContextTray from 'jsx/context_cards/RestStudentContextTray'
  23. const StudentContextTray = ENV.GRAPHQL_ENABLED
  24. ? GraphQLStudentContextTray
  25. : RestStudentContextTray;
  26. const handleClickEvent = (event) => {
  27. const studentId = $(event.target).attr('data-student_id');
  28. const courseId = $(event.target).attr('data-course_id');
  29. if (ENV.STUDENT_CONTEXT_CARDS_ENABLED && studentId && courseId) {
  30. event.preventDefault();
  31. const container = document.getElementById('StudentTray__Container')
  32. const returnFocusToHandler = () => {
  33. const focusableItems = [$(event.target)];
  34. if ($('.search-query')) {
  35. focusableItems.push($('.search-query'))
  36. }
  37. if ($('[name="search_term"]')) {
  38. focusableItems.push($('[name="search_term"]'))
  39. }
  40. return focusableItems;
  41. }
  42. ReactDOM.render(
  43. <StudentContextTray
  44. key={`student_context_card_${courseId}_${studentId}`}
  45. courseId={courseId}
  46. studentId={studentId}
  47. returnFocusTo={returnFocusToHandler}
  48. />, container
  49. )
  50. }
  51. }
  52. $(document).on('click', '.student_context_card_trigger', handleClickEvent);
  53. export default handleClickEvent;