From 36fb93def5ae35f13cab9cd81fe639f8836e4850 Mon Sep 17 00:00:00 2001 From: mertmit Date: Sat, 14 Jan 2023 23:11:22 +0300 Subject: [PATCH] feat: row height for grid view Signed-off-by: mertmit --- packages/nc-gui/components.d.ts | 5 ++ .../nc-gui/components/cell/MultiSelect.vue | 6 +- packages/nc-gui/components/cell/TextArea.vue | 29 +++++++- .../nc-gui/components/smartsheet/Toolbar.vue | 2 + .../smartsheet/toolbar/RowHeight.vue | 70 +++++++++++++++++++ packages/nocodb-sdk/src/lib/Api.ts | 19 +++++ .../nocodb/src/lib/meta/api/gridViewApis.ts | 11 +++ .../src/lib/migrations/XcMigrationSourcev2.ts | 4 ++ .../migrations/v2/nc_025_add_row_height.ts | 16 +++++ packages/nocodb/src/lib/models/GridView.ts | 41 ++++++++--- scripts/sdk/swagger.json | 41 +++++++++++ 11 files changed, 234 insertions(+), 10 deletions(-) create mode 100644 packages/nc-gui/components/smartsheet/toolbar/RowHeight.vue create mode 100644 packages/nocodb/src/lib/migrations/v2/nc_025_add_row_height.ts diff --git a/packages/nc-gui/components.d.ts b/packages/nc-gui/components.d.ts index a07986cb7f..95fead216e 100644 --- a/packages/nc-gui/components.d.ts +++ b/packages/nc-gui/components.d.ts @@ -222,6 +222,10 @@ declare module '@vue/runtime-core' { MdiScriptTextKeyOutline: typeof import('~icons/mdi/script-text-key-outline')['default'] MdiScriptTextOutline: typeof import('~icons/mdi/script-text-outline')['default'] MdiShieldKeyOutline: typeof import('~icons/mdi/shield-key-outline')['default'] + MdiSizeL: typeof import('~icons/mdi/size-l')['default'] + MdiSizeM: typeof import('~icons/mdi/size-m')['default'] + MdiSizeS: typeof import('~icons/mdi/size-s')['default'] + MdiSizeXl: typeof import('~icons/mdi/size-xl')['default'] MdiSlack: typeof import('~icons/mdi/slack')['default'] MdiSort: typeof import('~icons/mdi/sort')['default'] MdiSortAscending: typeof import('~icons/mdi/sort-ascending')['default'] @@ -233,6 +237,7 @@ declare module '@vue/runtime-core' { MdiTableColumnPlusAfter: typeof import('~icons/mdi/table-column-plus-after')['default'] MdiTableColumnPlusBefore: typeof import('~icons/mdi/table-column-plus-before')['default'] MdiTableLarge: typeof import('~icons/mdi/table-large')['default'] + MdiTableRowHeight: typeof import('~icons/mdi/table-row-height')['default'] MdiText: typeof import('~icons/mdi/text')['default'] MdiThumbUp: typeof import('~icons/mdi/thumb-up')['default'] MdiTrashCan: typeof import('~icons/mdi/trash-can')['default'] diff --git a/packages/nc-gui/components/cell/MultiSelect.vue b/packages/nc-gui/components/cell/MultiSelect.vue index 7b7d69c191..049549033e 100644 --- a/packages/nc-gui/components/cell/MultiSelect.vue +++ b/packages/nc-gui/components/cell/MultiSelect.vue @@ -281,7 +281,7 @@ const onTagClick = (e: Event, onClose: Function) => { v-model:value="vModel" v-model:open="isOpen" mode="multiple" - class="w-full" + class="w-full overflow-hidden" :bordered="false" clear-icon show-search @@ -402,4 +402,8 @@ const onTagClick = (e: Event, onClose: Function) => { :deep(.ant-select-selection-overflow-item) { @apply "flex overflow-hidden"; } + +:deep(.ant-select-selection-overflow) { + @apply flex-nowrap; +} diff --git a/packages/nc-gui/components/cell/TextArea.vue b/packages/nc-gui/components/cell/TextArea.vue index d5bd1c4479..021c67b676 100644 --- a/packages/nc-gui/components/cell/TextArea.vue +++ b/packages/nc-gui/components/cell/TextArea.vue @@ -1,6 +1,7 @@ diff --git a/packages/nc-gui/components/smartsheet/Toolbar.vue b/packages/nc-gui/components/smartsheet/Toolbar.vue index d28c91773a..d822e8eab0 100644 --- a/packages/nc-gui/components/smartsheet/Toolbar.vue +++ b/packages/nc-gui/components/smartsheet/Toolbar.vue @@ -35,6 +35,8 @@ const { allowCSVDownload } = useSharedView() + + diff --git a/packages/nc-gui/components/smartsheet/toolbar/RowHeight.vue b/packages/nc-gui/components/smartsheet/toolbar/RowHeight.vue new file mode 100644 index 0000000000..9778f29177 --- /dev/null +++ b/packages/nc-gui/components/smartsheet/toolbar/RowHeight.vue @@ -0,0 +1,70 @@ + + + + + diff --git a/packages/nocodb-sdk/src/lib/Api.ts b/packages/nocodb-sdk/src/lib/Api.ts index 7b619c0d85..9ab6d9ed28 100644 --- a/packages/nocodb-sdk/src/lib/Api.ts +++ b/packages/nocodb-sdk/src/lib/Api.ts @@ -340,6 +340,7 @@ export interface GridType { deleted?: boolean; order?: number; lock_type?: 'collaborative' | 'locked' | 'personal'; + row_height?: number; } export interface GalleryType { @@ -2499,6 +2500,24 @@ export class Api< ...params, }), + /** + * No description + * + * @tags DB view + * @name GridUpdate + * @request PATCH:/api/v1/db/meta/grids/{viewId} + * @response `200` `any` OK + */ + gridUpdate: (viewId: string, data: GridType, params: RequestParams = {}) => + this.request({ + path: `/api/v1/db/meta/grids/${viewId}`, + method: 'PATCH', + body: data, + type: ContentType.Json, + format: 'json', + ...params, + }), + /** * No description * diff --git a/packages/nocodb/src/lib/meta/api/gridViewApis.ts b/packages/nocodb/src/lib/meta/api/gridViewApis.ts index 94c815f9eb..80f8574efb 100644 --- a/packages/nocodb/src/lib/meta/api/gridViewApis.ts +++ b/packages/nocodb/src/lib/meta/api/gridViewApis.ts @@ -12,6 +12,7 @@ import Project from '../../models/Project'; import View from '../../models/View'; import ncMetaAclMw from '../helpers/ncMetaAclMw'; import { metaApiMetrics } from '../helpers/apiMetrics'; +import GridView from '../../models/GridView'; // @ts-ignore export async function gridViewCreate(req: Request, res) { @@ -25,10 +26,20 @@ export async function gridViewCreate(req: Request, res) { res.json(view); } +export async function gridViewUpdate(req, res) { + Tele.emit('evt', { evt_type: 'view:updated', type: 'grid' }); + res.json(await GridView.update(req.params.viewId, req.body)); +} + const router = Router({ mergeParams: true }); router.post( '/api/v1/db/meta/tables/:tableId/grids/', metaApiMetrics, ncMetaAclMw(gridViewCreate, 'gridViewCreate') ); +router.patch( + '/api/v1/db/meta/grids/:viewId', + metaApiMetrics, + ncMetaAclMw(gridViewUpdate, 'gridViewUpdate') +); export default router; diff --git a/packages/nocodb/src/lib/migrations/XcMigrationSourcev2.ts b/packages/nocodb/src/lib/migrations/XcMigrationSourcev2.ts index 8cf290e503..b6e42c5b8c 100644 --- a/packages/nocodb/src/lib/migrations/XcMigrationSourcev2.ts +++ b/packages/nocodb/src/lib/migrations/XcMigrationSourcev2.ts @@ -12,6 +12,7 @@ import * as nc_021_add_fields_in_token from './v2/nc_021_add_fields_in_token'; import * as nc_022_qr_code_column_type from './v2/nc_022_qr_code_column_type'; import * as nc_023_multiple_source from './v2/nc_023_multiple_source'; import * as nc_024_barcode_column_type from './v2/nc_024_barcode_column_type'; +import * as nc_025_add_row_height from './v2/nc_025_add_row_height'; // Create a custom migration source class export default class XcMigrationSourcev2 { @@ -35,6 +36,7 @@ export default class XcMigrationSourcev2 { 'nc_022_qr_code_column_type', 'nc_023_multiple_source', 'nc_024_barcode_column_type', + 'nc_025_add_row_height', ]); } @@ -72,6 +74,8 @@ export default class XcMigrationSourcev2 { return nc_023_multiple_source; case 'nc_024_barcode_column_type': return nc_024_barcode_column_type; + case 'nc_025_add_row_height': + return nc_025_add_row_height; } } } diff --git a/packages/nocodb/src/lib/migrations/v2/nc_025_add_row_height.ts b/packages/nocodb/src/lib/migrations/v2/nc_025_add_row_height.ts new file mode 100644 index 0000000000..712904edbf --- /dev/null +++ b/packages/nocodb/src/lib/migrations/v2/nc_025_add_row_height.ts @@ -0,0 +1,16 @@ +import { Knex } from 'knex'; +import { MetaTable } from '../../utils/globals'; + +const up = async (knex: Knex) => { + await knex.schema.alterTable(MetaTable.GRID_VIEW, (table) => { + table.integer('row_height'); + }); +}; + +const down = async (knex) => { + await knex.schema.alterTable(MetaTable.GRID_VIEW, (table) => { + table.dropColumns('row_height'); + }); +}; + +export { up, down }; diff --git a/packages/nocodb/src/lib/models/GridView.ts b/packages/nocodb/src/lib/models/GridView.ts index 2b45514beb..40a98b0c9e 100644 --- a/packages/nocodb/src/lib/models/GridView.ts +++ b/packages/nocodb/src/lib/models/GridView.ts @@ -5,18 +5,15 @@ import View from './View'; import NocoCache from '../cache/NocoCache'; export default class GridView { - title: string; - show: boolean; - is_default: boolean; - order: number; - fk_view_id: string; - - columns?: GridViewColumn[]; - project_id?: string; base_id?: string; + meta?: string; + row_height?: number; + + columns?: GridViewColumn[]; + constructor(data: GridView) { Object.assign(this, data); } @@ -47,6 +44,7 @@ export default class GridView { fk_view_id: view.fk_view_id, project_id: view.project_id, base_id: view.base_id, + row_height: view.row_height, }; if (!(view.project_id && view.base_id)) { const viewRef = await View.get(view.fk_view_id, ncMeta); @@ -63,4 +61,31 @@ export default class GridView { const view = await this.get(id, ncMeta); return view; } + + static async update( + viewId: string, + body: Partial, + ncMeta = Noco.ncMeta + ) { + // get existing cache + const key = `${CacheScope.GRID_VIEW}:${viewId}`; + const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); + if (o) { + o.row_height = body.row_height; + // set cache + await NocoCache.set(key, o); + } + // update meta + return await ncMeta.metaUpdate( + null, + null, + MetaTable.GRID_VIEW, + { + row_height: body.row_height, + }, + { + fk_view_id: viewId, + } + ); + } } diff --git a/scripts/sdk/swagger.json b/scripts/sdk/swagger.json index 62fb7a6df3..a3ed9da5d0 100644 --- a/scripts/sdk/swagger.json +++ b/scripts/sdk/swagger.json @@ -3024,6 +3024,44 @@ } } }, + "/api/v1/db/meta/grids/{viewId}": { + "parameters": [ + { + "schema": { + "type": "string" + }, + "name": "viewId", + "in": "path", + "required": true + } + ], + "patch": { + "summary": "", + "operationId": "db-view-grid-update", + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": {} + } + } + } + }, + "tags": [ + "DB view" + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Grid" + } + } + } + } + } + }, "/api/v1/db/meta/grids/{gridId}/grid-columns": { "parameters": [ { @@ -8508,6 +8546,9 @@ "locked", "personal" ] + }, + "row_height": { + "type": "number" } }, "description": ""