forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(impact analysis): bugfixes for Impact Analysis (datahub-project#…
- Loading branch information
1 parent
a21e3c1
commit 2903646
Showing
8 changed files
with
193 additions
and
104 deletions.
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
123 changes: 123 additions & 0 deletions
123
datahub-web-react/src/app/entity/shared/components/styled/search/DownloadAsCsvModal.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,123 @@ | ||
import React, { useState } from 'react'; | ||
import { Button, Input, Modal } from 'antd'; | ||
import { useLocation } from 'react-router'; | ||
|
||
import { EntityType, FacetFilterInput, SearchAcrossEntitiesInput } from '../../../../../../types.generated'; | ||
import { SearchResultsInterface } from './types'; | ||
import { getSearchCsvDownloadHeader, transformResultsToCsvRow } from './downloadAsCsvUtil'; | ||
import { downloadRowsAsCsv } from '../../../../../search/utils/csvUtils'; | ||
import { useEntityRegistry } from '../../../../../useEntityRegistry'; | ||
import { useEntityData } from '../../../EntityContext'; | ||
import analytics, { EventType } from '../../../../../analytics'; | ||
|
||
type Props = { | ||
callSearchOnVariables: (variables: { | ||
input: SearchAcrossEntitiesInput; | ||
}) => Promise<SearchResultsInterface | null | undefined>; | ||
entityFilters: EntityType[]; | ||
filters: FacetFilterInput[]; | ||
query: string; | ||
setIsDownloadingCsv: (isDownloadingCsv: boolean) => any; | ||
showDownloadAsCsvModal: boolean; | ||
setShowDownloadAsCsvModal: (showDownloadAsCsvModal: boolean) => any; | ||
}; | ||
|
||
const SEARCH_PAGE_SIZE_FOR_DOWNLOAD = 1000; | ||
|
||
export default function DownloadAsCsvModal({ | ||
callSearchOnVariables, | ||
entityFilters, | ||
filters, | ||
query, | ||
setIsDownloadingCsv, | ||
showDownloadAsCsvModal, | ||
setShowDownloadAsCsvModal, | ||
}: Props) { | ||
const { entityData: entitySearchIsEmbeddedWithin } = useEntityData(); | ||
const location = useLocation(); | ||
|
||
const [saveAsTitle, setSaveAsTitle] = useState( | ||
entitySearchIsEmbeddedWithin ? `${entitySearchIsEmbeddedWithin.name}_impact.csv` : 'results.csv', | ||
); | ||
const entityRegistry = useEntityRegistry(); | ||
|
||
const triggerCsvDownload = (filename) => { | ||
setIsDownloadingCsv(true); | ||
console.log('preparing your csv'); | ||
|
||
let downloadPage = 0; | ||
let accumulatedResults: string[][] = []; | ||
|
||
analytics.event({ | ||
type: EventType.DownloadAsCsvEvent, | ||
query, | ||
entityUrn: entitySearchIsEmbeddedWithin?.urn, | ||
path: location.pathname, | ||
}); | ||
|
||
function fetchNextPage() { | ||
console.log('fetch page number ', downloadPage); | ||
callSearchOnVariables({ | ||
input: { | ||
types: entityFilters, | ||
query, | ||
start: SEARCH_PAGE_SIZE_FOR_DOWNLOAD * downloadPage, | ||
count: SEARCH_PAGE_SIZE_FOR_DOWNLOAD, | ||
filters, | ||
}, | ||
}).then((refetchData) => { | ||
console.log('fetched data for page number ', downloadPage); | ||
accumulatedResults = [ | ||
...accumulatedResults, | ||
...transformResultsToCsvRow(refetchData?.searchResults || [], entityRegistry), | ||
]; | ||
if ((refetchData?.start || 0) + (refetchData?.count || 0) < (refetchData?.total || 0)) { | ||
downloadPage += 1; | ||
fetchNextPage(); | ||
} else { | ||
setIsDownloadingCsv(false); | ||
downloadRowsAsCsv( | ||
getSearchCsvDownloadHeader(refetchData?.searchResults[0]), | ||
accumulatedResults, | ||
filename, | ||
); | ||
} | ||
}); | ||
} | ||
|
||
fetchNextPage(); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
centered | ||
onCancel={() => setShowDownloadAsCsvModal(false)} | ||
title="Download as..." | ||
visible={showDownloadAsCsvModal} | ||
footer={ | ||
<> | ||
<Button onClick={() => setShowDownloadAsCsvModal(false)} type="text"> | ||
Close | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
setShowDownloadAsCsvModal(false); | ||
triggerCsvDownload(saveAsTitle); | ||
}} | ||
disabled={saveAsTitle.length === 0} | ||
> | ||
Download | ||
</Button> | ||
</> | ||
} | ||
> | ||
<Input | ||
placeholder="datahub.csv" | ||
value={saveAsTitle} | ||
onChange={(e) => { | ||
setSaveAsTitle(e.target.value); | ||
}} | ||
/> | ||
</Modal> | ||
); | ||
} |
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.