-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Optimize collections listing [PT-185588012]
This change is to optimize the materials collection rendering when used on large collection pages like the NGSS Assessment Portal. Here are the changes that were made: - Styled Landing page content html textarea on the projects admin page to be full width, and taller and to use a monospace font. Previously it was a standard unstyled textarea. This just makes viewing and editing it easier. - Added optional opacity animation setting to existing cleanUpAssignViewAdjustment function in langing_page.html.haml. This was a request to ensure the content was visible when the each NGSS content area was revealed. - Added a public loadMaterialsCollections() method which caches the results for later use in renderMaterialsCollection(). The api endpoint already supported getting multiple collections. - Fixes a race condition between the MaterialsCollection onDataLoad callback prop and the initial mount of the component. The existing code in the project landing pages assumes the component is mounted.
- Loading branch information
1 parent
841a09c
commit d88984e
Showing
7 changed files
with
101 additions
and
49 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
react-components/src/library/helpers/materials-collection-cache.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const cache = {} | ||
|
||
export const loadMaterialsCollections = (ids, callback) => { | ||
const onComplete = () => { | ||
const data = ids.map(id => cache[id] || { name: 'MISSING-COLLECTION-' + id, materials: [] }) | ||
callback(data) | ||
} | ||
|
||
// ensure we only request each id once | ||
const missingIds = ids.filter(id => !cache[id]) | ||
if (missingIds.length === 0) { | ||
onComplete() | ||
return | ||
} | ||
|
||
jQuery.ajax({ | ||
url: Portal.API_V1.MATERIALS_BIN_COLLECTIONS, | ||
data: { | ||
id: missingIds, | ||
skip_lightbox_reloads: true | ||
}, | ||
dataType: 'json', | ||
success: (missingData) => { | ||
missingIds.forEach((id, index) => { | ||
cache[id] = missingData[index] | ||
}) | ||
}, | ||
complete: () => { | ||
onComplete() | ||
} | ||
}) | ||
} | ||
|
||
export const loadMaterialsCollection = (id, callback) => { | ||
loadMaterialsCollections([id], (data) => { | ||
callback(data[0]) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters