| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | |
| 8 | import type { |
| 9 | ApplyUncommittedChangesPreviewsFuncType, |
| 10 | UncommittedChangesPreviewContext, |
| 11 | } from '../previews'; |
| 12 | import type {RepoRelativePath, UncommittedChanges} from '../types'; |
| 13 | |
| 14 | import {Operation} from './Operation'; |
| 15 | |
| 16 | export class ForgetOperation extends Operation { |
| 17 | constructor(private filePath: RepoRelativePath) { |
| 18 | super('ForgetOperation'); |
| 19 | } |
| 20 | |
| 21 | static opName = 'Forget'; |
| 22 | |
| 23 | getArgs() { |
| 24 | return [ |
| 25 | 'forget', |
| 26 | { |
| 27 | type: 'repo-relative-file' as const, |
| 28 | path: this.filePath, |
| 29 | }, |
| 30 | ]; |
| 31 | } |
| 32 | |
| 33 | makeOptimisticUncommittedChangesApplier?( |
| 34 | context: UncommittedChangesPreviewContext, |
| 35 | ): ApplyUncommittedChangesPreviewsFuncType | undefined { |
| 36 | if ( |
| 37 | context.uncommittedChanges.some( |
| 38 | change => change.path === this.filePath && change.status === '?', |
| 39 | ) |
| 40 | ) { |
| 41 | return undefined; |
| 42 | } |
| 43 | |
| 44 | const func: ApplyUncommittedChangesPreviewsFuncType = (changes: UncommittedChanges) => { |
| 45 | return changes.map(change => |
| 46 | change.path === this.filePath ? {path: change.path, status: '?'} : change, |
| 47 | ); |
| 48 | }; |
| 49 | return func; |
| 50 | } |
| 51 | } |
| 52 | |