-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Paging improvement #13943
Merged
Merged
Paging improvement #13943
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
848c16c
fix(ui): databaseschema paging issue
chirag-madlani 922e1b8
fix minor issues
chirag-madlani 2c9a818
Merge branch 'main' into paging-improvement
chirag-madlani cb62458
test fixes
chirag-madlani affc05e
fix path issue and some cypress
chirag-madlani d1b7e4d
fix sonarcloud
chirag-madlani 8528378
Merge branch 'main' into paging-improvement
chirag-madlani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207 changes: 207 additions & 0 deletions
207
...ces/ui/src/components/Database/DatabaseSchema/DatabaseSchemaTable/DatabaseSchemaTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
/* | ||
* Copyright 2023 Collate. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { Col, Row, Switch, Typography } from 'antd'; | ||
import { AxiosError } from 'axios'; | ||
import { t } from 'i18next'; | ||
import { isEmpty } from 'lodash'; | ||
import QueryString from 'qs'; | ||
import React, { useCallback, useEffect, useMemo, useState } from 'react'; | ||
import { useHistory, useLocation, useParams } from 'react-router-dom'; | ||
import { | ||
INITIAL_PAGING_VALUE, | ||
PAGE_SIZE, | ||
} from '../../../../constants/constants'; | ||
import { SearchIndex } from '../../../../enums/search.enum'; | ||
import { DatabaseSchema } from '../../../../generated/entity/data/databaseSchema'; | ||
import { Include } from '../../../../generated/type/include'; | ||
import { Paging } from '../../../../generated/type/paging'; | ||
import { usePaging } from '../../../../hooks/paging/usePaging'; | ||
import { getDatabaseSchemas } from '../../../../rest/databaseAPI'; | ||
import { searchQuery } from '../../../../rest/searchAPI'; | ||
import { schemaTableColumns } from '../../../../utils/DatabaseDetails.utils'; | ||
import { showErrorToast } from '../../../../utils/ToastUtils'; | ||
import ErrorPlaceHolder from '../../../common/ErrorWithPlaceholder/ErrorPlaceHolder'; | ||
import NextPrevious from '../../../common/NextPrevious/NextPrevious'; | ||
import { PagingHandlerParams } from '../../../common/NextPrevious/NextPrevious.interface'; | ||
import Searchbar from '../../../common/SearchBarComponent/SearchBar.component'; | ||
import Table from '../../../common/Table/Table'; | ||
|
||
export const DatabaseSchemaTable = () => { | ||
const { fqn } = useParams<{ fqn: string }>(); | ||
const history = useHistory(); | ||
const location = useLocation(); | ||
const [schemas, setSchemas] = useState<DatabaseSchema[]>([]); | ||
const [isLoading, setIsLoading] = useState(true); | ||
const [showDeletedSchemas, setShowDeletedSchemas] = useState<boolean>(false); | ||
const searchValue = useMemo(() => { | ||
const param = location.search; | ||
const searchData = QueryString.parse( | ||
param.startsWith('?') ? param.substring(1) : param | ||
); | ||
|
||
return searchData.schema as string | undefined; | ||
}, [location.search]); | ||
const { | ||
currentPage, | ||
handlePageChange, | ||
pageSize, | ||
handlePageSizeChange, | ||
paging, | ||
handlePagingChange, | ||
showPagination, | ||
} = usePaging(); | ||
|
||
const fetchDatabaseSchema = useCallback( | ||
async (params?: Partial<Paging>) => { | ||
if (isEmpty(fqn)) { | ||
return; | ||
} | ||
|
||
try { | ||
setIsLoading(true); | ||
const { data, paging } = await getDatabaseSchemas({ | ||
databaseName: fqn, | ||
limit: pageSize, | ||
after: params?.after, | ||
before: params?.before, | ||
include: showDeletedSchemas ? Include.Deleted : Include.NonDeleted, | ||
fields: ['owner', 'usageSummary'], | ||
}); | ||
|
||
setSchemas(data); | ||
handlePagingChange(paging); | ||
} catch (error) { | ||
showErrorToast(error); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}, | ||
[pageSize, fqn, showDeletedSchemas] | ||
); | ||
|
||
const searchSchema = async ( | ||
searchValue: string, | ||
pageNumber = INITIAL_PAGING_VALUE | ||
) => { | ||
setIsLoading(true); | ||
try { | ||
const response = await searchQuery({ | ||
query: `(name.keyword:*${searchValue}*) OR (description.keyword:*${searchValue}*)`, | ||
pageNumber, | ||
pageSize: PAGE_SIZE, | ||
queryFilter: { | ||
query: { | ||
bool: { | ||
must: [{ term: { 'database.fullyQualifiedName': fqn } }], | ||
}, | ||
}, | ||
}, | ||
searchIndex: SearchIndex.DATABASE_SCHEMA, | ||
includeDeleted: showDeletedSchemas, | ||
trackTotalHits: true, | ||
}); | ||
const data = response.hits.hits.map((schema) => schema._source); | ||
const total = response.hits.total.value; | ||
setSchemas(data); | ||
handlePagingChange({ total }); | ||
} catch (error) { | ||
showErrorToast(error as AxiosError); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
const handleShowDeletedSchemas = useCallback((value: boolean) => { | ||
setShowDeletedSchemas(value); | ||
handlePageChange(INITIAL_PAGING_VALUE); | ||
}, []); | ||
|
||
const handleSchemaPageChange = useCallback( | ||
({ currentPage, cursorType }: PagingHandlerParams) => { | ||
if (cursorType) { | ||
fetchDatabaseSchema({ [cursorType]: paging[cursorType] }); | ||
} | ||
handlePageChange(currentPage); | ||
}, | ||
[paging, fetchDatabaseSchema] | ||
); | ||
|
||
const onSchemaSearch = (value: string) => { | ||
history.push({ | ||
search: QueryString.stringify({ | ||
schema: isEmpty(value) ? undefined : value, | ||
}), | ||
}); | ||
if (value) { | ||
searchSchema(value); | ||
} else { | ||
fetchDatabaseSchema(); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
fetchDatabaseSchema(); | ||
}, [fqn, pageSize, showDeletedSchemas]); | ||
|
||
return ( | ||
<Row gutter={[16, 16]}> | ||
<Col span={12}> | ||
<Searchbar | ||
removeMargin | ||
placeholder={t('label.search-for-type', { | ||
type: t('label.schema'), | ||
})} | ||
searchValue={searchValue} | ||
typingInterval={500} | ||
onSearch={onSchemaSearch} | ||
/> | ||
</Col> | ||
<Col className="flex items-center justify-end" span={12}> | ||
<Switch | ||
checked={showDeletedSchemas} | ||
data-testid="show-deleted" | ||
onClick={handleShowDeletedSchemas} | ||
/> | ||
<Typography.Text className="m-l-xs"> | ||
{t('label.deleted')} | ||
</Typography.Text>{' '} | ||
</Col> | ||
<Col span={24}> | ||
<Table | ||
bordered | ||
columns={schemaTableColumns} | ||
data-testid="database-databaseSchemas" | ||
dataSource={schemas} | ||
loading={isLoading} | ||
locale={{ | ||
emptyText: <ErrorPlaceHolder className="m-y-md" />, | ||
}} | ||
pagination={false} | ||
rowKey="id" | ||
size="small" | ||
/> | ||
</Col> | ||
<Col span={24}> | ||
{showPagination && ( | ||
<NextPrevious | ||
currentPage={currentPage} | ||
pageSize={pageSize} | ||
paging={paging} | ||
pagingHandler={handleSchemaPageChange} | ||
onShowSizeChange={handlePageSizeChange} | ||
/> | ||
)} | ||
</Col> | ||
</Row> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it simplify this component if
fetchDatabaseSchema
andsearchSchema
are replaced by single function that uses same query butquery_text
is:*
when search box is empty and(name.keyword:*${searchValue}*) OR (description.keyword:*${searchValue}*)
when search box is not emptyit would:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mgorsk1 Thanks for the comment and suggestion. We were following listing from DB calls and searching through ES at all the places. I will certainly take your feedback and see if we can club them in near future.
cc: @harshach