From d12625a3a3e241d80ce3fe8e577ba8a41320b189 Mon Sep 17 00:00:00 2001
From: Tyler Schicke <tyler_schicke@brown.edu>
Date: Fri, 1 Feb 2019 01:05:31 -0500
Subject: Changed formatting setting, added very basic generic FieldView, and
 added Schema view

---
 src/views/collections/CollectionSchemaView.tsx | 49 ++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 src/views/collections/CollectionSchemaView.tsx

(limited to 'src/views/collections/CollectionSchemaView.tsx')

diff --git a/src/views/collections/CollectionSchemaView.tsx b/src/views/collections/CollectionSchemaView.tsx
new file mode 100644
index 000000000..01a5ab639
--- /dev/null
+++ b/src/views/collections/CollectionSchemaView.tsx
@@ -0,0 +1,49 @@
+import { CollectionViewProps, DocumentFieldViewProps } from "../nodes/DocumentView";
+import React = require("react")
+import ReactTable, { ReactTableDefaults, CellInfo } from "react-table";
+import { observer } from "mobx-react";
+import { KeyStore as KS, Key } from "../../fields/Key";
+import { Document } from "../../fields/Document";
+import { FieldView } from "../nodes/FieldView";
+import "react-table/react-table.css"
+
+@observer
+export class CollectionSchemaView extends React.Component<CollectionViewProps> {
+    public static LayoutString() { return '<CollectionSchemaView Document={Document} fieldKey={DataKey} ContainingDocumentView={ContainingDocumentView}/>'; }
+
+    renderCell = (rowProps: CellInfo) => {
+        if (!this.props.ContainingDocumentView) {
+            return <div></div>
+        }
+        let props: DocumentFieldViewProps = {
+            doc: rowProps.value[0],
+            fieldKey: rowProps.value[1],
+            containingDocumentView: this.props.ContainingDocumentView
+        }
+        return <FieldView {...props} />
+    }
+
+    render() {
+        const { Document, fieldKey } = this.props;
+        const children = Document.GetListField<Document>(fieldKey, []);
+        const columns = Document.GetListField(KS.ColumnsKey,
+            [KS.Title, KS.Data, KS.Author])
+        return (
+            <ReactTable
+                data={children}
+                columns={columns.map(col => {
+                    return (
+                        {
+                            Header: col.Name,
+                            accessor: (doc: Document) => [doc, col],
+                            id: col.Id
+                        })
+                })}
+                column={{
+                    ...ReactTableDefaults.column,
+                    Cell: this.renderCell
+                }}
+            />
+        )
+    }
+}
\ No newline at end of file
-- 
cgit v1.2.3-70-g09d2

