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: Keep segment modal open on create / edit, add segment name to modal #4109

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions frontend/e2e/helpers.cafe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ export const createSegment = async (
await click(byId('create-segment'))
await waitForElementVisible(byId(`segment-${index}-name`))
await assertTextContent(byId(`segment-${index}-name`), id)
await closeModal()
}

export const waitAndRefresh = async (waitFor = 3000) => {
Expand Down
1 change: 0 additions & 1 deletion frontend/web/components/SegmentOverrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,6 @@ class TheComponent extends Component {
<CreateSegmentModal
className='my-2'
segment={this.state.segmentEditId}
isEdit
condensed
onComplete={() => {
this.setState({
Expand Down
15 changes: 11 additions & 4 deletions frontend/web/components/modals/CreateSegment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import AddMetadataToEntity, {
CustomMetadataField,
} from 'components/metadata/AddMetadataToEntity'
import { useGetSupportedContentTypeQuery } from 'common/services/useSupportedContentType'
import { setInterceptClose } from './base/ModalDefault'
import { setInterceptClose, setModalTitle } from './base/ModalDefault'

type PageType = {
number: number
Expand Down Expand Up @@ -90,7 +90,6 @@ const CreateSegment: FC<CreateSegmentType> = ({
identities,
identitiesLoading,
identity,
isEdit,
onCancel,
onComplete,
page,
Expand Down Expand Up @@ -119,7 +118,8 @@ const CreateSegment: FC<CreateSegmentType> = ({
},
],
}
const segment = _segment || defaultSegment
const [segment, setSegment] = useState(_segment || defaultSegment)
const isEdit = !!segment.id
const [
createSegment,
{
Expand Down Expand Up @@ -267,6 +267,7 @@ const CreateSegment: FC<CreateSegmentType> = ({
}, [])
useEffect(() => {
if (createSuccess && createSegmentData) {
setSegment(createSegmentData)
onComplete?.(createSegmentData)
}
//eslint-disable-next-line
Expand Down Expand Up @@ -740,7 +741,8 @@ type LoadingCreateSegmentType = {
environmentId: string
isEdit?: boolean
readOnly?: boolean
onComplete?: () => void
onSegmentRetrieved?: (segment: Segment) => void
onComplete?: (segment: Segment) => void
projectId: string
segment?: number
}
Expand Down Expand Up @@ -772,6 +774,11 @@ const LoadingCreateSegment: FC<LoadingCreateSegmentType> = (props) => {
},
)

useEffect(() => {
if (segmentData) {
props.onSegmentRetrieved?.(segmentData)
}
}, [segmentData])
const isEdge = Utils.getIsEdge()

const { data: identities, isLoading: identitiesLoading } =
Expand Down
13 changes: 8 additions & 5 deletions frontend/web/components/pages/SegmentsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Icon from 'components/Icon'
import PageTitle from 'components/PageTitle'
import Switch from 'components/Switch'
import Panel from 'components/base/grid/Panel'
import { setModalTitle } from 'components/modals/base/ModalDefault'

const CodeHelp = require('../../components/CodeHelp')
type SegmentsPageType = {
Expand Down Expand Up @@ -91,10 +92,10 @@ const SegmentsPage: FC<SegmentsPageType> = (props) => {
openModal(
'New Segment',
<CreateSegmentModal
onComplete={() => {
onComplete={(segment) => {
//todo: remove when CreateSegment uses hooks
closeModal()
refetch()
setModalTitle(`Edit Segment: ${segment.name}`)
toast('Created segment')
}}
environmentId={environmentId}
projectId={projectId}
Expand Down Expand Up @@ -124,11 +125,13 @@ const SegmentsPage: FC<SegmentsPageType> = (props) => {
`Edit Segment`,
<CreateSegmentModal
segment={id}
isEdit
onSegmentRetrieved={(segment) =>
setModalTitle(`Edit Segment: ${segment.name}`)
}
readOnly={readOnly}
onComplete={() => {
refetch()
closeModal()
toast('Updated Segment')
}}
environmentId={environmentId}
projectId={projectId}
Expand Down
1 change: 0 additions & 1 deletion frontend/web/components/pages/UserPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ const UserPage = class extends Component {
<CreateSegmentModal
segment={segment.id}
readOnly
isEdit
environmentId={this.props.match.params.environmentId}
projectId={this.props.match.params.projectId}
/>,
Expand Down
Loading