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 program id retrieval when sharing #2061

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 15 additions & 31 deletions frontend/public/src/containers/pages/records/LearnerRecordsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,13 @@ export class LearnerRecordsPage extends React.Component<Props, State> {
isRevoking: false,
isEnablingSharing: false
}

getProgramId() {
return this.props.match.params.program.length !== 36
? this.props.match.params.program
: false
//when the record is in the shared view the program parameter is a 36 char UUID
isSharedRecordView() {
return this.props.match.params.program.length === 36
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add a comment indicating what the 36 number is and how it's used.

}

getOnlyProgramId() {
return parseInt(this.props.match.params.program.length)
getProgramId() {
return parseInt(this.props.match.params.program)
}

// Renders program's courses table.
Expand Down Expand Up @@ -306,18 +304,12 @@ export class LearnerRecordsPage extends React.Component<Props, State> {
async onEnableRecordSharing() {
const { enableRecordSharing, addUserNotification } = this.props

this.setState({ isEnablingSharing: true })

const programId = this.getProgramId()

if (programId === null) {
if (this.props.match.params.program === null) {
return
}
this.setState({ isEnablingSharing: true })

const sharingResponse = await enableRecordSharing(
this.getOnlyProgramId(),
null
)
const sharingResponse = await enableRecordSharing(this.getProgramId(), null)

this.setState({ isEnablingSharing: false })

Expand All @@ -340,16 +332,13 @@ export class LearnerRecordsPage extends React.Component<Props, State> {
async onSubmitPartnerSchoolShare(values: any) {
const { enableRecordSharing, addUserNotification } = this.props

this.setState({ isEnablingSharing: true })

const programId = this.getProgramId()

if (programId === null) {
if (this.props.match.params.program === null) {
return
}
this.setState({ isEnablingSharing: true })

const sharingResponse = await enableRecordSharing(
this.getOnlyProgramId(),
this.getProgramId(),
values.partnerSchool
)

Expand Down Expand Up @@ -401,15 +390,12 @@ export class LearnerRecordsPage extends React.Component<Props, State> {
async onRevokeSharing() {
const { revokeRecordSharing, addUserNotification } = this.props

this.setState({ isRevoking: true })

const programId = this.getProgramId()

if (programId === null) {
if (this.props.match.params.program === null) {
return
}
this.setState({ isRevoking: true })

const sharingResponse = await revokeRecordSharing(this.getOnlyProgramId())
const sharingResponse = await revokeRecordSharing(this.getProgramId())

this.setState({ isRevoking: false })

Expand Down Expand Up @@ -587,16 +573,14 @@ export class LearnerRecordsPage extends React.Component<Props, State> {
render() {
const { learnerRecord, isLoading } = this.props
const { isRevoking, isEnablingSharing } = this.state

const isSharedRecord = this.getProgramId() ? true : false
const hasSharingEnabled = this.hasSharingEnabled(learnerRecord)

return (
<DocumentTitle title={`${SETTINGS.site_name} | ${RECORDS_PAGE_TITLE}`}>
<Loader isLoading={isLoading}>
<div className="std-page-body container">
<div className="d-flex flex-row-reverse mb-4">
{isSharedRecord ? (
{!this.isSharedRecordView() ? (
<div className="d-flex learner-record-sharing-controls mb-2">
{!hasSharingEnabled ? (
<button
Expand Down
Loading