diff --git a/src/guillo-gmi/components/index.js b/src/guillo-gmi/components/index.ts similarity index 100% rename from src/guillo-gmi/components/index.js rename to src/guillo-gmi/components/index.ts diff --git a/src/guillo-gmi/components/input/search_input.tsx b/src/guillo-gmi/components/input/search_input.tsx index 5b77b728..6aa2ad67 100644 --- a/src/guillo-gmi/components/input/search_input.tsx +++ b/src/guillo-gmi/components/input/search_input.tsx @@ -12,6 +12,7 @@ import { genericMessages } from '../../locales/generic_messages' import useClickAway from '../../hooks/useClickAway' import { get } from '../../lib/utils' import { SearchItem } from '../../types/guillotina' +import { Traversal } from '../../contexts' function debounce(func, wait) { let timeout @@ -27,7 +28,13 @@ function debounce(func, wait) { } } -const initialState = { +interface State { + page: number + items: SearchItem[] + loading: boolean + items_total: number +} +const initialState: State = { page: 0, items: undefined, loading: false, @@ -35,14 +42,14 @@ const initialState = { } interface Props { - onChange?: (value: SearchItem) => void + onChange?: (value: string) => void error?: string errorZoneClassName?: string - traversal?: any + traversal?: Traversal path?: string qs?: string[][] queryCondition?: string - value: SearchItem + value?: string btnClass?: string dataTestWrapper?: string dataTestSearchInput?: string @@ -70,13 +77,13 @@ export const SearchInput = ({ labelProperty = 'id', }: Props) => { const intl = useIntl() - const [options, setOptions] = useSetState(initialState) + const [options, setOptions] = useSetState(initialState) const [isOpen, setIsOpen] = useState(false) const [searchTerm, setSearchTerm] = useState('') const inputRef = useRef(null) const wrapperRef = useRef(null) const { PageSize, SearchEngine } = useConfig() - const [valueLabel, setValueLabel] = useState(undefined) + const [valueLabel, setValueLabel] = useState>(undefined) const [uid] = useState(generateUID('search_input')) useClickAway(wrapperRef, () => { @@ -103,7 +110,7 @@ export const SearchInput = ({ const inicializeLabels = async () => { if (labelProperty !== 'id' && value) { - let searchTermQs = [] + let searchTermQs = '' const searchTermParsed = [`id`, value] const { get: getSearch } = traversal.registry const fnName = getSearch('searchEngineQueryParamsFunction', SearchEngine) @@ -146,7 +153,7 @@ export const SearchInput = ({ const handleSearch = async (page = 0, concat = false, value = '') => { setOptions({ loading: true }) - let searchTermQs = [] + let searchTermQs = '' let searchTermParsed = [] if (value !== '') { searchTermParsed = parser(`${queryCondition}=${value}`) diff --git a/src/guillo-gmi/components/input/search_input_list.tsx b/src/guillo-gmi/components/input/search_input_list.tsx index 90df23a3..efe5c5f1 100644 --- a/src/guillo-gmi/components/input/search_input_list.tsx +++ b/src/guillo-gmi/components/input/search_input_list.tsx @@ -29,7 +29,13 @@ function debounce(func, wait) { } } -const initialState = { +interface State { + page: number + items: SearchItem[] + loading: boolean + items_total: number +} +const initialState: State = { page: 0, items: undefined, loading: false, @@ -37,14 +43,14 @@ const initialState = { } interface Props { - onChange: (value: SearchItem[]) => void + onChange: (value: string[]) => void error?: string errorZoneClassName?: string traversal?: any path?: string qs?: string[] queryCondition?: string - value: SearchItem[] + value: string[] btnClass?: string dataTestWrapper?: string dataTestSearchInput?: string @@ -72,7 +78,7 @@ export const SearchInputList = ({ labelProperty = 'id', }: Props) => { const intl = useIntl() - const [options, setOptions] = useSetState(initialState) + const [options, setOptions] = useSetState(initialState) const [valuesLabel, setValuesLabels] = useState(undefined) const [isOpen, setIsOpen] = useState(false) const [searchTerm, setSearchTerm] = useState('') @@ -107,7 +113,7 @@ export const SearchInputList = ({ const handleSearch = async (page = 0, concat = false, value = '') => { setOptions({ loading: true }) - let searchTermQs = [] + let searchTermQs = '' let searchTermParsed = [] if (value !== '') { searchTermParsed = parser(`${queryCondition}=${value}`) @@ -161,7 +167,7 @@ export const SearchInputList = ({ const inicializeLabels = async () => { if (labelProperty !== 'id' && value.length > 0) { setIsLoadingData(true) - let searchTermQs = [] + let searchTermQs = '' const searchTermParsed = ['__or', `id=${value.join('%26id=')}`] const { get: getSearch } = traversal.registry const fnName = getSearch('searchEngineQueryParamsFunction', SearchEngine) diff --git a/src/guillo-gmi/components/panel/properties.tsx b/src/guillo-gmi/components/panel/properties.tsx index a2361f47..e218f0b8 100644 --- a/src/guillo-gmi/components/panel/properties.tsx +++ b/src/guillo-gmi/components/panel/properties.tsx @@ -11,6 +11,10 @@ import { useTraversal } from '../../contexts' import { get } from '../../lib/utils' import { useIntl } from 'react-intl' import { genericMessages } from '../../locales/generic_messages' +import { + GuillotinaSchema, + GuillotinaSchemaProperty, +} from '../../types/guillotina' const _showProperties = ['@id', '@name', '@uid'] const _ignoreFields = [ @@ -29,13 +33,19 @@ const _ignoreFields = [ 'title', ] +interface State { + data: GuillotinaSchema + loading: boolean + error: string +} + export function PanelProperties() { const intl = useIntl() const Ctx = useTraversal() const modifyContent = Ctx.hasPerm('guillotina.ModifyContent') const cfg = useConfig() - const [schema, setSchema] = useSetState({ + const [schema, setSchema] = useSetState({ data: undefined, loading: false, error: undefined, @@ -55,7 +65,10 @@ export function PanelProperties() { const properties = Object.keys(schema?.data?.properties || []) .filter((key) => !ignoreFields.includes(key)) - .map((key) => ({ key, value: schema.data.properties[key] })) + .map((key) => ({ + key, + value: schema.data.properties[key] as GuillotinaSchemaProperty, + })) useEffect(() => { ;(async () => { @@ -139,7 +152,7 @@ export function PanelProperties() { value={Ctx.context[key]} schema={value} modifyContent={modifyContent} - required={get(schema.data, 'required', []).includes( + required={(schema.data?.required ?? []).includes( key )} /> diff --git a/src/guillo-gmi/components/widgets/tags.tsx b/src/guillo-gmi/components/widgets/tags.tsx index 615e9a2b..8cc78c37 100644 --- a/src/guillo-gmi/components/widgets/tags.tsx +++ b/src/guillo-gmi/components/widgets/tags.tsx @@ -14,6 +14,14 @@ const prepareAvailable = (items, already, title) => { return [def].concat(items).filter((item) => !already.includes(item.value)) } +interface Props { + items: string[] + available?: string[] + title: string + noData: string + onChange: (items: string[]) => void + loading?: boolean +} export function TagsWidget({ items, available, @@ -21,11 +29,11 @@ export function TagsWidget({ noData, onChange, loading, -}) { +}: Props) { const selectRef = useRef() const [result, setResult] = useState(items) - available = prepareAvailable(available || [], result, title) + const availableData = prepareAvailable(available || [], result, title) const remove = (value) => { const items = result.filter((item) => item !== value) @@ -61,7 +69,7 @@ export function TagsWidget({ {available.length > 1 && (