Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 7 additions & 5 deletions app/components/AssetAttributes/AssetAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ const assetAttributes = (props) => {

const applicableAttributes = configuration
.map((a) => {
// If the asset doesn't have a content type (needed for attribute detection),
// or the attribute doesn't apply to this asset, skip it
if (asset.contentTypes == null ||
(!a.appliesTo.includes('*') && !a.appliesTo.some((x) => asset.contentTypes.includes(x)))) {
return null;
const appliesToAll = a.appliesTo.includes('*');
// If the attribute doesn't apply to everything, we need to check the content type.
// If the asset has no content type, or its content types don't match our allowed ones, skip it.
if (!appliesToAll) {
if (asset.contentTypes == null || !a.appliesTo.some((x) => asset.contentTypes.includes(x))) {
return null;
}
}
return a;
})
Expand Down
42 changes: 20 additions & 22 deletions app/components/AssetDetails/AssetDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import AssetAttributes from '../AssetAttributes/AssetAttributes';
import NoteEditor from '../NoteEditor/NoteEditor';
import Loading from '../Loading/Loading';
import AssetUtil from '../../utils/asset';
import SourceControlHistory from '../SourceControlHistory/SourceControlHistory';
import styles from './AssetDetails.css';
import { styled } from '@mui/material/styles';
Expand Down Expand Up @@ -93,7 +94,7 @@ const assetDetails = (props) => {
}
};

const isExternalAsset = asset && asset.type === Constants.AssetType.URL;
const isExternalAsset = AssetUtil.isExternalAsset(asset);

let sourceControlAccordion = null;
if (!isExternalAsset && sourceControlEnabled) {
Expand All @@ -115,27 +116,24 @@ const assetDetails = (props) => {
);
}

let attributesAccordion = null;
if (!isExternalAsset) {
attributesAccordion = (
<Accordion defaultExpanded>
<CustomAccordionSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="attributes-content"
id="attributes-header"
>
<Typography className={styles.headingTitle}>Attributes</Typography>
</CustomAccordionSummary>
<AccordionDetails className={styles.details}>
<AssetAttributes
asset={asset}
configuration={assetAttributes}
onUpdateAttribute={updateAssetAttribute}
/>
</AccordionDetails>
</Accordion>
);
}
let attributesAccordion = (
<Accordion defaultExpanded>
<CustomAccordionSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="attributes-content"
id="attributes-header"
>
<Typography className={styles.headingTitle}>Attributes</Typography>
</CustomAccordionSummary>
<AccordionDetails className={styles.details}>
<AssetAttributes
asset={asset}
configuration={assetAttributes}
onUpdateAttribute={updateAssetAttribute}
/>
</AccordionDetails>
</Accordion>
);

let actions = null;
if (isExternalAsset) {
Expand Down
7 changes: 4 additions & 3 deletions app/components/AssetTree/AssetNode/AssetNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ function AssetNode(props) {
}}
>
<NodeIcon onClick={() => onToggle(node)}>
{node.type === Constants.AssetType.DIRECTORY &&
{(node.type === Constants.AssetType.DIRECTORY || node.type === Constants.AssetType.FOLDER) &&
(isOpen ? <FaChevronDown /> : <FaChevronRight />)}
</NodeIcon>
{checkbox}
<NodeIcon $marginright={10}>
{node.type === Constants.AssetType.FILE && (!node.attributes || !node.attributes.entrypoint) && <FaFile />}
{node.type === Constants.AssetType.FILE && node.attributes && node.attributes.entrypoint && <FaFileImport />}
{node.type === Constants.AssetType.DIRECTORY && isOpen === true && <FaFolderOpen />}
{node.type === Constants.AssetType.DIRECTORY && !isOpen && <FaFolder />}
{(node.type === Constants.AssetType.DIRECTORY || node.type === Constants.AssetType.FOLDER) && isOpen === true && <FaFolderOpen />}
{(node.type === Constants.AssetType.DIRECTORY || node.type === Constants.AssetType.FOLDER) && !isOpen && <FaFolder />}
{node.type === Constants.AssetType.ASSET_GROUP && <FaPaperclip />}
{node.type === Constants.AssetType.FILTER && <FaFilter />}
{node.type === Constants.AssetType.URL && <FaGlobe />}
Expand All @@ -141,6 +141,7 @@ function AssetNode(props) {
<StyledLabel role="button">{AssetUtil.getAssetNameForTree(node)}</StyledLabel>
</StyledTreeNode>


{isOpen &&
(!node.children
? null
Expand Down
2 changes: 1 addition & 1 deletion app/components/AssetTree/AssetTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class AssetTree extends Component {
// node - the node to try and add (will only be added if a directory)
// expandedNodes - the collection of URIs of expanded nodes
setNodeExpanded = (node, expandedNodes) => {
if (node.type === Constants.AssetType.DIRECTORY) {
if (node.type === Constants.AssetType.DIRECTORY || node.type === Constants.AssetType.FOLDER) {
expandedNodes.push(node.uri);
if (node.children) {
node.children.forEach((x) => this.setNodeExpanded(x, expandedNodes));
Expand Down
26 changes: 21 additions & 5 deletions app/components/Project/Assets/Assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,14 @@ const assetsComponent = (props) => {
// in that case.
useEffect(() => {
// Get a more recent copy of the asset from the updated project
if (project && project.assets && selectedAsset) {
const updatedAsset = AssetUtil.findDescendantAssetByUri(project.assets, selectedAsset.uri);
if (project && selectedAsset) {
let updatedAsset = null;
if (project.assets) {
updatedAsset = AssetUtil.findDescendantAssetByUri(project.assets, selectedAsset.uri);
}
if (!updatedAsset && project.externalAssets) {
updatedAsset = AssetUtil.findDescendantAssetByUri(project.externalAssets, selectedAsset.uri);
}
setSelectedAsset(updatedAsset);
if (onSelectedAsset) {
onSelectedAsset(updatedAsset);
Expand All @@ -112,19 +118,21 @@ const assetsComponent = (props) => {
setCurrentAssetGroup(null);
setGroupedAssets(null);
setFilterEnabled(true);
setExternalAssets(project.externalAssets ? project.externalAssets : AssetUtil.createEmptyExternalAssets());
setExternalAssets(project.externalAssets ? ProjectUtil._filterAssets(project.externalAssets, null) : AssetUtil.createEmptyExternalAssets());
}, [project]);

// Whenever the filter changes, update the list of assets to include only
// those that should be displayed.
const handleFilterChanged = (updatedFilter) => {
setFilter(updatedFilter);
setAssets(ProjectUtil.filterProjectAssets(project, updatedFilter));
setExternalAssets(project.externalAssets ? ProjectUtil._filterAssets(project.externalAssets, updatedFilter) : AssetUtil.createEmptyExternalAssets());
};

const handleFilterReset = () => {
setFilter(resetFilter(project));
setAssets(ProjectUtil.filterProjectAssets(project, null));
setExternalAssets(project.externalAssets ? ProjectUtil._filterAssets(project.externalAssets, null) : AssetUtil.createEmptyExternalAssets());
};

// When the user triggers saving an Asset Group, update the UI so the dialog
Expand Down Expand Up @@ -292,8 +300,14 @@ const assetsComponent = (props) => {
// The extra logic we use here is to enrich the selected asset, if it's missing some key
// information. The key thing we have right now is if it's missing the 'contentTypes' attribute.
if (asset && (asset.contentTypes === null || asset.contentTypes === undefined)) {
if (project && project.assets) {
const foundAsset = AssetUtil.findDescendantAssetByUri(project.assets, asset.uri);
if (project) {
let foundAsset = null;
if (project.assets) {
foundAsset = AssetUtil.findDescendantAssetByUri(project.assets, asset.uri);
}
if (!foundAsset && project.externalAssets) {
foundAsset = AssetUtil.findDescendantAssetByUri(project.externalAssets, asset.uri);
}
if (foundAsset !== null) {
asset = foundAsset;
}
Expand Down Expand Up @@ -474,6 +488,8 @@ const assetsComponent = (props) => {
onSave={handleSavedExternalAsset}
uri={editableExternalAsset ? editableExternalAsset.uri : ''}
name={editableExternalAsset ? editableExternalAsset.name : ''}
type={editableExternalAsset ? editableExternalAsset.type : Constants.AssetType.URL}
isNew={!editableExternalAsset}
/>
</>
);
Expand Down
25 changes: 20 additions & 5 deletions app/components/Project/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class Project extends Component<Props> {
let assetsCopy = null;
// Depending on if this is a core asset or an external asset, we need to select the correct container. The rest of
// the code will work the same.
const isExternalAsset = (asset.type === AssetType.URL);
const isExternalAsset = AssetUtil.isExternalAsset(asset);
if (isExternalAsset) {
assetsCopy = { ...project.externalAssets };
} else {
Expand Down Expand Up @@ -367,7 +367,16 @@ class Project extends Component<Props> {
*/
assetUpdateAttributeHandler = (asset, name, value) => {
const project = { ...this.props.project };
const assetsCopy = { ...project.assets };

// Depending on if this is an external asset or a main asset, determine the right collection
// of assets to use.
let assetsCopy = null;
const isExternalAsset = AssetUtil.isExternalAsset(asset);
if (isExternalAsset) {
assetsCopy = { ...project.externalAssets };
} else {
assetsCopy = { ...project.assets };
}

const existingAsset = AssetUtil.findDescendantAssetByUri(assetsCopy, asset.uri);
let actionDescription = '';
Expand All @@ -382,12 +391,18 @@ class Project extends Component<Props> {
}

existingAsset.attributes[name] = value;
project.assets = assetsCopy;

if (isExternalAsset) {
project.externalAssets = assetsCopy;
} else {
project.assets = assetsCopy;
}

if (this.props.onUpdated) {
this.props.onUpdated(
project,
ActionType.ATTRIBUTE_UPDATED,
EntityType.ASSET,
isExternalAsset ? EntityType.EXTERNAL_ASSET : EntityType.ASSET,
asset.uri,
`Asset ${ActionType.ATTRIBUTE_UPDATED}`,
actionDescription,
Expand All @@ -409,7 +424,7 @@ class Project extends Component<Props> {
// Depending on if this is an external asset or a main asset, determine the right collection
// of assets to use.
let assetsCopy = null;
const isExternalAsset = (asset.type === AssetType.URL);
const isExternalAsset = AssetUtil.isExternalAsset(asset);
if (isExternalAsset) {
assetsCopy = { ...project.externalAssets };
} else {
Expand Down
62 changes: 31 additions & 31 deletions app/components/ReproChecklist/ChecklistItem/ChecklistItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function ChecklistItem(props) {
Constants.ActionType.CHECKLIST_UPDATED,
Constants.ActionType.CHECKLIST_UPDATED,
`Set "${updatedItem.statement}" to "${formatYesNo(newValue)}"`,
{oldValue: formatYesNo(item.Value), newValue: formatYesNo(newValue)}
{ oldValue: formatYesNo(item.Value), newValue: formatYesNo(newValue) }
);
};

Expand Down Expand Up @@ -141,7 +141,7 @@ function ChecklistItem(props) {
Constants.ActionType.CHECKLIST_UPDATED,
Constants.ActionType.CHECKLIST_UPDATED,
`Set sub-item ${subCheck.id} of ${updatedItem.statement} to "Yes"`,
{oldValue: 'No', newValue: 'Yes'}
{ oldValue: 'No', newValue: 'Yes' }
);
};

Expand All @@ -154,8 +154,8 @@ function ChecklistItem(props) {
}

if (asset && asset.uri) {
if (asset.type === Constants.AssetType.URL) {
setAssetTitle(asset.name);
if (AssetUtil.isExternalAsset(asset)) {
setAssetTitle(asset.name ? asset.name : asset.uri);
} else {
const fileName = AssetUtil.getAssetNameFromUri(asset.uri);
setAssetTitle(fileName);
Expand Down Expand Up @@ -207,10 +207,10 @@ function ChecklistItem(props) {

const formatDisplayLink = (asset) => {
if (asset.isExternalAsset) {
return(<a href={asset.uri} target="">{asset.uri}</a>);
return (<a href={asset.uri} target="">{asset.uri}</a>);
}
//return (<div>{AssetUtil.absoluteToRelativePath(project.path, asset)}</div>);
return(<a href={`file://${asset.uri}`} target="">{AssetUtil.absoluteToRelativePath(project.path, asset)}</a>);
return (<a href={`file://${asset.uri}`} target="">{AssetUtil.absoluteToRelativePath(project.path, asset)}</a>);
};

const handleCopy = (uri) => {
Expand Down Expand Up @@ -321,33 +321,33 @@ function ChecklistItem(props) {
<div className={styles.assetContent}>
<table className={styles.assets}>
<tbody>
{item.assets.map((asset) => (
<tr key={asset.uri}>
<td className={styles.detailsCol}>
<div className={styles.assetName}>{asset.name}</div>
<div className={styles.assetLink}>{formatDisplayLink(asset)}</div>
<div className={styles.assetDescription}>{asset.description}</div>
</td>
<td className={styles.actionCol}>
{copiedAsset === asset.uri ? (
<Done className={styles.doneButton} />
) : (
<Tooltip title="Copy asset link/URL" enterDelay={300}>
<ContentCopy
className={styles.copyButton}
onClick={() => handleCopy(asset.uri)}
{item.assets.map((asset) => (
<tr key={asset.uri}>
<td className={styles.detailsCol}>
<div className={styles.assetName}>{asset.name}</div>
<div className={styles.assetLink}>{formatDisplayLink(asset)}</div>
<div className={styles.assetDescription}>{asset.description}</div>
</td>
<td className={styles.actionCol}>
{copiedAsset === asset.uri ? (
<Done className={styles.doneButton} />
) : (
<Tooltip title="Copy asset link/URL" enterDelay={300}>
<ContentCopy
className={styles.copyButton}
onClick={() => handleCopy(asset.uri)}
/>
</Tooltip>
)}
<Tooltip title="Remove asset reference" enterDelay={300}>
<Delete
className={styles.delButton}
onClick={() => handleDeleteAsset(asset.uri)}
/>
</Tooltip>
)}
<Tooltip title="Remove asset reference" enterDelay={300}>
<Delete
className={styles.delButton}
onClick={() => handleDeleteAsset(asset.uri)}
/>
</Tooltip>
</td>
</tr>
))}
</td>
</tr>
))}
</tbody>
</table>
</div>
Expand Down
Loading