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

Refactor/doma 10993/moved base news form into step #5723

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

Alexander-Turkin
Copy link
Contributor

merged NewsItemSharingForm and BaseNewsForm into one component (Input Step)

@toplenboren
Copy link
Member

@Alexander-Turkin
fix(condo): DOMA-10018 add wight to datepicker
4759628

Seems like this commit should not be here

isValid: boolean
}

export type TScope = {
Copy link
Member

Choose a reason for hiding this comment

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

We use other syntax: TScope -> ScopeType

@@ -143,59 +132,51 @@ type SelectAppsFormValues = {
validBefore: string
}

const HiddenBlock = styled.div<{ hide?: boolean }>`
export type SharingAppValues = {
Copy link
Member

Choose a reason for hiding this comment

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

SharingAppValuesType

Copy link
Member

Choose a reason for hiding this comment

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

Why do you need it here? You have already declared this exact variable in InputStep

Comment on lines 156 to 174
export const NO_RESIZE_STYLE: React.CSSProperties = { resize: 'none' }
export const FLEX_START_STYLE: React.CSSProperties = { alignItems: 'flex-start' }
export const BIG_MARGIN_BOTTOM_STYLE: React.CSSProperties = { marginBottom: '60px' }
export const MARGIN_BOTTOM_32_STYLE: React.CSSProperties = { marginBottom: '32px' }
export const MARGIN_BOTTOM_38_STYLE: React.CSSProperties = { marginBottom: '38px' }
export const MARGIN_BOTTOM_10_STYLE: React.CSSProperties = { marginBottom: '10px' }
export const MARGIN_BOTTOM_24_STYLE: React.CSSProperties = { marginBottom: '24px' }
export const MARGIN_TOP_8_STYLE: React.CSSProperties = { marginTop: '8px' }
export const MARGIN_TOP_44_STYLE: React.CSSProperties = { marginTop: '44px' }
export const FORM_FILED_COL_PROPS = { style: { width: '100%', padding: 0, height: '44px' } }
export const SCROLL_TO_FIRST_ERROR_CONFIG: ScrollOptions = { behavior: 'smooth', block: 'center' }
export const SHOW_TIME_CONFIG = { defaultValue: dayjs('00:00:00:000', 'HH:mm:ss:SSS') }
export const FULL_WIDTH_STYLE: React.CSSProperties = { width: '100%' }
const SMALL_VERTICAL_GUTTER: [Gutter, Gutter] = [0, 24]
const EXTRA_SMALL_VERTICAL_GUTTER: [Gutter, Gutter] = [0, 10]
const BIG_HORIZONTAL_GUTTER: [Gutter, Gutter] = [50, 0]
const ALL_SQUARE_BRACKETS_OCCURRENCES_REGEX = /\[[^\]]*?\]/g
const ADDITIONAL_DISABLED_MINUTES_COUNT = 5
const DATE_FORMAT = 'DD MMMM YYYY HH:mm'
export const SMALL_VERTICAL_GUTTER: [Gutter, Gutter] = [0, 24]
export const EXTRA_SMALL_VERTICAL_GUTTER: [Gutter, Gutter] = [0, 10]
export const BIG_HORIZONTAL_GUTTER: [Gutter, Gutter] = [50, 0]
export const ALL_SQUARE_BRACKETS_OCCURRENCES_REGEX = /\[[^\]]*?\]/g
export const ADDITIONAL_DISABLED_MINUTES_COUNT = 5
export const DATE_FORMAT = 'DD MMMM YYYY HH:mm'
Copy link
Member

Choose a reason for hiding this comment

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

I do not really like exporting this stuff elsewhere,

It is considered a bad practice in this project, better to stick to UI kit where possible, and just inline required values

You are exporting these values, this means that other engineers will use them, and project might become more coupled (https://www.geeksforgeeks.org/software-engineering-coupling-and-cohesion/) + this promotes bad practice

Lets remove these exports

Comment on lines 807 to 811
const res = { ...form.getFieldsValue(true) }

setSelectedTitle(res.title)
setSelectedBody(res.body)
setCondoFormValues(res)
Copy link
Member

Choose a reason for hiding this comment

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

res -> formValues

)}
</>
) : (
//TODO use custom selector with getRecipientCounter
Copy link
Member

Choose a reason for hiding this comment

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

If you add TODO, you should add a task number

B2BApp, B2BAppNewsSharingConfig, NewsItem as INewsItem,
NewsItemScope as INewsItemScope,
Property as IProperty,
} from '../../../../schema'
Copy link
Member

Choose a reason for hiding this comment

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

You should use absolute imports when possible

@@ -104,18 +92,19 @@ type StepData = {

export type SendPeriodType = 'now' | 'later'

export type TInitialValues = Partial<INewsItem> & Partial<{
Copy link
Member

Choose a reason for hiding this comment

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

Type

Comment on lines 169 to 170
const { app: sharingApp, id: ctxId } = sharingAppData ?? { ctxId: null, sharingApp: null }
const { id, newsSharingConfig } = sharingApp ?? { id: null, newsSharingConfig: null }
Copy link
Member

Choose a reason for hiding this comment

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

I do not really like that we have one big component that renders both sharing app and not sharing app. Does not look clean to me

I'd like to propose something like this:

BaseNewsForm - handles steps and skips logic

  • InputStep – just takes building blocks and compiles them in single component
    • bodyControl/IFrameBodyControl.tsx
    • bodyControl/CondoBodyControl.tsx
    • scopeControl/CondoScopeControl.tsx
    • scopeControl/GetRecipientsScopeControl.tsx
    • RecipientsDisplay.tsx
    • PreviewDisplay.tsx

We can discuss this

@toplenboren
Copy link
Member

@Alexander-Turkin
Merge remote-tracking branch 'origin/main'

Better to use rebase always

@toplenboren
Copy link
Member

Also, beware, when merging this PR you will be squasing all your commits into one

Name of squashed commit = name of the PR, so in your case name of the squashed commit will be: Refactor/doma 10993/moved base news form into step

Best to use semantic commits syntax for that :-)

[key: string]: {
title: string
body: string
type: string | null
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
type: string | null
type?: string

?

Comment on lines 15 to 17
import { TemplatesSelect } from '../../TemplatesSelect'
import { getBodyTemplateChangedRule, getTitleTemplateChangedRule } from '../BaseNewsForm'
import { TemplatesType } from '../BaseNewsForm'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import { TemplatesSelect } from '../../TemplatesSelect'
import { getBodyTemplateChangedRule, getTitleTemplateChangedRule } from '../BaseNewsForm'
import { TemplatesType } from '../BaseNewsForm'
import { TemplatesSelect } from '@condo/domains/news/components/TemplatesSelect'
import { getBodyTemplateChangedRule, getTitleTemplateChangedRule, TemplatesType } from '@condo/domains/news/components/NewsForm/BaseNewsForm'

use absolute import if it's other folder

return style
}

interface InputStepFormProps {
Copy link
Member

Choose a reason for hiding this comment

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

15 props looks too complicated. Try to reduce their number (for example, break them into different components, if possible)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

here I take out a huge piece of code so that a large number

Copy link
Member

Choose a reason for hiding this comment

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

I +1 @nomerdvadcatpyat, we can for example move onSkip to the BaseNewsForm, that would lower the complexity

Comment on lines 50 to 51
TitleInput: any
BodyInput: any
Copy link
Member

Choose a reason for hiding this comment

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

ReturnType<typeof useInputWithCounter> istead any

Comment on lines 54 to 59
newsItemData: {
type: string
validBefore?: string
title: string
body: string
}
Copy link
Member

Choose a reason for hiding this comment

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

Same type used in INewsItemSharingForm. Make separate type and reuse here and in INewsItemSharingForm

}
selectedBody: string
selectedTitle: string
form: any
Copy link
Member

Choose a reason for hiding this comment

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

FormInstance from antd.

And try to use useForm hook instead pass it in props:
const [form] = Form.useForm()

selectedBody: string
selectedTitle: string
form: any
ctxId: string
Copy link
Member

Choose a reason for hiding this comment

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

What is this context? It's not clear from the name

isValid: boolean
}

handleTemplateChange: (form: any) => (value: any) => void
Copy link
Member

Choose a reason for hiding this comment

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

add types here

<>
{
isCustomForm ? (
<Col style={{ marginLeft: '-10px', minHeight: '500px' }} span={formFieldsColSpan}>
Copy link
Member

Choose a reason for hiding this comment

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

strange margin

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied this code)

Copy link
Member

@toplenboren toplenboren Feb 6, 2025

Choose a reason for hiding this comment

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

Let me explain this one: since customForm is an IFrame, we should have negative margin, in order for IFrame to be able to render shadows, outlines, and other UI stuff.

Best to add a comment, so that is more obvious

import { NEWS_SHARING_PUSH_NOTIFICATION_SETTINGS } from '@condo/domains/miniapp/constants'
import { NEWS_TYPE_EMERGENCY } from '@condo/domains/news/constants/newsTypes'

import { MemoizedCondoNewsPreview, MemoizedSharingNewsPreview } from '../../NewsPreview'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import { MemoizedCondoNewsPreview, MemoizedSharingNewsPreview } from '../../NewsPreview'
import { MemoizedCondoNewsPreview, MemoizedSharingNewsPreview } from '@condo/domains/news/components/NewsPreview'

Copy link

sonarqubecloud bot commented Feb 6, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants