Skip to content

FIX: [DEV-10387] - Fix Widget delete issue #2039

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

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Changes from 2 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
18 changes: 18 additions & 0 deletions packages/dashboard/src/components/Widget/Widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const Widget = ({
const { overlay } = useGlobalContext()
const { config, data } = useContext(DashboardContext)
const dispatch = useContext(DashboardDispatchContext)
const updateConfig = config => dispatch({ type: 'UPDATE_CONFIG', payload: [config] })

const [isEditing, setIsEditing] = useState(false)
const [toggleName, setToggleName] = useState(
Expand Down Expand Up @@ -71,7 +72,24 @@ const Widget = ({

const deleteWidget = () => {
if (!widgetConfig) return
// if last widget left in row remove whole row on delete
if (widgetConfig.colIdx === 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if it's the last column but it's at index 2?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshlacey thats not issue. it will delete only last(one) widget.

let newVisualizations = { ...config.visualizations }
const rows = config.rows
const rowIdx = widgetConfig.rowIdx

//delete the instantiated widgets
if (rows[rowIdx] && rows[rowIdx].columns && rows[rowIdx].columns.length && config.visualizations) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can simplify this: rows[rowIdx]?.columns?.length

rows[rowIdx].columns.forEach(column => {
if (column.widget) {
delete newVisualizations[column.widget]
}
})
}

config.rows.splice(rowIdx, 1) // delete the row
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the functionality should be that you delete the column but leave a placeholder there, a single column so that you can still add a widget there if you want.

say for example you put a chart widget when you meant to put a table widget, it would be annoying if the row disappeared when you deleted the mistaken chart widget. you'd have to add a new row and if you have a lot of rows, move it all the way to the top.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshlacey i tryied to leave placeholder emty then the library that is being used thinks that widget is still there and cannot move new widget on top of it.and Cailin then asked to delete whole row

updateConfig({ ...config, rows, visualizations: newVisualizations })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you match the pattern everywhere else here and call the dispatch function directly?

}
dispatch({
type: 'DELETE_WIDGET',
payload: { uid: widgetConfig.uid as string }
Expand Down