Open tanbowensg opened 2 years ago
This is the screenshot of the chart demo:
And the JSON schema is:
{
"version": "sunmao/v1",
"kind": "Application",
"metadata": {
"name": "Chart Application"
},
"spec": {
"components": [
{
"id": "Title",
"type": "core/v1/text",
"properties": {
"value": {
"raw": "🌏 World Development Indicator Charts 📈",
"format": "plain"
}
},
"traits": [
{
"type": "core/v1/style",
"properties": {
"styles": [
{
"styleSlot": "content",
"style": "font-size: 24px;\nfont-weight: bold;"
}
]
}
}
]
},
{
"id": "Form",
"type": "chakra_ui/v1/form",
"properties": {
"hideSubmit": true
},
"traits": [
{
"type": "core/v1/style",
"properties": {
"styles": [
{
"styleSlot": "content",
"style": "margin-top: 8px;\noverflow: visible;"
}
]
}
}
]
},
{
"id": "FormTitle",
"type": "core/v1/text",
"properties": {
"value": {
"raw": "FILTERS",
"format": "plain"
}
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": {
"id": "Form",
"slot": "content"
}
}
},
{
"type": "core/v1/style",
"properties": {
"styles": [
{
"styleSlot": "content",
"style": "font-size: 18px;\nfont-weight: bold;"
}
]
}
}
]
},
{
"id": "Indicator",
"type": "chakra_ui/v1/formControl",
"properties": {
"label": "Indicator",
"fieldName": "indicator",
"isRequired": false,
"helperText": ""
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": {
"id": "Form",
"slot": "content"
}
}
}
]
},
{
"id": "IndicatorSelect",
"type": "chakra_ui/v1/select",
"properties": {
"options": "{{\nFetchIndicators.fetch.data?.[1]?.map((indicator)=> ({\n label: indicator.name,\n value: indicator.id\n})) ?? []\n}}",
"placeholder": "Select an indicator",
"defaultValue": "BG.GSR.NFSV.GD.ZS",
"isDisabled": false,
"isInvalid": false,
"isReadOnly": false,
"isRequired": false,
"size": "md",
"variant": "outline",
"errorBorderColor": "red",
"focusBorderColor": "blue"
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": {
"id": "Indicator",
"slot": "content"
}
}
}
]
},
{
"id": "Start",
"type": "chakra_ui/v1/formControl",
"properties": {
"label": "Start",
"fieldName": "start",
"isRequired": false,
"helperText": ""
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": {
"id": "Form",
"slot": "content"
}
}
}
]
},
{
"id": "StartInput",
"type": "chakra_ui/v1/numberInput",
"properties": {
"defaultValue": 1960,
"min": 1960,
"max": 2050,
"step": 1,
"precision": 0,
"clampValueOnBlur": false,
"allowMouseWheel": false,
"size": "md"
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": {
"id": "Start",
"slot": "content"
}
}
},
{
"type": "core/v1/style",
"properties": {
"styles": [
{
"styleSlot": "content",
"style": "width: 100%;"
}
]
}
}
]
},
{
"id": "End",
"type": "chakra_ui/v1/formControl",
"properties": {
"label": "End",
"fieldName": "end",
"isRequired": false,
"helperText": ""
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": {
"id": "Form",
"slot": "content"
}
}
}
]
},
{
"id": "EndInput",
"type": "chakra_ui/v1/numberInput",
"properties": {
"defaultValue": 2019,
"min": "{{Start.value}}",
"max": 2050,
"step": 1,
"precision": 0,
"clampValueOnBlur": false,
"allowMouseWheel": false,
"size": "md"
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": {
"id": "End",
"slot": "content"
}
}
},
{
"type": "core/v1/style",
"properties": {
"styles": [
{
"styleSlot": "content",
"style": "width: 100%;"
}
]
}
}
]
},
{
"id": "Countries",
"type": "chakra_ui/v1/formControl",
"properties": {
"label": "Countries",
"fieldName": "contries",
"isRequired": false,
"helperText": ""
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": {
"id": "Form",
"slot": "content"
}
}
}
]
},
{
"id": "CountriesSelect",
"type": "chakra_ui/v1/multiSelect",
"properties": {
"options": "{{\nFetchCountries.fetch.data?.[1]?.map((country)=> ({\n label: country.name,\n value: country.id\n})) ?? []\n}}",
"placeholder": "",
"defaultValue": [
{
"value": "CHN",
"name": "China",
"label": "China"
}
],
"isDisabled": false,
"isRequired": false,
"size": "md",
"variant": "outline"
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": {
"id": "Countries",
"slot": "content"
}
}
},
{
"type": "core/v1/style",
"properties": {
"styles": [
{
"styleSlot": "content",
"style": "overflow: visible;"
}
]
}
}
]
},
{
"id": "DataLineChart",
"type": "echarts/v1/line",
"properties": {
"notMerge": false,
"lazyUpdate": false,
"showLoading": "{{FetchDatas.fetch.loading}}",
"title": {
"text": "{{IndicatorSelect.value}}",
"left": "",
"right": "",
"top": "",
"bottom": ""
},
"grid": {
"left": "64",
"right": "64",
"top": "",
"bottom": "24",
"containLabel": true
},
"xAxis": [
{
"name": "Year",
"type": "category",
"data": "{{\nArray.from(new Set(FetchDatas.fetch.data[1]?.map(data=> data.date) ?? []))\n }}",
"nameLocation": "end",
"offset": 0,
"position": "bottom"
}
],
"yAxis": [
{
"name": "Value",
"type": "value",
"data": [],
"nameLocation": "end",
"offset": 0,
"position": "left"
}
],
"tooltip": {
"trigger": "axis",
"triggerOn": "mousemove"
},
"legend": {
"show": true,
"data": [],
"type": "scroll",
"left": "",
"right": "",
"top": "",
"bottom": "",
"icon": "circle"
},
"color": [],
"series": "{{\n(FetchDatas.fetch?.data?.[1] ?? []).reduce((result, data)=> {\n const categories = result.map((series) => series.name);\n const categoryIndex = categories.indexOf(data.country.value);\n\n if (categoryIndex === -1) {\n result.push({\n name: data.country.value,\n data: [data.value],\n });\n } else {\n result[categoryIndex].data.push(data.value);\n }\n \n return result\n}, []) ?? []\n}}"
},
"traits": [
{
"type": "core/v1/style",
"properties": {
"styles": [
{
"styleSlot": "wrapper",
"style": "margin-top: 24px;"
}
]
}
}
]
},
{
"id": "Footer",
"type": "chakra_ui/v1/hstack",
"properties": {
"direction": "row",
"wrap": "wrap",
"align": "",
"justify": "",
"spacing": "12px"
},
"traits": [
{
"type": "core/v1/style",
"properties": {
"styles": [
{
"styleSlot": "content",
"style": "border: none;"
}
]
}
}
]
},
{
"id": "FooterText",
"type": "core/v1/text",
"properties": {
"value": {
"raw": "Source:",
"format": "plain"
}
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": {
"id": "Footer",
"slot": "content"
}
}
}
]
},
{
"id": "FooterLink",
"type": "chakra_ui/v1/link",
"properties": {
"text": {
"raw": "World Bank Data API",
"format": "plain"
},
"href": "https://datahelpdesk.worldbank.org/knowledgebase/topics/125589-developer-information",
"isExternal": false
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": {
"id": "Footer",
"slot": "content"
}
}
}
]
},
{
"id": "FetchIndicators",
"type": "core/v1/dummy",
"properties": {},
"traits": [
{
"type": "core/v1/fetch",
"properties": {
"url": "http://api.worldbank.org/v2/indicator?format=json&source=2&per_page=100",
"method": "get",
"lazy": false,
"headers": {},
"body": {},
"onComplete": [],
"onError": []
}
}
]
},
{
"id": "FetchCountries",
"type": "core/v1/dummy",
"properties": {},
"traits": [
{
"type": "core/v1/fetch",
"properties": {
"url": "http://api.worldbank.org/v2/countries?per_page=200&format=json",
"method": "get",
"lazy": false,
"headers": {},
"body": {},
"onComplete": [],
"onError": []
}
}
]
},
{
"id": "FetchDatas",
"type": "core/v1/dummy",
"properties": {},
"traits": [
{
"type": "core/v1/fetch",
"properties": {
"url": "http://api.worldbank.org/V2/country/{{CountriesSelect.value.join(';')}}/indicator/{{IndicatorSelect.value}}?format=json&date={{StartInput.value}}%3A{{EndInput.value}}&per_page=100",
"method": "get",
"lazy": false,
"headers": {},
"body": {},
"onComplete": [],
"onError": []
}
}
]
}
]
}
}
This is the screenshot of the todolist demo:
And the JSON schema:
{
"kind": "Application",
"version": "example/v1",
"metadata": {
"name": "sunmao application",
"description": "sunmao empty application"
},
"spec": {
"components": [
{
"id": "Content",
"type": "arco/v1/content",
"properties": {},
"traits": [
{
"type": "core/v1/style",
"properties": {
"styles": [{ "styleSlot": "content", "style": "width:700px;" }]
}
}
]
},
{
"id": "hstack7",
"type": "chakra_ui/v1/hstack",
"properties": {
"direction": "row",
"wrap": "nowrap",
"align": "",
"justify": "",
"spacing": "24px"
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": { "id": "Content", "slot": "content" }
}
},
{
"type": "core/v1/style",
"properties": {
"styles": [{ "styleSlot": "content", "style": "border:none;" }]
}
}
]
},
{
"id": "AddTask",
"type": "arco/v1/input",
"properties": {
"allowClear": false,
"disabled": false,
"readOnly": false,
"defaultValue": "",
"placeholder": "Add a task",
"error": false,
"size": "default"
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": { "id": "hstack7", "slot": "content" }
}
},
{ "type": "core/v1/event", "properties": { "handlers": [] } },
{
"type": "core/v1/style",
"properties": {
"styles": [{ "styleSlot": "input", "style": "width: 100px;\n" }]
}
}
]
},
{
"id": "AddButton",
"type": "arco/v1/button",
"properties": {
"htmlType": "button",
"type": "primary",
"status": "default",
"long": false,
"size": "default",
"href": "",
"target": "",
"disabled": false,
"loading": false,
"loadingFixedWidth": false,
"iconOnly": false,
"shape": "square",
"text": "Add"
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": { "id": "hstack7", "slot": "content" }
}
},
{
"type": "core/v1/event",
"properties": {
"handlers": [
{
"type": "onClick",
"componentId": "addTodoItem",
"method": { "name": "triggerFetch", "parameters": {} },
"disabled": false,
"wait": { "type": "delay", "time": 0 }
}
]
}
},
{
"type": "core/v1/style",
"properties": {
"styles": [
{
"styleSlot": "content",
"style": "-webkit-margin-start:0px !important;\nmargin-inline-start:0px !important;\nmargin:0px !important;"
}
]
}
}
]
},
{
"id": "TaskList",
"type": "chakra_ui/v1/vstack",
"properties": {
"spacing": "24px",
"direction": "column",
"wrap": "nowrap",
"align": "",
"justify": ""
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": { "id": "Content", "slot": "content" }
}
},
{
"type": "core/v1/style",
"properties": {
"styles": [{ "styleSlot": "content", "style": "border:none" }]
}
}
]
},
{
"id": "TasksTable",
"type": "arco/v1/table",
"properties": {
"columns": [
{
"title": "Task",
"dataIndex": "name",
"sorter": false,
"sortDirections": ["ascend"],
"defaultSortOrder": "ascend",
"type": "text",
"filter": false,
"btnCfg": { "text": "undefined" },
"module": { "type": "undefined" }
},
{
"title": "Status",
"dataIndex": "status",
"sorter": false,
"filter": false,
"type": "text"
}
],
"data": "{{\n(getTodoList?.fetch?.data || []).map(el => ({\n name: el.label,\n id: el.id,\n \tkey: el.id,\n \tvalue:el.value,\n \tlabel:el.label,\n isDone:el.isDone ,status:el.isDone?'✅':'❌'\n})).reduce((prev,cur)=>{\n\tif(!cur.isDone){\n \tprev.unshift(cur);\n }else{\n \tprev.push(cur);\n }\n return prev;\n},[])\n}}",
"pagination": { "pageSize": 100 },
"tableLayoutFixed": false,
"borderCell": false,
"stripe": false,
"size": "default",
"pagePosition": "bottomCenter",
"rowSelectionType": "radio"
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": { "id": "TaskList", "slot": "content" }
}
}
]
},
{
"id": "EditButton",
"type": "arco/v1/button",
"properties": {
"htmlType": "button",
"type": "default",
"status": "default",
"long": false,
"size": "default",
"href": "",
"target": "",
"disabled": "{{!TasksTable.selectedRow}}",
"loading": false,
"loadingFixedWidth": false,
"iconOnly": false,
"shape": "square",
"text": "Edit"
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": { "id": "TaskList", "slot": "content" }
}
},
{
"type": "core/v1/event",
"properties": {
"handlers": [
{
"type": "onClick",
"componentId": "EditModal",
"method": { "name": "openModal", "parameters": {} },
"disabled": false,
"wait": { "type": "delay", "time": 0 }
}
]
}
}
]
},
{
"id": "EditModal",
"type": "arco/v1/modal",
"properties": {
"title": "EditForm",
"mask": true,
"simple": true,
"okText": "confirm",
"cancelText": "cancel",
"closable": true,
"maskClosable": true,
"confirmLoading": false
},
"traits": [
{ "type": "core/v1/event", "properties": { "handlers": [] } },
{
"type": "core/v1/slot",
"properties": {
"container": { "id": "Content", "slot": "content" }
}
},
{
"type": "core/v1/style",
"properties": {
"styles": [
{ "styleSlot": "content", "style": "z-index:1400 !important;" }
]
}
}
]
},
{
"id": "EditForm",
"type": "chakra_ui/v1/form",
"properties": { "hideSubmit": true },
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": { "id": "EditModal", "slot": "content" }
}
}
]
},
{
"id": "Id",
"type": "chakra_ui/v1/formControl",
"properties": {
"label": "Id",
"fieldName": "Id",
"isRequired": true,
"helperText": ""
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": { "id": "EditForm", "slot": "content" }
}
}
]
},
{
"id": "TodoId",
"type": "chakra_ui/v1/input",
"properties": {
"variant": "outline",
"placeholder": "Please input value",
"size": "md",
"focusBorderColor": "",
"isDisabled": true,
"isRequired": false,
"defaultValue": "{{ TasksTable.selectedRow?.id }}"
},
"traits": [
{
"type": "core/v1/slot",
"properties": { "container": { "id": "Id", "slot": "content" } }
}
]
},
{
"id": "Name",
"type": "chakra_ui/v1/formControl",
"properties": {
"label": "TaskName",
"fieldName": "TaskName",
"isRequired": false,
"helperText": ""
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": { "id": "EditForm", "slot": "content" }
}
}
]
},
{
"id": "TodoLabel",
"type": "chakra_ui/v1/input",
"properties": {
"variant": "outline",
"placeholder": "Please input value",
"size": "md",
"focusBorderColor": "",
"isDisabled": false,
"isRequired": false,
"defaultValue": "{{ TasksTable.selectedRow?.label }}"
},
"traits": [
{
"type": "core/v1/slot",
"properties": { "container": { "id": "Name", "slot": "content" } }
}
]
},
{
"id": "Status",
"type": "chakra_ui/v1/formControl",
"properties": {
"label": "IsDone",
"fieldName": "IsDone",
"isRequired": false,
"helperText": ""
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": { "id": "EditForm", "slot": "content" }
}
}
]
},
{
"id": "IsDone",
"type": "arco/v1/Switch",
"properties": {
"defaultChecked": "{{ TasksTable.selectedRow?.isDone }}",
"disabled": false,
"loading": false,
"type": "circle",
"size": "default"
},
"traits": [
{
"type": "core/v1/slot",
"properties": { "container": { "id": "Status", "slot": "content" } }
}
]
},
{
"id": "UpdateButton",
"type": "arco/v1/button",
"properties": {
"htmlType": "button",
"type": "primary",
"status": "default",
"long": false,
"size": "default",
"href": "",
"target": "",
"disabled": false,
"loading": false,
"loadingFixedWidth": false,
"iconOnly": false,
"shape": "square",
"text": "Update"
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": { "id": "EditModal", "slot": "footer" }
}
},
{
"type": "core/v1/event",
"properties": {
"handlers": [
{
"type": "onClick",
"componentId": "updateTodoItemStatus",
"method": { "name": "triggerFetch", "parameters": {} },
"disabled": false,
"wait": { "type": "delay", "time": 0 }
},
{
"type": "onClick",
"componentId": "EditModal",
"method": { "name": "closeModal", "parameters": {} },
"disabled": false,
"wait": { "type": "delay", "time": "100" }
}
]
}
}
]
},
{
"id": "DeleteButton",
"type": "arco/v1/button",
"properties": {
"htmlType": "button",
"type": "default",
"status": "danger",
"long": false,
"size": "default",
"href": "",
"target": "",
"disabled": false,
"loading": false,
"loadingFixedWidth": false,
"iconOnly": false,
"shape": "square",
"text": "Delete"
},
"traits": [
{
"type": "core/v1/slot",
"properties": {
"container": { "id": "EditModal", "slot": "footer" }
}
},
{
"type": "core/v1/event",
"properties": {
"handlers": [
{
"type": "onClick",
"componentId": "deleteTodoItem",
"method": { "name": "triggerFetch", "parameters": {} },
"disabled": false,
"wait": { "type": "delay", "time": 0 }
},
{
"type": "onClick",
"componentId": "EditModal",
"method": { "name": "closeModal", "parameters": {} },
"disabled": false,
"wait": { "type": "delay", "time": "100" }
}
]
}
}
]
},
{
"id": "getTodoList",
"type": "core/v1/dummy",
"properties": {},
"traits": [
{
"type": "core/v1/fetch",
"properties": {
"url": "http://62009413fdf5090017249522.mockapi.io/todolist",
"method": "get",
"lazy": false,
"headers": {},
"body": {},
"onComplete": [],
"onError": []
}
}
]
},
{
"id": "updateTodoItemStatus",
"type": "core/v1/dummy",
"properties": {},
"traits": [
{
"type": "core/v1/fetch",
"properties": {
"url": "https://62009413fdf5090017249522.mockapi.io/todolist/{{TodoId.value}}",
"method": "put",
"lazy": true,
"headers": { "Content-Type": "application/json" },
"body": { "isDone": "{{IsDone.value}}" },
"onComplete": [
{
"type": "",
"componentId": "getTodoList",
"method": { "name": "triggerFetch", "parameters": {} },
"disabled": false,
"wait": { "type": "delay", "time": 0 }
},
{
"type": "",
"componentId": "editor",
"method": { "name": "closeModal", "parameters": {} },
"disabled": false,
"wait": { "type": "delay", "time": 0 }
}
],
"onError": []
}
}
]
},
{
"id": "addTodoItem",
"type": "core/v1/dummy",
"properties": {},
"traits": [
{
"type": "core/v1/fetch",
"properties": {
"url": "http://62009413fdf5090017249522.mockapi.io/todolist",
"method": "post",
"lazy": true,
"headers": { "Content-Type": "application/json" },
"body": {
"label": "{{AddTask.value}}",
"value": "{{AddTask.value}}"
},
"onComplete": [
{
"type": "",
"componentId": "getTodoList",
"method": { "name": "triggerFetch", "parameters": {} },
"disabled": false,
"wait": { "type": "delay", "time": 0 }
}
],
"onError": []
}
}
]
},
{
"id": "deleteTodoItem",
"type": "core/v1/dummy",
"properties": {},
"traits": [
{
"type": "core/v1/fetch",
"properties": {
"url": "https://62009413fdf5090017249522.mockapi.io/todolist/{{TodoId.value}}",
"method": "delete",
"lazy": true,
"headers": {},
"body": {},
"onComplete": [
{
"type": "",
"componentId": "editor",
"method": { "name": "closeModal", "parameters": {} },
"disabled": false,
"wait": { "type": "delay", "time": 0 }
},
{
"type": "",
"componentId": "getTodoList",
"method": { "name": "triggerFetch", "parameters": {} },
"disabled": false,
"wait": { "type": "delay", "time": 0 }
}
],
"onError": []
}
}
]
}
]
}
}
Try to use arco components first.