Skip to content

Commit

Permalink
Fixing issue on first project load not showing existing tracers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Ryan Heath committed Sep 19, 2019
1 parent 2a916b1 commit 47fb5f5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 67 deletions.
30 changes: 16 additions & 14 deletions public/tracy/scripts/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,22 @@
dbprom = new Promise(r => r("BAD"));
break;
}
dbprom.then(t => {
try {
sendResponse(t);
} catch (e) {
console.error(
"failed to send a response to a database request",
message,
t,
e
);
// Send an empty response to make sure the UI doesn't get stuck.
sendResponse([]);
}
});
dbprom
.then(t => {
try {
sendResponse(t);
} catch (e) {
console.error(
"failed to send a response to a database request",
message,
t,
e
);
// Send an empty response to make sure the UI doesn't get stuck.
sendResponse([]);
}
})
.catch(e => console.log("[DB ERROR]", e));
return true;
}
}
Expand Down
45 changes: 15 additions & 30 deletions src/components/Options.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global chrome */
import React from "react";

export default class Options extends React.Component {
Expand Down Expand Up @@ -43,11 +44,20 @@ export default class Options extends React.Component {
};

createFirstProject = () => {
const proj = {
proj: { name: "first project", apiKey: this.generateUUID() }
};
this.props.updateProjects(this.props.projs.concat(proj));
this.props.changeSetting(proj);
// When we create the first project, make sure an API key wasn't already
// created for that project (can happen if you start to insert tracers before
// the UI ever opens). If so, use that API key.
chrome.storage.local.get({ apiKey: "" }, o => {
let key = o.apiKey;
if (!key) {
key = this.generateUUID();
}
const proj = {
proj: { name: "first project", apiKey: key }
};
this.props.updateProjects(this.props.projs.concat(proj));
this.props.changeSetting(proj);
});
};

render = () => (
Expand Down Expand Up @@ -82,28 +92,3 @@ export default class Options extends React.Component {
</div>
);
}

/* <h3>Tracy Local</h3>
<input
type="checkbox"
id="tracyLocal"
checked={this.props.tracyLocal}
onChange={this.handleOnChange}
/>
<h3>Server Host</h3>
<input
type="text"
id="tracyHost"
value={this.props.tracyHost}
onChange={this.handleOnChange}
disabled={this.props.tracyLocal}
/>
<h3>Server Port</h3>
<input
type="text"
id="tracyPort"
value={this.props.tracyPort}
onChange={this.handleOnChange}
disabled={this.props.tracyLocal}
/>
*/
32 changes: 9 additions & 23 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,16 @@ export const getTracerEvents = async tracerPayload => {
};

// getTracers returns all the tracers.
export const getTracers = async () => {
const { tracyLocal } = await new Promise(r =>
chrome.storage.local.get({ tracyLocal: true }, res => r(res))
);

// If the user has selected they want to use the local version
// query the local database. Otherwise, make an API request.
if (tracyLocal) {
return await new Promise(r =>
chrome.runtime.sendMessage(
{
"message-type": "database",
query: "getTracers"
},
res => r(res)
)
);
}
return await retryRequest(
newTracyRequest(`/tracers`, {
method: "GET"
})
export const getTracers = async () =>
await new Promise(r =>
chrome.runtime.sendMessage(
{
"message-type": "database",
query: "getTracers"
},
res => r(res)
)
);
};

export const retryRequest = async req => {
while (true) {
Expand Down

0 comments on commit 47fb5f5

Please sign in to comment.