Help

Re: Beta: create tables & fields and update field options from the Blocks SDK

3028 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Emma_Yeap
Airtable Employee
Airtable Employee

Hi!

We’ve released a new version of the SDK, 0.0.46, which contains three new functions:

Refer to FieldType for the write format for field options for each field type, and the documentation for each function (linked above) for specific usage details, quirks and example code snippets. (Note: we’re aware of some formatting issues in the FieldType docs and will update them shortly!)

These methods have an unstable_ prefix as several field types are not supported at this time (formulaic and linked record types: see FieldType for full details) and we anticipate we may need to tweak the API before releasing them as stable. The prefix will be removed in a future SDK version when ready.

Please let us know any feedback, both on these APIs and any missing features you’d like to see! We’d love to hear about your use cases too.

You can see the full list of SDK changes in the changelog.

Here’s an example of updateOptionsAsync in action and the block’s code:
new metadata writes gif

import {initializeBlock, useBase, Box, Button, FieldPicker, Input, Text} from '@airtable/blocks/ui';
import {FieldType} from '@airtable/blocks/models';
import React, {useState} from 'react';

async function addChoiceToSelectField(field, choiceName) {
    await field.unstable_updateOptionsAsync({
        choices: [
            // Include existing choices
            ...field.options.choices,
            // Color can also be specified here
            {name: choiceName},
        ]
    });
}

function AddOptionToSelectFieldBlock() {
    const base = useBase();
    const table = base.getTableByName('Table 1');
    const [field, setField] = useState(null);
    const [choiceName, setChoiceName] = useState("");
    const [successText, setSuccessText] = useState("");

    return <Box margin={2}>
        <FieldPicker
            table={table}
            field={field}
            onChange={field => setField(field)}
            allowedTypes={[FieldType.SINGLE_SELECT, FieldType.MULTIPLE_SELECTS]}
            placeholder='Pick a single or multiple select field'
            marginBottom={1}
        />
        {field && <Box display='flex'>
            <Input
                value={choiceName}
                onChange={e => {
                    setChoiceName(e.target.value)
                }}
                placeholder='Enter name for new choice'
                marginRight={1}
                marginBottom={1}
            />
            <Button
                onClick={async () => {
                    await addChoiceToSelectField(field, choiceName);
                    setSuccessText(`Choice '${choiceName}' created in field '${field.name}'`)
                }}
                variant='primary'
                disabled={!choiceName}
            >
                Create option
            </Button>
        </Box>}
        {successText && <Text>{successText}</Text>}
    </Box>;
}

initializeBlock(() => <AddOptionToSelectFieldBlock />);
8 Replies 8
openside
10 - Mercury
10 - Mercury

This is great, can’t wait to try it. Now… let’s not run any contests until after the unstable_ is removed, ok? ha ha, sorry couldn’t resist…

Any plans for field delete ? or ability to modify field type? (i.e. change single select to multiple select)

We don’t have any immediate plans to support those, but we’re going to be looking at all the feedback for these “metadata write” functions to work out what to prioritise next.

Would love to hear your use cases for field delete & field type update. For the existing functions we prioritised what we thought would solve the main use-cases, so learning about new use-cases is helpful for us!

Hi @Emma_Yeap
Thanks to @Billy_Littlefield answer to my POST, this is exactly the playground I was looking for to meet most of my hopes when Script-Block and Custom-Block appeared!
My first use-Cases to solve in 12/2019 were:

  • RAW backup of my Table in CSV or JSON including Field-Type, Field-Type-Options and Formula text ! (You would remind yourself that in the Beta version of Script-Block, this was possible but today it’s not possible anymore. :frowning: ).
  • My Own Formulas (Text) parse and collect to post them to my Gem & Snippets BASE’s Tables to hope better reusability ;
  • My Own Table Templates duplication with programmatic Field’s Name manipulations ;
  • Some new Table programmatic build following my own “matrix” or canevas or schema ;
  • My Own TABLE VIEW’s programmatic management ;

Even if your section is still experimental, unstable, with an unpredictable future, and doesn’t cover all my wishes yet, it gives me the opportunity to start entering Custom-Block from the side that’s a priority for me: first managing and manipulating my own Tables and Fields and Views before taking care of the Records and Data that it contains!

(My second motivation to enter and learn how to tame Custom-Block’s power is to be able to FORK the Page-Designer-Block to understand it before hard working to try to significantly improve it but stepping out my own real estate when I suggest to make Page-Designer forkable, I don’t even get a Maybe nor a NO! It’s just silence…)

Best,

olπ

Hi Olpy, thanks for sharing your use cases here! This is helpful for us to know - I’ve noted down your use cases and suggestions for future additions to the metadata writes APIs. Would love to hear your feedback on the existing APIs if you start trying them out as well.

For forking page designer, I’ve responded in the Custom Block Inspiration thread.

Thank you @Emma_Yeap for considering my Scripter-User reports.

Be sure that I will give feedback on the existing APIs during my Summer Holiday’s free-time, for 10 of july.

Best,

oLπ

Sean_Betts
4 - Data Explorer
4 - Data Explorer

Hi, I’m new to the Airtable API - what’s the best way to test this new functionality using curl?

Hi Sean - this functionality is currently only available through the Custom Blocks SDK, it is not part of the Airtable REST API. You can get access to the developer preview of the Custom Blocks SDK by filling out this form, and the documentation is available here.

Amit_Merckado
6 - Interface Innovator
6 - Interface Innovator

Hi, I would love to request function for creating views and sections too.
Would love to see those stuff in the REST API as well (for some reason METADATA API is closed for now)