-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #3352 remove saved queries from freactal * remove todo * #3352 incorporate comments from code review * #3352 changed error language
- Loading branch information
1 parent
8a67d1f
commit 89725dc
Showing
16 changed files
with
697 additions
and
446 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 was deleted.
Oops, something went wrong.
102 changes: 102 additions & 0 deletions
102
src/components/UserDashboard/SavedQueries/SavedQueriesTab.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,102 @@ | ||
import React, { ReactNode } from 'react'; | ||
import { DeleteFilled, WarningFilled } from '@ant-design/icons'; | ||
import { Alert, Button, List, Popconfirm, Space } from 'antd'; | ||
import { distanceInWords } from 'date-fns'; | ||
|
||
import { SavedQueriesStatuses, SavedQueryWithFileContent } from 'store/SavedQueriesTypes'; | ||
import { VirtualStudyPlusId } from 'store/virtualStudiesTypes'; | ||
import styleThemeColors from 'style/themes/default/colors.module.scss'; | ||
import { toKebabCase } from 'utils'; | ||
|
||
type Item = VirtualStudyPlusId | SavedQueryWithFileContent; | ||
|
||
type Items = Array<Item>; | ||
|
||
type Props = { | ||
items: Items; | ||
queryIdToStatus: Record<string, SavedQueriesStatuses>; | ||
makeDescription: (item: Item) => ReactNode; | ||
makeItemTitle: (item: Item) => ReactNode; | ||
makeNoItemsInfoMessage: () => ReactNode; | ||
onConfirmCb: (item: Item) => Promise<void>; | ||
}; | ||
|
||
const sortByEarliestToLatest = (items: Items) => | ||
[...items].sort((a, b) => Number(new Date(b.creationDate)) - Number(new Date(a.creationDate))); | ||
|
||
const SavedQueriesTab = (props: Props) => { | ||
const { | ||
items, | ||
queryIdToStatus, | ||
makeDescription, | ||
makeItemTitle, | ||
makeNoItemsInfoMessage, | ||
onConfirmCb, | ||
} = props; | ||
|
||
if (items.length === 0) { | ||
return <Alert message={makeNoItemsInfoMessage()} type="info" />; | ||
} | ||
const sortedQueries = sortByEarliestToLatest(items); | ||
|
||
return ( | ||
<List | ||
size={'small'} | ||
itemLayout="horizontal" | ||
dataSource={sortedQueries} | ||
renderItem={(item) => { | ||
const currentItemIsDeleting = queryIdToStatus[item.id] === SavedQueriesStatuses.deleting; | ||
const currentItemIsInError = queryIdToStatus[item.id] === SavedQueriesStatuses.error; | ||
return ( | ||
<List.Item | ||
actions={[ | ||
<Popconfirm | ||
key={`popUp-${toKebabCase(item.id)}`} | ||
title={'Permanently delete this query?'} | ||
okText="Delete" | ||
cancelText="Cancel" | ||
onConfirm={async () => { | ||
await onConfirmCb(item); | ||
}} | ||
> | ||
<Button | ||
type={'text'} | ||
icon={ | ||
currentItemIsInError ? ( | ||
<WarningFilled style={{ color: styleThemeColors.warningColor }} /> | ||
) : ( | ||
<DeleteFilled /> | ||
) | ||
} | ||
disabled={currentItemIsDeleting || currentItemIsInError} | ||
loading={currentItemIsDeleting} | ||
/> | ||
</Popconfirm>, | ||
]} | ||
> | ||
<List.Item.Meta | ||
title={makeItemTitle(item)} | ||
description={ | ||
<Space direction={'vertical'}> | ||
{makeDescription(item)} | ||
<span>Saved {distanceInWords(new Date(), new Date(item.creationDate))} ago</span> | ||
{currentItemIsInError && ( | ||
<Alert | ||
type={'error'} | ||
message={ | ||
'An error occurred while trying to delete the query.' + | ||
' Please refresh and retry or contact support.' | ||
} | ||
/> | ||
)} | ||
</Space> | ||
} | ||
/> | ||
</List.Item> | ||
); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default SavedQueriesTab; |
Oops, something went wrong.