Commit 84797041 authored by Ryo Yamashita's avatar Ryo Yamashita Committed by Yas Naoi
Browse files

Issue #3270268 by Ryo Yamashita, yas: Add the function to delete K8s Namespace in the SPA

parent 653cbca4
Loading
Loading
Loading
Loading
+17 −5
Changes for modules/cloud_dashboard/cloud_dashboard/src/molecules/DataTableRowWithOperationLinks.tsx: 17 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -132,10 +132,9 @@ const getOperations = (dataRecord: DataRecord): [string, string][] => {

const editData = (dataRecord: DataRecord) => {
  let urlParts = dataRecord.entityTypeId;
  if (urlParts.startsWith('aws_cloud_')) {
    urlParts = urlParts.replace('aws_cloud_', 'aws_cloud/');
  } else if (urlParts.startsWith('k8s_')) {
    urlParts = urlParts.replace('k8s_', 'k8s/');
  const modules = ['aws_cloud', 'k8s'];
  for (const module of modules) {
    urlParts = urlParts.replace(`${module}_`, `${module}/`);
  }
  window.location.href = `${ROUTE_URL}/${urlParts}/${dataRecord.id}?mode=edit`;
}
@@ -149,6 +148,15 @@ const scaleData = (dataRecord: DataRecord) => {
  window.location.href = `${ROUTE_URL}/${urlParts}/${dataRecord.id}?mode=scale`;
}

const deleteData = (dataRecord: DataRecord) => {
  let urlParts = dataRecord.entityTypeId;
  const modules = ['aws_cloud', 'k8s'];
  for (const module of modules) {
    urlParts = urlParts.replace(`${module}_`, `${module}/`);
  }
  window.location.href = `${ROUTE_URL}/${urlParts}/${dataRecord.id}?mode=delete`;
}

/**
 * Row data of DataTable.
 * Note: The OperationLinks column is added.
@@ -219,7 +227,11 @@ const DataTableRowWithOperationLinks = ({ dataRecord, dataColumnList, className,
          }
          <li role="presentation">
            {/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
            <a role="menuitem" href="#"><GlyphIcon iconName='trash' /> Delete</a>
            <a role="menuitem" href="#" onClick={(e) => {
              e.preventDefault();
              deleteData(dataRecord);
            }}>
              <GlyphIcon iconName='trash' /> Delete</a>
          </li>
        </ul>
      </Button.Group>
+9 −0
Changes for modules/cloud_dashboard/cloud_dashboard/src/pages/EntityInfoPage.tsx: 9 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ import EntityInfoPanel from 'organisms/EntityInfoPanel';
import MenuBar from 'organisms/MenuBar';
import K8sDeploymentScalePage from 'pages/k8s/K8sDeploymentScalePage';
import K8sEntityEditPage from 'pages/k8s/K8sEntityEditPage';
import K8sNamespaceDeletePage from 'pages/k8s/K8sNamespaceDeletePage';
import K8sNamespaceEditPage from 'pages/k8s/K8sNamespaceEditPage';
import K8sPodEditPage from 'pages/k8s/K8sPodEditPage';
import K8sScheduleEditPage from 'pages/k8s/K8sScheduleEditPage';
@@ -199,6 +200,14 @@ const EntityInfoPage = ({ entityInfoTemplate }: {
    && entityInfoTemplate.entityName === 'deployment') {
      return <K8sDeploymentScalePage entityInfoTemplate={entityInfoTemplate} />;
  }
  if (params.has('mode')
    && params.get('mode') === 'delete'
    && entityInfoTemplate.cloudServiceProvider === 'k8s') {
    switch (entityInfoTemplate.entityName) {
      case 'namespace':
        return <K8sNamespaceDeletePage entityInfoTemplate={entityInfoTemplate} />;
    }
  }

  return <FluidContainer className="px-0">
    <Row className="mx-0">
+53 −0
Changes for modules/cloud_dashboard/cloud_dashboard/src/pages/k8s/K8sNamespaceDeletePage.tsx: 53 added lines, 0 removed lines.
Original line number Diff line number Diff line
import Button from 'bootstrap3-components/Button';
import Col from 'bootstrap3-components/Col';
import FluidContainer from 'bootstrap3-components/FluidContainer';
import Form from 'bootstrap3-components/Form';
import GlyphIcon from 'bootstrap3-components/GlyphIcon';
import Row from 'bootstrap3-components/Row';
import EntityInfoTemplate from 'model/EntityInfoTemplate';
import MenuBar from 'organisms/MenuBar';
import LoadingEntityDataPage from 'pages/LoadingEntityDataPage';
import { useTranslation } from 'react-i18next';
import { useEntityData } from 'service/state';

/**
 * Page of entity info editor.
 *
 * @param entityInfoTemplate Template for viewing this entity data.
 */
const K8sNamespaceEditPage = ({ entityInfoTemplate }: {
  entityInfoTemplate: EntityInfoTemplate
}) => {

  const { entityData, cxud } = useEntityData(entityInfoTemplate);
  const { t } = useTranslation();

  return entityData === null
    ? <LoadingEntityDataPage />
    : <>
      <MenuBar />
      <FluidContainer className="px-0">
        <Row className="mx-0">
          <Col>
            <Form>
              <Form.Group>
                <Form.Label>Are you sure you want to delete the "{entityData.attributes['name']}" namespace?<br/>CAUTION: The role "{entityData.attributes['name']}" is also going to be deleted.</Form.Label>
              </Form.Group>
              <Button className="icon-before btn-success" onClick={() => {
                cxud({
                  'k8s_namespace': entityData.attributes['drupal_internal__id'],
                }, 'delete');
              }}>
                <GlyphIcon iconName="trash" />{' ' + t('Delete')}
              </Button>
              {/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
              <a href="#" className="button button--danger">{t('Cancel')}</a>
            </Form>
          </Col>
        </Row>
      </FluidContainer>
    </>;

}

export default K8sNamespaceEditPage;
+26 −0
Changes for modules/cloud_service_providers/k8s/src/Controller/ApiController.php: 26 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1023,4 +1023,30 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
    ], 500);
  }

  /**
   * {@inheritdoc}
   */
  public function deleteNamespace(Request $request, string $cloud_context, string $k8s_namespace): JsonResponse {
    $entity = $this->entityTypeManager
      ->getStorage('k8s_namespace')
      ->load($k8s_namespace);

    $service = new K8sOperationsService(
      $this->k8sService,
      $this->cloudService,
      $this->cloudConfigPluginManager
    );

    $result = $service->deleteNamespace($entity);

    return !empty($result)
    ? new JsonResponse([
      'result' => 'OK',
    ], 200)
    : new JsonResponse([
      'result' => 'NG',
      'reason' => 'Internal Server Error',
    ], 500);
  }

}
+15 −0
Changes for modules/cloud_service_providers/k8s/src/Controller/ApiControllerInterface.php: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -555,4 +555,19 @@ interface ApiControllerInterface {
   */
  public function scaleDeployment(Request $request, string $cloud_context): JsonResponse;

  /**
   * Delete K8s Namespace.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   Request.
   * @param string $cloud_context
   *   Cloud context string.
   * @param string $k8s_namespace
   *   The K8s Namespace.
   *
   * @return \Symfony\Component\HttpFoundation\JsonResponse
   *   The JSON response.
   */
  public function deleteNamespace(Request $request, string $cloud_context, string $k8s_namespace): JsonResponse;

}
Loading