@pipe0/react-sdk 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # @pipe0/react-sdk
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updates
8
+ - Updated dependencies
9
+ - @pipe0/client-sdk@0.0.47
@@ -0,0 +1,4 @@
1
+ import { config } from "@pipe0/eslint-config/react-internal";
2
+
3
+ /** @type {import("eslint").Linter.Config} */
4
+ export default config;
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@pipe0/react-sdk",
3
+ "version": "0.0.2",
4
+ "type": "module",
5
+ "description": "React utils to work with pipe0",
6
+ "keywords": [
7
+ "data enrichment",
8
+ "prospecting",
9
+ "company data",
10
+ "people data",
11
+ "sales technology",
12
+ "sales engineering"
13
+ ],
14
+ "publishConfig": {
15
+ "provenance": false,
16
+ "access": "public"
17
+ },
18
+ "exports": {
19
+ ".": "./src/index.ts"
20
+ },
21
+ "private": false,
22
+ "scripts": {
23
+ "lint": "eslint . --max-warnings 0",
24
+ "check-types": "tsc --noEmit"
25
+ },
26
+ "author": "",
27
+ "license": "MIT",
28
+ "dependencies": {
29
+ "@pipe0/client-sdk": "workspace:*",
30
+ "react": "catalog:",
31
+ "react-dom": "catalog:",
32
+ "@tanstack/react-table": "catalog:"
33
+ },
34
+ "devDependencies": {
35
+ "@pipe0/eslint-config": "workspace:*",
36
+ "@types/react": "catalog:",
37
+ "@types/node": "^22.13.2",
38
+ "eslint": "catalog:",
39
+ "@types/react-dom": "catalog:"
40
+ }
41
+ }
@@ -0,0 +1,210 @@
1
+ import {
2
+ getInitialTableData,
3
+ getTableDataAggregates,
4
+ type PipeCatalogTableData,
5
+ type PipeCategory,
6
+ type PipeId,
7
+ } from "@pipe0/client-sdk";
8
+ import {
9
+ type ColumnFilter,
10
+ createColumnHelper,
11
+ getCoreRowModel,
12
+ getFilteredRowModel,
13
+ getPaginationRowModel,
14
+ useReactTable,
15
+ } from "@tanstack/react-table";
16
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
17
+
18
+ export function useDebounce(
19
+ cb: (v: string) => unknown,
20
+ config: { initialValue?: string; timeout?: number } = {}
21
+ ) {
22
+ const { initialValue = "", timeout = 400 } = config;
23
+ const [value, setValue] = useState(initialValue);
24
+
25
+ const cbRef = useRef(cb);
26
+
27
+ const setImmediately = useCallback((v: string) => {
28
+ setValue(v);
29
+ cb(v);
30
+ }, []);
31
+
32
+ useEffect(() => {
33
+ if (!cbRef.current) return;
34
+ cbRef.current = cb;
35
+ const handle = setTimeout(() => {
36
+ cbRef.current(value);
37
+ }, timeout);
38
+
39
+ return () => clearTimeout(handle);
40
+ }, [value, timeout]);
41
+
42
+ return [value, setValue, setImmediately] as const;
43
+ }
44
+
45
+ export type InputFieldEntries = Record<string, PipeId[]>;
46
+ export type OutputFieldEntries = Record<string, PipeId[]>;
47
+
48
+ const columnHelper = createColumnHelper<PipeCatalogTableData>();
49
+
50
+ const columns = [
51
+ columnHelper.accessor("pipeId", {}),
52
+ columnHelper.accessor(
53
+ (row) => row.inputGroups.flatMap((g) => Object.keys(g.fields)).join(", "),
54
+ {
55
+ id: "inputFields",
56
+ }
57
+ ),
58
+ columnHelper.accessor((row) => row.outputFields.join(", "), {
59
+ id: "outputFields",
60
+ }),
61
+ columnHelper.accessor((row) => row.tags.join(", "), {
62
+ id: "tags",
63
+ }),
64
+ columnHelper.accessor((row) => row.providers.join(", "), {
65
+ id: "providers",
66
+ }),
67
+ columnHelper.accessor((row) => row.categories.join(", "), {
68
+ id: "categories",
69
+ }),
70
+ ];
71
+
72
+ export function usePipeCatalogTable(
73
+ config: {
74
+ initialColumnFilters?: ColumnFilter[];
75
+ } = {}
76
+ ) {
77
+ const {
78
+ initialColumnFilters: initialColumnFilters = [
79
+ { id: "category", value: "enrichment" },
80
+ ] as ColumnFilter[],
81
+ } = config;
82
+
83
+ const initialTableData = useMemo(() => getInitialTableData(), []);
84
+
85
+ const table = useReactTable({
86
+ columns,
87
+ data: initialTableData,
88
+ getCoreRowModel: getCoreRowModel(),
89
+ getPaginationRowModel: getPaginationRowModel(),
90
+ getFilteredRowModel: getFilteredRowModel(),
91
+ initialState: {
92
+ columnFilters: initialColumnFilters,
93
+ pagination: {
94
+ pageSize: 10,
95
+ },
96
+ },
97
+ });
98
+
99
+ const columnFilters = table.getState().columnFilters;
100
+ const x = "lsdfj";
101
+ const category: PipeCategory | null = useMemo(
102
+ () =>
103
+ (columnFilters.find((e) => e.id === "categories" && e.value)
104
+ ?.value as PipeCategory) || null,
105
+ [columnFilters]
106
+ );
107
+
108
+ const {
109
+ pipeIdsByInputField,
110
+ pipeIdsByOutputField,
111
+ pipeIdsByTag,
112
+ pipeIdsByProvider,
113
+ sortedTagEntries,
114
+ sortedInputFieldEntries,
115
+ sortedOutputFieldEntries,
116
+ sortedProviderEntries,
117
+ pipeEntriesByBasePipe,
118
+ } = useMemo(() => {
119
+ return getTableDataAggregates(initialTableData, category);
120
+ }, [category]);
121
+
122
+ const [expandedSidebarSections, setExpandedSidebarSections] = useState<
123
+ string[]
124
+ >(["tags"]);
125
+
126
+ const setCategory = (category: PipeCategory | null) => {
127
+ table.setGlobalFilter(null);
128
+ if (category) {
129
+ table.setColumnFilters([{ id: "categories", value: category }]);
130
+ } else {
131
+ table.setColumnFilters([]);
132
+ }
133
+ };
134
+
135
+ const [globalFilterInput, setGlobalFilterInput, setGlobalFilterImmediately] =
136
+ useDebounce((v) => {
137
+ if (v === table.getState().globalFilter) return;
138
+ table.setGlobalFilter(v);
139
+ if (v) {
140
+ table.setColumnFilters([]);
141
+ }
142
+ });
143
+
144
+ const addColumnFilter = (
145
+ id: "inputFields" | "outputFields" | "tags" | "providers",
146
+ value: string
147
+ ) => {
148
+ setGlobalFilterImmediately("");
149
+ table.setColumnFilters([
150
+ { id: "categories", value: category },
151
+ { id, value },
152
+ ]);
153
+ };
154
+
155
+ const resetColumnFilters = () => {
156
+ setGlobalFilterImmediately("");
157
+ table.setColumnFilters([{ id: "categories", value: null }]);
158
+ };
159
+
160
+ const removeColumnFilter = (
161
+ id: "inputFields" | "outputFields" | "tags" | "providers"
162
+ ) => {
163
+ table.getColumn(id)?.setFilterValue(null);
164
+ };
165
+
166
+ const isFilterChecked = (
167
+ id: "inputFields" | "outputFields" | "tags" | "providers",
168
+ value: string
169
+ ) => {
170
+ return columnFilters.some((f) => f.id === id && f.value === value);
171
+ };
172
+
173
+ const filterByField = (
174
+ id: "inputFields" | "outputFields",
175
+ fieldName: string
176
+ ) => {
177
+ setExpandedSidebarSections([id]);
178
+ setGlobalFilterImmediately("");
179
+ table.setColumnFilters([
180
+ { id: "categories", value: null },
181
+ { id, value: fieldName },
182
+ ]);
183
+ };
184
+
185
+ return {
186
+ table,
187
+ sidebar: {
188
+ sortedInputFieldEntries,
189
+ sortedOutputFieldEntries,
190
+ sortedTagEntries,
191
+ sortedProviderEntries,
192
+ pipeIdsByInputField,
193
+ pipeIdsByOutputField,
194
+ pipeIdsByProvider,
195
+ pipeIdsByTag,
196
+ expandedSidebarSections,
197
+ setExpandedSidebarSections,
198
+ removeColumnFilter,
199
+ addColumnFilter,
200
+ },
201
+ pipeEntriesByBasePipe,
202
+ filterByField,
203
+ globalFilterInput,
204
+ setGlobalFilterInput,
205
+ isFilterChecked,
206
+ resetColumnFilters,
207
+ category,
208
+ setCategory,
209
+ };
210
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./hooks/usePipeCatalogTable";
package/tsconfig.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2023",
4
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
5
+ "rootDir": "src",
6
+ "moduleDetection": "force",
7
+ "useDefineForClassFields": true,
8
+ "module": "esnext",
9
+ "moduleResolution": "bundler",
10
+ "noUncheckedIndexedAccess": true,
11
+ "resolveJsonModule": true,
12
+ "types": ["node"],
13
+ "noFallthroughCasesInSwitch": true,
14
+ "noUnusedLocals": false,
15
+ "noUnusedParameters": true,
16
+ "verbatimModuleSyntax": true,
17
+ "isolatedModules": true,
18
+ "skipLibCheck": true,
19
+ "noUncheckedSideEffectImports": true,
20
+ "outDir": "./dist",
21
+ "noEmit": false,
22
+ "declaration": true,
23
+ "declarationMap": true,
24
+ "esModuleInterop": true,
25
+ "strict": true,
26
+ "jsx": "react-jsx"
27
+ },
28
+ "include": ["./src"]
29
+ }