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

Asset Support (WIP) #1349

Closed
wants to merge 7 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const searchAndSortHooks = () => {
};

export const filteredList = ({ searchString, imageList }) => (
imageList.filter(({ displayName }) => displayName?.toLowerCase().includes(searchString?.toLowerCase()))
imageList.filter(({ expandedPath }) => expandedPath?.toLowerCase().includes(searchString?.toLowerCase()))
);

export const displayList = ({ sortBy, searchString, images }) => (
Expand Down
9 changes: 7 additions & 2 deletions src/editors/sharedComponents/SelectionModal/GalleryCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {
Badge,
Image,
Truncate,

Check failure on line 7 in src/editors/sharedComponents/SelectionModal/GalleryCard.jsx

View workflow job for this annotation

GitHub Actions / tests (18)

'Truncate' is defined but never used

Check failure on line 7 in src/editors/sharedComponents/SelectionModal/GalleryCard.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

'Truncate' is defined but never used
} from '@openedx/paragon';
import { FormattedMessage, FormattedDate, FormattedTime } from '@edx/frontend-platform/i18n';

Expand Down Expand Up @@ -65,8 +65,12 @@
)}
</div>
<div className="card-text px-3 py-2" style={{ marginTop: '10px' }}>
<h3 className="text-primary-500">
<Truncate>{asset.displayName}</Truncate>
<h3 className="text-primary-500" style={{ wordBreak: "break-word"}}>

Check failure on line 68 in src/editors/sharedComponents/SelectionModal/GalleryCard.jsx

View workflow job for this annotation

GitHub Actions / tests (18)

Strings must use singlequote

Check failure on line 68 in src/editors/sharedComponents/SelectionModal/GalleryCard.jsx

View workflow job for this annotation

GitHub Actions / tests (18)

A space is required before '}'

Check failure on line 68 in src/editors/sharedComponents/SelectionModal/GalleryCard.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

Strings must use singlequote

Check failure on line 68 in src/editors/sharedComponents/SelectionModal/GalleryCard.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

