edit.tsx 908 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import {t} from 'sentry/locale';
  2. import {Rule} from '../types';
  3. import ModalManager from './modalManager';
  4. type ModalManagerProps = ModalManager['props'];
  5. type Props = Omit<ModalManagerProps, 'title' | 'initialValues' | 'onGetNewRules'> & {
  6. rule: Rule;
  7. };
  8. function Edit({savedRules, rule, ...props}: Props) {
  9. const handleGetNewRules = (
  10. values: Parameters<ModalManagerProps['onGetNewRules']>[0]
  11. ) => {
  12. const updatedRule = {...values, id: rule.id};
  13. const newRules = savedRules.map(savedRule => {
  14. if (savedRule.id === updatedRule.id) {
  15. return updatedRule;
  16. }
  17. return savedRule;
  18. }) as Array<Rule>;
  19. return newRules;
  20. };
  21. return (
  22. <ModalManager
  23. {...props}
  24. savedRules={savedRules}
  25. title={t('Edit an advanced data scrubbing rule')}
  26. initialState={rule}
  27. onGetNewRules={handleGetNewRules}
  28. />
  29. );
  30. }
  31. export default Edit;