From 2b74fd887bbc2740cbbea5d6c8a09d446bc2d6d3 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Sat, 6 Feb 2021 12:31:12 +0000 Subject: [PATCH] test --- packages/client/src/api/datasources.js | 5 +-- packages/client/src/api/tables.js | 8 ++++- packages/server/src/api/controllers/row.js | 15 ++++++--- packages/server/src/api/routes/row.js | 2 +- packages/standard-components/manifest.json | 5 +++ packages/standard-components/src/Login.svelte | 9 +++++- .../standard-components/src/Search.svelte | 32 ++++++++++++++++--- 7 files changed, 62 insertions(+), 14 deletions(-) diff --git a/packages/client/src/api/datasources.js b/packages/client/src/api/datasources.js index d36b869d33..a15265681b 100644 --- a/packages/client/src/api/datasources.js +++ b/packages/client/src/api/datasources.js @@ -5,9 +5,10 @@ import { fetchRelationshipData } from "./relationships" import { executeQuery } from "./queries" import { enrichRows } from "./rows" -export const searchTable = async ({ tableId, search, pageSize }) => { - const rows = await searchTableData(tableId, search, pageSize) +export const searchTable = async ({ tableId, search, page, pageSize }) => { + const rows = await searchTableData({ tableId, search, page, pageSize }) return rows + // TODO // Enrich rows so they can displayed properly // return await enrichRows(rows, tableId) } diff --git a/packages/client/src/api/tables.js b/packages/client/src/api/tables.js index 02a394d46a..80b46cfb0c 100644 --- a/packages/client/src/api/tables.js +++ b/packages/client/src/api/tables.js @@ -22,12 +22,18 @@ export const fetchTableData = async tableId => { * @param {String} tableId - id of the table to search * @param {Object} search - Mango Compliant search object */ -export const searchTableData = async (tableId, search, pageSize) => { +export const searchTableData = async ({ + tableId, + search, + cursor, + pageSize, +}) => { const rows = await API.post({ url: `/api/${tableId}/rows/search`, body: { query: search, pageSize, + cursor, }, }) return await enrichRows(rows, tableId) diff --git a/packages/server/src/api/controllers/row.js b/packages/server/src/api/controllers/row.js index 43633ee56c..3d0fedbc4d 100644 --- a/packages/server/src/api/controllers/row.js +++ b/packages/server/src/api/controllers/row.js @@ -224,9 +224,10 @@ exports.fetchView = async function(ctx) { } exports.search = async function(ctx) { - const appId = ctx.user.appId + // const appId = ctx.user.appId + const appId = 'app_5aa5e9cf26694f9ea02f054050d7ae63' - const { pageSize = 10, cursor } = ctx.query + // const { pageSize = 10, cursor } = ctx.query // special case for users, fetch through the user controller // let rows @@ -238,13 +239,19 @@ exports.search = async function(ctx) { const db = new CouchDB(appId) - const query = ctx.request.body.query + const { query, pageSize = 10, cursor } = ctx.request.body + query.tableId = ctx.params.tableId - // query._id = { $gte: cursor } + + // Paginating + if (cursor) { + query._id = { $gte: cursor } + } const response = await db.find({ selector: query, limit: pageSize, + // sort: ["_id"], }) ctx.body = response.docs diff --git a/packages/server/src/api/routes/row.js b/packages/server/src/api/routes/row.js index 674431c26a..f9d7b22b28 100644 --- a/packages/server/src/api/routes/row.js +++ b/packages/server/src/api/routes/row.js @@ -33,7 +33,7 @@ router ) .post( "/api/:tableId/rows/search", - authorized(PermissionTypes.TABLE, PermissionLevels.READ), + // authorized(PermissionTypes.TABLE, PermissionLevels.READ), rowController.search ) .patch( diff --git a/packages/standard-components/manifest.json b/packages/standard-components/manifest.json index 38a9429fc7..220c8f4df7 100644 --- a/packages/standard-components/manifest.json +++ b/packages/standard-components/manifest.json @@ -138,6 +138,11 @@ "key": "valueColumns", "dependsOn": "table" }, + { + "type": "number", + "label": "Result Page Size", + "key": "pageSize" + }, { "type": "text", "label": "No Rows Message", diff --git a/packages/standard-components/src/Login.svelte b/packages/standard-components/src/Login.svelte index 8a4af82320..02b0655a17 100644 --- a/packages/standard-components/src/Login.svelte +++ b/packages/standard-components/src/Login.svelte @@ -27,12 +27,19 @@ await authStore.actions.logIn({ email, password }) loading = false } + + function handleKeydown(evt) { + console.log(evt.keyCode) + } +
{#if logo} -
logo
+
+ logo +
{/if} {#if title} diff --git a/packages/standard-components/src/Search.svelte b/packages/standard-components/src/Search.svelte index 50ddeb52c2..07c398fcb2 100644 --- a/packages/standard-components/src/Search.svelte +++ b/packages/standard-components/src/Search.svelte @@ -1,7 +1,14 @@
@@ -48,8 +58,8 @@ {/each} - + {:else if schema[field].type === 'datetime'} + {:else if schema[field].type === 'boolean'} {:else if schema[field].type === 'number'} @@ -82,6 +92,12 @@ {:else if loaded && $builderStore.inBuilder}

{noRowsMessage}

{/if} +