diff --git a/app/src/components/Archive.js b/app/src/components/Archive.js
index 2adc29eb..f6cc4be5 100644
--- a/app/src/components/Archive.js
+++ b/app/src/components/Archive.js
@@ -1,6 +1,14 @@
import React, {useState} from "react";
import {Card, Confirm, Container, Icon, Image, Placeholder, Tab} from "semantic-ui-react";
-import Paginator, {ClearButton, ExternalLink, SearchInput, textEllipsis, uploadDate, WROLModeMessage} from "./Common";
+import Paginator, {
+ ClearButton,
+ ExternalLink,
+ SearchInput,
+ TabRouter,
+ textEllipsis,
+ uploadDate,
+ WROLModeMessage
+} from "./Common";
import {deleteArchive, postDownload, refreshArchives} from "../api";
import Button from "semantic-ui-react/dist/commonjs/elements/Button";
import {Link, NavLink} from "react-router-dom";
@@ -289,73 +297,41 @@ function Domains() {
}
-export class ArchiveRoute extends React.Component {
-
- constructor(props) {
- super(props);
-
- this.panesTos = ['/archive', '/archive/domains', '/archive/manage'];
- this.state = {
- activeIndex: this.matchPaneTo(),
- }
-
- this.archivePanes = [
- {
- menuItem: {
- as: NavLink,
- content: 'Archives',
- id: 'archive',
- to: '/archive',
- exact: true,
- key: 'home',
- },
- render: () =>
+export function ArchiveRoute(props) {
+ const panes = [
+ {
+ menuItem: {
+ as: NavLink,
+ content: 'Archives',
+ id: 'archive',
+ to: '/archive',
+ exact: true,
+ key: 'home',
},
- {
- menuItem: {
- as: NavLink,
- content: 'Domains',
- id: 'domains',
- to: '/archive/domains',
- exact: true,
- key: 'domains',
- },
- render: () =>
+ render: () =>
+ },
+ {
+ menuItem: {
+ as: NavLink,
+ content: 'Domains',
+ id: 'domains',
+ to: '/archive/domains',
+ exact: true,
+ key: 'domains',
},
- {
- menuItem: {
- as: NavLink,
- content: 'Manage',
- id: 'manage',
- to: '/archive/manage',
- exact: true,
- key: 'manage',
- },
- render: () =>
+ render: () =>
+ },
+ {
+ menuItem: {
+ as: NavLink,
+ content: 'Manage',
+ id: 'manage',
+ to: '/archive/manage',
+ exact: true,
+ key: 'manage',
},
- ];
-
- }
-
- componentDidUpdate(prevProps, prevState, snapshot) {
- if (prevProps.location.pathname !== this.props.location.pathname) {
- this.setState({activeIndex: this.matchPaneTo()});
- }
- }
-
- matchPaneTo = () => {
- return this.panesTos.indexOf(this.props.location.pathname);
- }
-
- render() {
- return (
-
-
-
- )
- }
+ render: () =>
+ },
+ ];
+ return
}
diff --git a/app/src/components/Common.js b/app/src/components/Common.js
index e50fae2f..82425355 100644
--- a/app/src/components/Common.js
+++ b/app/src/components/Common.js
@@ -1,5 +1,5 @@
import React, {useEffect, useState} from "react";
-import {Card, Container, Form, Icon, Image, Input, Pagination, Progress} from 'semantic-ui-react';
+import {Card, Container, Form, Icon, Image, Input, Pagination, Progress, Tab} from 'semantic-ui-react';
import {Link} from "react-router-dom";
import Button from "semantic-ui-react/dist/commonjs/elements/Button";
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
@@ -635,3 +635,62 @@ export function textEllipsis(str, maxLength, {side = "end", ellipsis = "..."} =
}
return str;
}
+
+export class TabRouter extends React.Component {
+ constructor(props) {
+ super(props);
+
+ const panes = props.panes;
+ let paneTos = [];
+ for (let i = 0; i < panes.length; i++) {
+ const pane = panes[i];
+ paneTos = paneTos.concat([pane['menuItem']['to']]);
+ }
+
+ this.state = {
+ activeIndex: this.matchPaneTo(paneTos),
+ paneTos: paneTos,
+ };
+ }
+
+ matchPaneTo = (paneTos) => {
+ const pathname = this.props.location.pathname;
+ // Attempt to find the exact match first.
+ let activeIndex = paneTos.indexOf(pathname);
+ if (activeIndex !== -1) {
+ return activeIndex;
+ }
+
+ // Use the first tab if we can't find one.
+ activeIndex = 0;
+ // Try to find the most-exact match.
+ for (let i = 0; i < paneTos.length; i++) {
+ let to = paneTos[i];
+ if (pathname.startsWith(to) && to.length > paneTos[activeIndex].length) {
+ // "to" is a better match because it is longer than the last one we found.
+ activeIndex = i;
+ }
+ }
+ return activeIndex;
+ }
+
+ componentDidUpdate(prevProps, prevState, snapshot) {
+ if (prevProps.location.pathname !== this.props.location.pathname) {
+ this.setState({activeIndex: this.matchPaneTo(this.state.paneTos)});
+ }
+ }
+
+ render() {
+ const {panes, renderActiveOnly} = this.props;
+ return (
+ <>
+
+ >
+ )
+ }
+
+}
diff --git a/app/src/components/Nav.js b/app/src/components/Nav.js
index c93d8877..eb5a043f 100644
--- a/app/src/components/Nav.js
+++ b/app/src/components/Nav.js
@@ -14,8 +14,8 @@ const links = [
]
},
{text: 'Inventory', to: '/inventory', exact: true},
- {text: 'Archive', to: '/archive', exact: true},
- {text: 'Files', to: '/files', exact: true},
+ {text: 'Archive', to: '/archive'},
+ {text: 'Files', to: '/files'},
{
text: 'Apps', links: [
{to: '/apps/otp', text: 'One Time Pad', exact: true},
diff --git a/modules/files/api.py b/modules/files/api.py
index 72cee406..2d8a8cb6 100644
--- a/modules/files/api.py
+++ b/modules/files/api.py
@@ -14,6 +14,7 @@ bp = get_blueprint('Files', '/api/files')
def paths_to_files(paths: List[pathlib.Path]):
+ """Convert Paths to what the React UI expects."""
media_directory = get_media_directory()
new_files = []
for path in paths:
diff --git a/modules/files/lib.py b/modules/files/lib.py
index 438f17c6..6224be4e 100644
--- a/modules/files/lib.py
+++ b/modules/files/lib.py
@@ -51,9 +51,7 @@ def list_files(directories: List[str]) -> List[Path]:
@wrol_mode_check
def delete_file(file: str):
- """
- Delete a file in the media directory.
- """
+ """Delete a file in the media directory."""
file = get_media_directory() / file
if file.is_dir() or not file.is_file():
raise InvalidFile(f'Invalid file {file}')