Skip to content
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

Loader is not in the correct shape and change delete icon #1299

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen, within } from '@testing-library/react'
import { render, screen, within, fireEvent } from '@testing-library/react'
import React from 'react'
import { TWITTER_LINK, sourcesMapper } from '~/components/SourcesTableModal/SourcesView/constants'
import { RSS, TWITTER_HANDLE, YOUTUBE_CHANNEL } from '~/constants'
Expand Down Expand Up @@ -55,4 +55,40 @@ describe('Table Component Tests', () => {
expect(sourceTypeCell).toBeInTheDocument()
expect(sourceCell).toBeInTheDocument()
})

it('should display loader when clicking on delete icon', async () => {
const isEdit = true

render(<Table canEdit={isEdit} data={mockData} />)

const deleteIcon = screen.getByTestId('delete-icon-2')

fireEvent.click(deleteIcon)

const confirmDelete = await screen.findByText('Yes')

fireEvent.click(confirmDelete)

const loader = await screen.findByTestId('delete-loader-2')

expect(loader).toBeInTheDocument()
})

it('should display loader when clicking on edit icon and then check icon', async () => {
const isEdit = true

render(<Table canEdit={isEdit} data={mockData} />)

const editIcon = screen.getByTestId('edit-icon-1')

fireEvent.click(editIcon)

const checkIcon = screen.getByTestId('check-icon-1')

fireEvent.click(checkIcon)

const loader = await screen.findByTestId('edit-loader-1')

expect(loader).toBeInTheDocument()
})
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Table as MaterialTable, TableBody, TableRow } from '@mui/material'
import React, { useState } from 'react'
import { MdCheck, MdClose, MdDeleteForever, MdOutlineModeEdit } from 'react-icons/md'
import { MdCheck, MdClose, MdOutlineModeEdit } from 'react-icons/md'
import { ClipLoader } from 'react-spinners'
import styled from 'styled-components'
import { BaseTextInput } from '~/components/BaseTextInput'
Expand All @@ -15,6 +15,7 @@ import { RadarRequest, Sources } from '~/types'
import { colors } from '~/utils/colors'
import { StyledTableCell, StyledTableHead, StyledTableRow } from '../../common'
import { TWITTER_LINK, sourcesMapper } from '../../constants'
import DeleteIcon from '~/components/Icons/DeleteIcon'

type Props = {
data: Sources[] | undefined
Expand Down Expand Up @@ -121,11 +122,17 @@ const Table: React.FC<Props> = ({ data, canEdit = false }) => {
<StyledTableCell align="left">
<div className="delete-wrapper" id={`delete-${i.source}`}>
{loadingId === i.ref_id ? (
<ClipLoader color={colors.white} />
<ClipLoaderWrapper data-testid={`delete-loader-${i.ref_id}`}>
<ClipLoader color={colors.white} size={16} />
</ClipLoaderWrapper>
) : (
<ConfirmPopover message="Are you sure ?" onConfirm={() => handleRemove(i.ref_id)}>
<IconWrapper className="centered">
<MdDeleteForever />
<ConfirmPopover
data-testid={`delete-icon-${i.ref_id}`}
message="Are you sure?"
onConfirm={() => handleRemove(i.ref_id)}
>
<IconWrapper className="centered" data-testid={`delete-icon-${i.ref_id}`}>
<DeleteIcon />
</IconWrapper>
</ConfirmPopover>
)}
Expand Down Expand Up @@ -180,15 +187,21 @@ const EditableCell: React.FC<EditableCellProps> = ({ value, onSave, id, children
return (
<div>
{editing ? (
<EditModeCellWrapper direction="row">
<EditModeCellWrapper align="center" direction="row">
<BaseTextInput
className="editable-cell__input"
name="cell-input"
onChange={(val) => setName(val)}
value={name}
/>
<IconWrapper align="center" justify="center">
{loading ? <ClipLoader /> : <MdCheck onClick={handleSave} />}
{loading ? (
<ClipLoaderWrapper data-testid={`edit-loader-${id}`}>
<ClipLoader color={colors.white} size={12} />
</ClipLoaderWrapper>
) : (
<MdCheck data-testid={`check-icon-${id}`} onClick={handleSave} />
)}
</IconWrapper>
<IconWrapper align="center" className="secondary" justify="center" onClick={() => setEditing(false)}>
<MdClose />
Expand All @@ -198,7 +211,7 @@ const EditableCell: React.FC<EditableCellProps> = ({ value, onSave, id, children
<EditableCellWrapper direction="row">
{children}
<IconWrapper onClick={() => setEditing(true)}>
<MdOutlineModeEdit size={20} />
<MdOutlineModeEdit data-testid={`edit-icon-${id}`} size={20} />
</IconWrapper>
</EditableCellWrapper>
)}
Expand Down Expand Up @@ -231,14 +244,19 @@ const IconWrapper = styled(Flex)`
border-radius: 50%;
cursor: pointer;
background: transparent;
color: ${colors.lightBlue500};
align-items: center;
justify-content: center;
&.centered {
margin: 0 auto;
}

& + & {
margin-left: 4px;
}

&:hover {
background: rgba(255, 255, 255, 0.1);
}
`

const NoResultWrapper = styled(Flex)`
Expand Down Expand Up @@ -283,3 +301,9 @@ const StyledLink = styled.a`
color: ${colors.white};
}
`

const ClipLoaderWrapper = styled(Flex)`
display: flex;
justify-content: center;
align-items: center;
`
Loading