Skip to content

Commit

Permalink
feat(Walk): Add Up Folder navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
danactive committed Jun 14, 2020
1 parent dd369c9 commit 88472e5
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ui/app/components/List/tests/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('<List />', () => {
test('should pass all items props to rendered component', () => {
const items = [{ id: 1, name: 'Hello' }, { id: 2, name: 'World' }];

const component = ({ item, key }) => <li title={key}>{item.name}</li>;
const component = ({ item }) => <li>{item.name}</li>;

const { container, getByText } = render(
<List items={items} component={component} />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import walkUtils from './util';

const { isImage } = walkUtils;

function Contents({ item: file }) {
function ListFile({ item: file }) {
if (isImage(file)) {
return null;
}
Expand All @@ -27,4 +27,4 @@ function Contents({ item: file }) {
);
}

export default Contents;
export default ListFile;
31 changes: 29 additions & 2 deletions ui/app/containers/Walk/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useInjectReducer } from '../../utils/injectReducer';
import walkUtils from './util';

import GenericList from '../../components/GenericList';
import ListFolders from './ListFolders';
import ListFile from './ListFile';
import Menu from './Menu';
import OrganizePreviews from '../../components/OrganizePreviews';

Expand All @@ -24,6 +24,31 @@ function parseQueryString(find, from) {
return RegExp(`[?&]${find}(=([^&#]*)|&|#|$)`).exec(from)[2];
}

export function addUpFolderPath(itemFiles, path) {
const file = {
filename: '..',
mediumType: 'folder',
};

if (path) {
if (path.lastIndexOf('/') > -1) {
const splitPath = path.split('/');
splitPath.pop();
itemFiles.unshift({
path: splitPath.join('/'),
...file,
});
} else {
itemFiles.unshift({
path: '',
...file,
});
}
}

return itemFiles;
}

function Walk({
doListDirectory,
files,
Expand All @@ -46,6 +71,8 @@ function Walk({
content: file.filename,
...file,
}));
addUpFolderPath(itemFiles, path);

const itemImages = itemFiles.filter((file) => isImage(file));
const hasImages = !loading && itemImages.length > 0;

Expand All @@ -62,7 +89,7 @@ function Walk({
/>,
<GenericList
key="walk-GenericList"
component={ListFolders}
component={ListFile}
items={itemFiles}
loading={loading}
error={false}
Expand Down
18 changes: 18 additions & 0 deletions ui/app/containers/Walk/tests/ListFile.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* global describe, expect, test */
import React from 'react';
import { render } from 'react-testing-library';

import ListFile from '../ListFile';

describe('<ListFile />', () => {
test('should render a folder', () => {
const path = 'testPath';
const { container } = render(<ListFile item={{ mediumType: 'folder', path }} />);
expect(container.querySelector('a').href).toEqual(`http://localhost/?path=${path}`);
});

test('should avoid an image', () => {
const { container } = render(<ListFile item={{ mediumType: 'image', ext: 'JPEG' }} />);
expect(container.querySelector('li')).toEqual(null);
});
});
35 changes: 35 additions & 0 deletions ui/app/containers/Walk/tests/index.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* global beforeEach, describe, expect, test */
import { addUpFolderPath } from '..';

describe('Walk - addUpFolderPath', () => {
const file = {
filename: '..',
mediumType: 'folder',
};
let dummyFile;

beforeEach(() => {
dummyFile = { id: 'testid.js', ext: 'js' };
});

test('hide when at root folder', () => {
expect(addUpFolderPath([dummyFile], null)).toEqual([dummyFile]);
expect(addUpFolderPath([dummyFile])).toEqual([dummyFile]);
expect(addUpFolderPath([dummyFile], '')).toEqual([dummyFile]);
});

test('one level deep', () => {
const expectedFile = { ...file, path: '' };
expect(addUpFolderPath([dummyFile], 'galleries')).toEqual([expectedFile, dummyFile]);
});

test('two levels deep', () => {
const expectedFile = { ...file, path: 'galleries' };
expect(addUpFolderPath([dummyFile], 'galleries/gallery-demo')).toEqual([expectedFile, dummyFile]);
});

test('three levels deep', () => {
const expectedFile = { ...file, path: 'galleries/gallery-demo' };
expect(addUpFolderPath([dummyFile], 'galleries/gallery-demo/thumbs')).toEqual([expectedFile, dummyFile]);
});
});

0 comments on commit 88472e5

Please sign in to comment.