Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
66 changes: 66 additions & 0 deletions app/client/src/IDE/utils/getNextEntityAfterRemove.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import type { EntityItem } from "ee/IDE/Interfaces/EntityItem";
import { identifyEntityFromPath } from "navigation/FocusEntity";

/**
* Adds custom redirect logic to redirect after an item is deleted
* 1. Do not navigate if the deleted item is not selected
* 2. If it was the only item, navigate to the list url, to show the blank state
* 3. If there are other items, navigate to an item close to the current one
* **/

export enum RedirectAction {
NA = "NA", // No action is needed
LIST = "LIST", // Navigate to a creation URL
ITEM = "ITEM", // Navigate to this item
}

interface RedirectActionDescription<T> {
action: RedirectAction;
payload?: T;
}

export function getNextEntityAfterRemove<T extends EntityItem>(
removedId: string,
tabs: T[],
): RedirectActionDescription<T> {
const currentSelectedEntity = identifyEntityFromPath(
window.location.pathname,
);
const isSelectedActionRemoved = currentSelectedEntity.id === removedId;

// If removed item is not currently selected, don't redirect
if (!isSelectedActionRemoved) {
return {
action: RedirectAction.NA,
};
}

const indexOfTab = tabs.findIndex((item) => item.key === removedId);

switch (indexOfTab) {
case -1:
// If no other action is remaining, navigate to the creation url
return {
action: RedirectAction.LIST,
};
case 0:
// if the removed item is first item, then if tabs present, tabs + 1
// else otherItems[0] -> TODO: consider changing this logic after discussion with
// design team. May be new listing UI for side by side
if (tabs.length > 1) {
return {
action: RedirectAction.ITEM,
payload: tabs[1],
};
} else {
return {
action: RedirectAction.LIST,
};
}
default:
return {
action: RedirectAction.ITEM,
payload: tabs[indexOfTab - 1],
};
}
}
7 changes: 7 additions & 0 deletions app/client/src/IDE/utils/getUpdatedTabs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function getUpdatedTabs(newId: string, currentTabs: string[]) {
if (currentTabs.includes(newId)) return currentTabs;

const newTabs = [...currentTabs, newId];

return newTabs;
}
12 changes: 6 additions & 6 deletions app/client/src/IDE/utils/groupAndSortEntitySegmentList.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { groupBy, sortBy } from "lodash";
import type { EntityItem } from "ee/IDE/Interfaces/EntityItem";
import { groupBy, sortBy } from "lodash";

export type EditorSegmentList = Array<{
export type EditorSegmentList<T> = Array<{
group: string | "NA";
items: EntityItem[];
items: T[];
}>;

export const groupAndSortEntitySegmentList = (
items: EntityItem[],
): EditorSegmentList => {
export const groupAndSortEntitySegmentList = <T extends EntityItem>(
items: T[],
): EditorSegmentList<T> => {
const groups = groupBy(items, (item) => {
if (item.group) return item.group;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const useBlockExecution = () => {
// this gets the url of the current action's datasource
const actionDatasourceUrl =
action.datasource.datasourceConfiguration?.url || "";
const actionDatasourceUrlPath = action.actionConfiguration.path || "";
const actionDatasourceUrlPath = action.actionConfiguration?.path || "";
// this gets the name of the current action's datasource
const actionDatasourceName = action.datasource.name || "";

Expand Down
79 changes: 6 additions & 73 deletions app/client/src/sagas/IDESaga.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FocusEntityInfo } from "navigation/FocusEntity";
import { FocusEntity, identifyEntityFromPath } from "navigation/FocusEntity";
import { FocusEntity } from "navigation/FocusEntity";
import { all, call, put, select, takeEvery } from "redux-saga/effects";
import { getJSTabs, getQueryTabs } from "selectors/ideSelectors";
import {
Expand Down Expand Up @@ -27,6 +27,11 @@ import {
selectQuerySegmentEditorTabs,
} from "ee/selectors/appIDESelectors";
import { getCurrentBasePageId } from "selectors/editorSelectors";
import {
getNextEntityAfterRemove,
getUpdatedTabs,
RedirectAction,
} from "./helper";

export function* updateIDETabsOnRouteChangeSaga(entityInfo: FocusEntityInfo) {
const { entity, id, params } = entityInfo;
Expand Down Expand Up @@ -54,14 +59,6 @@ export function* updateIDETabsOnRouteChangeSaga(entityInfo: FocusEntityInfo) {
}
}

function* getUpdatedTabs(newId: string, currentTabs: string[]) {
if (currentTabs.includes(newId)) return currentTabs;

const newTabs = [...currentTabs, newId];

return newTabs;
}

export function* handleJSEntityRedirect(deletedId: string) {
const basePageId: string = yield select(getCurrentBasePageId);
const jsTabs: EntityItem[] = yield select(selectJSSegmentEditorTabs);
Expand Down Expand Up @@ -108,70 +105,6 @@ export function* handleQueryEntityRedirect(deletedId: string) {
}
}

/**
* Adds custom redirect logic to redirect after an item is deleted
* 1. Do not navigate if the deleted item is not selected
* 2. If it was the only item, navigate to the list url, to show the blank state
* 3. If there are other items, navigate to an item close to the current one
* **/

export enum RedirectAction {
NA = "NA", // No action is needed
LIST = "LIST", // Navigate to a creation URL
ITEM = "ITEM", // Navigate to this item
}

interface RedirectActionDescription {
action: RedirectAction;
payload?: EntityItem;
}

export function getNextEntityAfterRemove(
removedId: string,
tabs: EntityItem[],
): RedirectActionDescription {
const currentSelectedEntity = identifyEntityFromPath(
window.location.pathname,
);
const isSelectedActionRemoved = currentSelectedEntity.id === removedId;

// If removed item is not currently selected, don't redirect
if (!isSelectedActionRemoved) {
return {
action: RedirectAction.NA,
};
}

const indexOfTab = tabs.findIndex((item) => item.key === removedId);

switch (indexOfTab) {
case -1:
// If no other action is remaining, navigate to the creation url
return {
action: RedirectAction.LIST,
};
case 0:
// if the removed item is first item, then if tabs present, tabs + 1
// else otherItems[0] -> TODO: consider changing this logic after discussion with
// design team. May be new listing UI for side by side
if (tabs.length > 1) {
return {
action: RedirectAction.ITEM,
payload: tabs[1],
};
} else {
return {
action: RedirectAction.LIST,
};
}
default:
return {
action: RedirectAction.ITEM,
payload: tabs[indexOfTab - 1],
};
}
}

function* storeIDEViewChangeSaga(
action: ReduxAction<{ view: EditorViewMode }>,
) {
Expand Down
2 changes: 1 addition & 1 deletion app/client/src/sagas/getNextEntityAfterRemove.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EditorState } from "IDE/enums";
import { PluginType } from "entities/Plugin";
import * as FocusEntityObj from "navigation/FocusEntity";
import { RedirectAction, getNextEntityAfterRemove } from "./IDESaga";
import { RedirectAction, getNextEntityAfterRemove } from "./helper";
import { FocusEntity } from "navigation/FocusEntity";
import type { EntityItem } from "ee/IDE/Interfaces/EntityItem";

Expand Down