Skip to content

Feature extension #1334

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

Merged
merged 10 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added Movefolder in redux.
  • Loading branch information
Imiss-U1025 committed Nov 22, 2024
commit 69c741568e53d25824ed47abf6e726aacf35103f
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const ReduxActionTypes = {
FETCH_RAW_CURRENT_USER_SUCCESS: "FETCH_RAW_CURRENT_USER_SUCCESS",
FETCH_API_KEYS: "FETCH_API_KEYS",
FETCH_API_KEYS_SUCCESS: "FETCH_API_KEYS_SUCCESS",

MOVE_TO_FOLDER2_SUCCESS: "MOVE_TO_FOLDER2_SUCCESS",

/* plugin RELATED */
FETCH_DATA_SOURCE_TYPES: "FETCH_DATA_SOURCE_TYPES",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const folderReducer = createReducer(initialState, {
state: FolderReduxState,
action: ReduxAction<MoveToFolderPayload>
): FolderReduxState => {
const elements = { ...state.folderElements };
let elements = { ...state.folderElements };
elements[action.payload.sourceFolderId ?? ""] = elements[
action.payload.sourceFolderId ?? ""
]?.filter(
Expand All @@ -120,6 +120,44 @@ export const folderReducer = createReducer(initialState, {
folderElements: elements,
};
},
[ReduxActionTypes.MOVE_TO_FOLDER2_SUCCESS]: (
state: FolderReduxState,
action: ReduxAction<MoveToFolderPayload>
): FolderReduxState => {
let elements = { ...state.folderElements };
let tempIndex: number | undefined;
let tempNode: any;
let temp = elements[""].map((item, index) => {
if (item.folderId === action.payload.sourceFolderId && item.folder) {

const tempSubApplications = item.subApplications?.filter(e =>
(e.folder && e.folderId !== action.payload.sourceId) ||
(!e.folder && e.applicationId !== action.payload.sourceId)
);
tempNode = item.subApplications?.filter(e =>
(e.folder && e.folderId === action.payload.sourceId) ||
(!e.folder && e.applicationId === action.payload.sourceId)
);
return { ...item, subApplications: tempSubApplications };
}
if (item.folderId === action.payload.folderId && item.folder) {
tempIndex = index;
return item;
}
return item;
});
if (tempIndex !== undefined) {
const targetItem = temp[tempIndex];
if (targetItem.folder && Array.isArray(targetItem.subApplications)) {
targetItem.subApplications.push(tempNode[0]);
}
}
elements[""] = temp;
return {
...state,
folderElements: elements,
};
},
[ReduxActionTypes.DELETE_FOLDER_SUCCESS]: (
state: FolderReduxState,
action: ReduxAction<DeleteFolderPayload>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface MoveToFolderPayload {
sourceFolderId: string;
sourceId: string;
folderId: string;
moveFlag?: boolean;
}

export const moveToFolder = (
Expand Down
6 changes: 4 additions & 2 deletions client/packages/lowcoder/src/redux/sagas/folderSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,16 @@ export function* deleteFolderSaga(action: ReduxActionWithCallbacks<DeleteFolderP

export function* moveToFolderSaga(action: ReduxActionWithCallbacks<MoveToFolderPayload, any, any>) {
try {
const { moveFlag } = action.payload;
delete action.payload.moveFlag;
const response: AxiosResponse<GenericApiResponse<void>> = yield FolderApi.moveToFolder(
action.payload
);
const isValidResponse: boolean = validateResponse(response);

const type = moveFlag ? ReduxActionTypes.MOVE_TO_FOLDER2_SUCCESS : ReduxActionTypes.MOVE_TO_FOLDER_SUCCESS;
if (isValidResponse) {
yield put({
type: ReduxActionTypes.MOVE_TO_FOLDER_SUCCESS,
type,
payload: action.payload,
});
action.onSuccessCallback && action.onSuccessCallback(response);
Expand Down