-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use metadata slice to save if the visualization is savable or not. Disable the save button if not and show error messages. Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com> * Add some comments about store subscriber and editor state Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com> * create a seperate use_can_save hook Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com> Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com> Co-authored-by: Ashwin P Chandran <ashwinpc@amazon.com>
- Loading branch information
1 parent
730a75a
commit 65005be
Showing
8 changed files
with
127 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/plugins/wizard/public/application/utils/use/use_can_save.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { useTypedSelector } from '../state_management'; | ||
|
||
export const useCanSave = () => { | ||
const isEmpty = useTypedSelector( | ||
(state) => state.visualization.activeVisualization?.aggConfigParams?.length === 0 | ||
); | ||
const hasNoChange = useTypedSelector((state) => state.metadata.editor.state !== 'dirty'); | ||
const hasDraftAgg = useTypedSelector( | ||
(state) => !!state.visualization.activeVisualization?.draftAgg | ||
); | ||
const errorMsg = getErrorMsg(isEmpty, hasNoChange, hasDraftAgg); | ||
|
||
return errorMsg; | ||
}; | ||
|
||
// TODO: Need to finalize the error messages | ||
const getErrorMsg = (isEmpty, hasNoChange, hasDraftAgg) => { | ||
if (isEmpty) { | ||
return 'The canvas is empty. Add some aggregations before saving.'; | ||
} else if (hasNoChange) { | ||
return 'Add some changes before saving.'; | ||
} else if (hasDraftAgg) { | ||
return 'Has unapplied aggregations changes, update them before saving.'; | ||
} else { | ||
return undefined; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters