Skip to content

Commit

Permalink
chore: replace remaining prompts (#21218)
Browse files Browse the repository at this point in the history
  • Loading branch information
daibhin authored Apr 3, 2024
1 parent 7b1611e commit 4a15065
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 178 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/insights-duplication.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Insights', () => {

cy.get('[data-attr="insight-save-dropdown"]').click()
cy.get('[data-attr="insight-save-as-new-insight"]').click()
cy.get('.ant-modal-content .ant-btn-primary').click()
cy.get('button[type=submit]').click()
cy.get('[data-attr="top-bar-name"] .EditableField__display').should('contain', `${insightName} (copy)`)

savedInsights.checkInsightIsInListView(`${insightName} (copy)`)
Expand Down
157 changes: 0 additions & 157 deletions frontend/src/lib/logic/promptLogic.tsx

This file was deleted.

12 changes: 6 additions & 6 deletions frontend/src/models/insightsModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ export const insightsModel = kea<insightsModelType>([
renameInsight: async ({ item }) => {
LemonDialog.openForm({
title: 'Rename insight',
initialValues: { name: item.name },
initialValues: { insightName: item.name },
content: (
<LemonField name="name">
<LemonField name="insightName">
<LemonInput data-attr="insight-name" placeholder="Please enter the new name" autoFocus />
</LemonField>
),
errors: {
name: (name) => (!name ? 'You must enter a name' : undefined),
insightName: (name) => (!name ? 'You must enter a name' : undefined),
},
onSubmit: async ({ name }) => {
onSubmit: async ({ insightName }) => {
const updatedItem = await api.update(
`api/projects/${teamLogic.values.currentTeamId}/insights/${item.id}`,
{ name }
{ name: insightName }
)
lemonToast.success(
<>
Renamed insight from <b>{item.name}</b> to <b>{name}</b>
Renamed insight from <b>{item.name}</b> to <b>{insightName}</b>
</>
)
actions.renameInsightSuccess(updatedItem)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { Monaco } from '@monaco-editor/react'
import { LemonDialog, LemonInput } from '@posthog/lemon-ui'
import { actions, connect, kea, key, listeners, path, props, propsChanged, reducers, selectors } from 'kea'
import { combineUrl } from 'kea-router'
import api from 'lib/api'
import { promptLogic } from 'lib/logic/promptLogic'
import { LemonField } from 'lib/lemon-ui/LemonField'
// Note: we can oly import types and not values from monaco-editor, because otherwise some Monaco code breaks
// auto reload in development. Specifically, on this line:
// `export const suggestWidgetStatusbarMenu = new MenuId('suggestWidgetStatusBar')`
Expand Down Expand Up @@ -45,7 +46,6 @@ export const hogQLQueryEditorLogic = kea<hogQLQueryEditorLogicType>([
}),
connect({
actions: [dataWarehouseSavedQueriesLogic, ['createDataWarehouseSavedQuery']],
logic: [promptLogic({ key: `save-as-view` })],
}),
actions({
saveQuery: true,
Expand Down Expand Up @@ -170,12 +170,18 @@ export const hogQLQueryEditorLogic = kea<hogQLQueryEditorLogicType>([
}
},
saveAsView: async () => {
promptLogic({ key: `save-as-view` }).actions.prompt({
LemonDialog.openForm({
title: 'Save as view',
placeholder: 'Please enter the name of the view',
value: '',
error: 'You must enter a name',
success: actions.saveAsViewSuccess,
initialValues: { viewName: '' },
content: (
<LemonField name="viewName">
<LemonInput placeholder="Please enter the name of the view" autoFocus />
</LemonField>
),
errors: {
viewName: (name) => (!name ? 'You must enter a name' : undefined),
},
onSubmit: ({ viewName }) => actions.saveAsViewSuccess(viewName),
})
},
saveAsViewSuccess: async ({ name }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { LemonDialog, LemonInput } from '@posthog/lemon-ui'
import { actions, connect, kea, key, listeners, path, props, propsChanged, reducers, selectors } from 'kea'
import { FEATURE_FLAGS } from 'lib/constants'
import { LemonField } from 'lib/lemon-ui/LemonField'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { promptLogic } from 'lib/logic/promptLogic'
import { objectsEqual } from 'lib/utils'
import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'
import { filterTestAccountsDefaultsLogic } from 'scenes/settings/project/filterTestAccountDefaultsLogic'
Expand Down Expand Up @@ -79,7 +80,7 @@ export const insightDataLogic = kea<insightDataLogicType>([
dataNodeLogic({ key: insightVizDataNodeKey(props) } as DataNodeLogicProps),
['loadData', 'loadDataSuccess', 'loadDataFailure', 'setResponse as setInsightData'],
],
logic: [insightDataTimingLogic(props), promptLogic({ key: `save-as-insight` })],
logic: [insightDataTimingLogic(props)],
})),

actions({
Expand Down Expand Up @@ -256,12 +257,18 @@ export const insightDataLogic = kea<insightDataLogicType>([
actions.insightLogicSaveInsight(redirectToViewMode)
},
saveAs: async () => {
promptLogic({ key: `save-as-insight` }).actions.prompt({
LemonDialog.openForm({
title: 'Save as new insight',
placeholder: 'Please enter the new name',
value: `${values.insight.name || values.insight.derived_name} (copy)`,
error: 'You must enter a name',
success: actions.saveAsNamingSuccess,
initialValues: { insightName: `${values.insight.name || values.insight.derived_name} (copy)` },
content: (
<LemonField name="insightName">
<LemonInput data-attr="insight-name" placeholder="Please enter the new name" autoFocus />
</LemonField>
),
errors: {
insightName: (name) => (!name ? 'You must enter a name' : undefined),
},
onSubmit: async ({ insightName }) => actions.saveAsNamingSuccess(insightName),
})
},
saveAsNamingSuccess: ({ name }) => {
Expand Down

0 comments on commit 4a15065

Please sign in to comment.