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

feat: add and remove insight from dashboard modal #27138

Merged
merged 18 commits into from
Jan 8, 2025

Conversation

k11kirky
Copy link
Contributor

@k11kirky k11kirky commented Dec 23, 2024

Problem

You cannot add existing insights to a dashboard from the dashboard screen. This creates a confusing UX and likely duplicate created insights.

Changes

When you click add insight from the dashboard a new modal will pop up allowing you to select an exisitng insight or create a new one.

Screenshot 2024-12-23 at 10 16 59 AM

@k11kirky k11kirky requested a review from a team December 23, 2024 18:17
Copy link
Contributor

github-actions bot commented Dec 23, 2024

Size Change: 0 B

Total Size: 1.11 MB

ℹ️ View Unchanged
Filename Size
frontend/dist/toolbar.js 1.11 MB

compressed-size-action

Copy link
Contributor

@thmsobrmlr thmsobrmlr left a comment

Choose a reason for hiding this comment

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

Hey @k11kirky, awesome job getting this started - seriously, this is such a great addition! It's kind of wild we didn’t have this feature already.

A few remarks from my end:

  • Pagination in the modal does not work.
  • It would be great to have an "in progress" state that disables the individual buttons, while an insight is added or removed.
  • I know our UI is quite inconsistent across places, but it would be great if we'd get more consistent eventually (i.e. doesn't need to be addressed here, just wanted to share). In particular it would be nice to be closer to the "Add insight to dashboard" modal visually, e.g.
    • A secondary "Add to dashboard" button instead of the primary "+".
    • "Close" and "Add new insight" buttons in footer.
    • Plain view vs table.

</>
}
>
{/* <p>Add insight to dashboard {dashboard?.name}</p> */}
Copy link
Contributor

Choose a reason for hiding this comment

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

leftover

Copy link
Contributor

Choose a reason for hiding this comment

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

This file seems to contain a lot of duplication from the saved insights page. Can we dry up the code and at least import all the metadata from there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree and updated

@k11kirky k11kirky requested a review from thmsobrmlr January 3, 2025 23:54
Copy link
Contributor

@thmsobrmlr thmsobrmlr left a comment

Choose a reason for hiding this comment

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

Hi @k11kirky, thanks for addressing the feedback! I gave this another look, and pagination still seems a bit broken on my end. For example the page doesn't reset when a filter is changed, is stored in the url although we use kea state and the item count is off when navigating to a second page.

Now I don't want perfect to be the enemy of good and maybe these issues already exist on the original page (I didn't check), but it looks like there is a bunch of code that was just copied over and isn't necessary for the modal either.

I'm thinking we might want to properly generalize the table from the saved insights page or come up with a custom one for the modal. What do you think?


import type { addInsightToDashboardLogicType } from './addInsightToDasboardModalLogicType'

export const addInsightToDashboardLogic = kea<addInsightToDashboardLogicType>([
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: the file is called addInsightToDasboard**Modal**Logic, but the logic is called just addInsightToDashboardLogic

Comment on lines 296 to 298
onClick={() => {
showAddInsightToDashboardModal()
}}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
onClick={() => {
showAddInsightToDashboardModal()
}}
onClick={showAddInsightToDashboardModal}

logic: savedInsightsLogic,
}

export function InsightIcon({
Copy link
Contributor

Choose a reason for hiding this comment

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

This icon can reuse the one from the saved insights page.


const INSIGHTS_PER_PAGE = 15

export const scene: SceneExport = {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need for a scene export. Scenes are "routes" in our app and since this is a modal, we don't need one. Assuming this is a leftover from copying the saved insights page.

Comment on lines 187 to 190
{tab === SavedInsightsTabs.History ? (
<ActivityLog scope={ActivityScope.INSIGHT} />
) : tab === SavedInsightsTabs.Alerts ? (
<Alerts alertId={alertModalId} />
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't necessary here.

@k11kirky k11kirky requested a review from thmsobrmlr January 7, 2025 23:53
Copy link
Contributor

@thmsobrmlr thmsobrmlr left a comment

Choose a reason for hiding this comment

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

Thank you, everything works now ✨

Comment on lines +146 to +171
<>
<LemonTable
loading={insightsLoading}
columns={columns}
dataSource={insights.results}
pagination={{
controlled: true,
currentPage: modalPage,
pageSize: INSIGHTS_PER_PAGE,
entryCount: count,
onForward: () => setModalPage(modalPage + 1),
onBackward: () => setModalPage(modalPage - 1),
}}
sorting={sorting}
onSort={(newSorting) =>
setModalFilters({
order: newSorting
? `${newSorting.order === -1 ? '-' : ''}${newSorting.columnKey}`
: undefined,
})
}
rowKey="id"
loadingSkeletonRows={INSIGHTS_PER_PAGE}
nouns={['insight', 'insights']}
/>
</>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: React.Fragment isn't required any more

Suggested change
<>
<LemonTable
loading={insightsLoading}
columns={columns}
dataSource={insights.results}
pagination={{
controlled: true,
currentPage: modalPage,
pageSize: INSIGHTS_PER_PAGE,
entryCount: count,
onForward: () => setModalPage(modalPage + 1),
onBackward: () => setModalPage(modalPage - 1),
}}
sorting={sorting}
onSort={(newSorting) =>
setModalFilters({
order: newSorting
? `${newSorting.order === -1 ? '-' : ''}${newSorting.columnKey}`
: undefined,
})
}
rowKey="id"
loadingSkeletonRows={INSIGHTS_PER_PAGE}
nouns={['insight', 'insights']}
/>
</>
<LemonTable
loading={insightsLoading}
columns={columns}
dataSource={insights.results}
pagination={{
controlled: true,
currentPage: modalPage,
pageSize: INSIGHTS_PER_PAGE,
entryCount: count,
onForward: () => setModalPage(modalPage + 1),
onBackward: () => setModalPage(modalPage - 1),
}}
sorting={sorting}
onSort={(newSorting) =>
setModalFilters({
order: newSorting
? `${newSorting.order === -1 ? '-' : ''}${newSorting.columnKey}`
: undefined,
})
}
rowKey="id"
loadingSkeletonRows={INSIGHTS_PER_PAGE}
nouns={['insight', 'insights']}
/>

@k11kirky k11kirky changed the title feat: add insight and remove insight from dashoard feat: add and remove insight from dashboard modal Jan 8, 2025
@k11kirky k11kirky enabled auto-merge (squash) January 8, 2025 16:14
@k11kirky k11kirky merged commit 76eb0bf into master Jan 8, 2025
99 checks passed
@k11kirky k11kirky deleted the feat/add-insight-to-dashboard-modal branch January 8, 2025 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants