Skip to content

Commit

Permalink
feat: add first-pass model for state tree (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswhong authored Jul 16, 2019
1 parent 017c993 commit 660b639
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 0 deletions.
50 changes: 50 additions & 0 deletions app/models/dataset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { JSONSchema7 } from 'json-schema'

// meta.citations
interface Citation {
name: string
URL: string
email: string
}

// meta.contributors
interface User {
id: string
fullName: string
email: string
}

interface Meta {
accessURL: string
accrualPeriodicity: string
citations: Citation[]
contributors: User[]
description: string
downloadURL: string
homeURL: string
identifier: string
keywords: string[]
language: string[]
license: {
type: string
URL: string
}
readmeURL: string
title: string
theme: string[]
version: string
}

export interface Commit {
path: string
message: string
author: string
timestamp: Date
}

export default interface Dataset {
meta?: Meta
schema?: JSONSchema7
body?: object | []
commit?: Commit
}
114 changes: 114 additions & 0 deletions app/models/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { RouterState } from 'react-router-redux'
import Dataset, { Commit } from './dataset'

enum ApiConnection {
neverConnected = 0,
connected = 1,
connectionFailure = -1
}

enum ModalType {
CreateDataset,
AddDataset,
}

type Modal =
| {
type: ModalType.CreateDataset
dirPath?: string
bodyPath?: string
}
| {
type: ModalType.AddDataset
initialURL?: string | null
}

interface UI {
apiConnection: ApiConnection
showDatasetList: boolean
errorMessage: string | null
message: string | null
hasAcceptedTOS: boolean
hasSetPeername: boolean
modal: Modal
showDiff: boolean
sidebarWidth: boolean
}

// currently selected dataset, tab, dataset component, commit, etc
interface Selections {
peername: string
name: string | null
activeTab: string
component: string
commit: string
}

// info about the current value of a list being paginated
interface PageInfo {
isFetching: boolean
pageCount: number
fetchedAll: boolean
error: string
}

// dataset summary info to show in dataset list
interface DatasetSummary {
title: string
peername: string
name: string
hash: string
isLinked: boolean
changed: boolean
}

// list of local datasets
interface MyDatasets {
pageInfo: PageInfo
value: DatasetSummary[]
filter: string // filter string from ui
}

// info about a dataset component as compared the same component in previous commit
interface ComponentStatus {
filepath: string
status: 'changed' | 'unchanged' | 'removed' | 'added'
errors: object[]
warnings: object[]
}

interface Pages {
[key: string]: PageInfo
}

interface DatasetComparison {
path: string
prevPath: string
peername: string
name: string
pages: Pages
diff: object
value: Dataset
status: {
meta: ComponentStatus
schema: ComponentStatus
body: ComponentStatus
}
}

interface WorkingDataset extends DatasetComparison {
history: {
pageInfo: PageInfo
value: Commit[]
}
}

export default interface Store {
session: string
ui: UI
selections: Selections
myDatasets: MyDatasets
workingDataset: WorkingDataset
workingHistory: DatasetComparison
router: RouterState
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"@types/enzyme": "3.10.2",
"@types/history": "4.7.2",
"@types/jest": "24.0.15",
"@types/json-schema": "^7.0.3",
"@types/node": "12.6.2",
"@types/react": "16.8.23",
"@types/react-dom": "16.8.4",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@
dependencies:
"@types/jest-diff" "*"

"@types/json-schema@^7.0.3":
version "7.0.3"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
integrity sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==

"@types/node@*":
version "12.6.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.6.1.tgz#d5544f6de0aae03eefbb63d5120f6c8be0691946"
Expand Down

0 comments on commit 660b639

Please sign in to comment.