MCPcopy Create free account
hub / github.com/Rello/analytics / render

Function render

js/jsonPicker.js:169–217  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

167 let offset = 0;
168 const more = action(t('analytics', 'Show more'), () => render());
169 const render = () => {
170 more.remove();
171 items.slice(offset, offset + 50).forEach(([key, values]) => {
172 const path = [...parts, key];
173 const value = values.find(picker.isContainer) ?? values[0];
174 if (!picker.isContainer(value)) {
175 choose(key, path, value, parent);
176 return;
177 }
178 const details = document.createElement('details');
179 const summary = document.createElement('summary');
180 const isArray = Array.isArray(value);
181 const name = document.createElement('span');
182 name.textContent = key + ' (' + Object.keys(value).length + ')';
183 summary.appendChild(name);
184 details.appendChild(summary);
185 details.addEventListener('toggle', () => {
186 if (!details.open || details.dataset.loaded) return;
187 details.dataset.loaded = 'true';
188 if (!fields && isArray && value.some(item => picker.isContainer(item))) {
189 // TRANSLATORS: JSON selection action; {name} is an array or group name from the source data, e.g. orders.
190 details.appendChild(action(t('analytics', 'Use all {name} and choose the relevant fields', {name: key}), () => showFields(value, path), picker.selectable(path)));
191 } else if (!fields && Object.values(value).every(item => !picker.isContainer(item))) {
192 details.appendChild(action(t('analytics', 'Use entries as rows'), () => {
193 rowPath = null;
194 selected = [path.join('/')];
195 update();
196 tree.querySelectorAll('input[type="checkbox"]').forEach(box => { box.checked = false; });
197 }, picker.selectable(path)));
198 }
199 if (Object.keys(value).length === 0) {
200 const empty = document.createElement('p');
201 empty.className = 'userGuidance';
202 empty.textContent = t('analytics', 'No sample rows available.');
203 details.appendChild(empty);
204 } else if (parts.length < 20) {
205 children(fields ? values : [value], path, details, fields);
206 } else {
207 const hint = document.createElement('p');
208 hint.className = 'userGuidance';
209 hint.textContent = t('analytics', 'This nesting is too deep to browse. Enter the Object path manually.');
210 details.appendChild(hint);
211 }
212 });
213 parent.appendChild(details);
214 });
215 offset += 50;
216 if (offset < items.length) parent.appendChild(more);
217 };
218 render();
219 };
220 const showFields = (records, parts, initialFields = []) => {

Callers 1

childrenFunction · 0.70

Calls 9

chooseFunction · 0.85
actionFunction · 0.85
showFieldsFunction · 0.85
childrenFunction · 0.85
findMethod · 0.80
updateFunction · 0.70
tFunction · 0.50
removeMethod · 0.45
addEventListenerMethod · 0.45

Tested by

no test coverage detected