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

Issue #3311750 by Ryo Yamashita, yas: Refactor to allow flexible configuration...

Issue #3311750 by Ryo Yamashita, yas: Refactor to allow flexible configuration of initial form values in SPA
parent 5979b50e
Loading
Loading
Loading
Loading
+3 −6
Changes for modules/cloud_dashboard/cloud_dashboard/src/constant/form_template/launch_template/aws_cloud.ts: 3 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -82,26 +82,23 @@ const AWS_CLOUD_LAUNCH_TEMPLATE: EntityFormTemplate[] = [
            url: '/cloud_dashboard/aws_cloud/{cloud_context}/aws_cloud_network_interface/subnet_options',
            defaultValue: ''
          },
          // TODO: Check specifications (name key)
          {
            type: 'multi-select', labelName: 'Security groups', name: 'security_groups',
            url: '/cloud_dashboard/aws_cloud/{cloud_context}/aws_cloud_network_interface/security_group_options/{subnet_id}',
            defaultValue: []
            defaultValue: ["{tryNotNull(getValue(aws_cloud_security_group,relationship(field_security_group,drupal_internal__target_id),drupal_internal__id,name),'')}"]
          },
          // TODO: Check specifications (name key)
          {
            type: 'join', labelName: 'SSH key', name: 'ssh_key', info: {
              entityTypeId: 'aws_cloud_key_pair',
              keyColumn: 'key_pair_name',
              label: '{key_pair_name}'
            },
            defaultValue: ''
            defaultValue: "{tryNotNull(getValue(aws_cloud_key_pair,relationship(field_ssh_key,drupal_internal__target_id),drupal_internal__id,key_pair_name),'')}"
          },
          // TODO: Check specifications (name key)
          {
            type: 'select', labelName: 'Network interface', name: 'network_interface_id',
            url: '/cloud_dashboard/aws_cloud/{cloud_context}/aws_cloud_elastic_ip/{entity_id}/unassociated_network_interface_ids',
            defaultValue: ''
            defaultValue: "{tryNotNull(relationship(field_security_group,drupal_internal__target_id), '')}"
          },
        ]
      },
+34 −1
Changes for modules/cloud_dashboard/cloud_dashboard/src/hooks/drupal_jsonapi.ts: 34 added lines, 1 removed line.
Original line number Diff line number Diff line
import { CACHE_EXPIRED_UNIXTIME, FETCH_TIMEOUT_MS } from 'constant/other';
import EntityColumn from 'model/EntityColumn';
import EntityData from 'model/EntityData';
import SortInfo from 'model/SortInfo';
import { useEffect, useState } from 'react';
import { getLocalStorageItem } from 'service/utility';
import { getLocalStorageItem } from 'service/storage';

type CacheType = Record<string, { response: any, unixtime: number }>;
export type GetEntityListAllType = (entityTypeId: string, filter?: { [key: string]: string }, bundleId?: string) => Promise<EntityData[]>;
export type GetJsonDataType = <T>(url: string, filter?: { [key: string]: string; }) => Promise<T>;
export type ReadDataCacheType = (entityColumnList: EntityColumn[]) => Promise<Record<string, EntityData[]>>;

type GetEntityListOption = {
  // Maximum number of data to be retrieved.
@@ -223,11 +225,42 @@ const useDrupalJsonApi = () => {
    return await getJson<T>(downloadUrl);
  }

  /**
   * Read entity's data for convert entity's data by JSON:API.
   *
   * @param entityColumnList Information about the entities that will be loaded in advance.
   * @returns Data cache.
   */
  const readDataCache = async (
    entityColumnList: EntityColumn[]
  ) => {
    const dataCache: Record<string, EntityData[]> = {};
    for (const entityColumn of entityColumnList) {
      switch (entityColumn.type) {
        case 'join': {
          const entityTypeId = entityColumn.info.entityTypeId;
          if (!(entityTypeId in dataCache)) {
            dataCache[entityTypeId] = await getEntityListAll(entityTypeId);
          }
          break;
        }
        case 'relationship':
          const entityTypeId = entityColumn.info.entityTypeId;
          if (!(entityTypeId in dataCache)) {
            dataCache[entityTypeId] = await getEntityListAll(entityTypeId);
          }
          break;
      }
    }
    return dataCache;
  };

  return {
    getEntityList,
    getEntityListAll,
    removeJsonapiServerUri,
    getJsonData,
    readDataCache,
  };
}

+1 −1
Changes for modules/cloud_dashboard/cloud_dashboard/src/hooks/drupal_oauth2.ts: 1 added line, 1 removed line.
Original line number Diff line number Diff line
import { OAUTH2_CLIENT_SECRET, ROUTE_URL } from 'constant/other';
import { useEffect, useState } from 'react';
import { getLocalStorageItem, setLocalStorageItem } from 'service/utility';
import { getLocalStorageItem, setLocalStorageItem } from 'service/storage';

const LOGIN_FORM_URI = ROUTE_URL;
const ENTER_URI = ROUTE_URL + '/providers';
+14 −0
Changes for modules/cloud_dashboard/cloud_dashboard/src/model/ScriptToken.ts: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
type ScriptToken = {
  type: 'keyword' | 'text',
  value: string
} | {
  type: 'right-bracket'
} | {
  type: 'left-bracket'
} | {
  type: 'comma'
} | {
  type: 'null'
}

export default ScriptToken;
+2 −2
Changes for modules/cloud_dashboard/cloud_dashboard/src/molecules/CidrInputBlock.tsx: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
import CidrBlock from 'model/CidrBlock';
import { Button, Col, Form, Row, Table } from 'react-bootstrap';
import { Button, Col, Row, Table } from 'react-bootstrap';
import { BsTrashFill } from 'react-icons/bs';

const StringInput = ({ label, placeholder, value, setValue, readOnly }: {
@@ -94,7 +94,7 @@ const CidrInputBlock = ({ label, value, setValue }: {

  // If there are no cidr objects, initialize a blank one.
  // Otherwise, the "+" and up/down arrows do not show up.
  if (value.length == 0) {
  if (value.length === 0) {
    addCidr(0);
  }

Loading