From 2a56900e3e764b4c1c418b1087cd8bd93e7502fd Mon Sep 17 00:00:00 2001 From: Pawel Kowalczyk Date: Fri, 26 Oct 2018 10:16:43 +0200 Subject: [PATCH] api response init Feature #13969 Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk --- src/store/advanced-tab/advanced-tab.ts | 160 +++++++++++++++--- src/store/resources/resources.ts | 2 +- .../advanced-tab-dialog.tsx | 78 ++++----- 3 files changed, 178 insertions(+), 62 deletions(-) diff --git a/src/store/advanced-tab/advanced-tab.ts b/src/store/advanced-tab/advanced-tab.ts index ecbd3448..e525d102 100644 --- a/src/store/advanced-tab/advanced-tab.ts +++ b/src/store/advanced-tab/advanced-tab.ts @@ -5,20 +5,23 @@ import { dialogActions } from '~/store/dialog/dialog-actions'; import { RootState } from '~/store/store'; import { Dispatch } from 'redux'; -import { ResourceKind, extractUuidKind } from '~/models/resource'; +import { ResourceKind, extractUuidKind, Resource } from '~/models/resource'; import { getResource } from '~/store/resources/resources'; import { GroupContentsResourcePrefix } from '~/services/groups-service/groups-service'; import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions'; +import { ContainerRequestResource } from '~/models/container-request'; +import { CollectionResource } from '~/models/collection'; export const ADVANCED_TAB_DIALOG = 'advancedTabDialog'; export interface AdvancedTabDialogData { + apiResponse: any; pythonHeader: string; pythonExample: string; - CLIGetHeader: string; - CLIGetExample: string; - CLIUpdateHeader: string; - CLIUpdateExample: string; + cliGetHeader: string; + cliGetExample: string; + cliUpdateHeader: string; + cliUpdateExample: string; curlHeader: string; curlExample: string; } @@ -38,44 +41,54 @@ enum ProjectData { DELETE_AT = 'delete_at' } +interface AdvancedData extends Resource { + storageClassesConfirmed: string[]; + outputName: string; + deleteAt: string; +} + export const openAdvancedTabDialog = (uuid: string) => (dispatch: Dispatch, getState: () => RootState) => { const { resources } = getState(); const kind = extractUuidKind(uuid); - const data = getResource(uuid)(resources); + const data = getResource(uuid)(resources); if (data) { + console.log(data); if (kind === ResourceKind.COLLECTION) { const dataCollection: AdvancedTabDialogData = { + apiResponse: collectionApiResponse(data), pythonHeader: pythonHeader(CollectionData.COLLECTION), pythonExample: pythonExample(data.uuid, GroupContentsResourcePrefix.COLLECTION), - CLIGetHeader: CLIGetHeader(CollectionData.COLLECTION), - CLIGetExample: CLIGetExample(data.uuid, GroupContentsResourcePrefix.COLLECTION), - CLIUpdateHeader: CLIUpdateHeader(CollectionData.COLLECTION, CollectionData.STORAGE_CLASSES_CONFIRMED), - CLIUpdateExample: CLIUpdateExample(data.uuid, CollectionData.COLLECTION, data.storageClassesConfirmed, CollectionData.STORAGE_CLASSES_CONFIRMED), + cliGetHeader: cliGetHeader(CollectionData.COLLECTION), + cliGetExample: cliGetExample(data.uuid, GroupContentsResourcePrefix.COLLECTION), + cliUpdateHeader: cliUpdateHeader(CollectionData.COLLECTION, CollectionData.STORAGE_CLASSES_CONFIRMED), + cliUpdateExample: cliUpdateExample(data.uuid, CollectionData.COLLECTION, data.storageClassesConfirmed, CollectionData.STORAGE_CLASSES_CONFIRMED), curlHeader: curlHeader(CollectionData.COLLECTION, CollectionData.STORAGE_CLASSES_CONFIRMED), curlExample: curlExample(data.uuid, GroupContentsResourcePrefix.COLLECTION, data.storageClassesConfirmed, CollectionData.COLLECTION, CollectionData.STORAGE_CLASSES_CONFIRMED) }; dispatch(dialogActions.OPEN_DIALOG({ id: ADVANCED_TAB_DIALOG, data: dataCollection })); } else if (kind === ResourceKind.PROCESS) { const dataProcess: AdvancedTabDialogData = { + apiResponse: containerRequestApiResponse(data), pythonHeader: pythonHeader(ProcessData.CONTAINER_REQUEST), pythonExample: pythonExample(data.uuid, GroupContentsResourcePrefix.PROCESS), - CLIGetHeader: CLIGetHeader(ProcessData.CONTAINER_REQUEST), - CLIGetExample: CLIGetExample(data.uuid, GroupContentsResourcePrefix.PROCESS), - CLIUpdateHeader: CLIUpdateHeader(ProcessData.CONTAINER_REQUEST, ProcessData.OUTPUT_NAME), - CLIUpdateExample: CLIUpdateExample(data.uuid, ProcessData.CONTAINER_REQUEST, data.outputName, ProcessData.OUTPUT_NAME), + cliGetHeader: cliGetHeader(ProcessData.CONTAINER_REQUEST), + cliGetExample: cliGetExample(data.uuid, GroupContentsResourcePrefix.PROCESS), + cliUpdateHeader: cliUpdateHeader(ProcessData.CONTAINER_REQUEST, ProcessData.OUTPUT_NAME), + cliUpdateExample: cliUpdateExample(data.uuid, ProcessData.CONTAINER_REQUEST, data.outputName, ProcessData.OUTPUT_NAME), curlHeader: curlHeader(ProcessData.CONTAINER_REQUEST, ProcessData.OUTPUT_NAME), curlExample: curlExample(data.uuid, GroupContentsResourcePrefix.PROCESS, data.outputName, ProcessData.CONTAINER_REQUEST, ProcessData.OUTPUT_NAME) }; dispatch(dialogActions.OPEN_DIALOG({ id: ADVANCED_TAB_DIALOG, data: dataProcess })); } else if (kind === ResourceKind.PROJECT) { const dataProject: AdvancedTabDialogData = { + apiResponse: `'${data}'`, pythonHeader: pythonHeader(ProjectData.GROUP), pythonExample: pythonExample(data.uuid, GroupContentsResourcePrefix.PROJECT), - CLIGetHeader: CLIGetHeader(ProjectData.GROUP), - CLIGetExample: CLIGetExample(data.uuid, GroupContentsResourcePrefix.PROJECT), - CLIUpdateHeader: CLIUpdateHeader(ProjectData.GROUP, ProjectData.DELETE_AT), - CLIUpdateExample: CLIUpdateExample(data.uuid, ProjectData.GROUP, data.deleteAt, ProjectData.DELETE_AT), + cliGetHeader: cliGetHeader(ProjectData.GROUP), + cliGetExample: cliGetExample(data.uuid, GroupContentsResourcePrefix.PROJECT), + cliUpdateHeader: cliUpdateHeader(ProjectData.GROUP, ProjectData.DELETE_AT), + cliUpdateExample: cliUpdateExample(data.uuid, ProjectData.GROUP, data.deleteAt, ProjectData.DELETE_AT), curlHeader: curlHeader(ProjectData.GROUP, ProjectData.DELETE_AT), curlExample: curlExample(data.uuid, GroupContentsResourcePrefix.PROJECT, data.deleteAt, ProjectData.GROUP, ProjectData.DELETE_AT) }; @@ -97,20 +110,20 @@ const pythonExample = (uuid: string, resourcePrefix: string) => { return pythonExample; }; -const CLIGetHeader = (resourceKind: string) => +const cliGetHeader = (resourceKind: string) => `An example arv command to get a ${resourceKind} using its uuid:`; -const CLIGetExample = (uuid: string, resourcePrefix: string) => { +const cliGetExample = (uuid: string, resourcePrefix: string) => { const cliGetExample = `arv ${resourcePrefix} get \\ --uuid ${uuid}`; return cliGetExample; }; -const CLIUpdateHeader = (resourceKind: string, resourceName: string) => +const cliUpdateHeader = (resourceKind: string, resourceName: string) => `An example arv command to update the "${resourceName}" attribute for the current ${resourceKind}:`; -const CLIUpdateExample = (uuid: string, resourceKind: string, resource: string | string[], resourceName: string) => { +const cliUpdateExample = (uuid: string, resourceKind: string, resource: string | string[], resourceName: string) => { const CLIUpdateCollectionExample = `arv ${resourceKind} update \\ --uuid ${uuid} \\ --${resourceKind} '{"${resourceName}":${resource}}'`; @@ -133,4 +146,107 @@ const curlExample = (uuid: string, resourcePrefix: string, resource: string | st EOF`; return curlExample; +}; + +const containerRequestApiResponse = (apiResponse: ContainerRequestResource) => { + const response = `{ + "uuid": "${apiResponse.uuid}", + "owner_uuid": "${apiResponse.ownerUuid}", + "created_at": "${apiResponse.createdAt}", + "modified_at": "${apiResponse.modifiedAt}", + "modified_by_client_uuid": "${apiResponse.modifiedByClientUuid}", + "modified_by_user_uuid": "${apiResponse.modifiedByUserUuid}", + "name": "${apiResponse.name}", + "description": "${apiResponse.description}", + "properties": "${apiResponse.properties}", + "state": "${apiResponse.state}", + "requesting_container_uuid": "${apiResponse.requestingContainerUuid}", + "container_uuid": "${apiResponse.containerUuid}", + "container_count_max": "${apiResponse.containerCountMax}", + "mounts": "${apiResponse.mounts}", + "runtime_constraints": "${apiResponse.runtimeConstraints}", + "container_image": "${apiResponse.containerImage}", + "environment": "${apiResponse.environment}", + "cwd": "${apiResponse.cwd}", + "command": "${apiResponse.command}", + "output_path": "${apiResponse.outputPath}", + "priority": "${apiResponse.priority}", + "expires_at": "${apiResponse.expiresAt}", + "filters": "${apiResponse.filters}" + "use_existing": "${apiResponse.useExisting}", + "output_uuid": "${apiResponse.outputUuid}", + "scheduling_parameters": "${apiResponse.schedulingParameters}", + "kind": "${apiResponse.kind}", + "log_uuid": "${apiResponse.logUuid}", + "output_name": "${apiResponse.outputName}", + "output_ttl": "${apiResponse.outputTtl}", +}`; + + return response; +}; + +const collectionApiResponse = (apiResponse: CollectionResource) => { + const response = `{ + "uuid": "${apiResponse.uuid}", + "owner_uuid": "${apiResponse.ownerUuid}", + "created_at": "${apiResponse.createdAt}", + "modified_at": "${apiResponse.modifiedAt}", + "modified_by_client_uuid": "${apiResponse.modifiedByClientUuid}", + "modified_by_user_uuid": "${apiResponse.modifiedByUserUuid}", + "portable_data_hash": "${apiResponse.portableDataHash}", + "replication_desired": "${apiResponse.replicationDesired}", + "replication_confirmed_at": "${apiResponse.replicationConfirmedAt}", + "replication_confirmed": "${apiResponse.replicationConfirmed}", + + "manifest_text": "${apiResponse.manifestText}", + "name": "${apiResponse.name}", + "description": "${apiResponse.description}", + "properties": "${apiResponse.properties}", + "delete_at": "${apiResponse.deleteAt}", + + "trash_at": "${apiResponse.trashAt}", + "is_trashed": "${apiResponse.isTrashed}", + + + +}`; + + return response; +}; + +const groupRequestApiResponse = (apiResponse: ContainerRequestResource) => { + const response = `{ + "uuid": "${apiResponse.uuid}", + "owner_uuid": "${apiResponse.ownerUuid}", + "created_at": "${apiResponse.createdAt}", + "modified_at": "${apiResponse.modifiedAt}", + "modified_by_client_uuid": "${apiResponse.modifiedByClientUuid}", + "modified_by_user_uuid": "${apiResponse.modifiedByUserUuid}", + "name": "${apiResponse.name}", + "description": "${apiResponse.description}", + "properties": "${apiResponse.properties}", + "state": "${apiResponse.state}", + "requesting_container_uuid": "${apiResponse.requestingContainerUuid}", + "container_uuid": "${apiResponse.containerUuid}", + "container_count_max": "${apiResponse.containerCountMax}", + "mounts": "${apiResponse.mounts}", + "runtime_constraints": "${apiResponse.runtimeConstraints}", + "container_image": "${apiResponse.containerImage}", + "environment": "${apiResponse.environment}", + "cwd": "${apiResponse.cwd}", + "command": "${apiResponse.command}", + "output_path": "${apiResponse.outputPath}", + "priority": "${apiResponse.priority}", + "expires_at": "${apiResponse.expiresAt}", + "filters": "${apiResponse.filters}" + "use_existing": "${apiResponse.useExisting}", + "output_uuid": "${apiResponse.outputUuid}", + "scheduling_parameters": "${apiResponse.schedulingParameters}", + "kind": "${apiResponse.kind}", + "log_uuid": "${apiResponse.logUuid}", + "output_name": "${apiResponse.outputName}", + "output_ttl": "${apiResponse.outputTtl}", +}`; + + return response; }; \ No newline at end of file diff --git a/src/store/resources/resources.ts b/src/store/resources/resources.ts index 189fd4b1..e7153dec 100644 --- a/src/store/resources/resources.ts +++ b/src/store/resources/resources.ts @@ -7,7 +7,7 @@ import { ResourceKind } from '~/models/resource'; export type ResourcesState = { [key: string]: Resource }; -export const getResource = (id: string) => +export const getResource = (id: string) => (state: ResourcesState): T | undefined => state[id] as T; diff --git a/src/views-components/advanced-tab-dialog/advanced-tab-dialog.tsx b/src/views-components/advanced-tab-dialog/advanced-tab-dialog.tsx index a2808293..e26d2a83 100644 --- a/src/views-components/advanced-tab-dialog/advanced-tab-dialog.tsx +++ b/src/views-components/advanced-tab-dialog/advanced-tab-dialog.tsx @@ -10,20 +10,23 @@ import { compose } from 'redux'; import { ADVANCED_TAB_DIALOG } from "~/store/advanced-tab/advanced-tab"; import { DefaultCodeSnippet } from "~/components/default-code-snippet/default-code-snippet"; -type CssRules = 'content' | 'codeSnippet' | 'secondContentText'; +type CssRules = 'content' | 'codeSnippet' | 'spacing'; const styles: StyleRulesCallback = theme => ({ content: { - paddingTop: theme.spacing.unit * 3 + paddingTop: theme.spacing.unit * 3, + minHeight: '400px', + minWidth: '1232px' }, codeSnippet: { borderRadius: theme.spacing.unit * 0.5, border: '1px solid', - borderColor: theme.palette.grey["400"] + borderColor: theme.palette.grey["400"], + maxHeight: '400px' + }, + spacing: { + paddingBottom: theme.spacing.unit * 2 }, - secondContentText: { - paddingTop: theme.spacing.unit * 2 - } }); export const AdvancedTabDialog = compose( @@ -46,22 +49,23 @@ export const AdvancedTabDialog = compose( const { classes, open, closeDialog } = this.props; const { value } = this.state; const { + apiResponse, pythonHeader, pythonExample, - CLIGetHeader, - CLIGetExample, - CLIUpdateHeader, - CLIUpdateExample, + cliGetHeader, + cliGetExample, + cliUpdateHeader, + cliUpdateExample, curlHeader, curlExample } = this.props.data; return this.setState({ value: 0 })} > Advanced - + @@ -69,34 +73,14 @@ export const AdvancedTabDialog = compose( - {value === 0 &&
- API CONTENT -
} - {value === 1 &&
- METADATA CONTENT -
} - {value === 2 &&
- {pythonHeader} - -
} + {value === 0 &&
{dialogContentExample(apiResponse, classes)}
} + {value === 1 &&
{dialogContentHeader('(No metadata links found)')}
} + {value === 2 && dialogContent(pythonHeader, pythonExample, classes)} {value === 3 &&
- {CLIGetHeader} - - {CLIUpdateHeader} - -
} - {value === 4 &&
- {curlHeader} - + {dialogContent(cliGetHeader, cliGetExample, classes)} + {dialogContent(cliUpdateHeader, cliUpdateExample, classes)}
} + {value === 4 && dialogContent(curlHeader, curlExample, classes)}
; } } -); \ No newline at end of file +); + +const dialogContent = (header: string, example: string, classes: any) => +
+ {dialogContentHeader(header)} + {dialogContentExample(example, classes)} +
; + +const dialogContentHeader = (header: string) => + + {header} + ; + +const dialogContentExample = (example: string, classes: any) => + ; \ No newline at end of file -- 2.39.5