Files
baserow/web-frontend/stories/FormulaInputField.stories.js

509 lines
13 KiB
JavaScript

import FormulaInputField from '@baserow/modules/core/components/formula/FormulaInputField'
const mockNodesHierarchy = [
{
name: 'Data',
type: 'data',
identifier: null,
icon: null,
order: null,
description: null,
example: null,
highlightingColor: null,
nodes: [
{
name: 'User',
type: 'data',
identifier: 'user',
icon: 'iconoir-question-mark',
order: null,
description: null,
example: null,
highlightingColor: null,
signature: null,
nodes: [
{
name: 'Is authenticated',
type: 'data',
identifier: 'is_authenticated',
description: null,
icon: 'baserow-icon-circle-checked',
highlightingColor: null,
example: null,
order: null,
signature: null,
},
{
name: 'Id',
type: 'data',
identifier: 'id',
description: null,
icon: 'baserow-icon-hashtag',
highlightingColor: null,
example: null,
order: null,
signature: null,
},
{
name: 'Email',
type: 'data',
identifier: 'email',
description: null,
icon: 'iconoir-text',
highlightingColor: null,
example: null,
order: null,
signature: null,
},
{
name: 'Username',
type: 'data',
identifier: 'username',
description: null,
icon: 'iconoir-text',
highlightingColor: null,
example: null,
order: null,
signature: null,
},
{
name: 'Role',
type: 'data',
identifier: 'role',
description: null,
icon: 'iconoir-text',
highlightingColor: null,
example: null,
order: null,
signature: null,
},
],
},
{
name: 'Data records',
type: 'data',
identifier: 'data_source',
highlightingColor: null,
description: null,
example: null,
order: null,
icon: 'iconoir-question-mark',
signature: null,
nodes: [
{
name: 'List rows',
identifier: '543',
description: null,
highlightingColor: null,
example: null,
icon: 'iconoir-list',
type: 'array',
order: null,
nodes: [
{
name: 'Id',
type: 'data',
order: null,
description: null,
highlightingColor: null,
example: null,
icon: 'baserow-icon-hashtag',
identifier: 'id',
signature: null,
},
{
name: 'Name',
type: 'data',
description: null,
example: null,
highlightingColor: null,
order: null,
icon: 'iconoir-text',
identifier: 'field_7094',
signature: null,
},
{
name: 'Last name',
type: 'data',
order: null,
description: null,
example: null,
highlightingColor: null,
icon: 'iconoir-text',
identifier: 'field_7095',
signature: null,
},
{
name: 'Notes',
type: 'data',
description: null,
example: null,
highlightingColor: null,
order: null,
icon: 'iconoir-text',
identifier: 'field_7096',
signature: null,
},
{
name: 'Active',
type: 'data',
description: null,
example: null,
highlightingColor: null,
order: null,
icon: 'baserow-icon-circle-checked',
identifier: 'field_7097',
signature: null,
},
],
},
],
},
],
},
{
name: 'Functions',
type: 'function',
identifier: null,
order: null,
signature: null,
description: null,
example: null,
highlightingColor: null,
icon: null,
nodes: [
{
name: 'Text',
identifier: null,
order: null,
signature: null,
description: null,
example: null,
highlightingColor: null,
icon: null,
nodes: [
{
name: 'concat',
type: 'function',
description: 'Concatenates multiple text values together',
example: "concat('Hello', ' ', 'World')",
highlightingColor: 'blue',
icon: 'iconoir-text',
identifier: null,
order: null,
signature: {
parameters: [
{
type: 'string',
required: true,
},
],
variadic: true,
minArgs: 1,
maxArgs: null,
},
},
{
name: 'upper',
type: 'function',
description: 'Converts text to uppercase',
example: "upper('hello world')",
highlightingColor: 'blue',
icon: 'iconoir-text',
identifier: null,
order: null,
signature: {
parameters: [
{
type: 'string',
required: true,
},
],
variadic: false,
minArgs: 1,
maxArgs: 1,
},
},
{
name: 'lower',
type: 'function',
description: 'Converts text to lowercase',
example: "lower('HELLO WORLD')",
highlightingColor: 'blue',
icon: 'iconoir-text',
identifier: null,
order: null,
signature: {
parameters: [
{
type: 'string',
required: true,
},
],
variadic: false,
minArgs: 1,
maxArgs: 1,
},
},
{
name: 'substring',
type: 'function',
description: 'Extracts a portion of text',
example: "substring('Hello World', 0, 5)",
highlightingColor: 'blue',
icon: 'iconoir-text',
identifier: null,
order: null,
signature: {
parameters: [
{
type: 'text',
required: true,
},
{
type: 'number',
required: true,
},
{
type: 'number',
required: false,
},
],
variadic: false,
minArgs: 2,
maxArgs: 3,
},
},
],
},
{
name: 'Math',
type: 'function',
identifier: null,
order: null,
signature: null,
description: null,
example: null,
highlightingColor: null,
icon: null,
nodes: [
{
name: 'round',
type: 'function',
description: 'Rounds a number to specified decimal places',
highlightingColor: 'green',
example: 'round(3.14159, 2)',
icon: 'iconoir-calculator',
identifier: null,
order: null,
signature: {
parameters: [
{
type: 'number',
required: true,
},
{
type: 'number',
required: false,
},
],
variadic: false,
minArgs: 1,
maxArgs: 2,
},
},
{
name: 'sum',
type: 'function',
description: 'Calculates the sum of multiple numbers',
example: 'sum(1, 2, 3, 4)',
highlightingColor: 'green',
icon: 'iconoir-calculator',
identifier: null,
order: null,
signature: {
parameters: [
{
type: 'number',
required: true,
},
{
type: 'number',
required: false,
},
],
variadic: true,
minArgs: 1,
maxArgs: null,
},
},
],
},
],
},
{
name: 'Operators',
type: 'operator',
nodes: [
{
name: 'Arithmetic',
example: null,
signature: null,
highlightingColor: null,
icon: null,
identifier: null,
order: null,
description: null,
nodes: [
{
name: 'add',
type: 'operator',
description: 'Adds two numbers',
example: '5 + 3',
highlightingColor: 'green',
icon: 'iconoir-calculator',
identifier: null,
order: null,
signature: {
operator: '+',
parameters: [
{
type: 'number',
required: true,
},
{
type: 'number',
required: true,
},
],
variadic: false,
minArgs: 2,
maxArgs: 2,
},
},
{
name: 'multiply',
type: 'operator',
description: 'Multiplies two numbers',
example: '5 * 3',
highlightingColor: 'green',
icon: 'iconoir-calculator',
signature: {
operator: '*',
parameters: [
{
type: 'number',
required: true,
},
{
type: 'number',
required: true,
},
],
variadic: false,
minArgs: 2,
maxArgs: 2,
},
},
],
},
],
},
{
name: 'Other',
type: 'function',
identifier: null,
order: null,
signature: null,
description: null,
example: null,
highlightingColor: null,
icon: null,
empty: true,
emptyText: 'No data available',
},
]
export default {
title: 'Baserow/Form Elements/FormulaInputField',
component: FormulaInputField,
tags: ['autodocs'],
argTypes: {
value: {
control: 'text',
description: 'The formula string value.',
},
placeholder: {
control: 'text',
description: 'Placeholder text when empty.',
},
disabled: {
control: 'boolean',
description: 'Disable the input field.',
},
readOnly: {
control: 'boolean',
description: 'Make the input read-only.',
},
loading: {
control: 'boolean',
description: 'Show loading state.',
},
small: {
control: 'boolean',
description: 'Use the small variant.',
},
mode: {
control: 'select',
options: ['advanced', 'simple', 'raw'],
description: 'The editor mode.',
},
contextPosition: {
control: 'select',
options: ['bottom', 'left', 'right'],
description: 'Position of the context menu.',
},
nodesHierarchy: {
control: 'object',
description: 'Hierarchy of available functions and fields.',
},
allowNodeSelection: {
control: 'select',
options: ['none', 'all', 'array', 'object'],
description: 'Allow selecting nodes in the hierarchy.',
},
},
args: {
value: '',
placeholder: 'Enter formula...',
disabled: false,
readOnly: false,
loading: false,
small: false,
mode: 'advanced',
contextPosition: 'bottom',
nodesHierarchy: mockNodesHierarchy,
allowNodeSelection: 'all',
},
parameters: {
design: {
type: 'figma',
url: 'https://www.figma.com/design/pARSkP8ldSqMVxV1t2gYYT/Application-builder?node-id=1314-35740&m=dev',
},
},
}
export const Default = {
render: (args) => ({
components: { FormulaInputField },
setup() {
return { args }
},
template: `
<div style="padding: 20px; max-width: 600px; height: 400px;">
<FormulaInputField v-bind="args" />
</div>
`,
}),
}