From 41983bd6c3136db002a212a2c096adefcf9a11f3 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 19 Jul 2023 21:35:56 -0700 Subject: [PATCH] Increase limit (#562) (#563) Signed-off-by: Tyler Ohlsen (cherry picked from commit a334f087618b9f2bd5c90c20a04c1fe101434a5a) Co-authored-by: Tyler Ohlsen --- .../AddAnomalyDetector.tsx | 67 ++++++++++--------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/public/components/FeatureAnywhereContextMenu/CreateAnomalyDetector/AddAnomalyDetector.tsx b/public/components/FeatureAnywhereContextMenu/CreateAnomalyDetector/AddAnomalyDetector.tsx index 106d0dff..486324c0 100644 --- a/public/components/FeatureAnywhereContextMenu/CreateAnomalyDetector/AddAnomalyDetector.tsx +++ b/public/components/FeatureAnywhereContextMenu/CreateAnomalyDetector/AddAnomalyDetector.tsx @@ -204,28 +204,32 @@ function AddAnomalyDetector({ const maxAssociatedCount = uiSettings.get( PLUGIN_AUGMENTATION_MAX_OBJECTS_SETTING ); - await savedObjectLoader.findAll().then(async (resp) => { - if (resp !== undefined) { - const savedAugmentObjects = get(resp, 'hits', []); - // gets all the saved object for this visualization - const savedObjectsForThisVisualization = - savedAugmentObjects.filter( - (savedObj) => - get(savedObj, 'visId', '') === embeddable.vis.id + await savedObjectLoader + .findAll('', 100, [], { + type: 'visualization', + id: embeddable.vis.id as string, + }) + .then(async (resp) => { + if (resp !== undefined) { + const savedObjectsForThisVisualization = get( + resp, + 'hits', + [] ); - if ( - maxAssociatedCount <= savedObjectsForThisVisualization.length - ) { - notifications.toasts.addDanger( - `Cannot create the detector and associate it to the visualization due to the limit of the max + if ( + maxAssociatedCount <= + savedObjectsForThisVisualization.length + ) { + notifications.toasts.addDanger( + `Cannot create the detector and associate it to the visualization due to the limit of the max amount of associated plugin resources (${maxAssociatedCount}) with ${savedObjectsForThisVisualization.length} associated to the visualization` - ); - } else { - handleSubmit(formikProps); + ); + } else { + handleSubmit(formikProps); + } } - } - }); + }); } } }); @@ -244,20 +248,21 @@ function AddAnomalyDetector({ useEffect(async () => { // Gets all augmented saved objects - await savedObjectLoader.findAll().then(async (resp) => { - if (resp !== undefined) { - const savedAugmentObjects = get(resp, 'hits', []); - // gets all the saved object for this visualization - const savedObjectsForThisVisualization = savedAugmentObjects.filter( - (savedObj) => get(savedObj, 'visId', '') === embeddable.vis.id - ); - if (maxAssociatedCount <= savedObjectsForThisVisualization.length) { - setAssociationLimitReached(true); - } else { - setAssociationLimitReached(false); + await savedObjectLoader + .findAll('', 100, [], { + type: 'visualization', + id: embeddable.vis.id as string, + }) + .then(async (resp) => { + if (resp !== undefined) { + const savedObjectsForThisVisualization = get(resp, 'hits', []); + if (maxAssociatedCount <= savedObjectsForThisVisualization.length) { + setAssociationLimitReached(true); + } else { + setAssociationLimitReached(false); + } } - } - }); + }); }, []); const getEmbeddableSection = () => {