diff --git a/changelogs/unreleased/88573.json b/changelogs/unreleased/88573.json
new file mode 100644
index 0000000000..685c733cb5
--- /dev/null
+++ b/changelogs/unreleased/88573.json
@@ -0,0 +1,5 @@
+{
+ "title": "SearchTreeView: add onParentChange props to get parent update",
+ "type": "feat",
+ "packages": "core"
+}
diff --git a/packages/apps/dms/src/components/organisms/ParentDirectorySearchBar/ParentDirectorySearchBar.tsx b/packages/apps/dms/src/components/organisms/ParentDirectorySearchBar/ParentDirectorySearchBar.tsx
index 3bd53da62f..341ed0b752 100644
--- a/packages/apps/dms/src/components/organisms/ParentDirectorySearchBar/ParentDirectorySearchBar.tsx
+++ b/packages/apps/dms/src/components/organisms/ParentDirectorySearchBar/ParentDirectorySearchBar.tsx
@@ -16,9 +16,10 @@
* along with this program. If not, see .
*/
-import React, {useCallback, useMemo} from 'react';
+import React, {useCallback} from 'react';
+import {StyleSheet} from 'react-native';
import {useDispatch, useSelector, useTranslator} from '@axelor/aos-mobile-core';
-import {AutoCompleteSearch} from '@axelor/aos-mobile-ui';
+import {AutoCompleteSearch, Label} from '@axelor/aos-mobile-ui';
import {searchDirectory} from '../../../features/documentSlice';
interface ParentDirectorySearchBarProps {
@@ -28,6 +29,7 @@ interface ParentDirectorySearchBarProps {
onChange?: (any: any) => void;
readonly?: boolean;
required?: boolean;
+ displayRootInfo?: boolean;
}
const ParentDirectorySearchBar = ({
@@ -37,12 +39,11 @@ const ParentDirectorySearchBar = ({
onChange = () => {},
readonly = false,
required = false,
+ displayRootInfo = false,
}: ParentDirectorySearchBarProps) => {
const I18n = useTranslator();
const dispatch = useDispatch();
- const {user} = useSelector(state => state.user);
- const {mobileSettings} = useSelector(state => state.appConfig);
const {
loadingDirectory,
moreLoadingDirectory,
@@ -50,17 +51,6 @@ const ParentDirectorySearchBar = ({
directoryList,
} = useSelector(state => state.dms_document);
- const extendedDirectoryList = useMemo(
- () => [
- {
- ...(user.dmsRoot ?? mobileSettings?.defaultDmsRoot),
- fileName: I18n.t('Dms_Root'),
- },
- ...directoryList,
- ],
- [I18n, directoryList, mobileSettings?.defaultDmsRoot, user.dmsRoot],
- );
-
const searchParentDirectoryAPI = useCallback(
({searchValue, page = 0}) => {
dispatch((searchDirectory as any)({searchValue, page}));
@@ -69,26 +59,42 @@ const ParentDirectorySearchBar = ({
);
return (
- item.fileName}
- placeholder={I18n.t(title)}
- showDetailsPopup={true}
- loadingList={loadingDirectory}
- moreLoading={moreLoadingDirectory}
- isListEnd={isListEndDirectory}
- navigate={false}
- oneFilter={false}
- translator={I18n.t}
- />
+ <>
+ {displayRootInfo && defaultValue == null && (
+
+ )}
+ item.fileName}
+ placeholder={I18n.t(title)}
+ showDetailsPopup={true}
+ loadingList={loadingDirectory}
+ moreLoading={moreLoadingDirectory}
+ isListEnd={isListEndDirectory}
+ navigate={false}
+ oneFilter={false}
+ translator={I18n.t}
+ />
+ >
);
};
+const styles = StyleSheet.create({
+ label: {
+ width: '90%',
+ alignSelf: 'center',
+ },
+});
+
export default ParentDirectorySearchBar;
diff --git a/packages/apps/dms/src/components/templates/DocumentList/DocumentList.tsx b/packages/apps/dms/src/components/templates/DocumentList/DocumentList.tsx
index f8434cbf22..9af9f8c760 100644
--- a/packages/apps/dms/src/components/templates/DocumentList/DocumentList.tsx
+++ b/packages/apps/dms/src/components/templates/DocumentList/DocumentList.tsx
@@ -16,8 +16,9 @@
* along with this program. If not, see .
*/
-import React, {useMemo, useState} from 'react';
+import React, {useEffect, useMemo, useState} from 'react';
import {
+ headerActionsProvider,
SearchTreeView,
useNavigation,
useDispatch,
@@ -52,6 +53,7 @@ const DocumentList = ({
const [author, setAuthor] = useState(null);
const [selectedExtensions, setSelectedExtensions] = useState([]);
+ const [parentList, setParentList] = useState([]);
const {
loadingDocument,
@@ -78,6 +80,25 @@ const DocumentList = ({
[author?.id, selectedExtensions],
);
+ useEffect(() => {
+ headerActionsProvider.registerModel('dms_all_documents', {
+ actions: [
+ {
+ key: 'newDocument',
+ order: 10,
+ iconName: 'plus-lg',
+ title: I18n.t('Dms_NewDocument'),
+ iconColor: Colors.primaryColor.background,
+ onPress: () =>
+ navigation.navigate('DocumentFormScreen', {
+ parent: parentList.at(-1),
+ }),
+ showInHeader: true,
+ },
+ ],
+ });
+ }, [Colors, I18n, navigation, parentList]);
+
return (
);
diff --git a/packages/apps/dms/src/hooks/use-dms-header-actions.ts b/packages/apps/dms/src/hooks/use-dms-header-actions.ts
index f03efb1aea..85c2733212 100644
--- a/packages/apps/dms/src/hooks/use-dms-header-actions.ts
+++ b/packages/apps/dms/src/hooks/use-dms-header-actions.ts
@@ -24,36 +24,12 @@ import {
useSelector,
useTranslator,
} from '@axelor/aos-mobile-core';
-import {useThemeColor} from '@axelor/aos-mobile-ui';
import {getAction} from '../utils';
export const useDMSHeaders = () => {
- useAllDocumentsActions();
useAttachedFilesGenericAction();
};
-const useAllDocumentsActions = () => {
- const Colors = useThemeColor();
- const navigation = useNavigation();
- const I18n = useTranslator();
-
- useEffect(() => {
- headerActionsProvider.registerModel('dms_all_documents', {
- actions: [
- {
- key: 'newDocument',
- order: 10,
- iconName: 'plus-lg',
- title: I18n.t('Dms_NewDocument'),
- iconColor: Colors.primaryColor.background,
- onPress: () => navigation.navigate('DocumentFormScreen'),
- showInHeader: true,
- },
- ],
- });
- }, [Colors, I18n, navigation]);
-};
-
const useAttachedFilesGenericAction = () => {
const I18n = useTranslator();
const navigation = useNavigation();
diff --git a/packages/apps/dms/src/i18n/en.json b/packages/apps/dms/src/i18n/en.json
index 5f344511ef..2825d13aea 100644
--- a/packages/apps/dms/src/i18n/en.json
+++ b/packages/apps/dms/src/i18n/en.json
@@ -13,10 +13,10 @@
"Dms_Name": "Name",
"Dms_Folder": "Folder",
"Dms_File": "File",
- "Dms_Root": "Root",
"Dms_AttachedFiles": "Attached files",
"Dms_NoAttachedFiles": "No attached files",
"Dms_DoYouWantToAddFile": "Do you want to add a file?",
+ "Dms_SearchBarRootInfo": "If the parent folder stays empty then the file will be saved on your root folder",
"Dms_SliceAction_SearchDocument": "search document",
"Dms_SliceAction_SearchDirectory": "search directory",
"Dms_SliceAction_SearchFavoriteDocument": "search favorite document",
diff --git a/packages/apps/dms/src/i18n/fr.json b/packages/apps/dms/src/i18n/fr.json
index dede94f65b..c1c8591706 100644
--- a/packages/apps/dms/src/i18n/fr.json
+++ b/packages/apps/dms/src/i18n/fr.json
@@ -13,10 +13,10 @@
"Dms_Name": "Nom",
"Dms_Folder": "Dossier",
"Dms_File": "Fichier",
- "Dms_Root": "Racine",
"Dms_AttachedFiles": "Fichiers joints",
"Dms_NoAttachedFiles": "Pas de fichiers joints",
"Dms_DoYouWantToAddFile": "Voulez-vous ajouter un fichier ?",
+ "Dms_SearchBarRootInfo": "Si le dossier parent reste vide alors le document sera enregistré à votre dossier racine",
"Dms_SliceAction_SearchDocument": "recherche sur les documents",
"Dms_SliceAction_SearchDirectory": "recherche sur les dossiers",
"Dms_SliceAction_SearchFavoriteDocument": "recherche sur les documents favoris",
diff --git a/packages/apps/dms/src/models/forms.ts b/packages/apps/dms/src/models/forms.ts
index 163e66757c..a84c3dcd3a 100644
--- a/packages/apps/dms/src/models/forms.ts
+++ b/packages/apps/dms/src/models/forms.ts
@@ -36,9 +36,8 @@ export const dms_formsRegister: FormConfigs = {
type: 'object',
widget: 'custom',
customComponent: ParentDirectorySearchBar,
+ options: {displayRootInfo: true},
hideIf: ({objectState}) => objectState.isAttachedFileCreation,
- requiredIf: ({objectState}) =>
- !objectState.parent?.fileName && !objectState.isAttachedFileCreation,
},
fileName: {
titleKey: 'Dms_Name',
diff --git a/packages/apps/dms/src/screens/DocumentFormScreen.tsx b/packages/apps/dms/src/screens/DocumentFormScreen.tsx
index 8fcbd2ef0c..e39eb2d517 100644
--- a/packages/apps/dms/src/screens/DocumentFormScreen.tsx
+++ b/packages/apps/dms/src/screens/DocumentFormScreen.tsx
@@ -18,15 +18,11 @@
import React, {useCallback, useMemo} from 'react';
import {StyleSheet} from 'react-native';
-import {FormView, useSelector, useTranslator} from '@axelor/aos-mobile-core';
+import {FormView, useSelector} from '@axelor/aos-mobile-core';
import {createDocument, updateDocument} from '../features/documentSlice';
const DocumentFormScreen = ({navigation, route}) => {
- const parent = route?.params?.parent;
- const document = route?.params?.document;
- const model = route?.params?.model;
- const modelId = route?.params?.modelId;
- const I18n = useTranslator();
+ const {parent, document, model, modelId} = route?.params ?? {};
const {user} = useSelector(state => state.user);
const {mobileSettings} = useSelector(state => state.appConfig);
@@ -39,31 +35,14 @@ const DocumentFormScreen = ({navigation, route}) => {
[model, modelId, parent],
);
- const defaultValue = useMemo(
- () =>
- document && {
- ...document,
- parent: document.parent ?? {
- fileName: I18n.t('Dms_Root'),
- },
- },
- [I18n, document],
- );
+ const defaultValue = useMemo(() => document, [document]);
const documentAPI = useCallback(
(_document, isCreation, dispatch) => {
const parentId = _document.parent?.id;
if (parentId == null) {
- _document.parent = null;
- }
-
- if (parentId === user.dmsRoot?.id) {
- _document.parent = user.dmsRoot;
- }
-
- if (parentId === mobileSettings?.defaultDmsRoot?.id) {
- _document.parent = mobileSettings?.defaultDmsRoot;
+ _document.parent = user.dmsRoot ?? mobileSettings?.defaultDmsRoot;
}
const sliceFunction = isCreation ? createDocument : updateDocument;
diff --git a/packages/core/src/components/templates/SearchTreeView/SearchTreeView.tsx b/packages/core/src/components/templates/SearchTreeView/SearchTreeView.tsx
index e6319ba106..30b0662bdc 100644
--- a/packages/core/src/components/templates/SearchTreeView/SearchTreeView.tsx
+++ b/packages/core/src/components/templates/SearchTreeView/SearchTreeView.tsx
@@ -71,6 +71,7 @@ interface SearchTreeViewProps {
displayBreadcrumb?: boolean;
defaultParent?: any;
manageParentFilter?: boolean;
+ onParentChange?: (parent: any) => void;
}
const SearchTreeView = ({
@@ -111,6 +112,7 @@ const SearchTreeView = ({
displayBreadcrumb = false,
defaultParent,
manageParentFilter = true,
+ onParentChange,
}: SearchTreeViewProps) => {
const I18n = useTranslator();
const dispatch = useDispatch();
@@ -127,6 +129,10 @@ const SearchTreeView = ({
}
}, [defaultParent, isFocused]);
+ useEffect(() => {
+ onParentChange(parent);
+ }, [onParentChange, parent]);
+
const handleChangeParent = value => {
setParent(current => {
const _parent = [...current];