Skip to content

Commit

Permalink
Merge branch 'feat/add-imperative-unselect-all' into v2-develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Jan 10, 2024
2 parents 814fc36 + dc2cd81 commit df85eef
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: Release
on:
push:
branches:
# - main
# - develop
- v2
- v2-develop
- alpha
workflow_dispatch:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update_dependent_projects_alpha.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update dependent projects (ALPHA)
name: Update dependent projects (alpha)

on:
release:
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/update_dependent_projects_v2-develop.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
dependentProject: ${{ matrix.project }}
tagName: ${{ github.event.release.tag_name }}
dependentProjectBranch: ${{ matrix.branch }}
libraryName: ${{ env.LIBRARY_NAME }}
githubToken: ${{ secrets.GH_PAT }}
28 changes: 28 additions & 0 deletions .github/workflows/update_dependent_projects_v2.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
dependentProject: ${{ matrix.project }}
tagName: ${{ github.event.release.tag_name }}
dependentProjectBranch: ${{ matrix.branch }}
libraryName: ${{ env.LIBRARY_NAME }}
githubToken: ${{ secrets.GH_PAT }}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@
"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": {
"branches": [
"main",
"v2",
{
"name": "develop",
"name": "v2-develop",
"prerelease": "rc"
},
{
Expand Down
16 changes: 12 additions & 4 deletions src/components/Table.tsx
Original file line number Diff line number Diff line change
@@ -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<TableRef, TableProps>((props, ref) => {
const {
height,
loading,
Expand Down Expand Up @@ -37,6 +37,12 @@ export const Table = (props: TableProps) => {
selectionRowKeysProps,
});

useImperativeHandle(ref, () => ({
unselectAll: () => {
toggleAllRowsSelected([]);
},
}));

const onChange = useShiftSelected(
dataSource.map((el) => el.id),
changeSelected,
Expand Down Expand Up @@ -137,4 +143,6 @@ export const Table = (props: TableProps) => {
</table>
</Container>
);
};
});

Table.displayName = "Table";
46 changes: 29 additions & 17 deletions src/stories/Table.stories.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -395,21 +395,33 @@ export const AddingMoreChilds = (): React.ReactElement => {
};

export const HeavyTable = (): React.ReactElement => {
const tableRef = useRef<TableRef>(null);

return (
<Table
dataSource={heavyTable}
columns={columns}
onRowSelectionChange={(selectedRows: any) => {
console.log("selectedRows: " + JSON.stringify(selectedRows));
}}
onRowStyle={() => undefined}
onRowDoubleClick={(record: any) => {
alert("double clicked record" + JSON.stringify(record));
}}
loadingComponent={<Spin />}
height={"100%"}
sorter={undefined}
loading={false}
/>
<>
<Button
onClick={() => {
tableRef.current?.unselectAll();
}}
>
Unselect all
</Button>
<Table
ref={tableRef}
dataSource={heavyTable}
columns={columns}
onRowSelectionChange={(selectedRows: any) => {
console.log("selectedRows: " + JSON.stringify(selectedRows));
}}
onRowStyle={() => undefined}
onRowDoubleClick={(record: any) => {
alert("double clicked record" + JSON.stringify(record));
}}
loadingComponent={<Spin />}
height={"100%"}
sorter={undefined}
loading={false}
/>
</>
);
};
4 changes: 4 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ export type TableProps = {
selectionRowKeys?: number[];
customStyle?: customStyle;
};

export interface TableRef {
unselectAll: () => void;
}

0 comments on commit df85eef

Please sign in to comment.