Skip to content

Commit

Permalink
refactor: manage company in data fetching in project
Browse files Browse the repository at this point in the history
  • Loading branch information
gca-axelor committed Dec 19, 2024
1 parent 55ca23f commit 2f55081
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/apps/project/src/api/project-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export async function searchProject({
differentiateBusinessProjects = true,
statusList,
userId,
companyId,
}) {
return createStandardSearch({
model: 'com.axelor.apps.project.db.Project',
Expand All @@ -110,6 +111,7 @@ export async function searchProject({
sortKey: 'project_project',
page,
provider: 'model',
companyId,
});
}

Expand All @@ -132,14 +134,15 @@ export async function fetchProjectById({projectId}) {
});
}

export async function searchSubProject({page = 0, projectId}) {
export async function searchSubProject({page = 0, projectId, companyId}) {
return createStandardSearch({
model: 'com.axelor.apps.project.db.Project',
criteria: createSubProjectCriteria({projectId}),
fieldKey: 'project_project',
sortKey: 'project_project',
page,
provider: 'model',
companyId,
});
}

Expand Down
4 changes: 3 additions & 1 deletion packages/apps/project/src/api/project-task-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,10 @@ export async function getTag({activeCompany}) {
sortKey: 'project_Tag',
page: 0,
numberElementsByPage: null,
companyId: activeCompany?.id,
isCompanyM2M: true,
domain:
'(self.concernedModelSet IS EMPTY OR :metaModel member of self.concernedModelSet) AND (self.companySet IS EMPTY OR :activeCompany member of self.companySet)',
'(self.concernedModelSet IS EMPTY OR :metaModel member of self.concernedModelSet)',
domainContext: {
metaModel: {id: res?.data?.data?.[0]?.id},
activeCompany: {id: activeCompany?.id},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ const SubProjectView = () => {
isListEndSubProject,
subProjectList,
} = useSelector((state: any) => state.project_project);
const {user} = useSelector(state => state.user);

const sliceFunctionData = useMemo(
() => ({
projectId: project.id,
companyId: user.activeCompany?.id,
}),
[project.id],
[project.id, user.activeCompany?.id],
);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const ProjectListView = ({
const navigation = useNavigation();
const {getCustomSelectionItems} = useTypeHelpers();

const {user} = useSelector(state => state.user);
const {userId} = useSelector((state: any) => state.auth);
const {loading, moreLoading, isListEnd, projectList, projectStatusList} =
useSelector((state: any) => state.project_project);
Expand All @@ -62,8 +63,15 @@ const ProjectListView = ({
isBusinessProject: businessProject,
statusList: selectedStatus,
userId: isAssignedToMe ? userId : null,
companyId: user.activeCompany?.id,
}),
[businessProject, isAssignedToMe, selectedStatus, userId],
[
businessProject,
isAssignedToMe,
selectedStatus,
user.activeCompany?.id,
userId,
],
);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const ProjectSearchBarAux = ({
const I18n = useTranslator();
const dispatch = useDispatch();

const {user} = useSelector(state => state.user);
const {projectList, loading, moreLoading, isListEnd} = useSelector(
(state: any) => state.project_project,
);
Expand All @@ -61,10 +62,11 @@ const ProjectSearchBarAux = ({
page,
searchValue,
differentiateBusinessProjects,
companyId: user.activeCompany?.id,
}),
);
},
[differentiateBusinessProjects, dispatch],
[differentiateBusinessProjects, dispatch, user.activeCompany?.id],
);

return (
Expand Down

0 comments on commit 2f55081

Please sign in to comment.