Skip to content

Commit

Permalink
Fixed hiistory update issue and render issue
Browse files Browse the repository at this point in the history
  • Loading branch information
halwan-bot committed Nov 20, 2020
1 parent c50fa2d commit 92f1d6d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 25 deletions.
1 change: 1 addition & 0 deletions control/content/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ const initIconComponent = (imageUrl = "") => {
imageUrl: imageUrl,
title: "Icon",
dimensionsLabel: "400x400",
multiSelection: false
});

let thumbElement = document
Expand Down
2 changes: 1 addition & 1 deletion tests/control/content.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ describe("Test The Control Side", () => {
buildfire.datastore.save({}, "metrics", async (err, data) => {
if (err) reject(err);
else {
await buildfire.datastore.save(
await buildfire.publicData.save(
{ metrics: {} },
`history${clientProfile}`,
async (err, result) => {
Expand Down
22 changes: 9 additions & 13 deletions widget/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,7 @@ buildfire.datastore.onUpdate((event) => {
metrics.id = event.id;
renderInit();
} else if (event.tag === "settings") {
return Settings.load().then(() => {
if (!isQeuryProvided && Settings.dataPolicyType === "private") {
Settings.tags = [];
}
loadApp();
});
loadApp();
}
}
});
Expand All @@ -139,12 +134,13 @@ buildfire.publicData.onUpdate((event) => {
if (event.status && event.nModified) {
Histories.getHistories(clientProfile).then((result) => {
histories = result;
loadApp();
renderInit();
});
} else if (event.tag && event.tag.indexOf("history") > -1) {
Histories.getHistories(clientProfile).then((result) => {
histories = result;
renderInit();
});
} else if (event.data && event.id && event.tag.includes("history")) {
histories = event.data;
histories = event.id;
loadApp();
}
});

Expand Down Expand Up @@ -627,10 +623,10 @@ buildfire.history.onPop((breadcrumb) => {
helpers.showElem("#metricsScreen");
helpers.hideElem("#updateHistoryContainer, #updateHistoryButton");

renderInit();

if (numberOfPops) {
buildfire.history.pop();
} else {
renderInit();
}
} else {
// This condition is for preventing the control side from going back (when clicking back in widget)
Expand Down
12 changes: 3 additions & 9 deletions widget/js/classes/histories.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class Histories {
if (err) {
console.error(err);
return reject(err);
}
else {
} else {
// Check if there is already objects in the database
if (!result.data.metrics) {
// If there is no object, then create the parent object
Expand All @@ -20,8 +19,7 @@ class Histories {
if (err) {
console.error(err);
return reject(err);
}
else {
} else {
this.getHistories(clientProfile).then((result) => {
resolve(result);
});
Expand All @@ -38,7 +36,7 @@ class Histories {
}

static updateMetricHistory({ clientProfile, nodeSelector, historyId }, data) {
const dateOnly = helpers.getAbsoluteDate()
const dateOnly = helpers.getCurrentDate();

return new Promise((resolve, reject) => {
if (!nodeSelector) return reject("nodeSelector not provided");
Expand Down Expand Up @@ -98,10 +96,6 @@ class Histories {
updatedMetricId = updatedMetricId[updatedMetricId.length - 1];
// Track action
Analytics.trackAction(`METRIC_${updatedMetricId}_HISTORY_UPDATE`);

Metrics.getMetrics().then((result) => {
resolve(result);
});
}
);
});
Expand Down
2 changes: 1 addition & 1 deletion widget/js/classes/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Metrics {
}

static updateMetricHistory({ nodeSelector, metricsId }, data) {
const dateOnly = helpers.getAbsoluteDate();
const dateOnly = helpers.getCurrentDate();

return new Promise((resolve, reject) => {
if (!nodeSelector) return reject("nodeSelector not provided");
Expand Down
2 changes: 1 addition & 1 deletion widget/js/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const helpers = {
uuidv4: (m = Math, d = Date, h = 16, s = (s) => m.floor(s).toString(h)) =>
s(d.now() / 1000) + " ".repeat(h).replace(/./g, () => s(m.random() * h)),
// Returns current date in ISO string
getAbsoluteDate: () => {
getCurrentDate: () => {
let date = new Date();
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
},
Expand Down

0 comments on commit 92f1d6d

Please sign in to comment.