Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bulk update separation #356

Merged
merged 9 commits into from
Apr 17, 2023
Merged

Conversation

derek-ho
Copy link
Collaborator

@derek-ho derek-ho commented Apr 14, 2023

Description

Delete fixed (minus toast for delete and rename), separate out bulk update for event analytics add viz to operational panel flow. Still need to do bulk update for SO to add new and old viz

Issues Resolved

[List any issues this PR will resolve]

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Derek Ho <dxho@amazon.com>
Signed-off-by: Derek Ho <dxho@amazon.com>
Signed-off-by: Derek Ho <dxho@amazon.com>
Signed-off-by: Derek Ho <dxho@amazon.com>
@@ -46,9 +46,12 @@ export class SaveAsCurrentVisualization extends SavedQuerySaver {
}

addToPanel({ selectedPanels, saveTitle, notifications, visId }) {
const uuidRx = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/;
const soPanels = selectedPanels.filter((id) => id.panel.id.match(uuidRx));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate and unused variable?

@@ -46,9 +46,12 @@ export class SaveAsCurrentVisualization extends SavedQuerySaver {
}

addToPanel({ selectedPanels, saveTitle, notifications, visId }) {
const uuidRx = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/;
const soPanels = selectedPanels.filter((id) => id.panel.id.match(uuidRx));
const opsPanels = selectedPanels.filter((id) => !id.panel.id.match(uuidRx));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • use uuidRx.test(id.panel.id)
  • id variable name is not accurate
  • i'm not sure if the logic should be here, e.g. what happens to panels in .observability index? save_as_current_vis don't support them anymore?
  • not sure if it helps but you can check .observability and .kibana visualizations handling here as reference, for example bulk delete
    /**
    * Delete a list of objects. Assumes object is osd visualization if id is a
    * UUID. Rest and failed ids will then be deleted by PPL client.
    *
    * @param params - SavedObjectsDeleteBulkParams
    * @returns SavedObjectsDeleteResponse
    */
    static async deleteBulk(
    params: SavedObjectsDeleteBulkParams
    ): Promise<SavedObjectsDeleteResponse> {
    const idMap = params.objectIdList.reduce((prev, id) => {
    const type = OSDSavedObjectClient.extractType(id);
    const key = type === '' ? 'non_osd' : type;
    return { ...prev, [key]: [...(prev[key] || []), id] };
    }, {} as { [k in 'non_osd' | ObservabilitySavedObjectsType]: string[] });

@@ -76,9 +76,12 @@ export class SaveAsNewVisualization extends SavedQuerySaver {
}

addToPanel({ selectedPanels, saveTitle, notifications, visId }) {
const uuidRx = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar comments and probably define regex globally

…vability into bulk-update

Signed-off-by: Derek Ho <dxho@amazon.com>
Signed-off-by: Derek Ho <dxho@amazon.com>
Signed-off-by: Derek Ho <dxho@amazon.com>
Signed-off-by: Derek Ho <dxho@amazon.com>

const allVisualizations = panel!.visualizations;

const visualizationsWithNewPanel = addVisualizationPanel(vizId, undefined, allVisualizations);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ps48 @joshuali925 can you verify this line makes sense? Since we want to add a viz to panel as a new one, pass in undefined into this function:

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is correct for adding panels to a visualization. For replace workflow, you can use the same function and pass OldVisualizationId.

@@ -58,7 +58,7 @@ export const addVisualizationPanel = (
// client: ILegacyScopedClusterClient,
// panelId: string,
savedVisualizationId: string,
oldVisualizationId?: string,
oldVisualizationId: string | undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought var?: string meant string | undefined exactly?
I've even "fixed" my own bugs many times with the ? syntax.

Thuoghts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe... I think what it is doing is makes it optional, which it cannot be since a required parameter comes after. This gets rid of it but maybe the more right thing is to put it at the end...

@@ -358,7 +356,7 @@ export const Home = ({
chrome={chrome}
parentBreadcrumbs={customPanelBreadCrumbs}
cloneCustomPanel={cloneCustomPanel}
deleteCustomPanel={deleteCustomPanel}
deleteCustomPanel={deleteCustomPanelSO}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete savedobject should be in panel_slice. Therefore, we should collapse a reference and just call dispatch(deletePanel) (or whatever) directly from <CustomPanelViewSO>. Dont' pass it in.

We're trying to eliminate all prop-drilling, especially functions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can modify this in a follow up PR

@@ -76,9 +83,14 @@ export class SaveAsNewVisualization extends SavedQuerySaver {
}

addToPanel({ selectedPanels, saveTitle, notifications, visId }) {
const { dispatch } = this.dispatchers;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider context here, as well as SRP-SingleResponsibilityPrinciple.

Wer are inside "saved_objects/saved_object_savers".... This, despite it's name, is the Observability index re-invention of saved objects.
We don't want to add any code here. This whole module will (eventually) be deprecated/removed.

Also, wrt. SRP, although "saving things" sounds like a single responsibliity, we can see from the code that saving to SavedObject-Core (via Redux/Dispatch) is very different from using SavedObjectSavers.
These are different responsibilities.

Recommendation :
Lift the filter/split of saved-object (UUID) and Observability (non-UUID) out of this method. Pass the non-UUID into this method, and specifically call dispatch from the caller (which is a component, which is insdie React context, which has correct context for useDispatch() ). This will also remove the prop-drilling of "dispatchers".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can see from the code that saving to SavedObject-Core (via Redux/Dispatch) is very different from using SavedObjectSavers

Why does this happen? I didn't look into impl details but essentially the difference between saving SO vs. observability object is the client. If the client can be abstracted, then the same operation should work for both cases

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshuali925 @pjfitzgibbons can we merge this in as is? I understand it may not be right but theres a few other p0 items today, once we make the final go-no go call I can refactor to be correct

@derek-ho derek-ho merged commit b0a87fc into opensearch-project:main Apr 17, 2023
pjfitzgibbons pushed a commit that referenced this pull request Apr 18, 2023
* bulk update separation

Signed-off-by: Derek Ho <dxho@amazon.com>

* fix up pr

Signed-off-by: Derek Ho <dxho@amazon.com>

* individual panel delete SO

Signed-off-by: Derek Ho <dxho@amazon.com>

* also separate out on newly created ones

Signed-off-by: Derek Ho <dxho@amazon.com>

* resolve pr comments

Signed-off-by: Derek Ho <dxho@amazon.com>

* bulk update new so panels

Signed-off-by: Derek Ho <dxho@amazon.com>

* fix PR

Signed-off-by: Derek Ho <dxho@amazon.com>

---------

Signed-off-by: Derek Ho <dxho@amazon.com>

(cherry picked from commit b0a87fc)
Signed-off-by: Peter Fitzgibbons <pjfitz@amazon.com>
joshuali925 pushed a commit to joshuali925/dashboards-observability that referenced this pull request Apr 18, 2023
* bulk update separation

Signed-off-by: Derek Ho <dxho@amazon.com>

* fix up pr

Signed-off-by: Derek Ho <dxho@amazon.com>

* individual panel delete SO

Signed-off-by: Derek Ho <dxho@amazon.com>

* also separate out on newly created ones

Signed-off-by: Derek Ho <dxho@amazon.com>

* resolve pr comments

Signed-off-by: Derek Ho <dxho@amazon.com>

* bulk update new so panels

Signed-off-by: Derek Ho <dxho@amazon.com>

* fix PR

Signed-off-by: Derek Ho <dxho@amazon.com>

---------

Signed-off-by: Derek Ho <dxho@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants