Skip to content

Commit

Permalink
feat: make containerStore optional
Browse files Browse the repository at this point in the history
  • Loading branch information
akhmyrov committed Apr 10, 2023
1 parent 957aefc commit cff74b1
Show file tree
Hide file tree
Showing 24 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bestdoctor/ke-beta",
"version": "13.3.3",
"version": "13.3.4",
"description": "BestDoctor back-office UI constructor",
"author": "pro100filipp",
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/AsyncReadOnlyWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const AsyncReadOnlyWidget = (props: WidgetProps): JSX.Element => {

const [content, setContent] = useState<string>('')

const context = containerStore.getState()
const context = containerStore?.getState()

const { dataResourceUrl, widgetDescription } = useWidgetInitialization({ ...props, context })
const effectiveCacheTime = getAccessor(cacheTime, mainDetailObject, context)
Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/CheckboxWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const CheckboxWidget = (
isReadOnly,
} = props

const context = containerStore.getState()
const context = containerStore?.getState()

const { targetUrl, content, widgetDescription } = useWidgetInitialization({ ...props, context })
const [value, setValue] = React.useState<boolean>(!!content)
Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/CodeWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const StyledCodeWidget = styled.pre`
const CodeWidget = (props: WidgetProps): JSX.Element => {
const { containerStore, style, helpText, useClipboard, notifier, name } = props

const { content, widgetDescription } = useWidgetInitialization({ ...props, context: containerStore.getState() })
const { content, widgetDescription } = useWidgetInitialization({ ...props, context: containerStore?.getState() })

const element = parse(content.toString())

Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/DateTimeRangeListWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const DateTimeRangeListWidget = (props: DateTimeRangeWidgetProps): JSX.Element =
inputCount = 1,
} = props

const context = containerStore.getState()
const context = containerStore?.getState()
const { targetUrl, content, widgetDescription } = useWidgetInitialization({ ...props, context })

const value = content || getInitialValue(inputCount)
Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/DateTimeRangeWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const DateTimeRangeWidget = (props: DateTimeRangeWidgetProps): JSX.Element => {
mainDetailObject,
} = props

const context = containerStore.getState()
const context = containerStore?.getState()
let iStartDate = null
let iEndDate = null

Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/DateTimeWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const DateTimeWidget = (props: DateTimeWidgetProps): JSX.Element => {
wrapperClassName,
} = props

const context = containerStore.getState()
const context = containerStore?.getState()
const { targetUrl, content, isRequired, widgetDescription } = useWidgetInitialization({ ...props, context })

const contentDate = content ? new Date(content as string) : null
Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/DateWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const DateWidget = (props: DateWidgetProps): JSX.Element => {
mainDetailObject,
} = props

const context = containerStore.getState()
const context = containerStore?.getState()
const { targetUrl, content, isRequired, widgetDescription } = useWidgetInitialization(
{ ...props, context },
{ allowAllDefinedValues: getAccessor(allowAllDefinedValues) }
Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/EmailChipInputWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const EmailChipInputWidget = (props: EmailChipInputWidgetProps): JSX.Elem
inputClassName,
mainDetailObject,
} = props
const context = containerStore.getState()
const context = containerStore?.getState()

const { targetUrl, content, isRequired, widgetDescription } = useWidgetInitialization({ ...props, context })

Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/ForeignKeySelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const ForeignKeySelectWidget = (props: ForeignKeySelectWidgetProps): JSX.Element
menuPlacement,
} = props

const context = containerStore.getState()
const context = containerStore?.getState()

const { targetUrl, content, dataResourceUrl, isRequired, widgetDescription } = useWidgetInitialization(
{ ...props, context },
Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/InputWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const InputWidget = forwardRef<HTMLInputElement, InputWidgetProps>((props: Input
labelContainerProps,
inputProps,
} = props
const context = containerStore.getState()
const context = containerStore?.getState()

const { targetUrl, content, isRequired, widgetDescription } = useWidgetInitialization({ ...props, context })

Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/LinkWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type LinkWidgetProps = WidgetProps & {
const LinkWidget = (props: LinkWidgetProps): JSX.Element => {
const { name, mainDetailObject, href, helpText, style, containerStore, target = '_blank', linkProps } = props

const context = containerStore.getState()
const context = containerStore?.getState()
const { content, widgetDescription } = useWidgetInitialization({ ...props, context })
const linkHref = getWidgetContent(name, mainDetailObject, href, context)

Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/MultiSelectWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const MultiSelectWidget = (props: MultiSelectWidgetProps): JSX.Element => {
menuPlacement,
} = props

const context = containerStore.getState()
const context = containerStore?.getState()
const { targetUrl, content, dataResourceUrl, isRequired, widgetDescription } = useWidgetInitialization({
...props,
context,
Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/PhoneChipInputWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const PhoneChipInputWidget = (props: PhoneChipInputWidgetProps): JSX.Elem
inputClassName,
mainDetailObject,
} = props
const context = containerStore.getState()
const context = containerStore?.getState()

const { targetUrl, content, isRequired, widgetDescription } = useWidgetInitialization({ ...props, context })

Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/RadioButtonWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const RadioButtonWidget = (props: RadioButtonWidgetProps): JSX.Element => {
cacheTime,
getSelectedValue,
} = props
const context = containerStore.getState()
const context = containerStore?.getState()
const effectiveCacheTime = getAccessor(cacheTime, mainDetailObject, context)

const { dataResourceUrl, content, widgetDescription } = useWidgetInitialization({ ...props, context })
Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/ReadOnlyWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ReadOnlyWidget = (props: ReadOnlyWidgetProps): JSX.Element => {

const { content, isRequired, widgetDescription } = useWidgetInitialization({
...props,
context: containerStore.getState(),
context: containerStore?.getState(),
})

const styles = useMultiStyleConfig('ReadOnlyWidget', props)
Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/RegexInputWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const RegexInputWidget = forwardRef<HTMLInputElement, RegexInputWidgetPro
labelContainerProps,
regexp,
} = props
const context = containerStore.getState()
const context = containerStore?.getState()

const { targetUrl, content, isRequired, widgetDescription } = useWidgetInitialization({ ...props, context })

Expand Down
8 changes: 4 additions & 4 deletions src/DetailView/widgets/SelectWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type BaseSelectWidgetProps = {
style?: object
setInitialValue: Function
handleChange: Function
containerStore: Store<object>
containerStore: Store<object> | undefined
required?: Accessor<boolean>
isDisabled?: boolean
isClearable?: boolean
Expand All @@ -49,7 +49,7 @@ const getSelectContent = (
name: string,
detailObject: DetailObject,
displayValue: GenericAccessor,
context: {}
context: object | undefined
): [string, string] => {
// TODO Remove this
try {
Expand Down Expand Up @@ -82,7 +82,7 @@ const BaseSelectWidget = forwardRef<HTMLSelectElement, BaseSelectWidgetProps>(
widgetStyles: extenrnalStyles,
} = props

const context = containerStore.getState()
const context = containerStore?.getState()

const [value, label] = getSelectContent(name, mainDetailObject, displayValue, context)
const isRequired = getAccessorWithDefault(required, mainDetailObject, context, false)
Expand Down Expand Up @@ -156,7 +156,7 @@ const SelectWidget = forwardRef<HTMLSelectElement, SelectWidgetProps>((props: Se
cacheTime,
} = props
const targetUrl = getData(dataTarget, mainDetailObject) || mainDetailObject.url
const context = containerStore.getState()
const context = containerStore?.getState()
const effectiveCacheTime = getAccessor(cacheTime, mainDetailObject, context)

const [value] = getSelectContent(name, mainDetailObject, displayValue, context)
Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/SwitchWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const SwitchWidget = (props: WidgetProps): JSX.Element => {
const { name, helpText, targetPayload, submitChange, setInitialValue, containerStore, style, mainDetailObject } =
props

const context = containerStore.getState()
const context = containerStore?.getState()

const { targetUrl, content, widgetDescription } = useWidgetInitialization({ ...props, context })
const [value, setValue] = useState<boolean>(!!content)
Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/TextEditorWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const TextEditorWidget = (props: TextEditorProps): JSX.Element => {
mainDetailObject,
} = props

const context = containerStore.getState()
const context = containerStore?.getState()
const { targetUrl, content, isRequired, widgetDescription } = useWidgetInitialization({ ...props, context })

setInitialValue({ [name]: content })
Expand Down
2 changes: 1 addition & 1 deletion src/DetailView/widgets/TextValidationWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const TextValidationWidget = (props: WidgetProps & { validateValue?: Accessor<an
validateValue,
} = props

const context = containerStore.getState()
const context = containerStore?.getState()
const { content, widgetDescription } = useWidgetInitialization({ ...props, context })
const value = getAccessor(validateValue, mainDetailObject, context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const AsyncDualSelectWidget = (props: DualSelectWidgetProps): JSX.Element => {
useClipboard,
} = props

const context = containerStore.getState()
const context = containerStore?.getState()

const { targetUrl, content, isRequired, widgetDescription } = useWidgetInitialization({
...props,
Expand Down
2 changes: 1 addition & 1 deletion src/common/hooks/useWidgetInitialization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getAccessor, getAccessorWithDefault, getData, getWidgetContent } from '
import type { GenericAccessor, DetailObject, WidgetProps } from '../../typing'

type InitializationParameters = {
context: object // store for wizards and common detail view widgets
context: object | undefined // store for wizards and common detail view widgets
}

type InitializationArguments = WidgetProps & InitializationParameters
Expand Down
2 changes: 1 addition & 1 deletion src/typing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type WidgetProps = {
submitChange: Function
notBlockingValidators?: ValidatorFunction[]
blockingValidators?: ValidatorFunction[]
containerStore: Store<object>
containerStore: Store<object> | undefined
containerErrorsStore?: Store<ErrorElement[]> | undefined
helpText?: string
description?: string | JSX.Element
Expand Down

0 comments on commit cff74b1

Please sign in to comment.