Skip to content

Commit

Permalink
wip: strict
Browse files Browse the repository at this point in the history
  • Loading branch information
rboixaderg committed Mar 30, 2024
1 parent 4e4c5eb commit e641882
Show file tree
Hide file tree
Showing 24 changed files with 244 additions and 180 deletions.
2 changes: 1 addition & 1 deletion src/guillo-gmi/components/TdLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface Props {
style?: IndexSignature
}
export function TdLink({ model, children, style = {} }: Props) {
const link = useRef<HTMLAnchorElement>()
const link = useRef<HTMLAnchorElement>(null)

function onClick() {
if (link && link.current) {
Expand Down
4 changes: 2 additions & 2 deletions src/guillo-gmi/components/behaviors/iworkflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export function IWorkflow() {
}

const getStateTitle = () => {
if (vocabulary.data?.items?.length > 0) {
const vocabularyValue = vocabulary.data.items.find(
if ((vocabulary.data?.items ?? []).length > 0) {
const vocabularyValue = vocabulary?.data?.items.find(
(item) => item.token === currentState
)
if (vocabularyValue) {
Expand Down
2 changes: 1 addition & 1 deletion src/guillo-gmi/components/input/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function Dropdown({
optionDisabledWhen,
options,
}: Props) {
const ref = useRef(null)
const ref = useRef<HTMLDivElement>(null)
const [isActive, setIsActive] = useState(false)
const position = isRight ? 'is-right' : ''
const status = isActive
Expand Down
62 changes: 26 additions & 36 deletions src/guillo-gmi/components/input/search_input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,10 @@ import { useConfig } from '../../hooks/useConfig'
import { useIntl } from 'react-intl'
import { genericMessages } from '../../locales/generic_messages'
import useClickAway from '../../hooks/useClickAway'
import { get } from '../../lib/utils'
import { debounce, get } from '../../lib/utils'
import { SearchItem } from '../../types/guillotina'
import { Traversal } from '../../contexts'

function debounce(func, wait) {
let timeout
return function () {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const context = this
// eslint-disable-next-line prefer-rest-params
const args = arguments
const later = function () {
timeout = null
func.apply(context, args)
}
clearTimeout(timeout)
timeout = setTimeout(later, wait)
}
}
import { IndexSignature } from '../../types/global'

interface State {
page: number
Expand All @@ -37,7 +22,7 @@ interface State {
}
const initialState: State = {
page: 0,
items: undefined,
items: [],
loading: false,
items_total: 0,
}
Expand All @@ -46,7 +31,7 @@ interface Props {
onChange?: (value: string) => void
error?: string
errorZoneClassName?: string
traversal?: Traversal
traversal: Traversal
path?: string
qs?: string[][]
queryCondition?: string
Expand All @@ -64,27 +49,29 @@ export const SearchInput = ({
onChange,
error,
errorZoneClassName,
traversal = null,
path = null,
traversal,
path = undefined,
qs = [],
queryCondition = 'id__in',
value,
btnClass = '',
dataTestWrapper = 'wrapperSearchInputTest',
dataTestSearchInput = 'searchInputTest',
dataTestItem = 'searchInputItemTest',
renderTextItemOption = null,
typeNameQuery = null,
renderTextItemOption = undefined,
typeNameQuery = undefined,
labelProperty = 'id',
}: Props) => {
const intl = useIntl()
const [options, setOptions] = useSetState<State>(initialState)
const [isOpen, setIsOpen] = useState(false)
const [searchTerm, setSearchTerm] = useState('')
const inputRef = useRef(null)
const wrapperRef = useRef(null)
const wrapperRef = useRef<HTMLInputElement>(null)
const { PageSize, SearchEngine } = useConfig()
const [valueLabel, setValueLabel] = useState<Partial<SearchItem>>(undefined)
const [valueLabel, setValueLabel] = useState<Partial<SearchItem> | undefined>(
undefined
)
const [uid] = useState(generateUID('search_input'))

useClickAway(wrapperRef, () => {
Expand Down Expand Up @@ -115,13 +102,13 @@ export const SearchInput = ({
const searchTermParsed = [`id`, value]
const { get: getSearch } = traversal.registry
const fnName = getSearch('searchEngineQueryParamsFunction', SearchEngine)
const qsParsed = traversal.client[fnName]({
const qsParsed = traversal.client.getQueryParamsSearchFunction(fnName)({
path: traversal.path,
start: 0,
pageSize: PageSize,
withDepth: false,
})
let typeNameParsed = []
let typeNameParsed: string[][] = []
if (typeNameQuery) {
typeNameParsed = parser(`type_name__in=${typeNameQuery}`)
}
Expand All @@ -138,24 +125,27 @@ export const SearchInput = ({
...typeNameParsed,
])
}
const data = await traversal.client.search(
const data = await traversal.client.search<SearchItem>(
path ? path : traversal.client.getContainerFromPath(traversal.path),
searchTermQs,
false,
false
)
const newValuesLabel = data.items.reduce((result, item) => {
result[item.id] = get(item, labelProperty, item.id)
return result
}, {})
const newValuesLabel = data.items.reduce<IndexSignature<string>>(
(result, item) => {
result[item.id] = get(item, labelProperty, item.id)
return result
},
{}
)
setValueLabel(newValuesLabel)
}
}

const handleSearch = async (page = 0, concat = false, value = '') => {
setOptions({ loading: true })
let searchTermQs = ''
let searchTermParsed = []
let searchTermParsed: string[][] = []
if (value !== '') {
searchTermParsed = parser(`${queryCondition}=${value}`)
}
Expand All @@ -168,7 +158,7 @@ export const SearchInput = ({
withDepth: false,
})
const sortParsed = parser(`_sort_des=${labelProperty}`)
let typeNameParsed = []
let typeNameParsed: string[][] = []
if (typeNameQuery) {
typeNameParsed = parser(`type_name__in=${typeNameQuery}`)
}
Expand All @@ -188,7 +178,7 @@ export const SearchInput = ({
])
}

const data = await traversal.client.search(
const data = await traversal.client.search<SearchItem>(
path ? path : traversal.client.getContainerFromPath(traversal.path),
searchTermQs,
false,
Expand All @@ -205,7 +195,7 @@ export const SearchInput = ({
})
}

const renderTextItemOptionFn = (item) => {
const renderTextItemOptionFn = (item: SearchItem) => {
if (renderTextItemOption) {
return renderTextItemOption(item)
}
Expand Down
68 changes: 28 additions & 40 deletions src/guillo-gmi/components/input/search_input_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,10 @@ import { useConfig } from '../../hooks/useConfig'
import { useIntl } from 'react-intl'
import { genericMessages } from '../../locales/generic_messages'
import useClickAway from '../../hooks/useClickAway'
import { get } from '../../lib/utils'
import { debounce, get } from '../../lib/utils'
import { SearchItem } from '../../types/guillotina'
import { Traversal } from '../../contexts'

function debounce(func, wait) {
let timeout
return function () {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const context = this
// eslint-disable-next-line prefer-rest-params
const args = arguments
const later = function () {
timeout = null
func.apply(context, args)
}
clearTimeout(timeout)
timeout = setTimeout(later, wait)
}
}
import { IndexSignature } from '../../types/global'

interface State {
page: number
Expand All @@ -38,7 +23,7 @@ interface State {
}
const initialState: State = {
page: 0,
items: undefined,
items: [],
loading: false,
items_total: 0,
}
Expand All @@ -47,9 +32,9 @@ interface Props {
onChange: (value: string[]) => void
error?: string
errorZoneClassName?: string
traversal?: Traversal
traversal: Traversal
path?: string
qs?: string[]
qs?: string[][]
queryCondition?: string
value: string[]
btnClass?: string
Expand All @@ -65,26 +50,28 @@ export const SearchInputList = ({
onChange,
error,
errorZoneClassName,
traversal = null,
path = null,
traversal,
path = undefined,
qs = [],
queryCondition = 'id__in',
value,
btnClass = '',
dataTestWrapper = 'wrapperSearchInputTest',
dataTestSearchInput = 'searchInputTest',
dataTestItem = 'searchInputItemTest',
renderTextItemOption = null,
typeNameQuery = null,
renderTextItemOption = undefined,
typeNameQuery = undefined,
labelProperty = 'id',
}: Props) => {
const intl = useIntl()
const [options, setOptions] = useSetState<State>(initialState)
const [valuesLabel, setValuesLabels] = useState(undefined)
const [valuesLabel, setValuesLabels] = useState<IndexSignature | undefined>(
undefined
)
const [isOpen, setIsOpen] = useState(false)
const [searchTerm, setSearchTerm] = useState('')
const inputRef = useRef(null)
const wrapperRef = useRef(null)
const wrapperRef = useRef<HTMLInputElement>(null)
const { PageSize, SearchEngine } = useConfig()
const [isLoadingData, setIsLoadingData] = useState(false)

Expand Down Expand Up @@ -115,7 +102,7 @@ export const SearchInputList = ({
const handleSearch = async (page = 0, concat = false, value = '') => {
setOptions({ loading: true })
let searchTermQs = ''
let searchTermParsed = []
let searchTermParsed: string[][] = []
if (value !== '') {
searchTermParsed = parser(`${queryCondition}=${value}`)
}
Expand All @@ -128,7 +115,7 @@ export const SearchInputList = ({
withDepth: false,
})
const sortParsed = parser(`_sort_des=${labelProperty}`)
let typeNameParsed = []
let typeNameParsed: string[][] = []
if (typeNameQuery) {
typeNameParsed = parser(`type_name__in=${typeNameQuery}`)
}
Expand All @@ -148,13 +135,13 @@ export const SearchInputList = ({
])
}

const data = await traversal.client.search(
const data = await traversal.client.search<SearchItem>(
path ? path : traversal.client.getContainerFromPath(traversal.path),
searchTermQs,
false,
false
)
const newItems =
const newItems: SearchItem[] =
options.items && concat ? [...options.items, ...data.items] : data.items

setOptions({
Expand All @@ -172,13 +159,13 @@ export const SearchInputList = ({
const searchTermParsed = ['__or', `id=${value.join('%26id=')}`]
const { get: getSearch } = traversal.registry
const fnName = getSearch('searchEngineQueryParamsFunction', SearchEngine)
const qsParsed = traversal.client[fnName]({
const qsParsed = traversal.client.getQueryParamsSearchFunction(fnName)({
path: traversal.path,
start: 0,
pageSize: 100,
withDepth: false,
})
let typeNameParsed = []
let typeNameParsed: string[][] = []
if (typeNameQuery) {
typeNameParsed = parser(`type_name__in=${typeNameQuery}`)
}
Expand All @@ -195,18 +182,19 @@ export const SearchInputList = ({
...typeNameParsed,
])
}
const data = await traversal.client.search(
const data = await traversal.client.search<SearchItem>(
path ? path : traversal.client.getContainerFromPath(traversal.path),
searchTermQs,
false,
false,
0,
100
false
)
const newValuesLabel = data.items.reduce<IndexSignature<string>>(
(result, item) => {
result[item.id] = get(item, labelProperty, item.id)
return result
},
{}
)
const newValuesLabel = data.items.reduce((result, item) => {
result[item.id] = get(item, labelProperty, item.id)
return result
}, {})
setValuesLabels(newValuesLabel)
setIsLoadingData(false)
}
Expand Down
2 changes: 1 addition & 1 deletion src/guillo-gmi/components/input/select_vocabulary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const SelectVocabulary = forwardRef<HTMLSelectElement, Props>(
if (
get<GuillotinaVocabularyItem | null>(vocabulary, 'data.items', null)
) {
const vocData = vocabulary.data.items.map((item) => {
const vocData = (vocabulary?.data?.items ?? []).map((item) => {
return {
text: item.title,
value: item.token,
Expand Down
4 changes: 2 additions & 2 deletions src/guillo-gmi/components/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ interface State {
username: string
password: string
loading: boolean
errors: string
errors?: string
}
const initialState = {
username: '',
password: '',
loading: undefined,
loading: false,
errors: undefined,
}

Expand Down
8 changes: 4 additions & 4 deletions src/guillo-gmi/components/panel/permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,12 @@ export function AddPermission({ refresh, reset }: AddPermissionProps) {

const principalsData = await Ctx.client.getPrincipals(Ctx.path)
const groups = principalsData.groups.map((group) => ({
text: group.id,
value: group.id,
text: group['@name'],
value: group['@name'],
}))
const users = principalsData.users.map((user) => ({
text: user.fullname || user.id,
value: user.id,
text: user.fullname || user['@name'],
value: user['@name'],
}))
principals = [...groups, ...users]

Expand Down
Loading

0 comments on commit e641882

Please sign in to comment.