Skip to content

Commit 21be303

Browse files
Aleksy Lisowskipiotrczarnas
Aleksy Lisowski
authored andcommitted
Merged PR 2616: 11693 tables tab on connection page
tables tab on connection page
2 parents dfb42f1 + 6fceef1 commit 21be303

File tree

5 files changed

+187
-20
lines changed

5 files changed

+187
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import React, { useEffect, useState } from 'react';
2+
import { LabelModel, TableListModel } from '../../../api';
3+
import { LabelsApiClient, SearchApiClient } from '../../../services/apiClient';
4+
import { CheckTypes } from '../../../shared/routes';
5+
import { useDecodedParams } from '../../../utils';
6+
import Button from '../../Button';
7+
import Input from '../../Input';
8+
import TableList from '../../TableList';
9+
type TLabel = LabelModel & { clicked: boolean };
10+
type TTableWithSchema = TableListModel & { schema?: string };
11+
export default function ConnectionTables() {
12+
const {
13+
checkTypes,
14+
connection
15+
}: {
16+
checkTypes: CheckTypes;
17+
connection: string;
18+
} = useDecodedParams();
19+
const [tables, setTables] = useState<TableListModel[]>([]);
20+
const [filters, setFilters] = useState<any>({
21+
page: 1,
22+
limit: 50,
23+
checkType: checkTypes
24+
});
25+
const [table, setTable] = useState('');
26+
const [schema, setSchema] = useState('');
27+
const [labels, setLabels] = useState<TLabel[]>([]);
28+
29+
const onChangeFilters = (obj: Partial<any>) => {
30+
setFilters((prev: any) => ({
31+
...prev,
32+
...obj
33+
}));
34+
};
35+
36+
const onChangeLabels = (index: number) => {
37+
const arr = [...labels];
38+
arr[index] = { ...arr[index], clicked: !arr[index].clicked };
39+
40+
const filteredlabels: string[] = arr
41+
.filter((x) => x.clicked && x.label)
42+
.map((x) => x.label)
43+
.filter((x): x is string => typeof x === 'string');
44+
45+
getTables(filteredlabels);
46+
setLabels(arr);
47+
};
48+
49+
const getTables = async (labels: string[] = []) => {
50+
const addPrefix = (str: string) => {
51+
return str.includes('*') || str.length === 0 ? str : '*' + str + '*';
52+
};
53+
return SearchApiClient.findTables(
54+
connection,
55+
addPrefix(schema),
56+
addPrefix(table),
57+
labels,
58+
filters.page,
59+
filters.pageSize,
60+
filters.checkType
61+
).then((res) => {
62+
const arr: TTableWithSchema[] = [];
63+
res.data.forEach((item) => {
64+
const jItem = { ...item, schema: item.target?.schema_name };
65+
arr.push(jItem);
66+
});
67+
setTables(arr);
68+
return arr;
69+
});
70+
};
71+
72+
const refetchTables = (tables?: TableListModel[]) => {
73+
tables?.forEach((table) => {
74+
if (!table?.data_quality_status) {
75+
setTimeout(() => {
76+
getTables();
77+
}, 5000);
78+
}
79+
});
80+
};
81+
82+
useEffect(() => {
83+
getTables().then((res) => {
84+
refetchTables(res);
85+
});
86+
const getLabels = () => {
87+
LabelsApiClient.getAllLabelsForTables().then((res) => {
88+
const array: TLabel[] = res.data.map((item) => {
89+
return { ...item, clicked: false };
90+
});
91+
setLabels(array);
92+
});
93+
};
94+
getLabels();
95+
}, [connection, filters]);
96+
97+
return (
98+
<>
99+
<div className="flex items-center gap-x-4 mb-4 mt-2 px-4">
100+
<Input
101+
label="Schema name"
102+
value={schema}
103+
onChange={(e) => setSchema(e.target.value)}
104+
/>
105+
<Input
106+
label="Table name"
107+
value={table}
108+
onChange={(e) => setTable(e.target.value)}
109+
/>
110+
<Button
111+
label="Search"
112+
onClick={() =>
113+
getTables(
114+
labels
115+
.filter((x) => x.clicked && x.label)
116+
.map((x) => x.label)
117+
.filter((x): x is string => typeof x === 'string')
118+
)
119+
}
120+
color="primary"
121+
className="mt-5"
122+
/>
123+
</div>
124+
<TableList
125+
tables={tables}
126+
setTables={setTables}
127+
filters={filters}
128+
onChangeFilters={onChangeFilters}
129+
labels={labels}
130+
onChangeLabels={onChangeLabels}
131+
/>
132+
</>
133+
);
134+
}

