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

New: added migration scripts (fixes #79) #80

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

chris-steele
Copy link

#79

New

  • added migration scripts

@chris-steele chris-steele marked this pull request as draft January 29, 2025 16:22
@chris-steele chris-steele marked this pull request as ready for review February 4, 2025 09:58
Copy link
Contributor

@joe-allen-89 joe-allen-89 left a comment

Choose a reason for hiding this comment

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

Cheers for this Chris. A few suggested changes/best practice bits most of which are in multiple places, I've not added a suggestion to each one but any questions give me a shout.

whereFromPlugin('Glossary - from v2.0.3', { name: 'adapt-contrib-glossary', version: '<2.1.0' });

whereContent('Glossary - where configured', async (content) => {
course = getCourse(content);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an advantage to moving this to a function? The common practice so far has been to keep the find function within the whereContent.

Best to use find rather than filter as we'll only have a single instance of course.

Suggested change
course = getCourse(content);
const course = content.find(({ _type }) => _type === 'course');

Copy link
Author

Choose a reason for hiding this comment

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

@joe-allen-89 I just moved it to a function as I use it several times.

migrations/v2.js Outdated

whereContent('Glossary - where configured', async (content) => {
course = getCourse(content);
if (course._glossary) return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify to the below?

Suggested change
if (course._glossary) return true;
return course._glossary;

migrations/v2.js Outdated
Comment on lines 49 to 53
courseGlossaryGlobals = getGlobals(content);
if (courseGlossaryGlobals) return true;
course._globals._extensions = course._globals._extensions || {};
courseGlossaryGlobals = course._globals._extensions._glossary = {};
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

course = content.find(({ _type }) => _type === 'course');
if (!_.has(course, '_globals._components._glossary')) _.set(course, '_globals._components._glossary', {});
courseGlossaryGlobals = course._globals._components._glossary;
return true;

Copy link
Author

Choose a reason for hiding this comment

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

Forgot to update this to use _.set and _.has

migrations/v2.js Outdated
});

checkContent('Glossary - check attribute clearSearch', async (content) => {
return course._glossary.clearSearch === '';
Copy link
Contributor

Choose a reason for hiding this comment

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

@chris-steele currently none of the checkContent functions have the throw Error included, think they'll need updating to do this by using the isValid/isInvalid that we've used in the other repos.

Suggested change
return course._glossary.clearSearch === '';
isValid = course._glossary.clearSearch === '';
if (!isValid) throw new Error('Glossary - clearSearch global attribute not found')
return

migrations/v3.js Outdated
return true;
});

mutateContent('Glossary - add new globals', async (content) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Whilst this does work, from a best practise perspective it would be better to split these up, so having a mutate and check for each attribute seperately. It does add to the code but it does make the logs much easier to read in case of an issue.

Comment on lines +45 to +47
if (course._glossary.description !== '') return true;
course._glossary.description = 'Select here to view the glossary for this course';
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Think we can condense this slightly, thoughts?

Suggested change
if (course._glossary.description !== '') return true;
course._glossary.description = 'Select here to view the glossary for this course';
return true;
if (course._glossary.description === '') course._glossary.description = 'Select here to view the glossary for this course';
return true;

migrations/v4.js Outdated

whereContent('Glossary has items', async content => {
course = getCourse(content);
return course._glossary?._items?.length > 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return course._glossary?._items?.length > 0;
return course._glossary?._items?.length;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs Reviewing
Development

Successfully merging this pull request may close these issues.

2 participants