-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DT-1051] Add identity and reason to Terminate in the UI (#1399)
* Fix extra space if there is no user defined reason * Add Web UI reason to terminate and reset on workflow * Add identity to terminate workflow * Remove workflow and use workflows namespace instead * Refactor reason and placeholder into utils with tests * Fix batch cancel toast translation * Add identity to terminateWorkflows
- Loading branch information
1 parent
6a149d5
commit b320645
Showing
10 changed files
with
207 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,9 @@ export enum ResetReapplyType { | |
Signal = 1, | ||
None = 2, | ||
} | ||
|
||
export enum Action { | ||
Cancel, | ||
Reset, | ||
Terminate, | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { Action } from '../models/workflow-actions'; | ||
import { getPlacholder, formatReason } from './workflow-actions'; | ||
|
||
describe('getPlacholder', () => { | ||
describe('without an authorized user', () => { | ||
it('should return the correct placeholder', () => { | ||
expect(getPlacholder(Action.Cancel)).toEqual('Canceled from the Web UI'); | ||
expect(getPlacholder(Action.Reset)).toEqual('Reset from the Web UI'); | ||
expect(getPlacholder(Action.Terminate)).toEqual( | ||
'Terminated from the Web UI', | ||
); | ||
}); | ||
}); | ||
|
||
describe('with authorized user', () => { | ||
it('should return the correct placeholder', () => { | ||
expect(getPlacholder(Action.Cancel, '[email protected]')).toEqual( | ||
'Canceled from the Web UI by [email protected]', | ||
); | ||
expect(getPlacholder(Action.Reset, '[email protected]')).toEqual( | ||
'Reset from the Web UI by [email protected]', | ||
); | ||
expect(getPlacholder(Action.Terminate, '[email protected]')).toEqual( | ||
'Terminated from the Web UI by [email protected]', | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('formatReason', () => { | ||
describe('without an authorized user', () => { | ||
it('should return the reason with the placeholder', () => { | ||
expect( | ||
formatReason({ action: Action.Cancel, reason: 'Testing' }), | ||
).toEqual('Testing Canceled from the Web UI'); | ||
expect(formatReason({ action: Action.Reset, reason: 'Testing' })).toEqual( | ||
'Testing Reset from the Web UI', | ||
); | ||
expect( | ||
formatReason({ action: Action.Terminate, reason: 'Testing' }), | ||
).toEqual('Testing Terminated from the Web UI'); | ||
}); | ||
}); | ||
|
||
it('should return the placeholder if there is no reason', () => { | ||
const reason = ''; | ||
expect(formatReason({ action: Action.Cancel, reason })).toEqual( | ||
'Canceled from the Web UI', | ||
); | ||
expect(formatReason({ action: Action.Reset, reason })).toEqual( | ||
'Reset from the Web UI', | ||
); | ||
expect(formatReason({ action: Action.Terminate, reason })).toEqual( | ||
'Terminated from the Web UI', | ||
); | ||
}); | ||
|
||
describe('with an authorized user', () => { | ||
it('should return the reason with the placeholder', () => { | ||
const reason = 'Testing'; | ||
|
||
expect( | ||
formatReason({ | ||
action: Action.Cancel, | ||
reason, | ||
email: '[email protected]', | ||
}), | ||
).toEqual('Testing Canceled from the Web UI by [email protected]'); | ||
expect( | ||
formatReason({ | ||
action: Action.Reset, | ||
reason, | ||
email: '[email protected]', | ||
}), | ||
).toEqual('Testing Reset from the Web UI by [email protected]'); | ||
expect( | ||
formatReason({ | ||
action: Action.Terminate, | ||
reason, | ||
email: '[email protected]', | ||
}), | ||
).toEqual('Testing Terminated from the Web UI by [email protected]'); | ||
}); | ||
|
||
it('should return the placeholder if there is no reason', () => { | ||
const reason = ''; | ||
|
||
expect( | ||
formatReason({ | ||
action: Action.Cancel, | ||
reason, | ||
email: '[email protected]', | ||
}), | ||
).toEqual('Canceled from the Web UI by [email protected]'); | ||
expect( | ||
formatReason({ | ||
action: Action.Reset, | ||
reason, | ||
email: '[email protected]', | ||
}), | ||
).toEqual('Reset from the Web UI by [email protected]'); | ||
expect( | ||
formatReason({ | ||
action: Action.Terminate, | ||
reason, | ||
email: '[email protected]', | ||
}), | ||
).toEqual('Terminated from the Web UI by [email protected]'); | ||
}); | ||
}); | ||
}); |
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,50 @@ | ||
import { translate } from '$lib/i18n/translate'; | ||
import { Action } from '$lib/models/workflow-actions'; | ||
|
||
type PastActionText = 'terminated' | 'reset' | 'canceled'; | ||
|
||
function unhandledAction(action: never) { | ||
console.error('Unhandled action:', action); | ||
} | ||
|
||
const getPastTenseActionText = (action: Action): PastActionText => { | ||
switch (action) { | ||
case Action.Cancel: | ||
return 'canceled'; | ||
case Action.Reset: | ||
return 'reset'; | ||
case Action.Terminate: | ||
return 'terminated'; | ||
default: | ||
unhandledAction(action); | ||
} | ||
}; | ||
|
||
export const getPlacholder = (action: Action, email?: string): string => { | ||
const translatedAction = translate( | ||
'workflows', | ||
getPastTenseActionText(action), | ||
); | ||
|
||
return email | ||
? translate('workflows', 'workflow-action-reason-placeholder-with-email', { | ||
action: translatedAction, | ||
email, | ||
}) | ||
: translate('workflows', 'workflow-action-reason-placeholder', { | ||
action: translatedAction, | ||
}); | ||
}; | ||
|
||
export const formatReason = ({ | ||
action, | ||
reason, | ||
email, | ||
}: { | ||
action: Action; | ||
reason: string; | ||
email?: string; | ||
}) => { | ||
const placeholder = getPlacholder(action, email); | ||
return reason ? [reason.trim(), placeholder].join(' ') : placeholder; | ||
}; |
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