Apr 22, 2020 11:42 PM
Hi!
We’ve released a new version of the SDK, 0.0.46, which contains three new functions:
base.unstable_createTableAsync()
table.unstable_createFieldAsync()
field.unstable_updateOptionsAsync()
SELECT
field)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:
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 />);
Apr 23, 2020 08:44 AM
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)
Apr 23, 2020 10:15 AM
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!
Jun 19, 2020 01:53 PM
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:
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π
Jun 22, 2020 11:47 PM
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.
Jun 23, 2020 04:26 AM
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π
Jul 03, 2020 03:34 AM
Hi, I’m new to the Airtable API - what’s the best way to test this new functionality using curl?
Jul 03, 2020 06:03 AM
Jan 20, 2022 04:09 AM
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)