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

refactor: remove attached files feature from core package #841

Merged
merged 3 commits into from
Dec 17, 2024
Merged
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/88363.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "Attached files: remove attached files feature from core package",
"type": "feat",
"packages": "core"
}
12 changes: 8 additions & 4 deletions docs/doc/en/Outil/Gestion_des_headers.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,30 @@ export interface HeaderActions {
export interface HeaderOptions {
model?: string;
modelId?: number;
options?: any;
disablePrint?: boolean;
disableMailMessages?: boolean;
disableJsonFields?: boolean;
attachedFileScreenTitle?: string;
barcodeFieldname?: string;
headerTitle?: string;
actions?: ActionType[];
}
```

By default, the core package provides two actions for the header: follow-up messages on each object and attached files. These can be configured via the following props:
By default, the core package provides a few actions for the header: follow-up messages on each object, barcode display, custom fields or even report printing. These can be configured via the following props:

- _model_: full name of the ERP model.
- _modelId_: object identifier.
- _options_: object containing options for the generic actions.
- _disablePrint_: condition for displaying or not report printing on the object.
- _disableMailMessages_: condition for displaying or not displaying follow-up messages on the object.
- _disableJsonFields_: condition for displaying studio fields.
- _attachedFileScreenTitle_: screen name for attached files.
- _barcodeFieldname_: name of attribute containing barcode file on ERP (default `barCode`).
- _headerTitle_: screen name for dynamic titles.

Attached files are displayed only if the current object has them, with an indicator of their number. Follow-up messages are only displayed when `model` and `modelId` are set and not disabled by the `disableMailMessages` attribute.
:::caution
Since version 8.3, the attached files feature is managed as a generic action from the DMS package. It will be added to every screen with a registered model and modelId.
:::

Additional actions can then be added using the `actions` attribute. Each action then has the following structure:

Expand Down
12 changes: 8 additions & 4 deletions docs/doc/fr/Outil/Gestion_des_headers.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,30 @@ export interface HeaderActions {
export interface HeaderOptions {
model?: string;
modelId?: number;
options?: any;
disablePrint?: boolean;
disableMailMessages?: boolean;
disableJsonFields?: boolean;
attachedFileScreenTitle?: string;
barcodeFieldname?: string;
headerTitle?: string;
actions?: ActionType[];
}
```

Le package core fournit par défaut deux actions pour le header qui sont les messages de suivi sur chaque objet ainsi que les fichiers joints. Elles sont paramétrables via les props suivantes :
Le package core fournit par défaut plusieurs actions pour le header: les messages de suivi sur chaque objet, l'affichage du code-barre, les champs studio or encore l'impression de rapport. Elles sont paramétrables via les props suivantes :

- _model_ : nom complet du modèle sur l’ERP.
- _modelId_ : identifiant de l’objet.
- _options_: objet contenant des options pour les actions génériques.
- _disablePrint_: ccondition pour l'affichage ou non de l'impression de rapport.
- _disableMailMessages_ : condition pour l'affichage ou non des messages de suivi sur l'objet.
- _disableJsonFields_ : condition pour l’affichage ou non des champs studio.
- _attachedFileScreenTitle_ : nom de l'écran pour les fichiers joints.
- _barcodeFieldname_ : nom de l’attribut contenant le fichier code-barre sur l’ERP (par défaut `barCode`).
- _headerTitle_ : nom de l'écran pour permettre les titres dynamiques.

Les fichiers joints s’affichent uniquement si l’objet actuel en possède avec un indicateur sur leur nombre. Les messages de suivi eux n’affichent lorsque `model` et `modelId` sont renseignés et qu’il ne sont pas désactivés par l’attribut `disableMailMessages`.
:::caution
Depuis la version 8.3, la fonctionnalité des fichiers joints est gérée comme une action générique du module DMS. Elle sera ajoutée à tous les écrans avec un model et un modelId enregistrés.
:::

Il est ensuite possible d’ajouter des actions supplémentaires avec l’attribut `actions`. Chaque action possède alors la structure suivante :

Expand Down
13 changes: 6 additions & 7 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ It contains:
- Auth module with login and user screens
- Translations management system
- Various helper tools : clipboard, file viewer, external app management
- Management of MailMessages and attaches files on objects
- Management of MailMessages
- AOS linked components or using external libraries : Camera, Scanner, PlanningView, Stopwatch, ...
- Menu management
- Storage management
Expand Down Expand Up @@ -306,13 +306,13 @@ const Colors = useThemeColor();
)}
```

### Add MailMessages and attached files
### Add MailMessages

- Management of MailMessages and attaches files on objects
- Management of MailMessages on objects

This package provides a component to add MailMessages and file attachments functionality to the header. This component also allows to display its children if there are any as a dropdown menu.
This package provides a component to add MailMessages functionality to the header. This component also allows to display its children if there are any as a dropdown menu.

For the first two functionalities of this component, it is necessary to provide in props the name of the object model ("com.axelor.apps.stock.db.StockCorrection" for the stock corrections for example), the id of the current object, and the navigation attribute to go on the dedicated screens:
For the first functionality of this component, it is necessary to provide in props the name of the object model ("com.axelor.apps.stock.db.StockCorrection" for the stock corrections for example), the id of the current object, and the navigation attribute to go on the dedicated screens:

```typescript
import {HeaderOptionsMenu} from '@axelor/aos-mobile-core';
Expand All @@ -326,8 +326,7 @@ React.useLayoutEffect(() => {
<HeaderOptionsMenu
model={...}
modelId={...}
navigation={navigation}
disableMailMessages={...}>
navigation={navigation}>
<DropdownMenuItem
icon="..."
placeholder={...}
Expand Down
65 changes: 0 additions & 65 deletions packages/core/src/api/attached-files-api.ts

This file was deleted.

8 changes: 2 additions & 6 deletions packages/core/src/api/metafile-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,9 @@ const createCriteria = (listFiles): Criteria[] => {
return [];
};

export async function fetchFileDetails({listFiles, isMetaFile}) {
const model = isMetaFile
? 'com.axelor.meta.db.MetaFile'
: 'com.axelor.dms.db.DMSFile';

export async function fetchFileDetails({listFiles}) {
return createStandardSearch({
model: model,
model: 'com.axelor.meta.db.MetaFile',
criteria: createCriteria(listFiles),
fieldKey: 'core_metaFile',
numberElementsByPage: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ const HeaderOptionsMenu = ({
disableMailMessages,
disableJsonFields,
disablePrint,
attachedFileScreenTitle,
barcodeFieldname,
}) => {
const {
mailMessagesAction,
attachedFilesAction,
barcodeAction,
printAction,
jsonFieldsAction,
Expand All @@ -52,7 +50,6 @@ const HeaderOptionsMenu = ({
disablePrint,
barcodeFieldname,
disableJsonFields,
attachedFileScreenTitle,
});

const collapseMenuItems = useMemo(
Expand Down Expand Up @@ -88,7 +85,6 @@ const HeaderOptionsMenu = ({
const allActions = useMemo(
() =>
[
attachedFilesAction,
mailMessagesAction,
printAction,
barcodeAction,
Expand All @@ -100,7 +96,6 @@ const HeaderOptionsMenu = ({
.sort((a, b) => a.order - b.order),
[
actions,
attachedFilesAction,
barcodeAction,
jsonFieldsAction,
mailMessagesAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const MailMessageCommentCard = ({
);

const handleCommentAttachedFilesPress = useCallback(() => {
navigation.navigate('AttachedFilesScreen', {
navigation.navigate('MailMessageAttachedFilesScreen', {
files: files,
});
}, [navigation, files]);
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/components/templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export {default as AttachedFilesView} from './AttachedFilesView/AttachedFilesView';
export {default as GlobalToolBox} from './GlobalToolBox/GlobalToolBox';
export {default as MailMessageView} from './MailMessageView/MailMessageView';
export {default as PeriodInput} from './PeriodInput/PeriodInput';
Expand Down
42 changes: 0 additions & 42 deletions packages/core/src/features/attachedFilesSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,8 @@

import {createAsyncThunk, createSlice} from '@reduxjs/toolkit';
import {handlerApiCall} from '../apiProviders/utils';
import {countAttachments, fetchAttachedFiles} from '../api/attached-files-api';
import {fetchFileDetails} from '../api/metafile-api';

export const getAttachedFiles = createAsyncThunk(
'attachedFiles/getAttachedFiles',
async function (data, {getState}) {
return handlerApiCall({
fetchFunction: fetchAttachedFiles,
data: data,
action: 'Base_SliceAction_FetchAttachedFiles',
getState: getState,
responseOptions: {isArrayResponse: true},
});
},
);

export const getAttachedFilesDetails = createAsyncThunk(
'attachedFiles/getAttachedFilesDetails',
async function (data, {getState}) {
Expand All @@ -47,50 +33,22 @@ export const getAttachedFilesDetails = createAsyncThunk(
},
);

export const countAttachmentFiles = createAsyncThunk(
'attachedFiles/countAttachmentFiles',
async function (data, {getState}) {
return handlerApiCall({
fetchFunction: countAttachments,
data: data,
action: 'Base_SliceAction_CountAttachedFiles',
getState: getState,
responseOptions: {isArrayResponse: true, returnTotal: true},
});
},
);

const initialState = {
loading: false,
attachedFilesList: [],
attachments: 0,
};

const attachedFilesSlice = createSlice({
name: 'attachedFiles',
initialState,
extraReducers: builder => {
builder.addCase(getAttachedFiles.pending, state => {
state.loading = true;
});
builder.addCase(getAttachedFiles.fulfilled, (state, action) => {
state.loading = false;
state.attachedFilesList = action.payload;
});
builder.addCase(getAttachedFilesDetails.pending, state => {
state.loading = true;
});
builder.addCase(getAttachedFilesDetails.fulfilled, (state, action) => {
state.loading = false;
state.attachedFilesList = action.payload;
});
builder.addCase(countAttachmentFiles.pending, state => {
state.loading = true;
});
builder.addCase(countAttachmentFiles.fulfilled, (state, action) => {
state.loading = false;
state.attachments = action.payload;
});
},
});

Expand Down
Loading
Loading