Use state update attribution

Summary: Use the string sent from the client to show which section triggered a state update.

Reviewed By: pasqualeanatriello

Differential Revision: D17162190

fbshipit-source-id: a72eea1c6fc0fba851028aa050f0c6772a590e8d
This commit is contained in:
Mihaela Ogrezeanu
2019-09-10 06:54:37 -07:00
committed by Facebook Github Bot
parent e05a3bdeca
commit 0c307b7c27

View File

@@ -53,32 +53,46 @@ public class ChangesetDebug implements ChangesetDebugListener {
public void onChangesetApplied( public void onChangesetApplied(
Section rootSection, Section rootSection,
Section oldSection,
ChangesInfo changesInfo, ChangesInfo changesInfo,
String surfaceId, String surfaceId,
ChangesetDebugInfo changesetDebugInfo) {} @ApplyNewChangeSet int source,
String attribution) {}
public void onChangesetApplied( public void onChangesetApplied(
Section rootSection, Section rootSection,
Section oldRootSection,
ChangesInfo changesInfo, ChangesInfo changesInfo,
String surfaceId, String surfaceId,
@ApplyNewChangeSet int attribution, ChangesetDebugInfo changesetDebugInfo) {
String extra) {
final FlipperArray.Builder tree = new FlipperArray.Builder(); final FlipperArray.Builder tree = new FlipperArray.Builder();
final FlipperObject.Builder changesetData = new FlipperObject.Builder(); final FlipperObject.Builder changesetData = new FlipperObject.Builder();
final Section oldRootSection = changesetDebugInfo.getOldSection();
final int eventSource = changesetDebugInfo.getSource();
final String attribution = changesetDebugInfo.getAttribution();
final String stateUpdateAttribution = changesetDebugInfo.getUpdateStateAttribution();
final String sourceName = SectionsLogEventUtils.applyNewChangeSetSourceToString(attribution); final String eventSourceName =
SectionsLogEventUtils.applyNewChangeSetSourceToString(eventSource);
extractSidePanelChangesetData(changesInfo, changesetData, rootSection.getGlobalKey()); extractSidePanelChangesetData(changesInfo, changesetData, rootSection.getGlobalKey());
createSectionTree(rootSection, tree, oldRootSection); createSectionTree(rootSection, tree, oldRootSection, stateUpdateAttribution);
List<DataModelChangeInfo> prevData = getDataFromPreviousTree(oldRootSection); List<DataModelChangeInfo> prevData = getDataFromPreviousTree(oldRootSection);
applyChangesInfoOnPreviousData(prevData, changesInfo, tree); applyChangesInfoOnPreviousData(prevData, changesInfo, tree);
String eventSourceSection;
if (stateUpdateAttribution == null) {
eventSourceSection = rootSection == null ? "" : rootSection.getSimpleName();
} else {
final Section updatedStateSection =
findSectionInPreviousTree(oldRootSection, stateUpdateAttribution);
eventSourceSection = updatedStateSection == null ? "" : updatedStateSection.getSimpleName();
}
sSectionsFlipperPlugin.onChangesetApplied( sSectionsFlipperPlugin.onChangesetApplied(
sourceName + " " + extra, eventSourceName + " " + eventSourceSection,
isEventAsync(attribution), isEventAsync(eventSource),
surfaceId, surfaceId,
sChangesetIdGenerator.incrementAndGet() + "-" + surfaceId, sChangesetIdGenerator.incrementAndGet() + "-" + surfaceId,
tree.build(), tree.build(),
@@ -262,9 +276,13 @@ public class ChangesetDebug implements ChangesetDebugListener {
} }
private static void addRemovedSectionNodes( private static void addRemovedSectionNodes(
Section previousRoot, Section currentRoot, final FlipperArray.Builder tree) { Section previousRoot,
Section currentRoot,
final FlipperArray.Builder tree,
String stateUpdateAttribution) {
final Map<String, Section> prevSections = serializeChildren(previousRoot); final Map<String, Section> prevSections = serializeChildren(previousRoot);
final Map<String, Section> currSections = serializeChildren(currentRoot); final Map<String, Section> currSections = serializeChildren(currentRoot);
final boolean checkStateUpdateTrigger = stateUpdateAttribution != null;
for (String prevSectionKey : prevSections.keySet()) { for (String prevSectionKey : prevSections.keySet()) {
if (!currSections.containsKey(prevSectionKey)) { if (!currSections.containsKey(prevSectionKey)) {
@@ -276,6 +294,9 @@ public class ChangesetDebug implements ChangesetDebugListener {
"parent", section.getParent() == null ? null : section.getParent().getGlobalKey()); "parent", section.getParent() == null ? null : section.getParent().getGlobalKey());
nodeBuilder.put("removed", true); nodeBuilder.put("removed", true);
nodeBuilder.put("isSection", true); nodeBuilder.put("isSection", true);
if (checkStateUpdateTrigger && stateUpdateAttribution.equals(prevSectionKey)) {
nodeBuilder.put("didTriggerStateUpdate", true);
}
tree.put(nodeBuilder.build()); tree.put(nodeBuilder.build());
} }
} }
@@ -435,9 +456,12 @@ public class ChangesetDebug implements ChangesetDebugListener {
} }
private static void createSectionTree( private static void createSectionTree(
Section rootSection, FlipperArray.Builder tree, Section oldRootSection) { Section rootSection,
createSectionTreeRecursive(rootSection, "", tree, oldRootSection, 0); FlipperArray.Builder tree,
addRemovedSectionNodes(oldRootSection, rootSection, tree); Section oldRootSection,
String stateUpdateAttribution) {
createSectionTreeRecursive(rootSection, "", tree, oldRootSection, 0, stateUpdateAttribution);
addRemovedSectionNodes(oldRootSection, rootSection, tree, stateUpdateAttribution);
} }
private static void createSectionTreeRecursive( private static void createSectionTreeRecursive(
@@ -445,7 +469,8 @@ public class ChangesetDebug implements ChangesetDebugListener {
String parentKey, String parentKey,
FlipperArray.Builder tree, FlipperArray.Builder tree,
Section oldRootSection, Section oldRootSection,
int startIndex) { int startIndex,
String stateUpdateAttribution) {
if (rootSection == null) { if (rootSection == null) {
return; return;
} }
@@ -458,13 +483,15 @@ public class ChangesetDebug implements ChangesetDebugListener {
final Section oldSection = findSectionInPreviousTree(oldRootSection, globalKey); final Section oldSection = findSectionInPreviousTree(oldRootSection, globalKey);
final boolean isDirty = ChangesetDebugConfiguration.isSectionDirty(oldSection, rootSection); final boolean isDirty = ChangesetDebugConfiguration.isSectionDirty(oldSection, rootSection);
final boolean triggeredStateUpdate =
stateUpdateAttribution != null && stateUpdateAttribution.equals(globalKey);
nodeBuilder.put("identifier", globalKey); nodeBuilder.put("identifier", globalKey);
nodeBuilder.put("name", name); nodeBuilder.put("name", name);
nodeBuilder.put("parent", parentKey); nodeBuilder.put("parent", parentKey);
nodeBuilder.put("isDirty", isDirty); nodeBuilder.put("isDirty", isDirty);
nodeBuilder.put("isReused", !isDirty); nodeBuilder.put("isReused", !isDirty);
nodeBuilder.put("didTriggerStateUpdate", false); // TODO nodeBuilder.put("didTriggerStateUpdate", triggeredStateUpdate);
nodeBuilder.put("isSection", true); nodeBuilder.put("isSection", true);
tree.put(nodeBuilder.build()); tree.put(nodeBuilder.build());
@@ -478,7 +505,12 @@ public class ChangesetDebug implements ChangesetDebugListener {
ChangesetDebugConfiguration.getSectionCount(rootSection.getChildren().get(i - 1)); ChangesetDebugConfiguration.getSectionCount(rootSection.getChildren().get(i - 1));
} }
createSectionTreeRecursive( createSectionTreeRecursive(
rootSection.getChildren().get(i), globalKey, tree, oldRootSection, startIndex); rootSection.getChildren().get(i),
globalKey,
tree,
oldRootSection,
startIndex,
stateUpdateAttribution);
} }
} }
} }