| 18 | } |
| 19 | |
| 20 | class App extends React.Component<any, AppState> { |
| 21 | private graphManager = new GraphManager(); |
| 22 | |
| 23 | constructor(props: any) { |
| 24 | super(props); |
| 25 | this.state = { |
| 26 | manifestUrl: Config.COMPONENTS_MANIFEST_JSON_URL, |
| 27 | loadedManifest: false |
| 28 | }; |
| 29 | } |
| 30 | |
| 31 | componentDidMount() { |
| 32 | this.refresh() |
| 33 | } |
| 34 | |
| 35 | componentDidUpdate() { |
| 36 | this.refresh() |
| 37 | } |
| 38 | |
| 39 | async refresh() { |
| 40 | if (!this.state.loadedManifest) { |
| 41 | if (this.state.manifestFile) { |
| 42 | const success = await this.graphManager.loadFile(this.state.manifestFile); |
| 43 | this.setState({ |
| 44 | weightServiceManager: success ? new WeightServiceManager(this.graphManager) : undefined, |
| 45 | loadedManifest: true |
| 46 | }) |
| 47 | } else if (this.state.manifestUrl) { |
| 48 | const success = await this.graphManager.loadUrl(this.state.manifestUrl, Config.COMPONENTS_MANIFEST_GZIP_URL); |
| 49 | this.setState({ |
| 50 | weightServiceManager: success ? new WeightServiceManager(this.graphManager) : undefined, |
| 51 | loadedManifest: true |
| 52 | }) |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | private onChangeManifestUrl(url: string) { |
| 58 | this.setState({ |
| 59 | manifestUrl: url, |
| 60 | loadedManifest: false |
| 61 | }) |
| 62 | } |
| 63 | |
| 64 | private onChangeManifestFile(acceptedFiles: File[]) { |
| 65 | if (acceptedFiles.length !== 1) { |
| 66 | alert("Upload a single ComponentsManifest.json") |
| 67 | return |
| 68 | } |
| 69 | |
| 70 | const file = acceptedFiles[0] |
| 71 | if (file.type != "application/json") { |
| 72 | alert("Manifest must be a json file") |
| 73 | return |
| 74 | } |
| 75 | |
| 76 | this.setState({ |
| 77 | manifestFile: file, |
nothing calls this directly
no outgoing calls
no test coverage detected