fix: fixed delete for additional video url fields in video editor (#2470)

This commit is contained in:
vladislavkeblysh
2025-10-15 19:47:03 +03:00
committed by GitHub
parent 9c0b545b2f
commit 411d4f053c
3 changed files with 8 additions and 10 deletions

View File

@@ -39,16 +39,14 @@ export const sourceHooks = ({ dispatch, previousVideoId, setAlert }) => ({
export const fallbackHooks = ({ fallbackVideos, dispatch }) => ({
addFallbackVideo: () => dispatch(actions.video.updateField({ fallbackVideos: [...fallbackVideos, ''] })),
/**
* Deletes the first occurrence of the given videoUrl from the fallbackVideos list
* @param {string} videoUrl - the video URL to delete
*/
deleteFallbackVideo: (videoUrl) => {
const index = fallbackVideos.findIndex(video => video === videoUrl);
const updatedFallbackVideos = [
...fallbackVideos.slice(0, index),
...fallbackVideos.slice(index + 1),
];
deleteFallbackVideo: (videoIndex) => {
const updatedFallbackVideos = fallbackVideos.toSpliced(videoIndex, 1);
dispatch(actions.video.updateField({ fallbackVideos: updatedFallbackVideos }));
},
});

View File

@@ -98,7 +98,8 @@ const VideoSourceWidget = () => {
<FormattedMessage {...messages.fallbackVideoMessage} />
</div>
{fallbackVideos.formValue.length > 0 ? fallbackVideos.formValue.map((videoUrl, index) => (
<Form.Row className="mt-3.5 mx-0 flex-nowrap">
// eslint-disable-next-line react/no-array-index-key
<Form.Row className="mt-3.5 mx-0 flex-nowrap" key={`${index}-${videoUrl}`}>
<Form.Group>
<Form.Control
floatingLabel={intl.formatMessage(messages.fallbackVideoLabel)}
@@ -107,13 +108,12 @@ const VideoSourceWidget = () => {
onBlur={fallbackVideos.onBlur(index)}
/>
<IconButtonWithTooltip
key={`top-delete-${videoUrl}`}
tooltipPlacement="top"
tooltipContent={intl.formatMessage(messages.deleteFallbackVideo)}
src={DeleteOutline}
iconAs={Icon}
alt={intl.formatMessage(messages.deleteFallbackVideo)}
onClick={() => deleteFallbackVideo(videoUrl)}
onClick={() => deleteFallbackVideo(index)}
/>
</Form.Group>
</Form.Row>

View File

@@ -150,7 +150,7 @@ describe('VideoSourceWidget', () => {
expect(screen.getAllByText('Video URL').length).toBe(3); // 1 main + 2 fallback
const deleteButtons = screen.getAllByRole('button', { name: /delete/i });
fireEvent.click(deleteButtons[0]);
expect(deleteFallbackVideo).toHaveBeenCalledWith('url1');
expect(deleteFallbackVideo).toHaveBeenCalledWith(0);
});
it('calls addFallbackVideo when add button is clicked', () => {