Skip to content

Commit 4a58620

Browse files
authored
Merge pull request #103 from CivicDataLab/102-revamp-graphqltable-component-to-graphqlpagination
102 revamp graphqltable component to graphqlpagination
2 parents 46cd558 + c3928bb commit 4a58620

6 files changed

Lines changed: 50 additions & 103 deletions

File tree

app/[locale]/(user)/datasets/components/DatasetCards/index.tsx

Lines changed: 0 additions & 39 deletions
This file was deleted.

app/[locale]/(user)/datasets/page.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515

1616
import { cn } from '@/lib/utils';
1717
import BreadCrumbs from '@/components/BreadCrumbs';
18-
import DatasetCards from './components/DatasetCards';
18+
import GraphqlPagination from '../../dashboard/components/GraphqlPagination/graphqlPagination';
19+
import Card from './components/Card';
1920
import Filter from './components/FIlter/Filter';
2021
import Styles from './dataset.module.scss';
2122

@@ -313,14 +314,17 @@ const DatasetsListing = () => {
313314

314315
<div className="flex flex-col gap-6">
315316
{facets && datasetDetails?.length > 0 && (
316-
<DatasetCards
317-
data={datasetDetails}
318-
totalCount={count}
317+
<GraphqlPagination
318+
totalRows={count}
319319
pageSize={queryParams.pageSize}
320320
currentPage={queryParams.currentPage}
321321
onPageChange={handlePageChange}
322322
onPageSizeChange={handlePageSizeChange}
323-
/>
323+
>
324+
{datasetDetails.map((item: any, index: any) => (
325+
<Card key={index} data={item} />
326+
))}
327+
</GraphqlPagination>
324328
)}
325329
</div>
326330
</div>

app/[locale]/dashboard/components/GraphqlTable/footer.tsx renamed to app/[locale]/dashboard/components/GraphqlPagination/footer.tsx

File renamed without changes.

app/[locale]/dashboard/components/GraphqlTable/graphqlTable.tsx renamed to app/[locale]/dashboard/components/GraphqlPagination/graphqlPagination.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,27 @@
11
import React from 'react';
2-
import { DataTable, Text } from 'opub-ui';
32

43
import Footer from './footer';
54

65
interface GraphqlTableProps {
7-
table: {
8-
columns: any[];
9-
rows: any[];
10-
};
116
totalRows: number;
127
pageSize: number;
138
currentPage: number;
149
onPageChange: (newPage: number) => void;
1510
onPageSizeChange: (newSize: number) => void;
11+
children: React.ReactNode;
1612
}
1713

18-
const GraphqlTable: React.FC<GraphqlTableProps> = ({
19-
table,
14+
const GraphqlPagination: React.FC<GraphqlTableProps> = ({
2015
totalRows,
2116
pageSize,
2217
currentPage,
2318
onPageChange,
2419
onPageSizeChange,
20+
children,
2521
}) => {
2622
return (
2723
<div>
28-
<DataTable
29-
columns={table.columns}
30-
rows={table.rows}
31-
hideFooter={true}
32-
hideSelection={true}
33-
defaultRowCount={100}
34-
/>
24+
{children}
3525
<Footer
3626
totalRows={totalRows}
3727
pageSize={pageSize}
@@ -43,4 +33,4 @@ const GraphqlTable: React.FC<GraphqlTableProps> = ({
4333
);
4434
};
4535

46-
export default GraphqlTable;
36+
export default GraphqlPagination;

app/[locale]/dashboard/organization/[organizationId]/dataset/[id]/edit/components/EditResource.tsx

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
11
import React from 'react';
2-
import Link from 'next/link';
3-
import {
4-
useParams,
5-
usePathname,
6-
useRouter,
7-
useSearchParams,
8-
} from 'next/navigation';
9-
import GraphqlTable from '@/app/[locale]/dashboard/components/GraphqlTable/graphqlTable';
2+
import { useParams, useRouter } from 'next/navigation';
103
import { graphql } from '@/gql';
114
import {
125
CreateFileResourceInput,
136
UpdateFileResourceInput,
147
} from '@/gql/generated/graphql';
15-
import { IconTrash } from '@tabler/icons-react';
16-
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
17-
import {
18-
parseAsBoolean,
19-
parseAsString,
20-
useQueryState,
21-
} from 'next-usequerystate';
8+
import { useMutation } from '@tanstack/react-query';
9+
import { parseAsString, useQueryState } from 'next-usequerystate';
2210
import {
2311
Button,
24-
ButtonGroup,
25-
Checkbox,
2612
Combobox,
27-
DataTable,
2813
Dialog,
2914
Divider,
3015
DropZone,
@@ -49,7 +34,6 @@ interface TListItem {
4934
}
5035

5136
export const EditResource = ({ reload, data }: any) => {
52-
5337
const updateResourceDoc: any = graphql(`
5438
mutation updateFileResource($fileResourceInput: UpdateFileResourceInput!) {
5539
updateFileResource(fileResourceInput: $fileResourceInput) {
@@ -163,12 +147,12 @@ export const EditResource = ({ reload, data }: any) => {
163147

164148
const ResourceList: TListItem[] =
165149
data.map((item: any) => ({
166-
label: item.name,
167-
value: item.id,
168-
description: item.description,
169-
dataset: item.dataset?.pk,
170-
fileDetails: item.fileDetails,
171-
})) || [];
150+
label: item.name,
151+
value: item.id,
152+
description: item.description,
153+
dataset: item.dataset?.pk,
154+
fileDetails: item.fileDetails,
155+
})) || [];
172156

173157
const getResourceObject = (resourceId: string) => {
174158
return ResourceList.find((item) => item.value === resourceId);
@@ -245,18 +229,21 @@ export const EditResource = ({ reload, data }: any) => {
245229
</div>
246230
);
247231

248-
249232
const listViewFunction = () => {
250-
setResourceId('')
233+
setResourceId('');
251234
};
252235

253236
const saveResource = () => {
254237
mutate({
255238
fileResourceInput: {
256239
id: resourceId,
257-
description: resourceDesc ? resourceDesc :getResourceObject(resourceId)?.description,
258-
name: resourceName ? resourceName: getResourceObject(resourceId)?.label,
259-
file: resourceFile
240+
description: resourceDesc
241+
? resourceDesc
242+
: getResourceObject(resourceId)?.description,
243+
name: resourceName
244+
? resourceName
245+
: getResourceObject(resourceId)?.label,
246+
file: resourceFile,
260247
},
261248
});
262249
};

app/[locale]/dashboard/user/datasets/page.tsx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import { useEffect, useState } from 'react';
44
import { useRouter } from 'next/navigation';
5+
import { DataTable } from 'opub-ui';
56

6-
import GraphqlTable from '../../components/GraphqlTable/graphqlTable';
7+
import GraphqlPagination from '../../components/GraphqlPagination/graphqlPagination';
78
import ListingHeader from '../../components/ListingHeader';
89

910
const Page = () => {
@@ -97,9 +98,15 @@ const Page = () => {
9798
count={120}
9899
label={'datasets'}
99100
/>
100-
<GraphqlTable
101-
table={{
102-
columns: [
101+
<GraphqlPagination
102+
totalRows={totalRows}
103+
pageSize={queryParams.pageSize}
104+
currentPage={queryParams.currentPage}
105+
onPageChange={handlePageChange}
106+
onPageSizeChange={handlePageSizeChange}
107+
>
108+
<DataTable
109+
columns={[
103110
{
104111
accessorKey: 'dataset_title',
105112
header: 'Dataset',
@@ -112,19 +119,17 @@ const Page = () => {
112119
accessorKey: 'org_types',
113120
header: '0rg Type',
114121
},
115-
],
116-
rows: rowData.map((item: any) => ({
122+
]}
123+
rows={rowData.map((item: any) => ({
117124
dataset_title: item._source.dataset_title,
118125
org_title: item._source.org_title,
119126
org_types: item._source.org_types,
120-
})),
121-
}}
122-
totalRows={totalRows}
123-
pageSize={queryParams.pageSize}
124-
currentPage={queryParams.currentPage}
125-
onPageChange={handlePageChange}
126-
onPageSizeChange={handlePageSizeChange}
127-
/>
127+
}))}
128+
hideFooter={true}
129+
hideSelection={true}
130+
defaultRowCount={100}
131+
/>
132+
</GraphqlPagination>
128133
</div>
129134
);
130135
};

0 commit comments

Comments
 (0)