@dexteel/mesf-core 5.4.2 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "5.4.2"
2
+ ".": "5.5.0"
3
3
  }
package/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ # Changelog
2
+
3
+ ## [5.5.0](https://github.com/dexteel/mesf-core-frontend/compare/@dexteel/mesf-core-v5.4.2...@dexteel/mesf-core-v5.5.0) (2025-06-18)
4
+
5
+
6
+ ### Features
7
+
8
+ * **asset tree:** update asset tree ([43a2ad3](https://github.com/dexteel/mesf-core-frontend/commit/43a2ad302185a3519dc6371457d5d5c30ed543b0))
9
+ * **asset tree:** update asset tree to support asset 0 and fix area selector ([3311536](https://github.com/dexteel/mesf-core-frontend/commit/3311536b5af0b5527495fcc3a14ab87e81c86c4c))
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * use PlantAssetId as prop in MESFMain ([6246891](https://github.com/dexteel/mesf-core-frontend/commit/6246891b0a5c07cecf83b4b175e3f60d043744ab))
15
+
16
+ ## [5.4.2] - 2025-05-29
17
+
18
+
19
+
1
20
  # Changelog
2
21
 
3
22
  ## [5.4.2](https://github.com/dexteel/mesf-core-frontend/compare/@dexteel/mesf-core-v5.4.1...@dexteel/mesf-core-v5.4.2) (2025-05-29)
@@ -9,6 +9,7 @@ interface Props {
9
9
  showAreaSelector?: boolean;
10
10
  showTrendingsIcon?: boolean;
11
11
  byPassHeaderRoutes?: string[];
12
+ plantAssetId?: number;
12
13
  }
13
- declare function MESFMain({ authentication, routes, navbar, navbarTitle, configurations, showAreaSelector, showTrendingsIcon, byPassHeaderRoutes, }: Props): React.JSX.Element;
14
+ declare function MESFMain({ authentication, routes, navbar, navbarTitle, configurations, showAreaSelector, showTrendingsIcon, byPassHeaderRoutes, plantAssetId, }: Props): React.JSX.Element;
14
15
  export { MESFMain };
@@ -1,6 +1,6 @@
1
1
  export interface AssetParameters {
2
2
  id: number;
3
- parent: number;
3
+ parent: number | null;
4
4
  text: string;
5
5
  data: {
6
6
  fileType: string;
@@ -3,11 +3,13 @@ export declare const useAssetContext: () => {
3
3
  state: {
4
4
  areasList: import("../models/Asset").Asset[];
5
5
  allAssets: import("../models/Asset").Asset[];
6
+ plantAssetId: number;
6
7
  };
7
8
  actions: import("@reduxjs/toolkit").CaseReducerActions<{
8
9
  setAreasList(state: import("immer/dist/internal").WritableDraft<{
9
10
  areasList: import("../models/Asset").Asset[];
10
11
  allAssets: import("../models/Asset").Asset[];
12
+ plantAssetId: number;
11
13
  }>, { payload }: {
12
14
  payload: any;
13
15
  type: string;
@@ -15,12 +17,22 @@ export declare const useAssetContext: () => {
15
17
  setAllAssets(state: import("immer/dist/internal").WritableDraft<{
16
18
  areasList: import("../models/Asset").Asset[];
17
19
  allAssets: import("../models/Asset").Asset[];
20
+ plantAssetId: number;
21
+ }>, { payload }: {
22
+ payload: any;
23
+ type: string;
24
+ }): void;
25
+ setPlantAssetId(state: import("immer/dist/internal").WritableDraft<{
26
+ areasList: import("../models/Asset").Asset[];
27
+ allAssets: import("../models/Asset").Asset[];
28
+ plantAssetId: number;
18
29
  }>, { payload }: {
19
30
  payload: any;
20
31
  type: string;
21
32
  }): void;
22
33
  }, "__">;
23
34
  };
24
- export declare const AssetProvider: ({ children }: {
35
+ export declare const AssetProvider: ({ children, plantAssetId, }: {
25
36
  children: ReactNode;
37
+ plantAssetId?: number;
26
38
  }) => React.JSX.Element;
package/dist/index.esm.js CHANGED
@@ -5337,6 +5337,7 @@ var ShiftsCrewsPage = function (props) {
5337
5337
  var AssetInitialState = {
5338
5338
  areasList: [],
5339
5339
  allAssets: [],
5340
+ plantAssetId: 1,
5340
5341
  };
5341
5342
  var AssetReducer = createSlice({
5342
5343
  name: "__",
@@ -5350,6 +5351,10 @@ var AssetReducer = createSlice({
5350
5351
  var payload = _a.payload;
5351
5352
  state.allAssets = payload;
5352
5353
  },
5354
+ setPlantAssetId: function (state, _a) {
5355
+ var payload = _a.payload;
5356
+ state.plantAssetId = payload;
5357
+ },
5353
5358
  },
5354
5359
  });
5355
5360
 
@@ -5359,17 +5364,21 @@ var AssetContext = createContext({
5359
5364
  });
5360
5365
  var useAssetContext = function () { return useContext(AssetContext); };
5361
5366
  var AssetProvider = function (_a) {
5362
- var children = _a.children;
5363
- var _b = useComplexState({
5364
- initialState: AssetReducer.getInitialState(),
5367
+ var children = _a.children, _b = _a.plantAssetId, plantAssetId = _b === void 0 ? 1 : _b;
5368
+ var _c = useComplexState({
5369
+ initialState: {
5370
+ areasList: [],
5371
+ allAssets: [],
5372
+ plantAssetId: plantAssetId,
5373
+ },
5365
5374
  reducers: AssetReducer.caseReducers,
5366
- }), state = _b[0], actions = _b[1];
5375
+ }), state = _c[0], actions = _c[1];
5367
5376
  return (React__default.createElement(AssetContext.Provider, { value: { state: state, actions: actions } }, children));
5368
5377
  };
5369
5378
 
5370
5379
  var DATA_ASSET_INITIAL_VALUES = {
5371
5380
  AssetId: null,
5372
- ParentAssetId: 1,
5381
+ ParentAssetId: 0,
5373
5382
  AssetName: "",
5374
5383
  IsAsset: false,
5375
5384
  CanBeDefaultAsset: false,
@@ -5484,7 +5493,7 @@ var ConfigurationAssetProvider = function (_a) {
5484
5493
  var TransformAssetModelData = function (node) {
5485
5494
  var model = {
5486
5495
  id: node.AssetId,
5487
- parent: node.ParentAssetId ? node.ParentAssetId : 0,
5496
+ parent: node.ParentAssetId === null ? -1 : node.ParentAssetId,
5488
5497
  text: node.AssetName,
5489
5498
  data: {
5490
5499
  fileType: "csv",
@@ -5599,26 +5608,21 @@ var useAssetCodes = function () {
5599
5608
  var buildTreeAssets = function (nodes) {
5600
5609
  if (nodes === undefined)
5601
5610
  return;
5602
- //tree build functions
5603
5611
  var idMapping = nodes.reduce(function (acc, el, i) {
5604
5612
  acc[el.id] = i;
5605
5613
  return acc;
5606
5614
  }, {});
5607
5615
  var root;
5608
5616
  nodes.forEach(function (el) {
5609
- // Handle the root element
5610
5617
  if (el.parentId === null) {
5611
5618
  root = el;
5612
5619
  return;
5613
5620
  }
5614
- // Use our mapping to locate the parent element in our data array
5615
5621
  var parentEl = nodes[idMapping[el.parentId]];
5616
- // Handle the case where the element has no parent
5617
5622
  if (!parentEl) {
5618
5623
  console.log(el);
5619
5624
  return;
5620
5625
  }
5621
- // Add our current el to its parent's `children` array
5622
5626
  if (!parentEl["children"]) {
5623
5627
  parentEl["children"] = [];
5624
5628
  }
@@ -5691,14 +5695,14 @@ var CreateNewAssetDialog = function (_a) {
5691
5695
  var _d = useState(false), assetCreatedSuccess = _d[0], setAssetCreatedSuccess = _d[1];
5692
5696
  var _e = useState(""), errorCreateAsset = _e[0], setErrorCreateAsset = _e[1];
5693
5697
  var _f = useState(false), isCreateSubmitLoading = _f[0], setIsCreateSubmitLoading = _f[1];
5694
- var allAssets = useAssetContext().state.allAssets;
5695
- var _g = useConfigurationAssetContext(), _h = _g.state, assetNodeSelectedInTree = _h.assetNodeSelectedInTree, assetCodes = _h.assetCodes, dataToCreateAsset = _h.dataToCreateAsset; _h.assetTreeName; var _j = _g.actions, setAssetNameToCreateAsset = _j.setAssetNameToCreateAsset, setAssetTreeName = _j.setAssetTreeName, setAssetParentAssetIdToCreateAsset = _j.setAssetParentAssetIdToCreateAsset, setParentAssetNameInNodeSelectedInTree = _j.setParentAssetNameInNodeSelectedInTree;
5698
+ var _g = useAssetContext().state, allAssets = _g.allAssets, plantAssetId = _g.plantAssetId;
5699
+ var _h = useConfigurationAssetContext(), _j = _h.state, assetNodeSelectedInTree = _j.assetNodeSelectedInTree, assetCodes = _j.assetCodes, dataToCreateAsset = _j.dataToCreateAsset; _j.assetTreeName; var _k = _h.actions, setAssetNameToCreateAsset = _k.setAssetNameToCreateAsset, setAssetTreeName = _k.setAssetTreeName, setAssetParentAssetIdToCreateAsset = _k.setAssetParentAssetIdToCreateAsset, setParentAssetNameInNodeSelectedInTree = _k.setParentAssetNameInNodeSelectedInTree;
5696
5700
  var loadFilterAssets = useAssetCodes().loadFilterAssets;
5697
- var _k = useForm({
5701
+ var _l = useForm({
5698
5702
  defaultValues: dataToCreateAsset
5699
5703
  ? dataToCreateAsset
5700
5704
  : DATA_ASSET_INITIAL_VALUES,
5701
- }), control = _k.control, handleSubmit = _k.handleSubmit, reset = _k.reset, setValue = _k.setValue, errors = _k.formState.errors;
5705
+ }), control = _l.control, handleSubmit = _l.handleSubmit, reset = _l.reset, setValue = _l.setValue, errors = _l.formState.errors;
5702
5706
  var handleCancel = function () {
5703
5707
  onHide(false);
5704
5708
  };
@@ -5737,6 +5741,14 @@ var CreateNewAssetDialog = function (_a) {
5737
5741
  setParentAssetNameInNodeSelectedInTree(description);
5738
5742
  };
5739
5743
  var handleFormSubmit = handleSubmit(handleCreateAsset);
5744
+ var getRootAssetId = function () {
5745
+ var rootAsset = allAssets.find(function (asset) { return asset.ParentAssetId === null; });
5746
+ return rootAsset ? rootAsset.AssetId : plantAssetId;
5747
+ };
5748
+ var getRootAssetName = function () {
5749
+ var rootAsset = allAssets.find(function (asset) { return asset.ParentAssetId === null; });
5750
+ return rootAsset ? rootAsset.AssetName : "Plant";
5751
+ };
5740
5752
  useEffect(function () {
5741
5753
  if (show) {
5742
5754
  reset();
@@ -5747,9 +5759,11 @@ var CreateNewAssetDialog = function (_a) {
5747
5759
  setParentAssetNameInNodeSelectedInTree(parentAssetNode === null || parentAssetNode === void 0 ? void 0 : parentAssetNode.AssetName);
5748
5760
  }
5749
5761
  else {
5750
- setAssetParentAssetIdToCreateAsset(1);
5751
- setAssetTreeName("Plant");
5762
+ var rootId = getRootAssetId();
5763
+ setAssetParentAssetIdToCreateAsset(rootId);
5764
+ setAssetTreeName(getRootAssetName());
5752
5765
  setAssetNameToCreateAsset("");
5766
+ setValue("ParentAssetId", rootId);
5753
5767
  }
5754
5768
  }
5755
5769
  }, [show]);
@@ -5777,8 +5791,10 @@ var CreateNewAssetDialog = function (_a) {
5777
5791
  React__default.createElement(Grid, { container: true },
5778
5792
  React__default.createElement(Grid, { item: true, md: 12, xs: 12, style: { marginBottom: "8px" } },
5779
5793
  React__default.createElement(Grid, { item: true, md: 12, xs: 12, style: { padding: 0, marginTop: 10 } },
5780
- React__default.createElement(Controller, { name: "ParentAssetId", control: control, render: function (_a) { return (React__default.createElement(TreePickerControl, { inputTitle: "Asset", title: "Asset Parent", dataSource: assetCodes, value: (assetNodeSelectedInTree === null || assetNodeSelectedInTree === void 0 ? void 0 : assetNodeSelectedInTree.AssetId) || 1, description: (assetNodeSelectedInTree === null || assetNodeSelectedInTree === void 0 ? void 0 : assetNodeSelectedInTree.ParentAssetName) ||
5781
- "Plant", onSelect: changeParentAssetId, selectBranch: true, selectActive: false, selectInternal: false })); } }))),
5794
+ React__default.createElement(Controller, { name: "ParentAssetId", control: control, render: function (_a) {
5795
+ var value = _a.field.value;
5796
+ return (React__default.createElement(TreePickerControlV2, { inputTitle: "Asset", title: "Asset Parent", dataSource: assetCodes, value: value, onSelect: changeParentAssetId, selectBranch: true, selectActive: false, selectInternal: false }));
5797
+ } }))),
5782
5798
  React__default.createElement(Grid, { container: true, style: { marginTop: "10px 0", padding: "0" } },
5783
5799
  React__default.createElement(Grid, { item: true, xs: 6, md: 6 },
5784
5800
  React__default.createElement(Controller, { name: "CanBeDefaultAsset", control: control, defaultValue: false, render: function (_a) {
@@ -5801,7 +5817,7 @@ var CreateNewAssetDialog = function (_a) {
5801
5817
  React__default.createElement(Button, { fullWidth: true, startIcon: isCreateSubmitLoading && (React__default.createElement(CircularProgress, { size: "1rem" })), disabled: isCreateSubmitLoading, variant: "contained", color: "primary", type: "submit" }, "Save")))))))))),
5802
5818
  React__default.createElement(ErrorModal, { error: errorCreateAsset, onHide: function () { return setErrorCreateAsset(""); } }),
5803
5819
  React__default.createElement(Snackbar, { open: assetCreatedSuccess, autoHideDuration: 2500, onClose: handleClose },
5804
- React__default.createElement(Alert$3, { severity: "info", onClose: handleClose }, "Document created succesfully"))));
5820
+ React__default.createElement(Alert$3, { severity: "info", onClose: handleClose }, "Document created successfully"))));
5805
5821
  };
5806
5822
 
5807
5823
  var useStyles$p = makeStyles(function (theme) { return ({
@@ -6219,8 +6235,14 @@ var useAssetActions = function (_a) {
6219
6235
  switch (_a.label) {
6220
6236
  case 0:
6221
6237
  dropTargetId = options.dropTargetId;
6222
- if (dropTargetId == 0) {
6223
- dropTargetId = 1;
6238
+ if (dropTargetId === -1 ||
6239
+ dropTargetId === null ||
6240
+ dropTargetId === undefined) {
6241
+ onAssetUpdateEnd({
6242
+ ok: false,
6243
+ message: "Cannot move assets to root level. Only one root asset (Plant) is allowed.",
6244
+ });
6245
+ return [2 /*return*/];
6224
6246
  }
6225
6247
  onAssetUpdateStart();
6226
6248
  return [4 /*yield*/, updateAsset(selectedNodes.map(function (cn) { return cn.id; }), dropTargetId)];
@@ -6387,7 +6409,7 @@ var CustomNode = function (_a) {
6387
6409
  var handleToggle = function (e) {
6388
6410
  var _a;
6389
6411
  e.stopPropagation();
6390
- if (openAssets[id]) {
6412
+ if (openAssets[id] === id) {
6391
6413
  var newOpenAssets = __assign({}, openAssets);
6392
6414
  delete newOpenAssets[id];
6393
6415
  setOpenAssets(newOpenAssets);
@@ -6654,7 +6676,7 @@ var AssetViewComponent = function () {
6654
6676
  paddingBottom: 10,
6655
6677
  } },
6656
6678
  React__default.createElement(Grid, null,
6657
- React__default.createElement(Tree, { rootId: 0, initialOpen: openAssetsArray, tree: allAssetNodes, enableAnimateExpand: true, classes: {
6679
+ React__default.createElement(Tree, { rootId: -1, initialOpen: openAssetsArray, tree: allAssetNodes, enableAnimateExpand: true, classes: {
6658
6680
  root: classes.assetRoot,
6659
6681
  dropTarget: classes.dropTarget,
6660
6682
  }, onDrop: handleDrop, onDragStart: handleDragStart, onDragEnd: handleDragEnd, canDrop: function (asset, options) {
@@ -14193,14 +14215,14 @@ var timezone = TimeService.getInstance().getServerTimeZone();
14193
14215
  moment$2.tz.setDefault(timezone);
14194
14216
  var base = document.getElementsByTagName("base")[0].getAttribute("href") || "/";
14195
14217
  function MESFMain(_a) {
14196
- var authentication = _a.authentication, routes = _a.routes, navbar = _a.navbar, _b = _a.navbarTitle, navbarTitle = _b === void 0 ? "MESF" : _b, configurations = _a.configurations, _c = _a.showAreaSelector, showAreaSelector = _c === void 0 ? false : _c, _d = _a.showTrendingsIcon, showTrendingsIcon = _d === void 0 ? true : _d, _e = _a.byPassHeaderRoutes, byPassHeaderRoutes = _e === void 0 ? [] : _e;
14218
+ var authentication = _a.authentication, routes = _a.routes, navbar = _a.navbar, _b = _a.navbarTitle, navbarTitle = _b === void 0 ? "MESF" : _b, configurations = _a.configurations, _c = _a.showAreaSelector, showAreaSelector = _c === void 0 ? false : _c, _d = _a.showTrendingsIcon, showTrendingsIcon = _d === void 0 ? true : _d, _e = _a.byPassHeaderRoutes, byPassHeaderRoutes = _e === void 0 ? [] : _e, _f = _a.plantAssetId, plantAssetId = _f === void 0 ? 1 : _f;
14197
14219
  return (React__default.createElement(React__default.Fragment, null,
14198
14220
  React__default.createElement(CssBaseline, null),
14199
14221
  React__default.createElement(ThemeProvider, { theme: themeMESF },
14200
14222
  React__default.createElement(AuthProvider, { authConfig: authentication },
14201
14223
  React__default.createElement(LocalizationProvider, { dateAdapter: AdapterMoment, dateLibInstance: moment$2 },
14202
14224
  React__default.createElement(UserProvider, null,
14203
- React__default.createElement(AssetProvider, null,
14225
+ React__default.createElement(AssetProvider, { plantAssetId: plantAssetId },
14204
14226
  React__default.createElement(UTLSettingsProvider, null,
14205
14227
  React__default.createElement(RouterContext.Provider, { value: routes },
14206
14228
  React__default.createElement(NavbarContext.Provider, { value: navbar },
@@ -14325,6 +14347,11 @@ var AreaSelector = function () {
14325
14347
  setDefaultAreaName(areaSelected === null || areaSelected === void 0 ? void 0 : areaSelected.AssetName);
14326
14348
  setDefaultAreaNameToChange(areaSelected === null || areaSelected === void 0 ? void 0 : areaSelected.AssetName);
14327
14349
  }
14350
+ else {
14351
+ setDefaultAreaId(0);
14352
+ setDefaultAreaName("Plant");
14353
+ setDefaultAreaNameToChange("Plant");
14354
+ }
14328
14355
  }, [defaultAreaId, areasList]);
14329
14356
  return (React__default.createElement(React__default.Fragment, null,
14330
14357
  React__default.createElement(Box, { mx: 2 },