File size: 1,127 Bytes
f6213fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
export function mountPanel(root, panels, id) {
  const panel = SF.el('section', {
    className: `deliveries-panel${id === 'overview' ? ' is-active' : ''}`,
  });
  panels[id] = panel;
  root.appendChild(panel);
  return panel;
}

export function createSelectField(label, options) {
  const select = SF.el('select');
  options.forEach((option) => {
    select.appendChild(SF.el('option', { value: option.value }, option.label));
  });
  const el = SF.el(
    'div',
    { className: 'deliveries-field' },
    SF.el('label', null, label),
    select,
  );
  return { el, select };
}

export function kpi(label, value) {
  return SF.el(
    'div',
    { className: 'deliveries-kpi' },
    SF.el('div', { className: 'deliveries-kpi__label' }, label),
    SF.el('div', { className: 'deliveries-kpi__value' }, value),
  );
}

export function showError(error) {
  const detail = error?.message || String(error);
  SF.showError('Deliveries UI', detail);
}

export async function fetchJson(url) {
  const response = await fetch(url);
  if (!response.ok) {
    throw new Error(`Request failed: ${url}`);
  }
  return response.json();
}