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

KUI-1523: fix 'undefined' course title in sub header #394

Merged
merged 10 commits into from
Dec 5, 2024

Conversation

axelbjo
Copy link
Contributor

@axelbjo axelbjo commented Oct 30, 2024

  • Handled correct mapping of credits and title for course title
  • Updated tests

@axelbjo axelbjo requested a review from belanglos as a code owner October 30, 2024 12:56
@axelbjo axelbjo requested a review from a user October 30, 2024 12:56
public/js/app/util/helpers.js Outdated Show resolved Hide resolved
public/js/app/pages/MemoEditingContainer.jsx Outdated Show resolved Hide resolved
public/js/app/util/__test__/helpers.test.js Show resolved Hide resolved
Copy link
Contributor

@amirhossein-haerian amirhossein-haerian left a comment

Choose a reason for hiding this comment

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

LGTM, I agree with Karl comments as well

@ghost
Copy link

ghost commented Nov 1, 2024

I've tested this and noticed that we made mistakes regarding languages earlier in the upl-main branch. So I think we need to take a steg back and fix that first.

We need to use memo language and user language in the correct places. First I noticed that the language of the title of the memo always will be created based on user language and not memo as in ref (might be introduced in this PR or earlier). And then I noticed that some content has incorrect language as well (not introduced in this PR).

Feels like the code is very confusing about this from before, so my suggestion is that we look at this with together next week and try fix it and refactor it to make it more clear.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

See comment above

@axelbjo
Copy link
Contributor Author

axelbjo commented Nov 18, 2024

Made it so that memo language is always used for fetching data. That seems to give the correct behaviour when I test it.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

I found a bug where a memo get wrong language, see my new comment in ladokApi.js.

I have not looked into the tests in details, but as I wrote in the other PR they needs to be fixed (or removed if not useful anymore)

Comment on lines 35 to 43
// test('combine course name for an object from a course rounds information endpoint in Swedish', () => {
// const courseTitle = combinedCourseName('ALLLLL', courseTypeTwo.course, 'sv')
// expect(courseTitle).toBe('ALLLLL Tillämpad programmering och datalogi 9.0 hp')
// })

test('combine course name for an object from a course rounds endpoint in English', () => {
const courseTitle = combinedCourseName('ALLLLL', courseTypeTwo.course, 'en')
expect(courseTitle).toBe('ALLLLL Applied Programming and Computer Science 9.0 credits')
})
// test('combine course name for an object from a course rounds endpoint in English', () => {
// const courseTitle = combinedCourseName('ALLLLL', courseTypeTwo.course, 'en')
// expect(courseTitle).toBe('ALLLLL Applied Programming and Computer Science 9.0 credits')
// })
Copy link

Choose a reason for hiding this comment

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

Fix test?

Comment on lines 30 to 32
sv: round.undervisningssprak ? round.undervisningssprak.name : '',
en: round.undervisningssprak ? round.undervisningssprak.nameOther : '',
},
Copy link

Choose a reason for hiding this comment

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

My memo gets wrong language if I create a new memo for a course in Swedish using English as user language.
The reason is that in _roundsCommonLanguages we are checking if language.en is "Swedish" to determine with memoLang to create the memo with (but it will be "Svenska" now).

To fix this with current setup, you could to something like this:

      language: {
        sv: (lang === 'sv' ? round.undervisningssprak?.name : round.undervisningssprak?.nameOther) ?? '',
        en: (lang === 'en' ? round.undervisningssprak?.name : round.undervisningssprak?.nameOther) ?? '',
      },

BUT I think it would be better to just set the language abbrev/code as property here instead, and then just use that one as is in the frontend to avoid these problem. Not sure, but maybe you still need to language string as well in other places? But I would suggestion moving from comparing with name anyway.

Note that the code in Ladok and our code isn't the same format ("sv" vs "SWE").

Suggested change
sv: round.undervisningssprak ? round.undervisningssprak.name : '',
en: round.undervisningssprak ? round.undervisningssprak.nameOther : '',
},
code: round.undervisningssprak.code === 'SWE' ? 'sv' : 'en'
sv: (lang === 'sv' ? round.undervisningssprak?.name : round.undervisningssprak?.nameOther) ?? '',
en: (lang === 'en' ? round.undervisningssprak?.name : round.undervisningssprak?.nameOther) ?? '',
},

Or maybe both language isn't needed, so that it could be like this?

Suggested change
sv: round.undervisningssprak ? round.undervisningssprak.name : '',
en: round.undervisningssprak ? round.undervisningssprak.nameOther : '',
},
name: round.undervisningssprak?.name ?? '',
code: round.undervisningssprak.code === 'SWE' ? 'sv' : 'en'
},

Comment on lines 54 to 61
// TODO: this test currently fails because the ladok data already has the correct translation once it's fetched

// test('renders main subheader, course name. English.', () => {
// render(<ChangedPublishedEmpty langAbbr="en" langIndex={0} />)
// const headers = getAllByRole('heading', { level: 1 })
// expect(headers.length).toBe(1)
// expect(headers[0]).toHaveTextContent('Edit published course memoEF1111 Project in Plasma Physics 9.0 credits')
// })
Copy link

Choose a reason for hiding this comment

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

Fix test?

Comment on lines 51 to 58
// TODO: this test currently fails because the ladok data already has the correct translation once it's fetched

// test('renders main subheader, course name. English.', () => {
// render(<CreateNewMemoPage langAbbr="en" langIndex={0} />)
// const headers = screen.getAllByRole('heading', { level: 1 })
// expect(headers.length).toBe(1)
// expect(headers[0]).toHaveTextContent('EF1111 Project in Plasma Physics 9.0 credits')
// })
Copy link

Choose a reason for hiding this comment

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

Fix test?

Comment on lines 33 to 35
campus: {
sv: round.studieort ? round.studieort.name : '',
en: round.studieort ? round.studieort.nameOther : '',
Copy link

Choose a reason for hiding this comment

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

Same thing with language and "other" here, but I can't see that campus is used anywhere, so maybe it can be removed instead of fixed.

@axelbjo axelbjo merged commit 332f0dc into upl-main Dec 5, 2024
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.

2 participants