Skip to content

Commit

Permalink
Merge pull request #181 from autentia/bugfix/update-project-filters
Browse files Browse the repository at this point in the history
Bugfix/update project filters
  • Loading branch information
Manumartin95 authored Oct 5, 2023
2 parents ac4c353 + e595363 commit 52783a3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ export const ActivityFormCombos = forwardRef<HTMLInputElement, Props>(
onChange={(item) => {
if (item?.name !== project?.name) onProjectChange()
}}
organization={organization}
projectOrganizationFilters={{
open: true,
organizationIds: organization ? [organization.id] : undefined
}}
/>
<ProjectRolesCombo
ref={projectRoleRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,38 @@ import { Control } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
import { useGetUseCase } from '../../../../../../../../../shared/arch/hooks/use-get-use-case'
import { ComboField } from '../../../../../../../../../shared/components/form-fields/combo-field'
import { Organization } from '../../../../../../organization/domain/organization'
import { Project } from '../../../../../../../../shared/project/domain/project'
import { GetProjectsQry } from '../../../../../../../../shared/project/application/binnacle/get-projects-qry'
import { ProjectOrganizationFilters } from '../../../../../../../../shared/project/domain/project-organization-filters'

interface ComboProps {
name?: string
isDisabled: boolean
organization?: Organization
control: Control<any>
onChange?: (item: Project) => void
projectOrganizationFilters: ProjectOrganizationFilters
}

export const ProjectsCombo = forwardRef<HTMLInputElement, ComboProps>((props, ref) => {
const { name = 'project', organization, control, isDisabled, onChange } = props
const { name = 'project', control, isDisabled, projectOrganizationFilters, onChange } = props
const { t } = useTranslation()

const [items, setItems] = useState<Project[]>([])
const { isLoading, executeUseCase } = useGetUseCase(GetProjectsQry)

useEffect(() => {
if (!organization) {
if (
!projectOrganizationFilters.organizationIds ||
projectOrganizationFilters.organizationIds.length === 0
) {
setItems([])
return
}

executeUseCase({ organizationIds: [organization.id], open: true }).then((projects) => {
executeUseCase(projectOrganizationFilters).then((projects) => {
setItems(projects)
})
}, [executeUseCase, organization])
}, [executeUseCase, projectOrganizationFilters])

return (
<ComboField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Project } from '../../../../../../../shared/project/domain/project'
import { Organization } from '../../../../../organization/domain/organization'

export interface AvailabilityTableFiltersSchema {
organization: Organization
project: Project
user: UserInfo
organization?: Organization
project?: Project
user?: UserInfo
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ export const AvailabilityTableFilters: FC<Props> = ({ onChange }) => {
/>
<ProjectsCombo
control={control}
organization={organization}
name={'project'}
onChange={(project: Project) => {
handleChange({ projectIds: project ? [project?.id] : undefined })
}}
isDisabled={projectDisabled}
projectOrganizationFilters={{
organizationIds: organization ? [organization.id] : undefined
}}
/>
<UserFilter
onChange={(userInfo: UserInfo) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { OrganizationFilters } from '../domain/organization-filters'

@singleton()
export class HttpOrganizationRepository implements OrganizationRepository {
protected static organizationPath = `/api/organizations`
protected static organizationPath = `/api/organization`

constructor(private httpClient: HttpClient) {}

Expand Down

0 comments on commit 52783a3

Please sign in to comment.