Skip to content

Commit

Permalink
Merge pull request #200 from AdiAkhileshSingh15/projentryptfeat
Browse files Browse the repository at this point in the history
[FIX] : Fixes the entrypoint component bugs 🐛
  • Loading branch information
lrasmus authored Apr 3, 2024
2 parents 38cf7c6 + 90c62f7 commit 58280d3
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 39 deletions.
1 change: 1 addition & 0 deletions app/components/AssetDetails/AssetDetails.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
}

.title {
margin-top: 10px;
margin-bottom: 10px;
white-space: nowrap;
overflow: hidden;
Expand Down
9 changes: 0 additions & 9 deletions app/components/Project/Assets/Assets.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@
margin: 5px;
}

.title {
margin-bottom: 10px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
font-size: 0.8em;
font-weight: bold;
}

.tree {
width: 50%;
margin: 0;
Expand Down
3 changes: 1 addition & 2 deletions app/components/Project/Assets/Assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ const assetsComponent = (props) => {
disabled={mode === 'paperclip'}
aria-label="group assets together"
>
<FaPlusSquare fontSize="small" /> &nbsp; New Group
<FaPlusSquare fontSize="small" /> &nbsp;New Group
</IconButton>
<EditableSelect
title="Select group"
Expand All @@ -406,7 +406,6 @@ const assetsComponent = (props) => {
/>
</div>
<div className={styles.details}>
<div className={styles.title}>{project.path}</div>
<ProjectEntryPoint
assets={assets}
rootUri={project.path}
Expand Down
9 changes: 9 additions & 0 deletions app/components/ProjectEntryPoint/ProjectEntryPoint.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
margin-top: 10px;
}

.title {
margin-bottom: 10px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
font-size: 0.8em;
font-weight: bold;
}

.heading {
background-color: #eee !important;
padding: 0 5px !important;
Expand Down
8 changes: 5 additions & 3 deletions app/components/ProjectEntryPoint/ProjectEntryPoint.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import path from 'path';
import { Accordion, AccordionDetails, AccordionSummary, Button, Typography } from '@mui/material';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
Expand Down Expand Up @@ -39,6 +40,7 @@ const projectEntryPoint = (props) => {
return (
// eslint-disable-next-line react/jsx-filename-extension
<div className={styles.container}>
<div className={styles.title}>{rootUri}</div>
<Accordion defaultExpanded>
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
Expand All @@ -51,10 +53,10 @@ const projectEntryPoint = (props) => {
<AccordionDetails className={styles.details}>
<ul className={styles.entryPointList} type="disc">
{entryPointsList.map((asset) => {
const fileName = asset.uri.split('/').pop();
let folder = asset.uri.replace(`${rootUri}/`, '').split('/')[0];
const fileName = asset.uri.split(path.sep).pop();
let folder = asset.uri.replace(`${rootUri}${path.sep}`, '').split(path.sep)[0];
if (folder === fileName) {
folder = rootUri.split('/').pop();
folder = rootUri.split(path.sep).pop();
}
return (
<li key={asset.uri} className={styles.entryPointItem}>
Expand Down
14 changes: 7 additions & 7 deletions app/utils/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ export default class AssetUtil {
const descendantsList = [];
// check if the asset uri has a descendant root uri in it
if (assetUri && rootUri && assetUri.includes(rootUri) && assetUri.indexOf(rootUri) === 0) {
// just loop through the asset uri and break it apart at each '/' and add to the list till we get to the root uri
while (assetUri !== rootUri && assetUri !== '') {
const lastSlash = assetUri.lastIndexOf('/');
// If we can't find a slash, we can't go any further
if (lastSlash === -1) {
// just loop through the asset uri and break it apart at each separator and add to the list till we get to the root uri
while (assetUri !== rootUri) {
const lastSep = assetUri.lastIndexOf(path.sep);
// If we can't find a separator, we can't go any further
if (lastSep === -1) {
break;
}
// Update the variable instead of modifying the function parameter directly
// eslint-disable-next-line no-param-reassign
assetUri = assetUri.substring(0, lastSlash);
assetUri = assetUri.substring(0, lastSep);
// Add the asset uri to the list
if (assetUri) {
if (assetUri !== rootUri.substring(0, rootUri.indexOf(path.sep))) {
descendantsList.push(assetUri);
}
}
Expand Down
93 changes: 75 additions & 18 deletions test/utils/asset.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,34 +363,91 @@ describe('services', () => {
});

describe('findAllDescendantAssetsByUri', () => {
it('should return an empty array if the asset URI is not specified', () => {
it.skipWindows('should return an empty array if the asset URI is not specified', () => {
expect(AssetUtil.findAllDescendantAssetsByUri(null, '/Test')).toBeArrayOfSize(0);
expect(AssetUtil.findAllDescendantAssetsByUri(undefined, '/Test')).toBeArrayOfSize(0);
});
it('should return an empty array if the root URI is not specified', () => {
it.skipWindows('should return an empty array if the root URI is not specified', () => {
expect(AssetUtil.findAllDescendantAssetsByUri('/Test', null)).toBeArrayOfSize(0);
expect(AssetUtil.findAllDescendantAssetsByUri('/Test', undefined)).toBeArrayOfSize(0);
});
it('should return an empty array if the asset URI and root URI are the same', () => {
expect(
AssetUtil.findAllDescendantAssetsByUri('/Test/Child', '/Test/Child'),
).toBeArrayOfSize(0);
});
it('should return an empty array if the asset URI is not a descendant of the root URI', () => {
expect(AssetUtil.findAllDescendantAssetsByUri('/Test', '/Other')).toBeArrayOfSize(0);
it.skipWindows(
'should return an empty array if the asset URI and root URI are the same',
() => {
expect(
AssetUtil.findAllDescendantAssetsByUri('/Test/Child', '/Test/Child'),
).toBeArrayOfSize(0);
},
);
it.skipWindows(
'should return an empty array if the asset URI is not a descendant of the root URI',
() => {
expect(AssetUtil.findAllDescendantAssetsByUri('/Test', '/Other')).toBeArrayOfSize(0);
},
);
it.skipWindows(
'should return an array containing all descendant URIs up to the root URI',
() => {
expect(AssetUtil.findAllDescendantAssetsByUri('/Test/Child1/Child2', '/Test')).toEqual([
'/Test/Child1',
'/Test',
]);
},
);
it.skipWindows('should return an empty array if the asset URI is a filename', () => {
expect(AssetUtil.findAllDescendantAssetsByUri('/Test', '/')).toBeArrayOfSize(0);
});
it('should return an array containing all descendant URIs up to the root URI', () => {
expect(AssetUtil.findAllDescendantAssetsByUri('/Test/Child1/Child2', '/Test')).toEqual([
'/Test/Child1',
'/Test',
]);
it.skipWindows(
'should return an empty array if the asset URI contains root URI but not as a prefix',
() => {
expect(AssetUtil.findAllDescendantAssetsByUri('/Test/Rt/Child', '/Rt')).toBeArrayOfSize(
0,
);
},
);
it.onWindows('should return an empty array if the asset URI is not specified', () => {
expect(AssetUtil.findAllDescendantAssetsByUri(null, 'C:\\Test')).toBeArrayOfSize(0);
expect(AssetUtil.findAllDescendantAssetsByUri(undefined, 'C:\\Test')).toBeArrayOfSize(0);
});
it('should return an empty array if the asset URI is a filename', () => {
expect(AssetUtil.findAllDescendantAssetsByUri('/Test', '/')).toBeArrayOfSize(0);
it.onWindows('should return an empty array if the root URI is not specified', () => {
expect(AssetUtil.findAllDescendantAssetsByUri('C:\\Test', null)).toBeArrayOfSize(0);
expect(AssetUtil.findAllDescendantAssetsByUri('C:\\Test', undefined)).toBeArrayOfSize(0);
});
it('should return an empty array if the asset URI contains root URI but not as a prefix', () => {
expect(AssetUtil.findAllDescendantAssetsByUri('/Test/Rt/Child', '/Rt')).toBeArrayOfSize(0);
it.onWindows(
'should return an empty array if the asset URI and root URI are the same',
() => {
expect(
AssetUtil.findAllDescendantAssetsByUri('C:\\Test\\Child', 'C:\\Test\\Child'),
).toBeArrayOfSize(0);
},
);
it.onWindows(
'should return an empty array if the asset URI is not a descendant of the root URI',
() => {
expect(AssetUtil.findAllDescendantAssetsByUri('C:\\Test', 'C:\\Other')).toBeArrayOfSize(
0,
);
},
);
it.onWindows(
'should return an array containing all descendant URIs up to the root URI',
() => {
expect(
AssetUtil.findAllDescendantAssetsByUri('C:\\Test\\Child1\\Child2', 'C:\\Test'),
).toEqual(['C:\\Test\\Child1', 'C:\\Test']);
},
);
it.onWindows('should return an empty array if the asset URI is a filename', () => {
expect(AssetUtil.findAllDescendantAssetsByUri('C:\\Test', 'C:\\')).toBeArrayOfSize(0);
});
it.onWindows(
'should return an empty array if the asset URI contains root URI but not as a prefix',
() => {
expect(
AssetUtil.findAllDescendantAssetsByUri('C:\\Test\\Rt\\Child', 'C:\\Rt'),
).toBeArrayOfSize(0);
},
);
});

describe('getAllNotes', () => {
Expand Down

0 comments on commit 58280d3

Please sign in to comment.