X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/8695e9d621330e691fbcc4bbc1d600d91bae2ac6..cc72c29b709759a4498ad232e3f0374e857c7a62:/src/store/advanced-tab/advanced-tab.ts diff --git a/src/store/advanced-tab/advanced-tab.ts b/src/store/advanced-tab/advanced-tab.ts index c48011d2..d9dabe5c 100644 --- a/src/store/advanced-tab/advanced-tab.ts +++ b/src/store/advanced-tab/advanced-tab.ts @@ -16,14 +16,18 @@ import { ServiceRepository } from '~/services/services'; import { FilterBuilder } from '~/services/api/filter-builder'; import { RepositoryResource } from '~/models/repositories'; import { SshKeyResource } from '~/models/ssh-key'; +import { VirtualMachinesResource } from '~/models/virtual-machines'; +import { UserResource } from '~/models/user'; +import { ListResults } from '~/services/common-service/common-resource-service'; +import { LinkResource } from '~/models/link'; import { KeepServiceResource } from '~/models/keep-services'; export const ADVANCED_TAB_DIALOG = 'advancedTabDialog'; interface AdvancedTabDialogData { apiResponse: any; - metadata: any; - user: string; + metadata: ListResults | string; + user: UserResource | string; pythonHeader: string; pythonExample: string; cliGetHeader: string; @@ -55,50 +59,137 @@ enum RepositoryData { } enum SshKeyData { - SSH_KEY = 'authorized_keys', + SSH_KEY = 'authorized_key', CREATED_AT = 'created_at' } +enum VirtualMachineData { + VIRTUAL_MACHINE = 'virtual_machine', + CREATED_AT = 'created_at' +} + +enum ResourcePrefix { + REPOSITORIES = 'repositories', + AUTORIZED_KEYS = 'authorized_keys', + VIRTUAL_MACHINES = 'virtual_machines', + KEEP_SERVICES = 'keep_services' +} + enum KeepServiceData { KEEP_SERVICE = 'keep_services', CREATED_AT = 'created_at' } -type AdvanceResourceKind = CollectionData | ProcessData | ProjectData | RepositoryData | SshKeyData | KeepServiceData; -type AdvanceResourcePrefix = GroupContentsResourcePrefix | 'repositories' | 'authorized_keys' | 'keep_services'; +type AdvanceResourceKind = CollectionData | ProcessData | ProjectData | RepositoryData | SshKeyData | VirtualMachineData | KeepServiceData; +type AdvanceResourcePrefix = GroupContentsResourcePrefix | ResourcePrefix; -export const openAdvancedTabDialog = (uuid: string, index?: number) => +export const openAdvancedTabDialog = (uuid: string) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const kind = extractUuidKind(uuid); switch (kind) { case ResourceKind.COLLECTION: const { data: dataCollection, metadata: metaCollection, user: userCollection } = await dispatch(getDataForAdvancedTab(uuid)); - const advanceDataCollection: AdvancedTabDialogData = advancedTabData(uuid, metaCollection, userCollection, collectionApiResponse, dataCollection, CollectionData.COLLECTION, GroupContentsResourcePrefix.COLLECTION, CollectionData.STORAGE_CLASSES_CONFIRMED, dataCollection.storageClassesConfirmed); + const advanceDataCollection: AdvancedTabDialogData = advancedTabData({ + uuid, + metadata: metaCollection, + user: userCollection, + apiResponseKind: collectionApiResponse, + data: dataCollection, + resourceKind: CollectionData.COLLECTION, + resourcePrefix: GroupContentsResourcePrefix.COLLECTION, + resourceKindProperty: CollectionData.STORAGE_CLASSES_CONFIRMED, + property: dataCollection.storageClassesConfirmed + }); dispatch(initAdvancedTabDialog(advanceDataCollection)); break; case ResourceKind.PROCESS: const { data: dataProcess, metadata: metaProcess, user: userProcess } = await dispatch(getDataForAdvancedTab(uuid)); - const advancedDataProcess: AdvancedTabDialogData = advancedTabData(uuid, metaProcess, userProcess, containerRequestApiResponse, dataProcess, ProcessData.CONTAINER_REQUEST, GroupContentsResourcePrefix.PROCESS, ProcessData.OUTPUT_NAME, dataProcess.outputName); + const advancedDataProcess: AdvancedTabDialogData = advancedTabData({ + uuid, + metadata: metaProcess, + user: userProcess, + apiResponseKind: containerRequestApiResponse, + data: dataProcess, + resourceKind: ProcessData.CONTAINER_REQUEST, + resourcePrefix: GroupContentsResourcePrefix.PROCESS, + resourceKindProperty: ProcessData.OUTPUT_NAME, + property: dataProcess.outputName + }); dispatch(initAdvancedTabDialog(advancedDataProcess)); break; case ResourceKind.PROJECT: const { data: dataProject, metadata: metaProject, user: userProject } = await dispatch(getDataForAdvancedTab(uuid)); - const advanceDataProject: AdvancedTabDialogData = advancedTabData(uuid, metaProject, userProject, groupRequestApiResponse, dataProject, ProjectData.GROUP, GroupContentsResourcePrefix.PROJECT, ProjectData.DELETE_AT, dataProject.deleteAt); + const advanceDataProject: AdvancedTabDialogData = advancedTabData({ + uuid, + metadata: metaProject, + user: userProject, + apiResponseKind: groupRequestApiResponse, + data: dataProject, + resourceKind: ProjectData.GROUP, + resourcePrefix: GroupContentsResourcePrefix.PROJECT, + resourceKindProperty: ProjectData.DELETE_AT, + property: dataProject.deleteAt + }); dispatch(initAdvancedTabDialog(advanceDataProject)); break; case ResourceKind.REPOSITORY: - const dataRepository = getState().repositories.items[index!]; - const advanceDataRepository: AdvancedTabDialogData = advancedTabData(uuid, '', '', repositoryApiResponse, dataRepository, RepositoryData.REPOSITORY, 'repositories', RepositoryData.CREATED_AT, dataRepository.createdAt); + const dataRepository = getState().repositories.items.find(it => it.uuid === uuid); + const advanceDataRepository: AdvancedTabDialogData = advancedTabData({ + uuid, + metadata: '', + user: '', + apiResponseKind: repositoryApiResponse, + data: dataRepository, + resourceKind: RepositoryData.REPOSITORY, + resourcePrefix: ResourcePrefix.REPOSITORIES, + resourceKindProperty: RepositoryData.CREATED_AT, + property: dataRepository!.createdAt + }); dispatch(initAdvancedTabDialog(advanceDataRepository)); break; case ResourceKind.SSH_KEY: - const dataSshKey = getState().auth.sshKeys[index!]; - const advanceDataSshKey: AdvancedTabDialogData = advancedTabData(uuid, '', '', sshKeyApiResponse, dataSshKey, SshKeyData.SSH_KEY, 'authorized_keys', SshKeyData.CREATED_AT, dataSshKey.createdAt); + const dataSshKey = getState().auth.sshKeys.find(it => it.uuid === uuid); + const advanceDataSshKey: AdvancedTabDialogData = advancedTabData({ + uuid, + metadata: '', + user: '', + apiResponseKind: sshKeyApiResponse, + data: dataSshKey, + resourceKind: SshKeyData.SSH_KEY, + resourcePrefix: ResourcePrefix.AUTORIZED_KEYS, + resourceKindProperty: SshKeyData.CREATED_AT, + property: dataSshKey!.createdAt + }); dispatch(initAdvancedTabDialog(advanceDataSshKey)); break; + case ResourceKind.VIRTUAL_MACHINE: + const dataVirtualMachine = getState().virtualMachines.virtualMachines.items.find(it => it.uuid === uuid); + const advanceDataVirtualMachine: AdvancedTabDialogData = advancedTabData({ + uuid, + metadata: '', + user: '', + apiResponseKind: virtualMachineApiResponse, + data: dataVirtualMachine, + resourceKind: VirtualMachineData.VIRTUAL_MACHINE, + resourcePrefix: ResourcePrefix.VIRTUAL_MACHINES, + resourceKindProperty: VirtualMachineData.CREATED_AT, + property: dataVirtualMachine.createdAt + }); + dispatch(initAdvancedTabDialog(advanceDataVirtualMachine)); + break; case ResourceKind.KEEP_SERVICE: - const dataKeepService = getState().keepServices[index!]; - const advanceDataKeepService: AdvancedTabDialogData = advancedTabData(uuid, '', '', keepServiceApiResponse, dataKeepService, KeepServiceData.KEEP_SERVICE, 'keep_services', KeepServiceData.CREATED_AT, dataKeepService.createdAt); + const dataKeepService = getState().keepServices.find(it => it.uuid === uuid); + const advanceDataKeepService: AdvancedTabDialogData = advancedTabData({ + uuid, + metadata: '', + user: '', + apiResponseKind: keepServiceApiResponse, + data: dataKeepService, + resourceKind: KeepServiceData.KEEP_SERVICE, + resourcePrefix: ResourcePrefix.KEEP_SERVICES, + resourceKindProperty: KeepServiceData.CREATED_AT, + property: dataKeepService!.createdAt + }); dispatch(initAdvancedTabDialog(advanceDataKeepService)); break; default: @@ -121,21 +212,23 @@ const getDataForAdvancedTab = (uuid: string) => const initAdvancedTabDialog = (data: AdvancedTabDialogData) => dialogActions.OPEN_DIALOG({ id: ADVANCED_TAB_DIALOG, data }); -const advancedTabData = (uuid: string, metadata: any, user: any, apiResponseKind: any, data: any, resourceKind: AdvanceResourceKind, - resourcePrefix: AdvanceResourcePrefix, resourceKindProperty: AdvanceResourceKind, property: any) => { +const advancedTabData = (args: { + uuid: string, metadata: ListResults | string, user: UserResource | string, apiResponseKind: any, data: any, resourceKind: AdvanceResourceKind, + resourcePrefix: AdvanceResourcePrefix, resourceKindProperty: AdvanceResourceKind, property: any +}) => { return { - uuid, - user, - metadata, - apiResponse: apiResponseKind(data), - pythonHeader: pythonHeader(resourceKind), - pythonExample: pythonExample(uuid, resourcePrefix), - cliGetHeader: cliGetHeader(resourceKind), - cliGetExample: cliGetExample(uuid, resourceKind), - cliUpdateHeader: cliUpdateHeader(resourceKind, resourceKindProperty), - cliUpdateExample: cliUpdateExample(uuid, resourceKind, property, resourceKindProperty), - curlHeader: curlHeader(resourceKind, resourceKindProperty), - curlExample: curlExample(uuid, resourcePrefix, property, resourceKind, resourceKindProperty), + uuid: args.uuid, + user: args.user, + metadata: args.metadata, + apiResponse: args.apiResponseKind(args.data), + pythonHeader: pythonHeader(args.resourceKind), + pythonExample: pythonExample(args.uuid, args.resourcePrefix), + cliGetHeader: cliGetHeader(args.resourceKind), + cliGetExample: cliGetExample(args.uuid, args.resourceKind), + cliUpdateHeader: cliUpdateHeader(args.resourceKind, args.resourceKindProperty), + cliUpdateExample: cliUpdateExample(args.uuid, args.resourceKind, args.property, args.resourceKindProperty), + curlHeader: curlHeader(args.resourceKind, args.resourceKindProperty), + curlExample: curlExample(args.uuid, args.resourcePrefix, args.property, args.resourceKind, args.resourceKindProperty), }; }; @@ -306,6 +399,20 @@ const sshKeyApiResponse = (apiResponse: SshKeyResource) => { return response; }; +const virtualMachineApiResponse = (apiResponse: VirtualMachinesResource) => { + const { uuid, ownerUuid, createdAt, modifiedAt, modifiedByClientUuid, modifiedByUserUuid, hostname } = apiResponse; + const response = `"hostname": ${stringify(hostname)}, +"uuid": "${uuid}", +"owner_uuid": "${ownerUuid}", +"modified_by_client_uuid": ${stringify(modifiedByClientUuid)}, +"modified_by_user_uuid": ${stringify(modifiedByUserUuid)}, +"modified_at": ${stringify(modifiedAt)}, +"modified_at": ${stringify(modifiedAt)}, +"created_at": "${createdAt}"`; + + return response; +}; + const keepServiceApiResponse = (apiResponse: KeepServiceResource) => { const { uuid, readOnly, serviceHost, servicePort, serviceSslFlag, serviceType,