Skip to content

Commit d0c34ca

Browse files
committed
add mutationwatcher
1 parent 01471a8 commit d0c34ca

File tree

3 files changed

+53
-32
lines changed

3 files changed

+53
-32
lines changed

service/src/main/kotlin/app/cash/backfila/client/EnvoyCallbackConnectorProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import com.squareup.moshi.Moshi
66
import java.net.URL
77
import javax.inject.Inject
88
import javax.inject.Singleton
9+
import misk.client.EnvoyClientEndpointProvider
10+
import misk.client.HttpClientEnvoyConfig
911
import misk.client.HttpClientFactory
1012
import misk.client.HttpClientsConfig
1113
import misk.moshi.adapter
1214
import retrofit2.Retrofit
1315
import retrofit2.adapter.guava.GuavaCallAdapterFactory
1416
import retrofit2.converter.wire.WireConverterFactory
15-
import misk.client.EnvoyClientEndpointProvider
16-
import misk.client.HttpClientEnvoyConfig
1717

1818
@Singleton
1919
class EnvoyCallbackConnectorProvider @Inject constructor(

service/src/main/kotlin/app/cash/backfila/ui/components/BackfillSearchForm.kt

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,30 +83,25 @@ fun TagConsumer<*>.BackfillSearchForm(
8383
8484
if (!datalist) return;
8585
86-
// Check if datalist is already populated to avoid duplicate fetches
87-
if (datalist.children.length > 0) return;
88-
8986
// Fetch and populate backfill names
90-
function loadBackfillNames() {
91-
const url = '/services/$serviceName/variants/$variantName/backfill-names';
92-
93-
fetch(url)
94-
.then(response => response.json())
95-
.then(data => {
96-
datalist.innerHTML = '';
97-
if (data.backfill_names) {
98-
data.backfill_names.forEach(name => {
99-
const option = document.createElement('option');
100-
option.value = name;
101-
datalist.appendChild(option);
102-
});
103-
}
104-
})
105-
.catch(err => console.error('Error loading backfill names:', err));
106-
}
87+
const url = '/services/$serviceName/variants/$variantName/backfill-names';
88+
fetch(url)
89+
.then(response => response.json())
90+
.then(data => {
91+
datalist.innerHTML = '';
92+
if (data.backfill_names) {
93+
data.backfill_names.forEach(name => {
94+
const option = document.createElement('option');
95+
option.value = name;
96+
datalist.appendChild(option);
97+
});
98+
}
99+
})
100+
.catch(err => console.error('Error loading backfill names:', err));
107101
108102
// Clear filters button handler
109-
if (clearFiltersBtn) {
103+
if (clearFiltersBtn && !clearFiltersBtn.hasAttribute('data-initialized')) {
104+
clearFiltersBtn.setAttribute('data-initialized', 'true');
110105
clearFiltersBtn.addEventListener('click', function() {
111106
let baseUrl = '/services/$serviceName';
112107
if ('$variantName' !== 'default') {
@@ -115,19 +110,44 @@ fun TagConsumer<*>.BackfillSearchForm(
115110
window.location.href = baseUrl;
116111
});
117112
}
118-
119-
loadBackfillNames();
120113
}
121114
122115
// Run on initial page load
123116
if (document.readyState === 'loading') {
124-
document.addEventListener('DOMContentLoaded', initBackfillForm);
117+
document.addEventListener('DOMContentLoaded', function() {
118+
initBackfillForm();
119+
setupAutoReloadWatcher();
120+
});
125121
} else {
126122
initBackfillForm();
123+
setupAutoReloadWatcher();
127124
}
128125
129-
// Simple periodic check to ensure dropdown stays populated after AutoReload
130-
setInterval(initBackfillForm, 5000); // Check every 5 seconds
126+
function setupAutoReloadWatcher() {
127+
// Watch for when the datalist gets replaced/removed by AutoReload
128+
const observer = new MutationObserver(function(mutations) {
129+
mutations.forEach(function(mutation) {
130+
if (mutation.type === 'childList') {
131+
// Check if nodes were added that contain our datalist
132+
mutation.addedNodes.forEach(function(node) {
133+
if (node.nodeType === Node.ELEMENT_NODE) {
134+
if (node.id === 'backfill-names' ||
135+
(node.querySelector && node.querySelector('#backfill-names'))) {
136+
// Datalist was re-added, initialize it
137+
setTimeout(initBackfillForm, 10);
138+
}
139+
}
140+
});
141+
}
142+
});
143+
});
144+
145+
// Start observing the entire document for changes
146+
observer.observe(document.body, {
147+
childList: true,
148+
subtree: true
149+
});
150+
}
131151
""".trimIndent()
132152
}
133153
}

service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillShowAction.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,12 @@ class BackfillShowAction @Inject constructor(
211211
if (it.isNaN()) 0.0 else it
212212
}
213213
+"""${String.format("%.1f", percentage)}%"""
214-
} else
215-
if (backfill.state == BackfillState.COMPLETE) {
216-
+"""Complete"""
217214
} else {
218-
+"""Computing..."""
215+
if (backfill.state == BackfillState.COMPLETE) {
216+
+"""Complete"""
217+
} else {
218+
+"""Computing..."""
219+
}
219220
}
220221
}
221222
}

0 commit comments

Comments
 (0)