Skip to content

Commit b6e20e7

Browse files
authored
Lint (#228)
* Update deps * configure prettier ignore to skip virtual env and static/ * make lint, lints ts * linting
1 parent 7f85d78 commit b6e20e7

32 files changed

+3431
-1200
lines changed

.prettierignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ www/
44
yarn.lock
55
yarn-error.log
66
cypress/videos
7-
cypress/screenshots
7+
cypress/screenshots
8+
venv/
9+
static/
10+
vendor/

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ docker-run:
4242
docker run -it -p 5000:5000 opencre:$(shell git rev-parse HEAD)
4343

4444
lint:
45-
[ -d "./venv" ] && . ./venv/bin/activate && black .
45+
[ -d "./venv" ] && . ./venv/bin/activate && black . && yarn lint
4646

4747
mypy:
4848
[ -d "./venv" ] && . ./venv/bin/activate && mypy --ignore-missing-imports --implicit-reexport --no-strict-optional --strict application

application/frontend/src/App.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@ import { Toaster } from 'react-hot-toast';
55
import { QueryClient, QueryClientProvider } from 'react-query';
66
import { BrowserRouter } from 'react-router-dom';
77

8+
import { GlobalFilterState, filterContext } from './hooks/applyFilters';
89
import { MainContentArea } from './scaffolding';
9-
import { filterContext, GlobalFilterState } from './hooks/applyFilters';
1010

1111
const queryClient = new QueryClient();
1212

1313
const App = () => (
1414
<div className="app">
1515
<filterContext.Provider value={GlobalFilterState}>
16-
<QueryClientProvider client={queryClient}>
17-
<BrowserRouter>
18-
<Toaster />
19-
<MainContentArea />
20-
</BrowserRouter>
21-
</QueryClientProvider>
16+
<QueryClientProvider client={queryClient}>
17+
<BrowserRouter>
18+
<Toaster />
19+
<MainContentArea />
20+
</BrowserRouter>
21+
</QueryClientProvider>
2222
</filterContext.Provider>
2323
</div>
2424
);
2525

2626
export default App;
27-
Lines changed: 95 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,42 @@
11
import './documentNode.scss';
22

3-
import React, { FunctionComponent, useMemo, useState, useEffect, useContext } from 'react';
3+
import axios from 'axios';
4+
import React, { FunctionComponent, useContext, useEffect, useMemo, useState } from 'react';
45
import { Link, useHistory } from 'react-router-dom';
6+
import { Button } from 'semantic-ui-react';
57

6-
import { DOCUMENT_TYPE_NAMES, TYPE_IS_PART_OF, TYPE_CONTAINS, TYPE_LINKED_TO, TYPE_RELATED } from '../../const';
8+
import {
9+
DOCUMENT_TYPE_NAMES,
10+
TYPE_CONTAINS,
11+
TYPE_IS_PART_OF,
12+
TYPE_LINKED_TO,
13+
TYPE_RELATED,
14+
} from '../../const';
15+
import { useEnvironment } from '../../hooks';
16+
import { applyFilters } from '../../hooks/applyFilters';
717
import { Document } from '../../types';
818
import { getDocumentDisplayName, groupLinksByType } from '../../utils';
9-
import { useEnvironment } from '../../hooks';
10-
import axios from 'axios';
11-
import { LoadingAndErrorIndicator } from '../LoadingAndErrorIndicator';
1219
import { getApiEndpoint, getInternalUrl } from '../../utils/document';
13-
import { Button } from 'semantic-ui-react';
1420
import { FilterButton } from '../FilterButton/FilterButton';
15-
import { applyFilters } from '../../hooks/applyFilters';
21+
import { LoadingAndErrorIndicator } from '../LoadingAndErrorIndicator';
1622

1723
export interface DocumentNode {
18-
node: Document,
19-
linkType: string,
20-
hasLinktypeRelatedParent?: Boolean,
24+
node: Document;
25+
linkType: string;
26+
hasLinktypeRelatedParent?: Boolean;
2127
}
2228

23-
const linkTypesToNest = [TYPE_IS_PART_OF, TYPE_RELATED]
24-
const linkTypesExcludedInNesting = [TYPE_CONTAINS]
25-
const linkTypesExcludedWhenNestingRelatedTo = [TYPE_RELATED, TYPE_IS_PART_OF, TYPE_CONTAINS]
29+
const linkTypesToNest = [TYPE_IS_PART_OF, TYPE_RELATED];
30+
const linkTypesExcludedInNesting = [TYPE_CONTAINS];
31+
const linkTypesExcludedWhenNestingRelatedTo = [TYPE_RELATED, TYPE_IS_PART_OF, TYPE_CONTAINS];
2632

27-
export const DocumentNode: FunctionComponent<DocumentNode> = ({ node, linkType, hasLinktypeRelatedParent }) => {
33+
export const DocumentNode: FunctionComponent<DocumentNode> = ({
34+
node,
35+
linkType,
36+
hasLinktypeRelatedParent,
37+
}) => {
2838
const [expanded, setExpanded] = useState<boolean>(false);
29-
const isStandard = node.doctype in ["Tool","Code", "Standard"];
39+
const isStandard = node.doctype in ['Tool', 'Code', 'Standard'];
3040
const { apiUrl } = useEnvironment();
3141
const [nestedNode, setNestedNode] = useState<Document>();
3242
const [loading, setLoading] = useState<boolean>(false);
@@ -42,7 +52,8 @@ export const DocumentNode: FunctionComponent<DocumentNode> = ({ node, linkType,
4252
useEffect(() => {
4353
if (!isStandard && linkTypesToNest.includes(linkType)) {
4454
setLoading(true);
45-
axios.get(getApiEndpoint(node, apiUrl))
55+
axios
56+
.get(getApiEndpoint(node, apiUrl))
4657
.then(function (response) {
4758
setLoading(false);
4859
setNestedNode(response.data.data);
@@ -56,90 +67,98 @@ export const DocumentNode: FunctionComponent<DocumentNode> = ({ node, linkType,
5667
}
5768
}, [id]);
5869

59-
60-
6170
const fetchedNodeHasLinks = () => {
6271
return usedNode.links && usedNode.links.length > 0;
63-
}
72+
};
6473

6574
const hasActiveLinks = () => {
6675
return getTopicsToDisplayOrderdByLinkType().length > 0;
67-
}
76+
};
6877

6978
const isNestedInRelated = (): Boolean => {
70-
return hasLinktypeRelatedParent || (linkType === TYPE_RELATED);
71-
}
79+
return hasLinktypeRelatedParent || linkType === TYPE_RELATED;
80+
};
7281

7382
const getTopicsToDisplayOrderdByLinkType = () => {
7483
return Object.entries(linksByType)
7584
.filter(([type, _]) => !linkTypesExcludedInNesting.includes(type))
76-
.filter(([type, _]) => isNestedInRelated() ? !linkTypesExcludedWhenNestingRelatedTo.includes(type) : true)
77-
}
85+
.filter(([type, _]) =>
86+
isNestedInRelated() ? !linkTypesExcludedWhenNestingRelatedTo.includes(type) : true
87+
);
88+
};
7889

7990
const Hyperlink = (hyperlink) => {
8091
if (!hyperlink.hyperlink) {
8192
return <></>;
8293
}
8394

84-
return <>
85-
<span>
86-
Reference:
87-
</span>
88-
<a href={hyperlink.hyperlink} target="_blank"> {hyperlink.hyperlink}</a>
89-
</>
90-
}
95+
return (
96+
<>
97+
<span>Reference:</span>
98+
<a href={hyperlink.hyperlink} target="_blank">
99+
{' '}
100+
{hyperlink.hyperlink}
101+
</a>
102+
</>
103+
);
104+
};
91105
const SimpleView = () => {
92-
return <>
93-
<div className={`title external-link document-node f2`}>
94-
<Link to={getInternalUrl(usedNode)}>
95-
<i aria-hidden="true" className="circle icon"></i>
96-
{getDocumentDisplayName(usedNode)}
97-
</Link>
98-
</div>
99-
<div className={`content`}></div>
100-
101-
</>
102-
}
106+
return (
107+
<>
108+
<div className={`title external-link document-node f2`}>
109+
<Link to={getInternalUrl(usedNode)}>
110+
<i aria-hidden="true" className="circle icon"></i>
111+
{getDocumentDisplayName(usedNode)}
112+
</Link>
113+
</div>
114+
<div className={`content`}></div>
115+
</>
116+
);
117+
};
103118

104119
const NestedView = () => {
105-
return <>
106-
107-
<LoadingAndErrorIndicator loading={loading} error={error} />
108-
<div className={`title${active} document-node`} onClick={() => setExpanded(!expanded)}>
109-
<i aria-hidden="true" className="dropdown icon"></i>
110-
<Link to={getInternalUrl(usedNode)}>
111-
{getDocumentDisplayName(usedNode)}
112-
</Link>
113-
</div>
114-
<div className={`content${active} document-node`}>
115-
<Hyperlink hyperlink={usedNode.hyperlink} />
116-
{expanded
117-
&& getTopicsToDisplayOrderdByLinkType().map(([type, links]) => {
118-
return (
119-
<div className="document-node__link-type-container" key={type}>
120-
<div>
121-
<span >{usedNode.doctype}: {usedNode.name} - {usedNode.section} </span>
122-
<b> {DOCUMENT_TYPE_NAMES[type]}</b>:
123-
</div>
124-
<div>
125-
<div className="accordion ui fluid styled f0">
126-
{links.map((link, i) =>
120+
return (
121+
<>
122+
<LoadingAndErrorIndicator loading={loading} error={error} />
123+
<div className={`title${active} document-node`} onClick={() => setExpanded(!expanded)}>
124+
<i aria-hidden="true" className="dropdown icon"></i>
125+
<Link to={getInternalUrl(usedNode)}>{getDocumentDisplayName(usedNode)}</Link>
126+
</div>
127+
<div className={`content${active} document-node`}>
128+
<Hyperlink hyperlink={usedNode.hyperlink} />
129+
{expanded &&
130+
getTopicsToDisplayOrderdByLinkType().map(([type, links]) => {
131+
return (
132+
<div className="document-node__link-type-container" key={type}>
133+
<div>
134+
<span>
135+
{usedNode.doctype}: {usedNode.name} - {usedNode.section}{' '}
136+
</span>
137+
<b> {DOCUMENT_TYPE_NAMES[type]}</b>:
138+
</div>
139+
<div>
140+
<div className="accordion ui fluid styled f0">
141+
{links.map((link, i) => (
127142
<div key={Math.random()}>
128-
<DocumentNode node={link.document} linkType={type} hasLinktypeRelatedParent={isNestedInRelated()} key={Math.random()} />
129-
<FilterButton document={link.document}/>
130-
</div>
131-
)
132-
}
143+
<DocumentNode
144+
node={link.document}
145+
linkType={type}
146+
hasLinktypeRelatedParent={isNestedInRelated()}
147+
key={Math.random()}
148+
/>
149+
<FilterButton document={link.document} />
150+
</div>
151+
))}
152+
</div>
133153
</div>
134154
</div>
135-
</div>
136-
);
137-
})}
155+
);
156+
})}
138157
{/* <FilterButton/> */}
139-
</div>
140-
</>
141-
142-
}
158+
</div>
159+
</>
160+
);
161+
};
143162

144163
return hasActiveLinks() ? <NestedView /> : <SimpleView />;
145164
};
Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,82 @@
1-
2-
import React, { FunctionComponent, useMemo, useState, useEffect } from 'react';
1+
import axios from 'axios';
2+
import React, { FunctionComponent, useEffect, useMemo, useState } from 'react';
33
import { Link, useHistory } from 'react-router-dom';
4+
import { Button } from 'semantic-ui-react';
45

5-
import { DOCUMENT_TYPE_NAMES, TYPE_IS_PART_OF, TYPE_CONTAINS, TYPE_LINKED_TO, TYPE_RELATED } from '../../const';
6+
import {
7+
DOCUMENT_TYPE_NAMES,
8+
TYPE_CONTAINS,
9+
TYPE_IS_PART_OF,
10+
TYPE_LINKED_TO,
11+
TYPE_RELATED,
12+
} from '../../const';
13+
import { useEnvironment } from '../../hooks';
614
import { Document, LinkedDocument } from '../../types';
715
import { getDocumentDisplayName, groupLinksByType } from '../../utils';
8-
import { useEnvironment } from '../../hooks';
9-
import axios from 'axios';
10-
import { LoadingAndErrorIndicator } from '../LoadingAndErrorIndicator';
1116
import { getApiEndpoint, getInternalUrl } from '../../utils/document';
12-
import { Button } from 'semantic-ui-react';
17+
import { LoadingAndErrorIndicator } from '../LoadingAndErrorIndicator';
1318

1419
export interface FilterButton {
15-
document: Document
20+
document: Document;
1621
}
1722

18-
export const ClearFilterButton: FunctionComponent = props => {
23+
export const ClearFilterButton: FunctionComponent = (props) => {
1924
let currentUrlParams = new URLSearchParams(window.location.search);
2025
const history = useHistory();
2126

2227
const ClearFilter = () => {
23-
currentUrlParams.set("applyFilters", "false");
24-
currentUrlParams.delete('filters')
25-
history.push(window.location.pathname + "?" + currentUrlParams.toString());
26-
window.location.href = window.location.href
27-
}
28+
currentUrlParams.set('applyFilters', 'false');
29+
currentUrlParams.delete('filters');
30+
history.push(window.location.pathname + '?' + currentUrlParams.toString());
31+
window.location.href = window.location.href;
32+
};
2833

34+
return (
35+
<div id="clearFilterButton">
36+
<Button
37+
onClick={() => {
38+
ClearFilter();
39+
}}
40+
content="Clear Filters"
41+
></Button>
42+
</div>
43+
);
44+
};
2945

30-
return <div id="clearFilterButton"><Button onClick={() => { ClearFilter() }} content="Clear Filters"></Button></div>
31-
}
32-
33-
export const FilterButton: FunctionComponent<FilterButton> = props => {
34-
let document = props.document
46+
export const FilterButton: FunctionComponent<FilterButton> = (props) => {
47+
let document = props.document;
3548
const [filters, setFilters] = useState<string[]>();
3649
let currentUrlParams = new URLSearchParams(window.location.search);
3750
const history = useHistory();
3851

3952
const handleFilter = (document: Document) => {
40-
var fltrs
41-
if (document.doctype == "CRE") {
42-
fltrs = filters && filters.length ? new Set([...filters, "" + document.id]) : ["" + document.id]
53+
var fltrs;
54+
if (document.doctype == 'CRE') {
55+
fltrs = filters && filters.length ? new Set([...filters, '' + document.id]) : ['' + document.id];
4356
// fltrs = filters && filters.length ? new Set([...filters, "c:" + document.id]) : ["c:" + document.id]
44-
} else if (document.doctype in ["Tool", "Code", "Standard"]) {
45-
fltrs = filters && filters.length ? new Set([...filters, "" + document.name]) : ["" + document.name]
57+
} else if (document.doctype in ['Tool', 'Code', 'Standard']) {
58+
fltrs = filters && filters.length ? new Set([...filters, '' + document.name]) : ['' + document.name];
4659
// fltrs = filters && filters.length ? new Set([...filters, "s:" + document.name]) : ["s:" + document.name]
4760
}
48-
fltrs.forEach(f => {
49-
if (!currentUrlParams.getAll("filters").includes(f)) {
61+
fltrs.forEach((f) => {
62+
if (!currentUrlParams.getAll('filters').includes(f)) {
5063
currentUrlParams.append('filters', f);
5164
}
52-
})
53-
history.push(window.location.pathname + "?" + currentUrlParams.toString());
54-
setFilters(Array.from(fltrs))
55-
}
56-
if (currentUrlParams.has("showButtons")) {
57-
return document.doctype in ["Tool", "Code", "Standard"] ? <Button onClick={() => { handleFilter(document) }} content="Filter this item"></Button> : <></>
65+
});
66+
history.push(window.location.pathname + '?' + currentUrlParams.toString());
67+
setFilters(Array.from(fltrs));
68+
};
69+
if (currentUrlParams.has('showButtons')) {
70+
return document.doctype in ['Tool', 'Code', 'Standard'] ? (
71+
<Button
72+
onClick={() => {
73+
handleFilter(document);
74+
}}
75+
content="Filter this item"
76+
></Button>
77+
) : (
78+
<></>
79+
);
5880
}
59-
return <></>
60-
81+
return <></>;
6182
};

0 commit comments

Comments
 (0)