From ec9cab81531780375f9fd76297694d34a2fd6c94 Mon Sep 17 00:00:00 2001 From: Salahuddin Saiet Date: Fri, 6 Dec 2024 16:12:13 +0200 Subject: [PATCH 01/16] fix: Update AgGrid --- plugins/community-plugin-aggrid/src/AgGrid.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/community-plugin-aggrid/src/AgGrid.js b/plugins/community-plugin-aggrid/src/AgGrid.js index 42bc621..ef54306 100644 --- a/plugins/community-plugin-aggrid/src/AgGrid.js +++ b/plugins/community-plugin-aggrid/src/AgGrid.js @@ -35,6 +35,15 @@ const AgGrid = ({ properties, methods, loading, events }) => { const memoDefaultColDef = useMemo(() => defaultColDef); + const getRowId = useCallback( + (params) => + params.data[properties.rowId] ?? + params.data.id ?? + params.data._id ?? + JSON.stringify(params.data), + [] + ); + const onRowClick = useCallback((event) => { if (events.onRowClick) { methods.triggerEvent({ @@ -92,7 +101,7 @@ const AgGrid = ({ properties, methods, loading, events }) => { name: 'onFilterChanged', event: { rows: event.api.rowModel.rowsToDisplay.map((row) => row.data), - filter: this.gridApi.getFilterModel(), + filter: gridRef.current.api.getFilterModel(), }, }); } @@ -111,7 +120,6 @@ const AgGrid = ({ properties, methods, loading, events }) => { }, []); useEffect(() => { - methods.registerMethod('exportDataAsCsv', (args) => gridRef.current.api.exportDataAsCsv(args)); methods.registerMethod('exportDataAsCsv', (args) => gridRef.current.api.exportDataAsCsv(args)); methods.registerMethod('sizeColumnsToFit', () => gridRef.current.api.sizeColumnsToFit()); methods.registerMethod('setFilterModel', (model) => gridRef.current.api.setFilterModel(model)); @@ -159,6 +167,7 @@ const AgGrid = ({ properties, methods, loading, events }) => { modules={[ClientSideRowModelModule, CsvExportModule]} columnDefs={processColDefs(columnDefs, methods)} ref={gridRef} + getRowId={getRowId} /> ); }; From 52f730328dd14d9a836b8f483ea1e0932906139e Mon Sep 17 00:00:00 2001 From: Salahuddin Saiet Date: Fri, 6 Dec 2024 17:02:49 +0200 Subject: [PATCH 02/16] wip: Render ag grid react buttons. --- .../src/processColDefs.js | 3 ++ .../src/renderButtons.js | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 plugins/community-plugin-aggrid/src/renderButtons.js diff --git a/plugins/community-plugin-aggrid/src/processColDefs.js b/plugins/community-plugin-aggrid/src/processColDefs.js index 5a36ac5..ca7c32d 100644 --- a/plugins/community-plugin-aggrid/src/processColDefs.js +++ b/plugins/community-plugin-aggrid/src/processColDefs.js @@ -16,6 +16,7 @@ import { renderHtml } from '@lowdefy/block-utils'; import { type } from '@lowdefy/helpers'; +import renderButtons from './renderButtons.js'; function recProcessColDefs(columnDefs, methods) { return columnDefs.map((col) => { @@ -30,6 +31,8 @@ function recProcessColDefs(columnDefs, methods) { methods, }); }; + } else if (type.isArray(col.blocks)) { + return renderButtons({ buttons: col.buttons }); } return { ...col, diff --git a/plugins/community-plugin-aggrid/src/renderButtons.js b/plugins/community-plugin-aggrid/src/renderButtons.js new file mode 100644 index 0000000..917c634 --- /dev/null +++ b/plugins/community-plugin-aggrid/src/renderButtons.js @@ -0,0 +1,45 @@ +/* + Copyright 2021 Lowdefy, Inc + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +import React, { useCallback } from 'react'; + +import Button from '@lowdefy/blocks-antd/blocks/Button/Button.js'; + +function renderButtons({ buttons, methods }) { + // TODO: Register button events + // buttons.array.forEach((button) => { + // methods.registerEvent({ + // name: `${button.event}` + // }); + // }); + return ( +
+ {buttons.map((button) => { +
+ ); +} + +export default renderButtons; From 3dac810397611c83077991f10520f41ac4b46044 Mon Sep 17 00:00:00 2001 From: Salahuddin Saiet Date: Thu, 12 Dec 2024 15:45:28 +0200 Subject: [PATCH 03/16] feat: Implemented ag grid buttons. $5h --- plugins/community-plugin-aggrid/package.json | 1 + plugins/community-plugin-aggrid/src/AgGrid.js | 4 +- .../src/processColDefs.js | 25 +++++-- .../src/renderBlocks.js | 65 +++++++++++++++++++ .../src/renderButtons.js | 45 ------------- 5 files changed, 87 insertions(+), 53 deletions(-) create mode 100644 plugins/community-plugin-aggrid/src/renderBlocks.js delete mode 100644 plugins/community-plugin-aggrid/src/renderButtons.js diff --git a/plugins/community-plugin-aggrid/package.json b/plugins/community-plugin-aggrid/package.json index 805bbf9..24d7c7b 100644 --- a/plugins/community-plugin-aggrid/package.json +++ b/plugins/community-plugin-aggrid/package.json @@ -53,6 +53,7 @@ "@ag-grid-community/react": "30.2.0", "@ag-grid-community/styles": "30.2.0", "@lowdefy/block-utils": "4.0.0-rc.11", + "@lowdefy/blocks-antd": "4.0.0-rc.11", "@lowdefy/helpers": "4.0.0-rc.11", "react": "18.2.0", "react-dom": "18.2.0" diff --git a/plugins/community-plugin-aggrid/src/AgGrid.js b/plugins/community-plugin-aggrid/src/AgGrid.js index ef54306..6f91282 100644 --- a/plugins/community-plugin-aggrid/src/AgGrid.js +++ b/plugins/community-plugin-aggrid/src/AgGrid.js @@ -21,7 +21,7 @@ import { CsvExportModule } from '@ag-grid-community/csv-export'; import processColDefs from './processColDefs.js'; -const AgGrid = ({ properties, methods, loading, events }) => { +const AgGrid = ({ components, events, loading, methods, properties }) => { const { quickFilterValue, columnDefs, @@ -165,7 +165,7 @@ const AgGrid = ({ properties, methods, loading, events }) => { onRowClicked={onRowClick} onCellClicked={onCellClicked} modules={[ClientSideRowModelModule, CsvExportModule]} - columnDefs={processColDefs(columnDefs, methods)} + columnDefs={processColDefs(columnDefs, methods, components, events)} ref={gridRef} getRowId={getRowId} /> diff --git a/plugins/community-plugin-aggrid/src/processColDefs.js b/plugins/community-plugin-aggrid/src/processColDefs.js index ca7c32d..6b7011b 100644 --- a/plugins/community-plugin-aggrid/src/processColDefs.js +++ b/plugins/community-plugin-aggrid/src/processColDefs.js @@ -16,13 +16,13 @@ import { renderHtml } from '@lowdefy/block-utils'; import { type } from '@lowdefy/helpers'; -import renderButtons from './renderButtons.js'; +import renderBlocks from './renderBlocks.js'; -function recProcessColDefs(columnDefs, methods) { +function recProcessColDefs(columnDefs, methods, components, events) { return columnDefs.map((col) => { const newColDef = {}; if (type.isArray(col.children)) { - newColDef.children = recProcessColDefs(col.children, methods); + newColDef.children = recProcessColDefs(col.children, methods, components); } if (type.isFunction(col.cellRenderer)) { newColDef.cellRenderer = (params) => { @@ -32,7 +32,20 @@ function recProcessColDefs(columnDefs, methods) { }); }; } else if (type.isArray(col.blocks)) { - return renderButtons({ buttons: col.buttons }); + //TODO: delete col.blocks + newColDef.cellRenderer = (params) => { + return renderBlocks({ + blocks: col.blocks, + methods, + components, + rowEvent: { + row: params.data, + rowIndex: params.rowIndex, + index: parseInt(params.node.id), + }, + events, + }); + }; } return { ...col, @@ -41,8 +54,8 @@ function recProcessColDefs(columnDefs, methods) { }); } -function processColDefs(columnDefs = [], methods) { - return recProcessColDefs(columnDefs, methods); +function processColDefs(columnDefs = [], methods, components, events) { + return recProcessColDefs(columnDefs, methods, components, events); } export default processColDefs; diff --git a/plugins/community-plugin-aggrid/src/renderBlocks.js b/plugins/community-plugin-aggrid/src/renderBlocks.js new file mode 100644 index 0000000..425f3e0 --- /dev/null +++ b/plugins/community-plugin-aggrid/src/renderBlocks.js @@ -0,0 +1,65 @@ +/* + Copyright 2021 Lowdefy, Inc + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +import React from 'react'; + +import Tag from '@lowdefy/blocks-antd/blocks/Tag/Tag.js'; +import Button from '@lowdefy/blocks-antd/blocks/Button/Button.js'; + +const typeMap = { + Button: ({ block, methods, components, rowEvent, events, eventId }) => { + return ( +