* dip * dip * Cleaning up grid density positioning. * dip * dip * dip * dip * code clean up * dip * dip(restructuring widget selection) * Deselect parents and children of a widget when user multi selects. * dip * dip * dip * dip * dip * fixing a bad merge * fixing tests * adding jest tests. * common util * dip * dip * fixes * restrict in deploy mode. * fixing dynamic layout. * fixing tests. * on paste fix. * fixing specs. * addressing code review comments * dip * dip * dip * fixing specs.
80 lines
2.1 KiB
TypeScript
80 lines
2.1 KiB
TypeScript
import { ReduxActionTypes, ReduxAction } from "constants/ReduxActionConstants";
|
|
import { all, put, takeLatest } from "redux-saga/effects";
|
|
import { updateRecentEntity } from "actions/globalSearchActions";
|
|
|
|
import {
|
|
matchApiPath,
|
|
matchDatasourcePath,
|
|
matchQueryPath,
|
|
matchBuilderPath,
|
|
} from "constants/routes";
|
|
import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants";
|
|
|
|
const getRecentEntity = (pathName: string) => {
|
|
const builderMatch = matchBuilderPath(pathName);
|
|
if (builderMatch)
|
|
return {
|
|
type: "page",
|
|
id: builderMatch?.params?.pageId,
|
|
params: builderMatch?.params,
|
|
};
|
|
|
|
const apiMatch = matchApiPath(pathName);
|
|
if (apiMatch)
|
|
return {
|
|
type: "action",
|
|
id: apiMatch?.params?.apiId,
|
|
params: apiMatch?.params,
|
|
};
|
|
|
|
const queryMatch = matchQueryPath(pathName);
|
|
if (queryMatch)
|
|
return {
|
|
type: "action",
|
|
id: queryMatch.params?.queryId,
|
|
params: queryMatch?.params,
|
|
};
|
|
|
|
const datasourceMatch = matchDatasourcePath(pathName);
|
|
if (datasourceMatch)
|
|
return {
|
|
type: "datasource",
|
|
id: datasourceMatch?.params?.datasourceId,
|
|
params: datasourceMatch?.params,
|
|
};
|
|
|
|
return {};
|
|
};
|
|
|
|
function* handleSelectWidget(action: ReduxAction<{ widgetId: string }>) {
|
|
const builderMatch = matchBuilderPath(window.location.pathname);
|
|
const { payload } = action;
|
|
const selectedWidget = payload.widgetId;
|
|
if (selectedWidget && selectedWidget !== MAIN_CONTAINER_WIDGET_ID)
|
|
yield put(
|
|
updateRecentEntity({
|
|
type: "widget",
|
|
id: selectedWidget,
|
|
params: builderMatch?.params,
|
|
}),
|
|
);
|
|
}
|
|
|
|
function* handlePathUpdated(
|
|
action: ReduxAction<{ location: typeof window.location }>,
|
|
) {
|
|
const { id, params, type } = getRecentEntity(
|
|
action.payload.location.pathname,
|
|
);
|
|
if (type && id && id.indexOf(":") === -1) {
|
|
yield put(updateRecentEntity({ type, id, params }));
|
|
}
|
|
}
|
|
|
|
export default function* recentEntitiesSagas() {
|
|
yield all([
|
|
takeLatest(ReduxActionTypes.SELECT_WIDGET_INIT, handleSelectWidget),
|
|
takeLatest(ReduxActionTypes.HANDLE_PATH_UPDATED, handlePathUpdated),
|
|
]);
|
|
}
|