Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve management of root element creation #847

Open
wants to merge 1 commit into
base: wip
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelogs/unreleased/88573.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "SearchTreeView: add onParentChange props to get parent update",
"type": "feat",
"packages": "core"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
*/

import React, {useCallback, useMemo} 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 {
Expand All @@ -28,6 +29,7 @@ interface ParentDirectorySearchBarProps {
onChange?: (any: any) => void;
readonly?: boolean;
required?: boolean;
displayRootInfo?: boolean;
}

const ParentDirectorySearchBar = ({
Expand All @@ -37,6 +39,7 @@ const ParentDirectorySearchBar = ({
onChange = () => {},
readonly = false,
required = false,
displayRootInfo = false,
}: ParentDirectorySearchBarProps) => {
const I18n = useTranslator();
const dispatch = useDispatch();
Expand Down Expand Up @@ -69,26 +72,42 @@ const ParentDirectorySearchBar = ({
);

return (
<AutoCompleteSearch
style={style}
title={I18n.t(title)}
objectList={extendedDirectoryList}
value={defaultValue}
required={required}
readonly={readonly}
onChangeValue={onChange}
fetchData={searchParentDirectoryAPI}
displayValue={item => item.fileName}
placeholder={I18n.t(title)}
showDetailsPopup={true}
loadingList={loadingDirectory}
moreLoading={moreLoadingDirectory}
isListEnd={isListEndDirectory}
navigate={false}
oneFilter={false}
translator={I18n.t}
/>
<>
<AutoCompleteSearch
style={style}
title={I18n.t(title)}
objectList={extendedDirectoryList}
value={defaultValue}
required={required}
readonly={readonly}
onChangeValue={onChange}
fetchData={searchParentDirectoryAPI}
displayValue={item => item.fileName}
placeholder={I18n.t(title)}
showDetailsPopup={true}
loadingList={loadingDirectory}
moreLoading={moreLoadingDirectory}
isListEnd={isListEndDirectory}
navigate={false}
oneFilter={false}
translator={I18n.t}
/>
{displayRootInfo && (
<Label
style={styles.label}
type="info"
message={I18n.t('Dms_SearchBarRootInfo')}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change message : "If the parent folder stays empty then the file will be saved on your root folder." (EN) / "Si le dossier parent reste vide alors le document sera enregistré à votre dossier racine" (FR)

Please display the message alors when the parent folder is empty

Also please move the label above the searchbar

/>
)}
</>
);
};

const styles = StyleSheet.create({
label: {
width: '90%',
alignSelf: 'center',
},
});

export default ParentDirectorySearchBar;
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React, {useMemo, useState} from 'react';
import React, {useEffect, useMemo, useState} from 'react';
import {
headerActionsProvider,
SearchTreeView,
useNavigation,
useDispatch,
Expand Down Expand Up @@ -48,6 +49,7 @@ const DocumentList = ({defaultParent}: DocumentListProps) => {

const [author, setAuthor] = useState(null);
const [selectedExtensions, setSelectedExtensions] = useState([]);
const [parentList, setParentList] = useState([]);

const {
loadingDocument,
Expand All @@ -74,6 +76,25 @@ const DocumentList = ({defaultParent}: DocumentListProps) => {
[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 (
<Screen removeSpaceOnTop={true}>
<SearchTreeView
Expand Down Expand Up @@ -152,6 +173,7 @@ const DocumentList = ({defaultParent}: DocumentListProps) => {
}
displayBreadcrumb
defaultParent={defaultParent}
onParentChange={setParentList}
/>
</Screen>
);
Expand Down
24 changes: 0 additions & 24 deletions packages/apps/dms/src/hooks/use-dms-header-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions packages/apps/dms/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"Dms_AttachedFiles": "Attached files",
"Dms_NoAttachedFiles": "No attached files",
"Dms_DoYouWantToAddFile": "Do you want to add a file?",
"Dms_SearchBarRootInfo": "To add a document to your root folder you must select 'Root' in the search bar",
"Dms_SliceAction_SearchDocument": "search document",
"Dms_SliceAction_SearchDirectory": "search directory",
"Dms_SliceAction_SearchFavoriteDocument": "search favorite document",
Expand Down
1 change: 1 addition & 0 deletions packages/apps/dms/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"Dms_AttachedFiles": "Fichiers joints",
"Dms_NoAttachedFiles": "Pas de fichiers joints",
"Dms_DoYouWantToAddFile": "Voulez-vous ajouter un fichier ?",
"Dms_SearchBarRootInfo": "Pour ajouter un document à votre dossier racine il faut sélectionner 'Racine' dans la barre de recherche",
"Dms_SliceAction_SearchDocument": "recherche sur les documents",
"Dms_SliceAction_SearchDirectory": "recherche sur les dossiers",
"Dms_SliceAction_SearchFavoriteDocument": "recherche sur les documents favoris",
Expand Down
1 change: 1 addition & 0 deletions packages/apps/dms/src/models/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const dms_formsRegister: FormConfigs = {
type: 'object',
widget: 'custom',
customComponent: ParentDirectorySearchBar,
options: {displayRootInfo: true},
hideIf: ({objectState}) => objectState.isAttachedFileCreation,
requiredIf: ({objectState}) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the parent folder is not required anymore

!objectState.parent?.fileName && !objectState.isAttachedFileCreation,
Expand Down
6 changes: 4 additions & 2 deletions packages/apps/dms/src/screens/DocumentFormScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ const DocumentFormScreen = ({navigation, route}) => {
const creationDefaultValue = useMemo(
() => ({
isAttachedFileCreation: model && modelId,
parent: parent,
parent: parent ?? {
fileName: I18n.t('Dms_Root'),
},
}),
[model, modelId, parent],
[I18n, model, modelId, parent],
);

const defaultValue = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ interface SearchTreeViewProps {
verticalActions?: boolean;
displayBreadcrumb?: boolean;
defaultParent?: any;
onParentChange?: (parent: any) => void;
}

const SearchTreeView = ({
Expand Down Expand Up @@ -109,6 +110,7 @@ const SearchTreeView = ({
verticalActions,
displayBreadcrumb = false,
defaultParent,
onParentChange,
}: SearchTreeViewProps) => {
const I18n = useTranslator();
const dispatch = useDispatch();
Expand All @@ -125,6 +127,10 @@ const SearchTreeView = ({
}
}, [defaultParent, isFocused]);

useEffect(() => {
onParentChange(parent);
}, [onParentChange, parent]);

const handleChangeParent = value => {
setParent(current => {
const _parent = [...current];
Expand Down
Loading