Skip to content

Commit

Permalink
feat(idpe-15219): remove pinned items from dashboards (#5789)
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedld authored Sep 16, 2022
1 parent 2c2408b commit 448d952
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 154 deletions.
3 changes: 1 addition & 2 deletions src/dashboards/components/DashboardHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {

// Utils
import {resetQueryCache} from 'src/shared/apis/queryCache'
import {updatePinnedItemByParam} from 'src/shared/contexts/pinneditems'

// Selectors
import {getTimeRange} from 'src/dashboards/selectors'
import {getByID} from 'src/resources/selectors'
Expand Down Expand Up @@ -103,7 +103,6 @@ const DashboardHeader: FC<Props> = ({

const handleRenameDashboard = (name: string) => {
updateDashboard(dashboard.id, {name})
updatePinnedItemByParam(dashboard.id, {name})
}

const handleChooseTimeRange = (timeRange: TimeRange) => {
Expand Down
69 changes: 2 additions & 67 deletions src/dashboards/components/dashboard_index/DashboardCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,8 @@ import {DEFAULT_DASHBOARD_NAME} from 'src/dashboards/constants'
import {relativeTimestampFormatter} from 'src/shared/utils/relativeTimestampFormatter'
import {shouldOpenLinkInNewTab} from 'src/utils/crossPlatform'
import {safeBlankLinkOpen} from 'src/utils/safeBlankLinkOpen'

import {
pinnedItemFailure,
pinnedItemSuccess,
} from 'src/shared/copy/notifications'
import {notify} from 'src/shared/actions/notifications'

import {
deletePinnedItemByParam,
updatePinnedItemByParam,
} from 'src/shared/contexts/pinneditems'

import {isFlagEnabled} from 'src/shared/utils/featureFlag'
import {CLOUD} from 'src/shared/constants'
import {PROJECT_NAME} from 'src/flows'

interface OwnProps {
Expand All @@ -64,13 +52,6 @@ interface OwnProps {
updatedAt: string
labels: string[]
onFilterChange: (searchTerm: string) => void
onPinDashboard: (
dashboardID: string,
name: string,
description: string
) => void
onUnpinDashboard: (DashboardID: string) => void
isPinned: boolean
}

type ReduxProps = ConnectedProps<typeof connector>
Expand Down Expand Up @@ -137,15 +118,6 @@ class DashboardCard extends PureComponent<Props> {
const {id, onUpdateDashboard} = this.props

onUpdateDashboard(id, {name})

if (isFlagEnabled('pinnedItems') && CLOUD && this.props.isPinned) {
try {
updatePinnedItemByParam(id, {name})
this.props.sendNotification(pinnedItemSuccess('dashboard', 'updated'))
} catch (err) {
this.props.sendNotification(pinnedItemFailure(err.message, 'update'))
}
}
}

private handleCloneDashboard = () => {
Expand All @@ -154,15 +126,6 @@ class DashboardCard extends PureComponent<Props> {
onCloneDashboard(id, name)
}

private handlePinDashboard = () => {
const {id, name, description, isPinned} = this.props
if (isPinned) {
this.props.onUnpinDashboard(id)
} else {
this.props.onPinDashboard(id, name, description)
}
}

private get contextMenu(): JSX.Element {
const settingsRef: RefObject<HTMLButtonElement> = createRef()

Expand All @@ -189,7 +152,7 @@ class DashboardCard extends PureComponent<Props> {
appearance={Appearance.Outline}
enableDefaultStyles={false}
style={minWidth}
contents={onHide => (
contents={_ => (
<List>
<List.Item
onClick={this.handleExport}
Expand All @@ -207,19 +170,6 @@ class DashboardCard extends PureComponent<Props> {
>
Clone
</List.Item>
{isFlagEnabled('pinnedItems') && CLOUD && (
<List.Item
onClick={() => {
this.handlePinDashboard()
onHide()
}}
size={ComponentSize.Small}
style={fontWeight}
testID="context-pin-dashboard"
>
{this.props.isPinned ? 'Unpin' : 'Pin'}
</List.Item>
)}
</List>
)}
triggerRef={settingsRef}
Expand All @@ -228,17 +178,9 @@ class DashboardCard extends PureComponent<Props> {
)
}

private handleDeleteDashboard = async () => {
private handleDeleteDashboard = () => {
const {id, name, onDeleteDashboard} = this.props
onDeleteDashboard(id, name)
if (isFlagEnabled('pinnedItems') && CLOUD && this.props.isPinned) {
try {
await deletePinnedItemByParam(id)
this.props.sendNotification(pinnedItemSuccess('dashboard', 'deleted'))
} catch (error) {
this.props.sendNotification(pinnedItemFailure(error.message, 'delete'))
}
}
}

private handleClickDashboard = event => {
Expand Down Expand Up @@ -270,13 +212,6 @@ class DashboardCard extends PureComponent<Props> {
const {id, onUpdateDashboard} = this.props

onUpdateDashboard(id, {description})
if (isFlagEnabled('pinnedItems') && CLOUD && this.props.isPinned) {
try {
updatePinnedItemByParam(id, {description})
} catch (err) {
this.props.sendNotification(pinnedItemFailure(err.message, 'update'))
}
}
}

private handleAddLabel = (label: Label) => {
Expand Down
85 changes: 0 additions & 85 deletions src/dashboards/components/dashboard_index/DashboardCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,10 @@ import {LimitStatus} from 'src/cloud/actions/limits'
import {getMe} from 'src/me/selectors'
import {getOrg} from 'src/organizations/selectors'

// Contexts
import {
addPinnedItem,
deletePinnedItemByParam,
PinnedItemTypes,
} from 'src/shared/contexts/pinneditems'

// Utils
import {extractDashboardLimits} from 'src/cloud/utils/limits'
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
import {CLOUD} from 'src/shared/constants'
import {notify} from 'src/shared/actions/notifications'

import {
pinnedItemFailure,
pinnedItemSuccess,
} from 'src/shared/copy/notifications'

let getPinnedItems
if (CLOUD) {
getPinnedItems = require('src/shared/contexts/pinneditems').getPinnedItems
}

interface StateProps {
limitStatus: LimitStatus['status']
}
Expand All @@ -51,22 +32,14 @@ type ReduxProps = ConnectedProps<typeof connector>
type Props = OwnProps & StateProps & ReduxProps

class DashboardCards extends PureComponent<Props> {
private _isMounted = true
private _assetLimitAlertStyle = {
height: 'inherit',
}

state = {
pinnedItems: [],
dashboardCardHeight: 'inherit',
}

public componentDidMount() {
if (isFlagEnabled('pinnedItems') && CLOUD) {
this.updatePinnedItems()
}
}

public componentDidUpdate() {
const card = document.querySelector<HTMLElement>(
'.dashboards-card-grid > .cf-resource-card'
Expand All @@ -78,15 +51,9 @@ class DashboardCards extends PureComponent<Props> {
}
}

public componentWillUnmount() {
this._isMounted = false
}

public render() {
const {dashboards, onFilterChange} = this.props

const {pinnedItems} = this.state

return (
<div className="dashboards-card-grid">
{dashboards.map(({id, name, description, labels, meta}) => (
Expand All @@ -98,11 +65,6 @@ class DashboardCards extends PureComponent<Props> {
updatedAt={meta.updatedAt}
description={description}
onFilterChange={onFilterChange}
onPinDashboard={this.handlePinDashboard}
onUnpinDashboard={this.handleUnpinDashboard}
isPinned={
!!pinnedItems.find(item => item?.metadata.dashboardID === id)
}
/>
))}
{this.props.limitStatus === 'exceeded' && (
Expand All @@ -118,53 +80,6 @@ class DashboardCards extends PureComponent<Props> {
</div>
)
}

public updatePinnedItems = () => {
getPinnedItems()
.then(res => {
if (this._isMounted) {
this.setState(prev => ({...prev, pinnedItems: res}))
}
})
.catch(err => console.error(err))
}

public handlePinDashboard = async (
dashboardID: string,
name: string,
description: string
) => {
const {org, me} = this.props

// add to pinned item list
try {
await addPinnedItem({
orgID: org.id,
userID: me.id,
metadata: {
dashboardID,
name,
description,
},
type: PinnedItemTypes.Dashboard,
})
this.props.sendNotification(pinnedItemSuccess('dashboard', 'added'))
this.updatePinnedItems()
} catch (err) {
this.props.sendNotification(pinnedItemFailure(err.message, 'add'))
}
}

public handleUnpinDashboard = async (dashboardID: string) => {
// delete from pinned item list
try {
await deletePinnedItemByParam(dashboardID)
this.props.sendNotification(pinnedItemSuccess('dashboard', 'deleted'))
this.updatePinnedItems()
} catch (err) {
this.props.sendNotification(pinnedItemFailure(err.message, 'delete'))
}
}
}

const mdtp = {
Expand Down

0 comments on commit 448d952

Please sign in to comment.