dqops/src/main/frontend/src/components/TableList/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export default function index({
130130

131131
const basicDimensionTypes = ['Completeness', 'Validity', 'Consistency'];
132132
const headerItems = [
133-
checkTypes && connection && schema
133+
checkTypes && connection
134134
? undefined
135135
: {
136136
label: 'Connection',
@@ -214,7 +214,7 @@ export default function index({
214214
</tbody>
215215
</table>
216216
</div>
217-
<div className="px-4 mb-50">
217+
<div className="px-4 mb-50 mt-2">
218218
<Pagination
219219
page={filters.page || 1}
220220
pageSize={filters.pageSize || 50}

dqops/src/main/frontend/src/pages/Connection/index.tsx

+15-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import ConnectionCommentView from '../../components/Connection/ConnectionView/Co
66
import ConnectionDefaultGroupingConfiguration from '../../components/Connection/ConnectionView/ConnectionDataStream';
77
import ConnectionDetail from '../../components/Connection/ConnectionView/ConnectionDetail';
88
import ConnectionLabelsView from '../../components/Connection/ConnectionView/ConnectionLabelsView';
9+
import ConnectionTables from '../../components/Connection/ConnectionView/ConnectionTables';
910
import { IncidentsNotificationsView } from '../../components/Connection/ConnectionView/IncidentsNotificationsView';
1011
import ScheduleDetail from '../../components/Connection/ConnectionView/ScheduleDetail';
1112
import SchemasView from '../../components/Connection/ConnectionView/SchemasView';
@@ -42,6 +43,10 @@ const initSourceTabs = [
4243
label: 'Schemas',
4344
value: 'schemas'
4445
},
46+
{
47+
label: 'Tables',
48+
value: 'tables'
49+
},
4550
{
4651
label: 'Default grouping template',
4752
value: 'data-groupings'
@@ -67,7 +72,11 @@ const ConnectionPage = () => {
6772
connection,
6873
tab: activeTab,
6974
checkTypes
70-
}: { connection: string; tab: string; checkTypes: CheckTypes } = useDecodedParams();
75+
}: {
76+
connection: string;
77+
tab: string;
78+
checkTypes: CheckTypes;
79+
} = useDecodedParams();
7180
const [tabs, setTabs] = useState(
7281
checkTypes === CheckTypes.SOURCES ? initSourceTabs : initCheckTabs
7382
);
@@ -159,6 +168,10 @@ const ConnectionPage = () => {
159168
{
160169
label: 'Schemas',
161170
value: 'schemas'
171+
},
172+
{
173+
label: 'Tables',
174+
value: 'tables'
162175
}
163176
]);
164177
// } else {
@@ -193,6 +206,7 @@ const ConnectionPage = () => {
193206
<ConnectionDefaultGroupingConfiguration />
194207
)}
195208
{activeTab === 'incidents' && <IncidentsNotificationsView />}
209+
{activeTab === 'tables' && <ConnectionTables />}
196210
</div>
197211
</>
198212
);

dqops/src/main/frontend/src/pages/Schema/SchemaTableItem.tsx

+19-13
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,20 @@ export default function SchemaTableItem({
111111
};
112112

113113
return (
114-
<tr className="text-sm">
114+
<tr className="text-sm h-10">
115115
{(!checkTypes || !connection || !schema) && (
116116
<>
117-
<td>
118-
<Button
119-
className="px-4 underline cursor-pointer text-sm"
120-
label={item.connection_name}
121-
onClick={() => goToConnection(item)}
122-
/>
123-
</td>
117+
{!connection && (
118+
<td>
119+
<div className="flex items-start">
120+
<Button
121+
className="px-4 underline cursor-pointer text-sm"
122+
label={item.connection_name}
123+
onClick={() => goToConnection(item)}
124+
/>
125+
</div>
126+
</td>
127+
)}
124128
<td>
125129
<Button
126130
className="px-4 underline cursor-pointer text-sm"
@@ -130,11 +134,13 @@ export default function SchemaTableItem({
130134
</td>
131135
</>
132136
)}
133-
<Button
134-
className="px-4 underline cursor-pointer text-sm"
135-
label={item.target?.table_name}
136-
onClick={() => goToTable(item)}
137-
/>
137+
<td>
138+
<Button
139+
className="px-4 underline cursor-pointer text-sm"
140+
label={item.target?.table_name}
141+
onClick={() => goToTable(item)}
142+
/>
143+
</td>
138144
<td className="px-4">
139145
{item?.disabled ? (
140146
<SvgIcon

dqops/src/main/frontend/src/pages/Schema/SchemaTables.tsx

+17-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { CheckTypes } from '../../shared/routes';
88
import { useDecodedParams } from '../../utils';
99

1010
type TLabel = LabelModel & { clicked: boolean };
11+
type TTableWithSchema = TableListModel & { schema?: string };
1112

1213
export const SchemaTables = () => {
1314
const {
@@ -57,8 +58,13 @@ export const SchemaTables = () => {
5758
filter,
5859
checkTypes === CheckTypes.SOURCES ? CheckTypes.PROFILING : checkTypes
5960
).then((res) => {
60-
setTables(res.data);
61-
return res;
61+
const arr: TTableWithSchema[] = [];
62+
res.data.forEach((item) => {
63+
const jItem = { ...item, schema: item.target?.schema_name };
64+
arr.push(jItem);
65+
});
66+
setTables(arr);
67+
return arr;
6268
});
6369
};
6470

@@ -74,7 +80,7 @@ export const SchemaTables = () => {
7480

7581
useEffect(() => {
7682
getTables().then((res) => {
77-
refetchTables(res.data);
83+
refetchTables(res);
7884
});
7985
const getLabels = () => {
8086
LabelsApiClient.getAllLabelsForTables().then((res) => {
@@ -97,7 +103,14 @@ export const SchemaTables = () => {
97103
/>
98104
<Button
99105
label="Search"
100-
onClick={getTables}
106+
onClick={() =>
107+
getTables(
108+
labels
109+
.filter((x) => x.clicked && x.label)
110+
.map((x) => x.label)
111+
.filter((x): x is string => typeof x === 'string')
112+
)
113+
}
101114
color="primary"
102115
className="mt-5"
103116
/>

0 commit comments

Comments
 (0)