-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: abbyhu2000 <[email protected]>
- Loading branch information
1 parent
d61c5af
commit 202acd0
Showing
2 changed files
with
35 additions
and
29 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
33 changes: 33 additions & 0 deletions
33
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,33 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { useTypedSelector } from '../state_management'; | ||
|
||
export const useCanSave = () => { | ||
let errorMsg = ''; | ||
const isEmpty = useTypedSelector( | ||
(state) => state.visualization.activeVisualization?.aggConfigParams?.length === 0 | ||
); | ||
const hasChange = useTypedSelector((state) => state.metadata.editorState.state === 'dirty'); | ||
const hasDraftAgg = useTypedSelector( | ||
(state) => !!state.visualization.activeVisualization?.draftAgg | ||
); | ||
|
||
// TODO: Need to finalize the error messages | ||
if (isEmpty) { | ||
errorMsg = 'The canvas is empty. Add some aggregations before saving.'; | ||
} else if (!hasChange) { | ||
errorMsg = 'Add some changes before saving.'; | ||
} else if (hasDraftAgg) { | ||
errorMsg = 'Has unapplied aggregations changes, update them before saving.'; | ||
} else { | ||
errorMsg = ''; | ||
} | ||
|
||
return { | ||
canSave: !isEmpty && hasChange && !hasDraftAgg, | ||
errorMsg, | ||
}; | ||
}; |