From dcd03d8a3f94505c53e667a4b967a29b698c5728 Mon Sep 17 00:00:00 2001 From: Ernst Widerberg Date: Wed, 30 Mar 2022 12:53:34 +0200 Subject: Merge redesign (refs/archive/redesign-2022-03-30) --- src/components/List.js | 148 ------------------------------------------------- 1 file changed, 148 deletions(-) delete mode 100644 src/components/List.js (limited to 'src/components/List.js') diff --git a/src/components/List.js b/src/components/List.js deleted file mode 100644 index acfc369..0000000 --- a/src/components/List.js +++ /dev/null @@ -1,148 +0,0 @@ -import React from "react"; - -import Pagination from "@mui/material/Pagination"; - -import ObjectComponent from "./ObjectComponent"; -import SearchForm from "./SearchForm"; - -class List extends React.Component { - constructor(props) { - super(props); - this.state = { - objects: [], - filter: { - field: null, - value: null - }, - page: 1, - totalPages: 1 - }; - - this.filter = this.filter.bind(this); - this.filterString = this.filterString.bind(this); - this.getData = this.getData.bind(this); - this.queryString = this.queryString.bind(this); - this.setPage = this.setPage.bind(this); - } - - componentDidMount() { - this.getData(); - } - - // - // Helpers - // - - filterString() { - return this.state.filter.field == null || - this.state.filter.value == null - ? null - : this.state.filter.field + "=" + this.state.filter.value; - } - - queryString() { - return [ - `limit=${window.injectedEnv.PER_PAGE}`, - `skip=${(this.state.page - 1) * window.injectedEnv.PER_PAGE}`, - this.filterString() - ] - .filter(x => x !== null) - .join("&"); - } - - // Fetch data from external source, update state - getData() { - fetch( - window.injectedEnv.COLLECTOR_URL + - "/sc/v0/get?" + - this.queryString(), - { - headers: { - Authorization: "Bearer " + this.props.token - } - } - ) - // TODO: Look at `status` or return code or both? - .then(resp => { - if (resp.status !== 200) - throw new Error( - `Unexpected HTTP response code from soc_collector: ${resp.status} ${resp.statusText}` - ); - this.setState({ - totalPages: parseInt(resp.headers.get("X-Total-Count")) - }); - return resp.json(); - }) - .then(json => { - if (json.status != "success") - throw new Error( - `Unexpected status from soc_collector: ${json.status}` - ); - this.setState({ - objects: json.docs - }); - }) - .catch(e => this.props.setError(e)); - } - - // - // Event handlers - // - - filter(field, value) { - this.setState( - { - filter: { - field: field, - value: value - }, - page: 1 - }, - this.getData - ); - } - - setPage(event, value) { - this.setState({ page: value }, () => { - this.getData(); - window.scrollTo(0, 0); - }); - } - - render() { - return ( -
-
-
- -
-
- {this.state.objects.map(data => { - return ( - - ); - })} -
- -
- ); - } -} - -export default List; -- cgit v1.1