Skip to content

Commit

Permalink
Request doc by entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaetanbrl committed Sep 1, 2023
1 parent a9d9d7d commit 3552bd9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions js/extension/stateManagement/epics/getDocuments.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
setDocuments,
docsLoading as loading,
} from "../actions/actions";
import { getPluginCfg, isActive } from "../selector/selector";
import { getEntity, getPluginCfg, isActive } from "../selector/selector";
import { wrapStartStop } from "@mapstore/observables/epics";

import { getDocuments } from "@js/extension/requests/documentsApi";
Expand All @@ -20,9 +20,10 @@ export function getDocumentsById(action$, store) {
if (!apiUrl || !idPlugin) {
return observable$;
}
const params = {...action?.params, entity: getEntity(store.getState())}
if (apiUrl) {
observable$ = Rx.Observable.defer(() =>
getDocuments(apiUrl, idPlugin, action?.params)
getDocuments(apiUrl, idPlugin, params)
)
.catch((e) => {
console.log("Error - Get list of documents");
Expand Down
10 changes: 6 additions & 4 deletions js/extension/stateManagement/selector/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ export const getIdToDelete = state => state?.docsManager?.idToDelete;
export const getIdToConsult = state => state?.docsManager?.idToConsult;

export const getEntity = (state) => {
let cfg = state?.pluginCfg;
let cfg = state?.docsManager?.pluginCfg;
if (cfg?.entity?.get) {
return get(state, cfg.entity.get);
}
if (cfg?.entity && cfg?.entity?.plugin && cfg?.entity?.plugin.propCfg) {
let pluginCfg = state[plugin]?.pluginCfg;
return pluginCfg ? pluginCfg[propCfg] : null;
if (cfg?.entity && cfg?.entity?.plugin && cfg?.entity?.propCfg && cfg?.entity?.attribute) {
const plugin = cfg?.entity?.plugin;
const propCfg = cfg?.entity?.propCfg;
let pluginCfg = state[plugin];
return pluginCfg ? pluginCfg[propCfg][cfg?.entity?.attribute] : null;
}
}

Expand Down

0 comments on commit 3552bd9

Please sign in to comment.