Add ability to link rows in tables, and link rows in the table with search block

This commit is contained in:
Andrew Kingston 2021-11-05 12:38:33 +00:00
parent 8c63b147fb
commit d5002d3dda
5 changed files with 109 additions and 23 deletions

View File

@ -2457,12 +2457,12 @@
"settings": [ "settings": [
{ {
"type": "dataProvider", "type": "dataProvider",
"label": "Provider", "label": "Data provider",
"key": "dataProvider" "key": "dataProvider"
}, },
{ {
"type": "number", "type": "number",
"label": "Row Count", "label": "Row count",
"key": "rowCount", "key": "rowCount",
"defaultValue": 8 "defaultValue": 8
}, },
@ -2496,9 +2496,36 @@
}, },
{ {
"type": "boolean", "type": "boolean",
"label": "Auto Columns", "label": "Show auto columns",
"key": "showAutoColumns", "key": "showAutoColumns",
"defaultValue": false "defaultValue": false
},
{
"type": "boolean",
"label": "Link table rows",
"key": "linkRows"
},
{
"type": "boolean",
"label": "Open link screens in modal",
"key": "linkPeek"
},
{
"type": "url",
"label": "Link screen",
"key": "linkURL"
},
{
"section": true,
"name": "Advanced",
"settings": [
{
"type": "field",
"label": "ID column for linking (appended to URL)",
"key": "linkColumn",
"placeholder": "Default"
}
]
} }
], ],
"context": { "context": {
@ -2662,8 +2689,22 @@
{ {
"type": "boolean", "type": "boolean",
"label": "Show auto columns", "label": "Show auto columns",
"key": "showAutoColumns", "key": "showAutoColumns"
"defaultValue": false },
{
"type": "boolean",
"label": "Link table rows",
"key": "linkRows"
},
{
"type": "boolean",
"label": "Open link in modal",
"key": "linkPeek"
},
{
"type": "url",
"label": "Link screen",
"key": "linkURL"
} }
] ]
}, },
@ -2684,10 +2725,22 @@
}, },
{ {
"type": "event", "type": "event",
"label": "Title Button Action", "label": "Title button action",
"key": "titleButtonOnClick" "key": "titleButtonOnClick"
} }
] ]
},
{
"section": true,
"name": "Advanced",
"settings": [
{
"type": "field",
"label": "ID column for linking (appended to URL)",
"key": "linkColumn",
"placeholder": "Default"
}
]
} }
], ],
"context": { "context": {

View File

@ -16,6 +16,10 @@
export let rowCount export let rowCount
export let quiet export let quiet
export let size export let size
export let linkRows
export let linkURL
export let linkColumn
export let linkPeek
export let showTitleButton export let showTitleButton
export let titleButtonText export let titleButtonText
export let titleButtonOnClick export let titleButtonOnClick
@ -138,6 +142,10 @@
rowCount, rowCount,
quiet, quiet,
size, size,
linkRows,
linkURL,
linkColumn,
linkPeek,
}} }}
/> />
</BlockComponent> </BlockComponent>

View File

@ -9,9 +9,13 @@
export let rowCount export let rowCount
export let quiet export let quiet
export let size export let size
export let linkRows
export let linkURL
export let linkColumn
export let linkPeek
const component = getContext("component") const component = getContext("component")
const { styleable, getAction, ActionTypes } = getContext("sdk") const { styleable, getAction, ActionTypes, routeStore } = getContext("sdk")
const setSorting = getAction( const setSorting = getAction(
dataProvider?.id, dataProvider?.id,
ActionTypes.SetDataProviderSorting ActionTypes.SetDataProviderSorting
@ -81,6 +85,19 @@
order: e.detail.order, order: e.detail.order,
}) })
} }
const onClick = e => {
if (!linkRows || !linkURL) {
return
}
const col = linkColumn || "_id"
const id = e.detail?.[col]
if (!id) {
return
}
const split = linkURL.split("/:")
routeStore.actions.navigate(`${split[0]}/${id}`, linkPeek)
}
</script> </script>
<div use:styleable={$component.styles} class={size}> <div use:styleable={$component.styles} class={size}>
@ -97,6 +114,7 @@
showAutoColumns={true} showAutoColumns={true}
disableSorting disableSorting
on:sort={onSort} on:sort={onSort}
on:click={onClick}
> >
<slot /> <slot />
</Table> </Table>

View File

@ -1,6 +1,8 @@
import { writable } from "svelte/store" import { get, writable } from "svelte/store"
import { push } from "svelte-spa-router" import { push } from "svelte-spa-router"
import * as API from "../api" import * as API from "../api"
import { peekStore } from "./peek"
import { builderStore } from "./builder"
const createRouteStore = () => { const createRouteStore = () => {
const initialState = { const initialState = {
@ -59,7 +61,25 @@ const createRouteStore = () => {
return state return state
}) })
} }
const navigate = push const navigate = (url, peek) => {
if (get(builderStore).inBuilder) {
return
}
if (url) {
// If we're already peeking, don't peek again
const isPeeking = get(store).queryParams?.peek
if (peek && !isPeeking) {
peekStore.actions.showPeek(url)
} else {
const external = !url.startsWith("/")
if (external) {
window.location.href = url
} else {
push(url)
}
}
}
}
const setRouterLoaded = () => { const setRouterLoaded = () => {
store.update(state => ({ ...state, routerLoaded: true })) store.update(state => ({ ...state, routerLoaded: true }))
} }

View File

@ -42,20 +42,7 @@ const triggerAutomationHandler = async action => {
const navigationHandler = action => { const navigationHandler = action => {
const { url, peek } = action.parameters const { url, peek } = action.parameters
if (url) { routeStore.actions.navigate(url, peek)
// If we're already peeking, don't peek again
const isPeeking = get(routeStore).queryParams?.peek
if (peek && !isPeeking) {
peekStore.actions.showPeek(url)
} else {
const external = !url.startsWith("/")
if (external) {
window.location.href = url
} else {
routeStore.actions.navigate(action.parameters.url)
}
}
}
} }
const queryExecutionHandler = async action => { const queryExecutionHandler = async action => {