go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/src/build/legacy/build_page/overview_tab/actions_section.tsx (about)

     1  // Copyright 2023 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  import { Button } from '@mui/material';
    16  import { observer } from 'mobx-react-lite';
    17  
    18  import { useStore } from '@/common/store';
    19  
    20  export const enum Dialog {
    21    None,
    22    CancelBuild,
    23    RetryBuild,
    24  }
    25  
    26  export interface ActionsSectionProps {
    27    openDialog: (dialog: Dialog) => void;
    28  }
    29  
    30  export const ActionsSection = observer(
    31    ({ openDialog }: ActionsSectionProps) => {
    32      const store = useStore();
    33      const build = store.buildPage.build;
    34  
    35      if (!build) {
    36        return <></>;
    37      }
    38  
    39      const canRetry = store.buildPage.canRetry;
    40  
    41      if (build.endTime) {
    42        return (
    43          <>
    44            <h3>Actions</h3>
    45            <div
    46              title={
    47                canRetry ? '' : 'You have no permission to retry this build.'
    48              }
    49            >
    50              <Button
    51                onClick={() => openDialog(Dialog.RetryBuild)}
    52                disabled={!canRetry}
    53              >
    54                Retry Build
    55              </Button>
    56            </div>
    57          </>
    58        );
    59      }
    60  
    61      const canCancel = build.cancelTime === null && store.buildPage.canCancel;
    62      let tooltip = '';
    63      if (!canCancel) {
    64        tooltip =
    65          build.cancelTime === null
    66            ? 'You have no permission to cancel this build.'
    67            : 'The build is already scheduled to be canceled.';
    68      }
    69  
    70      return (
    71        <>
    72          <h3>Actions</h3>
    73          <div title={tooltip}>
    74            <Button
    75              onClick={() => openDialog(Dialog.CancelBuild)}
    76              disabled={!canCancel}
    77            >
    78              Cancel Build
    79            </Button>
    80          </div>
    81        </>
    82      );
    83    },
    84  );