import

look

A spreadsheet import the app's server reads: upload, the column match and row errors, then one confirm.

Drawn

Import products

download template

Importing a file needs JavaScript. The template above works without it. The file needs these columns:

SKU, Name, Category, Price ฿

The sample

crates/blocks/src/kind/core/import.rs:161–182

pub(super) fn sample() -> Vec<Block> {
    let mut sku = ImportColumn::new("sku", "SKU", ImportType::Text);
    sku.required = Some(true);
    let mut price = ImportColumn::new("price", "Price ฿", ImportType::Money);
    price.required = Some(true);
    let mut cat = ImportColumn::new("cat", "Category", ImportType::Choice);
    cat.values = Some(vec!["Bakery".into(), "Dairy".into()]);
    let columns = vec![sku, ImportColumn::new("name", "Name", ImportType::Text), cat, price];
    let template = FileLink {
        name: "products.xlsx".into(),
        src: "https://example.com/files/template-products.xlsx".into(),
    };
    vec![Block::Import(Box::new(
        Import::new("Import products", columns)
            .id("products")
            .into("Products")
            .mb(10u32)
            .template(template)
            .read("read")
            .action("import"),
    ))]
}
{
  "blocks": [
    {
      "action": "import",
      "columns": [
        {
          "key": "sku",
          "label": "SKU",
          "required": true,
          "type": "text"
        },
        {
          "key": "name",
          "label": "Name",
          "type": "text"
        },
        {
          "key": "cat",
          "label": "Category",
          "type": "choice",
          "values": [
            "Bakery",
            "Dairy"
          ]
        },
        {
          "key": "price",
          "label": "Price ฿",
          "required": true,
          "type": "money"
        }
      ],
      "fallback": {
        "title": "Import products"
      },
      "id": "products",
      "into": "Products",
      "mb": 10,
      "read": "read",
      "template": {
        "name": "products.xlsx",
        "src": "https://example.com/files/template-products.xlsx"
      },
      "title": "Import products",
      "type": "import"
    }
  ],
  "fallback": {
    "title": "screen"
  },
  "id": "import",
  "type": "screen"
}

Its fallback

What a renderer without import draws: a row from the fallback the block carries.
Import products

Style hooks

.b-importthe block
[data-block=import]every block of the kind
[data-id=products]this one block
Every page here is a blocks Screen, written by site::page: no hand-written HTML. Source: https://github.com/jirathip-dev/blocks