Clean up data source context and remove explicit button actions for pagination

This commit is contained in:
Andrew Kingston 2021-05-13 12:30:45 +01:00
parent da40086c0b
commit d9923e1e98
7 changed files with 8 additions and 133 deletions

View File

@ -1,38 +0,0 @@
<script>
import { Select, Label } from "@budibase/bbui"
import { currentAsset, store } from "builderStore"
import { getActionProviderComponents } from "builderStore/dataBinding"
export let parameters
$: actionProviders = getActionProviderComponents(
$currentAsset,
$store.selectedComponentId,
"NextPage"
)
</script>
<div class="root">
<Label small>Data Provider</Label>
<Select
bind:value={parameters.componentId}
options={actionProviders}
getOptionLabel={(x) => x._instanceName}
getOptionValue={(x) => x._id}
/>
</div>
<style>
.root {
display: flex;
flex-direction: row;
align-items: center;
max-width: 800px;
margin: 0 auto;
}
.root :global(> div) {
flex: 1;
margin-left: var(--spacing-l);
}
</style>

View File

@ -1,38 +0,0 @@
<script>
import { Select, Label } from "@budibase/bbui"
import { currentAsset, store } from "builderStore"
import { getActionProviderComponents } from "builderStore/dataBinding"
export let parameters
$: actionProviders = getActionProviderComponents(
$currentAsset,
$store.selectedComponentId,
"PrevPage"
)
</script>
<div class="root">
<Label small>Data Provider</Label>
<Select
bind:value={parameters.componentId}
options={actionProviders}
getOptionLabel={(x) => x._instanceName}
getOptionValue={(x) => x._id}
/>
</div>
<style>
.root {
display: flex;
flex-direction: row;
align-items: center;
max-width: 800px;
margin: 0 auto;
}
.root :global(> div) {
flex: 1;
margin-left: var(--spacing-l);
}
</style>

View File

@ -6,8 +6,6 @@ import TriggerAutomation from "./TriggerAutomation.svelte"
import ValidateForm from "./ValidateForm.svelte" import ValidateForm from "./ValidateForm.svelte"
import LogIn from "./LogIn.svelte" import LogIn from "./LogIn.svelte"
import LogOut from "./LogOut.svelte" import LogOut from "./LogOut.svelte"
import NextPage from "./NextPage.svelte"
import PrevPage from "./PrevPage.svelte"
// defines what actions are available, when adding a new one // defines what actions are available, when adding a new one
// the component is the setup panel for the action // the component is the setup panel for the action
@ -47,12 +45,4 @@ export default [
name: "Log Out", name: "Log Out",
component: LogOut, component: LogOut,
}, },
{
name: "Next Page",
component: NextPage,
},
{
name: "Previous Page",
component: PrevPage,
},
] ]

View File

@ -5,6 +5,4 @@ export const TableNames = {
export const ActionTypes = { export const ActionTypes = {
ValidateForm: "ValidateForm", ValidateForm: "ValidateForm",
RefreshDatasource: "RefreshDatasource", RefreshDatasource: "RefreshDatasource",
NextPage: "NextPage",
PrevPage: "PrevPage",
} }

View File

@ -16,27 +16,27 @@ const saveRowHandler = async (action, context) => {
} }
} }
const deleteRowHandler = async (action) => { const deleteRowHandler = async action => {
const { tableId, revId, rowId } = action.parameters const { tableId, revId, rowId } = action.parameters
if (tableId && revId && rowId) { if (tableId && revId && rowId) {
await deleteRow({ tableId, rowId, revId }) await deleteRow({ tableId, rowId, revId })
} }
} }
const triggerAutomationHandler = async (action) => { const triggerAutomationHandler = async action => {
const { fields } = action.parameters const { fields } = action.parameters
if (fields) { if (fields) {
await triggerAutomation(action.parameters.automationId, fields) await triggerAutomation(action.parameters.automationId, fields)
} }
} }
const navigationHandler = (action) => { const navigationHandler = action => {
if (action.parameters.url) { if (action.parameters.url) {
routeStore.actions.navigate(action.parameters.url) routeStore.actions.navigate(action.parameters.url)
} }
} }
const queryExecutionHandler = async (action) => { const queryExecutionHandler = async action => {
const { datasourceId, queryId, queryParams } = action.parameters const { datasourceId, queryId, queryParams } = action.parameters
await executeQuery({ await executeQuery({
datasourceId, datasourceId,
@ -68,23 +68,7 @@ const refreshDatasourceHandler = async (action, context) => {
) )
} }
const nextPageHandler = async (action, context) => { const loginHandler = async action => {
return await executeActionHandler(
context,
action.parameters.componentId,
ActionTypes.NextPage
)
}
const prevPageHandler = async (action, context) => {
return await executeActionHandler(
context,
action.parameters.componentId,
ActionTypes.PrevPage
)
}
const loginHandler = async (action) => {
const { email, password } = action.parameters const { email, password } = action.parameters
await authStore.actions.logIn({ email, password }) await authStore.actions.logIn({ email, password })
} }
@ -103,8 +87,6 @@ const handlerMap = {
["Refresh Datasource"]: refreshDatasourceHandler, ["Refresh Datasource"]: refreshDatasourceHandler,
["Log In"]: loginHandler, ["Log In"]: loginHandler,
["Log Out"]: logoutHandler, ["Log Out"]: logoutHandler,
["Next Page"]: nextPageHandler,
["Previous Page"]: prevPageHandler,
} }
/** /**
@ -114,10 +96,9 @@ const handlerMap = {
export const enrichButtonActions = (actions, context) => { export const enrichButtonActions = (actions, context) => {
// Prevent button actions in the builder preview // Prevent button actions in the builder preview
if (get(builderStore).inBuilder) { if (get(builderStore).inBuilder) {
// TODO uncomment return () => {}
// return () => {}
} }
const handlers = actions.map((def) => handlerMap[def["##eventHandlerType"]]) const handlers = actions.map(def => handlerMap[def["##eventHandlerType"]])
return async () => { return async () => {
for (let i = 0; i < handlers.length; i++) { for (let i = 0; i < handlers.length; i++) {
try { try {

View File

@ -1384,7 +1384,6 @@
"icon": "Data", "icon": "Data",
"styleable": false, "styleable": false,
"hasChildren": true, "hasChildren": true,
"actions": ["NextPage", "PrevPage"],
"settings": [ "settings": [
{ {
"type": "dataSource", "type": "dataSource",

View File

@ -54,25 +54,8 @@
callback: () => fetchData(dataSource), callback: () => fetchData(dataSource),
metadata: { dataSource }, metadata: { dataSource },
}, },
{
type: ActionTypes.NextPage,
callback: () => nextPage(),
},
{
type: ActionTypes.PrevPage,
callback: () => prevPage(),
},
] ]
$: dataContext = { $: dataContext = { rows, schema, rowsLength: rows.length }
rows,
schema,
rowsLength: rows.length,
loading,
loaded,
pageNumber: pageNumber + 1,
hasNextPage,
hasPrevPage,
}
const getSortType = (schema, sortColumn) => { const getSortType = (schema, sortColumn) => {
if (!schema || !sortColumn || !schema[sortColumn]) { if (!schema || !sortColumn || !schema[sortColumn]) {