From 67d928491c5b935b3649fa11fa8f4c95f59d4023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20G=C3=BCell=20Segarra?= Date: Wed, 10 Jan 2024 11:45:32 +0100 Subject: [PATCH 1/2] fix: adjust semantic-release and gh actions --- .github/workflows/release.yaml | 4 +-- .../update_dependent_projects_alpha.yaml | 2 +- .../update_dependent_projects_v2-develop.yaml | 28 +++++++++++++++++++ .../update_dependent_projects_v2.yaml | 28 +++++++++++++++++++ package.json | 4 +-- 5 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/update_dependent_projects_v2-develop.yaml create mode 100644 .github/workflows/update_dependent_projects_v2.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 2235daf..1d23bc0 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -3,8 +3,8 @@ name: Release on: push: branches: - # - main - # - develop + - v2 + - v2-develop - alpha workflow_dispatch: diff --git a/.github/workflows/update_dependent_projects_alpha.yaml b/.github/workflows/update_dependent_projects_alpha.yaml index 4685334..57d257e 100644 --- a/.github/workflows/update_dependent_projects_alpha.yaml +++ b/.github/workflows/update_dependent_projects_alpha.yaml @@ -1,4 +1,4 @@ -name: Update dependent projects (ALPHA) +name: Update dependent projects (alpha) on: release: diff --git a/.github/workflows/update_dependent_projects_v2-develop.yaml b/.github/workflows/update_dependent_projects_v2-develop.yaml new file mode 100644 index 0000000..9ce9b08 --- /dev/null +++ b/.github/workflows/update_dependent_projects_v2-develop.yaml @@ -0,0 +1,28 @@ +name: Update dependent projects (v2-develop) + +on: + release: + types: [published] + workflow_dispatch: + +env: + LIBRARY_NAME: "gisce/react-formiga-table" + +jobs: + update-dependents: + if: github.event.release.prerelease == true && !contains(github.event.release.tag_name, '-alpha.') && contains(github.event.release.tag_name, '-rc.') + runs-on: ubuntu-latest + strategy: + matrix: + include: + - project: "gisce/react-ooui" + branch: "v2-develop" + steps: + - name: Call Reusable Workflow for each project + uses: gisce/create-update-version-pr@v0.0.5 + with: + dependentProject: ${{ matrix.project }} + tagName: ${{ github.event.release.tag_name }} + dependentProjectBranch: ${{ matrix.branch }} + libraryName: ${{ env.LIBRARY_NAME }} + githubToken: ${{ secrets.GH_PAT }} diff --git a/.github/workflows/update_dependent_projects_v2.yaml b/.github/workflows/update_dependent_projects_v2.yaml new file mode 100644 index 0000000..a200196 --- /dev/null +++ b/.github/workflows/update_dependent_projects_v2.yaml @@ -0,0 +1,28 @@ +name: Update dependent projects (v2) + +on: + release: + types: [published] + workflow_dispatch: + +env: + LIBRARY_NAME: "gisce/react-formiga-table" + +jobs: + update-dependents: + if: github.event.release.prerelease == false && contains(github.event.release.tag_name, 'v2') + runs-on: ubuntu-latest + strategy: + matrix: + include: + - project: "gisce/react-ooui" + branch: "v2" + steps: + - name: Call Reusable Workflow for each project + uses: gisce/create-update-version-pr@v0.0.5 + with: + dependentProject: ${{ matrix.project }} + tagName: ${{ github.event.release.tag_name }} + dependentProjectBranch: ${{ matrix.branch }} + libraryName: ${{ env.LIBRARY_NAME }} + githubToken: ${{ secrets.GH_PAT }} diff --git a/package.json b/package.json index c0350b1..da029f6 100644 --- a/package.json +++ b/package.json @@ -92,9 +92,9 @@ }, "release": { "branches": [ - "main", + "v2", { - "name": "develop", + "name": "v2-develop", "prerelease": "rc" }, { From dc2cd8179b91e8d0b1990e070c348fc2cc5cbc63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20G=C3=BCell=20Segarra?= Date: Wed, 10 Jan 2024 12:23:00 +0100 Subject: [PATCH 2/2] feat: add unselectAll imperative method --- package.json | 2 +- src/components/Table.tsx | 16 +++++++++--- src/stories/Table.stories.tsx | 46 ++++++++++++++++++++++------------- src/types/index.ts | 4 +++ 4 files changed, 46 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index da029f6..1d8a649 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "styled-components": "5.3.5" }, "lint-staged": { - "src/**/*.{js,jsx,ts,tsx}": "eslint --max-warnings=0", + "src/**/*.{js,jsx,ts,tsx}": "eslint", "src/**/*.{js,jsx,ts,tsx,json,css,md}": "prettier --write" }, "release": { diff --git a/src/components/Table.tsx b/src/components/Table.tsx index 068337c..082c364 100644 --- a/src/components/Table.tsx +++ b/src/components/Table.tsx @@ -1,14 +1,14 @@ -import React, { useCallback, useEffect } from "react"; +import { forwardRef, useImperativeHandle, useCallback, useEffect } from "react"; import { useExpandable } from "../hooks/useExpandable"; import { useSelectable } from "../hooks/useSelectable"; import { useShiftSelected } from "../hooks/useShiftSelect"; import { useSortable } from "../hooks/useSortable"; -import { TableProps } from "../types"; +import { TableProps, TableRef } from "../types"; import { Container } from "./Container"; import { Headers } from "./Headers"; import { Rows } from "./Rows"; -export const Table = (props: TableProps) => { +export const Table = forwardRef((props, ref) => { const { height, loading, @@ -37,6 +37,12 @@ export const Table = (props: TableProps) => { selectionRowKeysProps, }); + useImperativeHandle(ref, () => ({ + unselectAll: () => { + toggleAllRowsSelected([]); + }, + })); + const onChange = useShiftSelected( dataSource.map((el) => el.id), changeSelected, @@ -137,4 +143,6 @@ export const Table = (props: TableProps) => { ); -}; +}); + +Table.displayName = "Table"; diff --git a/src/stories/Table.stories.tsx b/src/stories/Table.stories.tsx index 96ab083..49b2218 100644 --- a/src/stories/Table.stories.tsx +++ b/src/stories/Table.stories.tsx @@ -1,8 +1,8 @@ -import React, { useState } from "react"; +import React, { useRef, useState } from "react"; import { ComponentMeta, ComponentStoryObj } from "@storybook/react"; import { Table } from "../components/Table"; import { Button, Spin } from "antd"; -import { OnCellRenderOpts, Sorter } from "../types"; +import { OnCellRenderOpts, Sorter, TableRef } from "../types"; import { PlusSquareOutlined, MinusSquareOutlined, @@ -395,21 +395,33 @@ export const AddingMoreChilds = (): React.ReactElement => { }; export const HeavyTable = (): React.ReactElement => { + const tableRef = useRef(null); + return ( - { - console.log("selectedRows: " + JSON.stringify(selectedRows)); - }} - onRowStyle={() => undefined} - onRowDoubleClick={(record: any) => { - alert("double clicked record" + JSON.stringify(record)); - }} - loadingComponent={} - height={"100%"} - sorter={undefined} - loading={false} - /> + <> + +
{ + console.log("selectedRows: " + JSON.stringify(selectedRows)); + }} + onRowStyle={() => undefined} + onRowDoubleClick={(record: any) => { + alert("double clicked record" + JSON.stringify(record)); + }} + loadingComponent={} + height={"100%"} + sorter={undefined} + loading={false} + /> + ); }; diff --git a/src/types/index.ts b/src/types/index.ts index cf56938..7a67d00 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -60,3 +60,7 @@ export type TableProps = { selectionRowKeys?: number[]; customStyle?: customStyle; }; + +export interface TableRef { + unselectAll: () => void; +}