* Fix: On renaming a widget via entity explorer the canvas gets resized * Fix: Close prop pane on resize start of unselected widget. * Fix: Match all - corejs polyfill * Fix: Proppane not updated properly when same type widgets are selected. * Feature: Draggable Proppane. * Bug fixes for draggable popup. * Fix: Property pane editor when selecting another widget. * resolve rebase bad merges. * cytest fix * cytest fix * cytest fix * cytest fix * cytest fix * cytest fix * cytest fixes * cytest fix * fixing draggable components inside porp pane. * Adding cypress test. * refactored Draggable list POC version * reverting unwanted changes. * prop pane bug fix * unwanted dependencies. * double click to open prop pane. * Fixing bugs in draggable prop pane. * one click prop pane open. * ignore drag/resize click captures * make prop pane draggable only via drag handler. * Fixed property pane title. * converting layer to hook and adding it to top most layer. * removing irrelevant comments. * close panel when widget changes. * fixing cytests. * bug fix * fixing cytest * Addressing code review comments. * bug fix
152 lines
3.6 KiB
TypeScript
152 lines
3.6 KiB
TypeScript
import _ from "lodash";
|
|
import { createReducer } from "utils/AppsmithUtils";
|
|
import {
|
|
ReduxAction,
|
|
ReduxActionTypes,
|
|
ReduxActionErrorTypes,
|
|
} from "constants/ReduxActionConstants";
|
|
|
|
import { DefaultCurrentUserDetails, User } from "constants/userConstants";
|
|
|
|
const initialState: UsersReduxState = {
|
|
loadingStates: {
|
|
fetchingUsers: false,
|
|
fetchingUser: false,
|
|
},
|
|
list: [],
|
|
users: [],
|
|
error: "",
|
|
current: undefined,
|
|
currentUser: undefined,
|
|
};
|
|
|
|
const usersReducer = createReducer(initialState, {
|
|
[ReduxActionTypes.FETCH_USER_INIT]: (state: UsersReduxState) => ({
|
|
...state,
|
|
loadingStates: {
|
|
...state.loadingStates,
|
|
fetchingUser: true,
|
|
},
|
|
}),
|
|
[ReduxActionTypes.PROP_PANE_MOVED]: (
|
|
state: UsersReduxState,
|
|
action: ReduxAction<PropertyPanePositionConfig>,
|
|
) => ({
|
|
...state,
|
|
propPanePreferences: {
|
|
isMoved: true,
|
|
position: {
|
|
...action.payload.position,
|
|
},
|
|
},
|
|
}),
|
|
[ReduxActionTypes.FETCH_USER_DETAILS_SUCCESS]: (
|
|
state: UsersReduxState,
|
|
action: ReduxAction<User>,
|
|
) => {
|
|
const users = [...state.users];
|
|
const userIndex = _.findIndex(users, { username: action.payload.username });
|
|
if (userIndex > -1) {
|
|
users[userIndex] = action.payload;
|
|
} else {
|
|
users.push(action.payload);
|
|
}
|
|
return {
|
|
...state,
|
|
loadingStates: {
|
|
...state.loadingStates,
|
|
fetchingUser: false,
|
|
},
|
|
users,
|
|
currentUser: action.payload,
|
|
};
|
|
},
|
|
[ReduxActionTypes.UPDATE_USER_DETAILS_SUCCESS]: (
|
|
state: UsersReduxState,
|
|
action: ReduxAction<User>,
|
|
) => {
|
|
const users = [...state.users];
|
|
const userIndex = _.findIndex(users, { username: action.payload.username });
|
|
if (userIndex > -1) {
|
|
users[userIndex] = action.payload;
|
|
} else {
|
|
users.push(action.payload);
|
|
}
|
|
return {
|
|
...state,
|
|
loadingStates: {
|
|
...state.loadingStates,
|
|
fetchingUser: false,
|
|
},
|
|
users,
|
|
currentUser: action.payload,
|
|
};
|
|
},
|
|
[ReduxActionTypes.FETCH_USER_SUCCESS]: (
|
|
state: UsersReduxState,
|
|
action: ReduxAction<User>,
|
|
) => {
|
|
const users = [...state.list];
|
|
const userIndex = _.findIndex(users, { username: action.payload.username });
|
|
if (userIndex > -1) {
|
|
users[userIndex] = action.payload;
|
|
} else {
|
|
users.push(action.payload);
|
|
}
|
|
return {
|
|
...state,
|
|
loadingStates: {
|
|
...state.loadingStates,
|
|
fetchingUser: false,
|
|
},
|
|
list: users,
|
|
};
|
|
},
|
|
[ReduxActionErrorTypes.FETCH_USER_DETAILS_ERROR]: (
|
|
state: UsersReduxState,
|
|
action: ReduxAction<{ error: string }>,
|
|
) => ({
|
|
...initialState,
|
|
error: action.payload.error,
|
|
}),
|
|
[ReduxActionErrorTypes.FETCH_USER_ERROR]: (state: UsersReduxState) => ({
|
|
...state,
|
|
loadingStates: { ...state.loadingStates, fetchingUser: false },
|
|
}),
|
|
[ReduxActionTypes.SET_CURRENT_USER_SUCCESS]: (
|
|
state: UsersReduxState,
|
|
action: ReduxAction<User>,
|
|
) => ({
|
|
...state,
|
|
current: action.payload,
|
|
}),
|
|
[ReduxActionTypes.LOGOUT_USER_SUCCESS]: (state: UsersReduxState) => ({
|
|
...state,
|
|
current: undefined,
|
|
currentUser: DefaultCurrentUserDetails,
|
|
users: [DefaultCurrentUserDetails],
|
|
}),
|
|
});
|
|
|
|
export interface PropertyPanePositionConfig {
|
|
isMoved: boolean;
|
|
position: {
|
|
left: number;
|
|
top: number;
|
|
};
|
|
}
|
|
export interface UsersReduxState {
|
|
current?: User;
|
|
list: User[];
|
|
loadingStates: {
|
|
fetchingUser: boolean;
|
|
fetchingUsers: boolean;
|
|
};
|
|
users: User[];
|
|
currentUser?: User;
|
|
error: string;
|
|
propPanePreferences?: PropertyPanePositionConfig;
|
|
}
|
|
|
|
export default usersReducer;
|