Apps
Empty, error and loading states on the admin page
Show an embedded app page's empty list, failed load and wait with the same look and words as the admin's own pages.
Your page embedded in the admin (Show a page in the admin) should show three states as the admin's own pages do: a list with nothing in it yet, a page that failed to load, and the spinner while it waits. app-page.js has a ready part for each; with them your page looks like the rest of the admin and uses its words. The admin is in Turkish, so the texts below stay Turkish.
Which one when
| State | When | How |
|---|---|---|
| Empty | The request succeeded, but the list has no records. | empty(…) or <bt-empty-state> |
| Error | The page's first load failed or didn't finish within 15 seconds. | load(…) on its own, or showError(…) |
| Loading | While the first load runs. | load(…) on its own |
An empty list is not an error: when your API answers 200 with an empty list, show the empty state. The error state is for the page's first load only; report an action that fails after a button press (save, delete) with a toast. Don't show a toast when the first load fails: one error state on the page is enough.
Words
- Empty: the heading "Henüz … yok" (Henüz değerlendirme yok), one sentence on what the list is for (Müşterilerin yazdığı değerlendirmeler burada görünür.) and the primary action where there is one (Dosya yükle, Hesap ekle); an action that adds something carries the plus icon (
plus). When a search matches nothing, the heading is "Aramanıza uyan … yok". - Error: the heading "Sayfa yüklenemedi" or "… yüklenemedi", the reason under it (your API's Turkish
message, or Bağlantı kurulamadı. when no connection was made) and the "Yeniden dene" button. Don't show the browser's English errors (Failed to fetch) or vague sentences such as "Bir hata oluştu.".
JavaScript
load(main, title, loader, draw, options) runs the page's first load: it draws the spinner, waits for the promise loader() returns and calls draw(data) with the result. If the promise rejects, or hasn't settled within 15 seconds, the error state replaces the spinner; its "Yeniden dene" runs the load again. The spinner never turns forever. options.back ({content, onAction}) adds a second button to the error state.
var P = biticaretAppPage
var app = biticaretAppBridge.createApp({ hostOrigin: document.body.dataset.host })
var main = document.getElementById('app')
function getJSON(path) {
return app.fetch(path).then(function (res) {
return res.json().then(
function (data) {
if (!res.ok) throw new Error(data.message || P.unexpectedAnswer)
return data
},
function () {
throw new Error(P.unexpectedAnswer)
}
)
})
}
P.load(main, 'Dosyalar', function () { return getJSON('/admin/api/files') }, function (data) {
if (data.files.length === 0) {
return P.show(main, 'Dosyalar', P.empty({
icon: 'upload',
heading: 'Henüz dosya yok',
body: 'Yüklediğiniz dosyalar burada görünür.',
action: { content: 'Dosya yükle', icon: 'plus', onAction: openUpload },
}))
}
P.show(main, 'Dosyalar', P.card({ title: 'Dosyalar' }, P.list(data.files.map(function (f) { return f.name }))))
})| Part | What it does |
|---|---|
empty({icon, heading, body, action, secondaryAction, inline}) |
The empty state in a card of its own. Each action is {content, icon, onAction}. inline: true draws a small one inside a card that is already there. |
load(main, title, loader, draw, {back}) |
The first load: the spinner, then the page or the error state (with the 15-second limit). |
showError(main, {title, heading, message, error, retry, back}) |
Draws the error state yourself: heading (default "Sayfa yüklenemedi"), the reason from message or error, "Yeniden dene" for retry. |
errorMessage(err) |
An error's Turkish reason: the API's message, or Bağlantı kurulamadı. for the browser's and App Bridge's English errors. |
unexpectedAnswer |
The sentence to show when your API answers without a message or with something that isn't JSON. |
loading(label) |
Draws the spinner only; use load for a first load. |
Your page script shouldn't draw its own spinner (bt-spinner), its own "Bir hata oluştu." card or a "Henüz … yok" paragraph outside bt-empty-state.
Go template
On pages drawn on the server, write the same states with the design system's elements. An empty list:
{{if .Rows}}
<bt-data-table accessibility-label="Ödemeler">…</bt-data-table>
{{else}}
<bt-card>
<bt-empty-state icon="orders" heading="Henüz ödeme yok" action-content="Ödeme bağlantısı oluştur" action-icon="plus" action-url="/admin/links/new">Onaylanan ödemeler burada görünür.</bt-empty-state>
</bt-card>
{{end}}A page whose data couldn't be read, with the admin's critical banner (bt-banner, tone="critical"); "Yeniden dene" opens the same page again:
{{if .LoadError}}
<bt-banner tone="critical" title="Sayfa yüklenemedi" action-content="Yeniden dene" action-url="{{.Path}}">{{.LoadError}}</bt-banner>
{{end}}The admin's own fallback
The admin waits 15 seconds for the app's frame to answer over App Bridge. app-bridge.js sends a handshake message (APP_READY) as soon as createApp is called; with an older library, any App Bridge message from the frame does the same. If no message arrives within 15 seconds (the app's server is down, the page doesn't open, or createApp is never called), the admin shows its own empty state in place of the frame: "Uygulama yanıt vermiyor", a "Yeniden dene" button that reloads the frame and a link to the app's page under Uygulamalar. So call createApp at the top of the page, without waiting for your data.