A space is required before '}'
{/* We use "break-word" above and avoid <Truncate> because sometimes

Check failure on line 69 in src/editors/sharedComponents/SelectionModal/GalleryCard.jsx

View workflow job for this annotation

GitHub Actions / tests (18)

Expected indentation of 12 space characters but found 10

Check failure on line 69 in src/editors/sharedComponents/SelectionModal/GalleryCard.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

Expected indentation of 12 space characters but found 10
we're displaying an entire path and not just the file name, and we
don't want to cut out the last part of the path that has the
actual file name). */}
{asset.expandedPath}
</h3>
{ asset.transcripts && (
<div style={{ margin: '0 0 5px 0' }}>
Expand Down Expand Up @@ -97,6 +101,7 @@
asset: PropTypes.shape({
contentType: PropTypes.string,
displayName: PropTypes.string,
expandedPath: PropTypes.string,
externalUrl: PropTypes.string,
id: PropTypes.string,
dateAdded: PropTypes.oneOfType([PropTypes.number, PropTypes.instanceOf(Date)]),
Expand Down
32 changes: 20 additions & 12 deletions src/editors/sharedComponents/TinyMceWidget/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,27 @@
const isCorrectAssetFormat = assetSrc.startsWith('/asset') && assetSrc.match(/\/asset-v1:\S+[+]\S+[@]\S+[+]\S+[@]/g)?.length >= 1;
// assets in expandable text areas so not support relative urls so all assets must have the lms
// endpoint prepended to the relative url
if (editorType === 'expandable') {
if (isCorrectAssetFormat) {
staticFullUrl = `${lmsEndpointUrl}${assetSrc}`;
} else {
staticFullUrl = `${lmsEndpointUrl}${getRelativeUrl({ courseId: learningContextId, displayName })}`;
}
} else if (!isCorrectAssetFormat) {
staticFullUrl = getRelativeUrl({ courseId: learningContextId, displayName });
if (learningContextId.startsWith('lib:')) {
// We're basically disabling this whole substitution path when the Learning Context is a Library,
// because the code currently just doesn't handle it correctly. Libraries don't mangle the path
// into an asset key–it might be sufficient to remove the initial "/" in a "/static/images/foo.png"
// link, and then set the base URL to the correct ComponentVersion base.
}

Check failure on line 108 in src/editors/sharedComponents/TinyMceWidget/hooks.js

View workflow job for this annotation

GitHub Actions / tests (18)

Closing curly brace does not appear on the same line as the subsequent block

Check failure on line 108 in src/editors/sharedComponents/TinyMceWidget/hooks.js

View workflow job for this annotation

GitHub Actions / tests (20)

Closing curly brace does not appear on the same line as the subsequent block
if (staticFullUrl) {
const currentSrc = src.substring(0, src.indexOf('"'));
content = currentContent.replace(currentSrc, staticFullUrl);
hasChanges = true;
else {
if (editorType === 'expandable') {
if (isCorrectAssetFormat) {
staticFullUrl = `${lmsEndpointUrl}${assetSrc}`;
} else {
staticFullUrl = `${lmsEndpointUrl}${getRelativeUrl({ courseId: learningContextId, displayName })}`;
}
} else if (!isCorrectAssetFormat) {
staticFullUrl = getRelativeUrl({ courseId: learningContextId, displayName });
}
if (staticFullUrl) {
const currentSrc = src.substring(0, src.indexOf('"'));
content = currentContent.replace(currentSrc, staticFullUrl);
hasChanges = true;
}
}
});
if (hasChanges) { return content; }
Expand Down
4 changes: 2 additions & 2 deletions src/files-and-videos/files-page/FilesPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ const FilesPage = ({
const tableColumns = [
{ ...thumbnailColumn },
{
Header: 'File name',
accessor: 'displayName',
Header: 'File path',
accessor: 'expandedPath',
},
{ ...fileSizeColumn },
{
Expand Down
8 changes: 3 additions & 5 deletions src/files-and-videos/generic/DeleteConfirmationModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Button,
Collapsible,
Hyperlink,
Truncate,

Check failure on line 11 in src/files-and-videos/generic/DeleteConfirmationModal.jsx

View workflow job for this annotation

GitHub Actions / tests (18)

'Truncate' is defined but never used

Check failure on line 11 in src/files-and-videos/generic/DeleteConfirmationModal.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

'Truncate' is defined but never used
} from '@openedx/paragon';

import messages from './messages';
Expand All @@ -35,9 +35,7 @@
styling="basic"
title={(
<h3 className="h5 m-n2">
<Truncate lines={1}>
{original.displayName}
</Truncate>
{original.expandedPath}
</h3>
)}
data-testid={`collapsible-${original.id}`}
Expand All @@ -61,7 +59,7 @@
title={intl.formatMessage(
messages.deleteConfirmationTitle,
{
fileName: firstSelectedRow?.displayName,
fileName: firstSelectedRow?.expandedPath,
fileNumber: selectedRows.length,
fileType,
},
Expand All @@ -82,7 +80,7 @@
{intl.formatMessage(
messages.deleteConfirmationMessage,
{
fileName: firstSelectedRow?.displayName,
fileName: firstSelectedRow?.expandedPath,
fileNumber: selectedRows.length,
fileType,
},
Expand Down
4 changes: 2 additions & 2 deletions src/files-and-videos/generic/InfoModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

return (
<ModalDialog
title={file?.displayName}
title={file?.expandedPath}

Check failure on line 40 in src/files-and-videos/generic/InfoModal.jsx

View workflow job for this annotation

GitHub Actions / tests (18)

'file.expandedPath' is missing in props validation

Check failure on line 40 in src/files-and-videos/generic/InfoModal.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

'file.expandedPath' is missing in props validation
isOpen={isOpen}
onClose={onClose}
size="lg"
Expand All @@ -49,7 +49,7 @@
<ModalDialog.Title>
<div style={{ wordBreak: 'break-word' }}>
<Truncate lines={2} className="font-weight-bold small mt-3">
{file?.displayName}
{file?.expandedPath}

Check failure on line 52 in src/files-and-videos/generic/InfoModal.jsx

View workflow job for this annotation

GitHub Actions / tests (18)

'file.expandedPath' is missing in props validation

Check failure on line 52 in src/files-and-videos/generic/InfoModal.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

'file.expandedPath' is missing in props validation
</Truncate>
</div>
</ModalDialog.Title>
Expand Down
4 changes: 2 additions & 2 deletions src/library-authoring/LibraryBlock/LibraryBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface LibraryBlockProps {
const LibraryBlock = ({ onBlockNotification, usageKey }: LibraryBlockProps) => {
const iframeRef = useRef<HTMLIFrameElement>(null);
const [iFrameHeight, setIFrameHeight] = useState(600);
const lmsBaseUrl = getConfig().LMS_BASE_URL;
const studioBaseUrl = getConfig().STUDIO_BASE_URL;

const intl = useIntl();

Expand Down Expand Up @@ -74,7 +74,7 @@ const LibraryBlock = ({ onBlockNotification, usageKey }: LibraryBlockProps) => {
<iframe
ref={iframeRef}
title={intl.formatMessage(messages.iframeTitle)}
src={`${lmsBaseUrl}/xblocks/v2/${usageKey}/embed/student_view/`}
src={`${studioBaseUrl}/xblocks/v2/${usageKey}/embed/student_view/`}
data-testid="block-preview"
style={{
width: '100%',
Expand Down
Loading