Skip to content

Commit 4a540b0

Browse files
authored
feat(idpe-15219): remove pinned items from Tasks (#5784)
1 parent 0aa4996 commit 4a540b0

File tree

4 files changed

+5
-145
lines changed

4 files changed

+5
-145
lines changed

src/tasks/components/TaskCard.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const setup = (override = {}) => {
3030
labels: [], // all labels
3131
onPinTask: jest.fn(),
3232
onUnpinTask: jest.fn(),
33-
isPinned: false,
3433
org: {id: 'BUCKSINSIX', name: 'Milwaukee Bucks'},
3534
me: {
3635
id: 'FORTHECULTURE',

src/tasks/components/TaskCard.tsx

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ import React, {PureComponent, RefObject, createRef} from 'react'
33
import {connect, ConnectedProps} from 'react-redux'
44
import {withRouter, RouteComponentProps} from 'react-router-dom'
55

6-
import {
7-
deletePinnedItemByParam,
8-
updatePinnedItemByParam,
9-
} from 'src/shared/contexts/pinneditems'
10-
116
// Components
127
import {
138
SlideToggle,
@@ -40,12 +35,8 @@ import {Task, Label} from 'src/types'
4035
// Constants
4136
import {DEFAULT_TASK_NAME} from 'src/dashboards/constants'
4237
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
43-
import {CLOUD} from 'src/shared/constants'
4438

45-
import {
46-
pinnedItemFailure,
47-
pinnedItemSuccess,
48-
} from 'src/shared/copy/notifications'
39+
// Utils
4940
import {notify} from 'src/shared/actions/notifications'
5041
import {downloadTaskTemplate} from 'src/tasks/apis'
5142
import {event} from 'src/cloud/utils/reporting'
@@ -60,9 +51,6 @@ interface PassedProps {
6051
onRunTask: (taskID: string) => void
6152
onUpdate: (name: string, taskID: string) => void
6253
onFilterChange: (searchTerm: string) => void
63-
onPinTask: (taskID: string, name: string) => void
64-
onUnpinTask: (taskID: string) => void
65-
isPinned: boolean
6654
}
6755

6856
type ReduxProps = ConnectedProps<typeof connector>
@@ -147,26 +135,12 @@ export class TaskCard extends PureComponent<
147135
)
148136
}
149137

150-
private handlePinTask = () => {
151-
const {task, isPinned} = this.props
152-
153-
if (isPinned) {
154-
this.props.onUnpinTask(task.id)
155-
} else {
156-
this.props.onPinTask(task.id, task.name)
157-
}
158-
}
159-
160-
private handleOnDelete = async task => {
138+
private handleOnDelete = task => {
161139
this.props.onDelete(task)
162-
try {
163-
await deletePinnedItemByParam(task.id)
164-
} catch (error) {
165-
this.props.sendNotification(pinnedItemFailure(error.message, 'delete'))
166-
}
167140
}
141+
168142
private get contextMenu(): JSX.Element {
169-
const {task, onClone, isPinned} = this.props
143+
const {task, onClone} = this.props
170144
const settingsRef: RefObject<HTMLButtonElement> = createRef()
171145

172146
return (
@@ -194,7 +168,7 @@ export class TaskCard extends PureComponent<
194168
appearance={Appearance.Outline}
195169
enableDefaultStyles={false}
196170
style={{minWidth: '112px'}}
197-
contents={onHide => (
171+
contents={_ => (
198172
<List>
199173
<List.Item
200174
onClick={this.handleExport}
@@ -230,19 +204,6 @@ export class TaskCard extends PureComponent<
230204
>
231205
Clone
232206
</List.Item>
233-
{isFlagEnabled('pinnedItems') && CLOUD && (
234-
<List.Item
235-
onClick={() => {
236-
this.handlePinTask()
237-
onHide()
238-
}}
239-
size={ComponentSize.Small}
240-
style={{fontWeight: 500}}
241-
testID="context-pin-task"
242-
>
243-
{isPinned ? 'Unpin' : 'Pin'}
244-
</List.Item>
245-
)}
246207
</List>
247208
)}
248209
triggerRef={settingsRef}
@@ -302,14 +263,6 @@ export class TaskCard extends PureComponent<
302263
task: {id},
303264
} = this.props
304265
onUpdate(name, id)
305-
if (isFlagEnabled('pinnedItems') && CLOUD && this.props.isPinned) {
306-
try {
307-
updatePinnedItemByParam(id, {name})
308-
this.props.sendNotification(pinnedItemSuccess('task', 'updated'))
309-
} catch (err) {
310-
this.props.sendNotification(pinnedItemFailure(err.message, 'update'))
311-
}
312-
}
313266
}
314267

315268
private handleExport = () => {

src/tasks/components/TasksList.tsx

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,16 @@ import {getSortedResources} from 'src/shared/utils/sort'
2222
import {getMe} from 'src/me/selectors'
2323
import {getOrg} from 'src/organizations/selectors'
2424

25-
// Contexts
26-
import {
27-
addPinnedItem,
28-
deletePinnedItemByParam,
29-
PinnedItemTypes,
30-
} from 'src/shared/contexts/pinneditems'
31-
3225
// Utils
3326
import {event} from 'src/cloud/utils/reporting'
3427
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
35-
import {CLOUD} from 'src/shared/constants'
3628
import {notify} from 'src/shared/actions/notifications'
3729

3830
// Constants
3931
import {GLOBAL_HEADER_HEIGHT} from 'src/identity/components/GlobalHeader/constants'
4032

4133
import {PaginationNav} from '@influxdata/clockface'
4234

43-
import {
44-
pinnedItemFailure,
45-
pinnedItemSuccess,
46-
} from 'src/shared/copy/notifications'
47-
48-
let getPinnedItems
49-
if (CLOUD) {
50-
getPinnedItems = require('src/shared/contexts/pinneditems').getPinnedItems
51-
}
52-
5335
interface OwnProps {
5436
pageHeight: number
5537
pageWidth: number
@@ -74,7 +56,6 @@ interface OwnProps {
7456
interface State {
7557
taskLabelsEdit: Task
7658
isEditingTaskLabels: boolean
77-
pinnedItems: any[]
7859
}
7960

8061
type ReduxProps = ConnectedProps<typeof connector>
@@ -86,7 +67,6 @@ class TasksList extends PureComponent<Props, State> implements Pageable {
8667
private memGetSortedResources =
8768
memoizeOne<typeof getSortedResources>(getSortedResources)
8869

89-
private isComponentMounted: boolean
9070
private paginationRef: RefObject<HTMLDivElement>
9171

9272
public currentPage: number = 1
@@ -98,14 +78,12 @@ class TasksList extends PureComponent<Props, State> implements Pageable {
9878
this.state = {
9979
taskLabelsEdit: null,
10080
isEditingTaskLabels: false,
101-
pinnedItems: [],
10281
}
10382

10483
this.paginationRef = createRef<HTMLDivElement>()
10584
}
10685

10786
public componentDidMount() {
108-
this.isComponentMounted = true
10987
const params = new URLSearchParams(window.location.search)
11088
const urlPageNumber = parseInt(params.get('page'), 10)
11189

@@ -116,9 +94,6 @@ class TasksList extends PureComponent<Props, State> implements Pageable {
11694
}
11795

11896
this.props.checkTaskLimits()
119-
if (CLOUD && isFlagEnabled('pinnedItems')) {
120-
this.updatePinnedItems()
121-
}
12297
}
12398

12499
public componentDidUpdate() {
@@ -129,10 +104,6 @@ class TasksList extends PureComponent<Props, State> implements Pageable {
129104
}
130105
}
131106

132-
public componentWillUnmount() {
133-
this.isComponentMounted = false
134-
}
135-
136107
public render() {
137108
const heightWithPagination =
138109
this.paginationRef?.current?.clientHeight ||
@@ -175,48 +146,6 @@ class TasksList extends PureComponent<Props, State> implements Pageable {
175146
)
176147
}
177148

178-
public updatePinnedItems = () => {
179-
getPinnedItems()
180-
.then(res => {
181-
if (this.isComponentMounted) {
182-
this.setState(prev => ({...prev, pinnedItems: res}))
183-
}
184-
})
185-
.catch(err => console.error(err))
186-
}
187-
188-
public handlePinTask = async (taskID: string, name: string) => {
189-
const {org, me} = this.props
190-
191-
// add to pinned item list
192-
try {
193-
await addPinnedItem({
194-
orgID: org.id,
195-
userID: me.id,
196-
metadata: {
197-
taskID,
198-
name,
199-
},
200-
type: PinnedItemTypes.Task,
201-
})
202-
this.props.sendNotification(pinnedItemSuccess('task', 'added'))
203-
this.updatePinnedItems()
204-
} catch (err) {
205-
this.props.sendNotification(pinnedItemFailure(err.message, 'add'))
206-
}
207-
}
208-
209-
public handleUnpinTask = async (taskID: string) => {
210-
// delete from pinned item list
211-
try {
212-
await deletePinnedItemByParam(taskID)
213-
this.props.sendNotification(pinnedItemSuccess('task', 'deleted'))
214-
this.updatePinnedItems()
215-
} catch (err) {
216-
this.props.sendNotification(pinnedItemFailure(err.message, 'delete'))
217-
}
218-
}
219-
220149
public paginate = page => {
221150
this.currentPage = page
222151
const url = new URL(location.href)
@@ -260,14 +189,6 @@ class TasksList extends PureComponent<Props, State> implements Pageable {
260189
onUpdate={this.props.onUpdate}
261190
onRunTask={this.props.onRunTask}
262191
onFilterChange={this.props.onFilterChange}
263-
onPinTask={this.handlePinTask}
264-
onUnpinTask={this.handleUnpinTask}
265-
isPinned={
266-
this.state.pinnedItems?.length &&
267-
!!this.state.pinnedItems.find(
268-
item => item?.metadata.taskID === task.id
269-
)
270-
}
271192
/>
272193
)
273194
}

src/tasks/containers/TasksPage.test.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,6 @@ jest.mock('src/languageSupport/languages/flux/parser', () => ({
6060
format_from_js_file: jest.fn(),
6161
}))
6262

63-
jest.mock('src/shared/contexts/pinneditems', () => ({
64-
getPinnedItems: jest.fn(() =>
65-
Promise.resolve({
66-
json: () => Promise.resolve([]),
67-
})
68-
),
69-
PinnedItemTypes: {Task: 'task'},
70-
addPinnedItem: jest.fn(() => {
71-
return new Promise(resolve => resolve())
72-
}),
73-
deletePinnedItemByParam: jest.fn(() => Promise.resolve()),
74-
}))
75-
7663
jest.mock('src/client', () => ({
7764
getTasks: jest.fn(() => {
7865
return {

0 commit comments

Comments
 (0)