-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #255 from VirtusLab-Open-Source/develop
Version 2.2.0 preparations
- Loading branch information
Showing
63 changed files
with
2,367 additions
and
1,312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v14.19.1 | ||
v14.20.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React, { BaseSyntheticEvent, useMemo } from 'react'; | ||
import { assertBoolean, assertString } from '../../../../types'; | ||
//@ts-ignore | ||
import { ToggleInput } from '@strapi/design-system/ToggleInput'; | ||
//@ts-ignore | ||
import { TextInput } from '@strapi/design-system/TextInput'; | ||
//@ts-ignore | ||
import { Select, Option } from '@strapi/design-system/Select'; | ||
//@ts-ignore | ||
import { useNotification } from '@strapi/helper-plugin'; | ||
import { getTrad } from '../../translations'; | ||
import { AdditionalFieldInputProps, Input } from './types'; | ||
import { isNil } from 'lodash'; | ||
import { useIntl } from 'react-intl'; | ||
|
||
const DEFAULT_STRING_VALUE = ""; | ||
const handlerFactory = | ||
({ field, prop, onChange }: Input) => | ||
({ target }: BaseSyntheticEvent) => { | ||
onChange(field.name, target[prop]); | ||
}; | ||
|
||
const AdditionalFieldInput: React.FC<AdditionalFieldInputProps> = ({ | ||
field, | ||
isLoading, | ||
onChange, | ||
value, | ||
error | ||
}) => { | ||
const toggleNotification = useNotification(); | ||
const { formatMessage } = useIntl(); | ||
const defaultInputProps = useMemo(() => ({ | ||
id: field.name, | ||
name: field.name, | ||
label: field.label, | ||
disabled: isLoading, | ||
error: error && formatMessage(error), | ||
}), [field, isLoading, error]); | ||
const handleBoolean = useMemo(() => handlerFactory({ field, onChange, prop: "checked" }), [onChange, field]); | ||
const handleString = useMemo(() => handlerFactory({ field, onChange, prop: "value" }), [onChange, field]); | ||
|
||
switch (field.type) { | ||
case 'boolean': | ||
if (!isNil(value)) | ||
assertBoolean(value); | ||
return ( | ||
<ToggleInput | ||
{...defaultInputProps} | ||
checked={!!value} | ||
onChange={handleBoolean} | ||
onLabel="true" | ||
offLabel="false" | ||
/> | ||
); | ||
case 'string': | ||
if (!isNil(value)) | ||
assertString(value); | ||
return ( | ||
<TextInput | ||
{...defaultInputProps} | ||
onChange={handleString} | ||
value={value || DEFAULT_STRING_VALUE} | ||
/> | ||
); | ||
case 'select': | ||
return ( | ||
<Select | ||
{...defaultInputProps} | ||
onChange={(v: string) => onChange(field.name, v)} | ||
value={isNil(value) ? field.multi ? [] : null : value} | ||
multi={field.multi} | ||
withTags={field.multi} | ||
> | ||
{field.options.map((option, index) => ( | ||
<Option key={`${field.name}-option-${index}`} value={option}> | ||
{option} | ||
</Option> | ||
))} | ||
</Select> | ||
); | ||
default: | ||
toggleNotification({ | ||
type: 'warning', | ||
message: getTrad('notification.error.customField.type'), | ||
}); | ||
throw new Error(`Type of custom field is unsupported`); | ||
} | ||
} | ||
|
||
export default AdditionalFieldInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { MessageDescriptor } from "react-intl"; | ||
import { NavigationItemCustomField } from "../../../../types"; | ||
|
||
export type AdditionalFieldInputProps = { | ||
field: NavigationItemCustomField; | ||
isLoading: boolean; | ||
onChange: (name: string, value: string) => void; | ||
value: string | boolean | string[] | null; | ||
error: MessageDescriptor | null; | ||
} | ||
export type TargetProp = "value" | "checked"; | ||
export type Input = { | ||
prop: TargetProp; | ||
} & Pick<AdditionalFieldInputProps, "onChange" | "field">; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React, { useState } from 'react'; | ||
import { Effect } from '../../../../types'; | ||
// @ts-ignore | ||
import { TextInput } from '@strapi/design-system/TextInput'; | ||
import { isArray } from 'lodash'; | ||
|
||
interface IProps { | ||
onChange: Effect<string[]>; | ||
initialValue?: string[]; | ||
id?: string; | ||
name?: string; | ||
label?: string; | ||
disabled?: boolean; | ||
error?: string | string[]; | ||
} | ||
|
||
const TextArrayInput: React.FC<IProps> = ({ onChange, initialValue, ...props }) => { | ||
const [value, setValue] = useState(isArray(initialValue) | ||
? initialValue.reduce((acc, cur) => `${acc}${cur}; `, "") | ||
: ""); | ||
const handleOnChange = ({target: { value }}: React.BaseSyntheticEvent) => { | ||
const newValue: string = value; | ||
const valuesArray = newValue | ||
.split(';') | ||
.map(v => v.trim()) | ||
.filter(v => !!v.length); | ||
setValue(value); | ||
onChange(valuesArray); | ||
} | ||
return ( | ||
<TextInput | ||
{...props} | ||
onChange={handleOnChange} | ||
value={value} | ||
/> | ||
) | ||
} | ||
|
||
export default TextArrayInput; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//@ts-ignore | ||
import { useQuery } from 'react-query'; | ||
import { pick } from 'lodash'; | ||
import { fetchAllContentTypes } from '../utils'; | ||
|
||
const useAllContentTypes = () => pick( | ||
useQuery('contentTypes', () => fetchAllContentTypes()), | ||
["data", "isLoading", "error"] | ||
); | ||
|
||
export default useAllContentTypes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.