Skip to content

Commit

Permalink
Resolved front end errors, untested
Browse files Browse the repository at this point in the history
  • Loading branch information
jbirddog committed Dec 13, 2023
1 parent acecbaa commit 7a789ea
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions spiffworkflow-frontend/src/components/DataStoreForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
// @ts-ignore
import { Button, Form, Stack, TextInput, TextArea } from '@carbon/react';
import { modifyProcessIdentifierForPathParam, slugifyString } from '../helpers';
import HttpService from '../services/HttpService';
import { DataStore } from '../interfaces';

Expand All @@ -26,9 +25,7 @@ export default function DataStoreForm({

const navigateToDataStores = (_result: any) => {
if (newDataStoreId) {
navigate(
`/dataStoress/${newDataStoreId}`
);
navigate(`/dataStoress/${newDataStoreId}`);
}
};

Expand All @@ -37,8 +34,8 @@ export default function DataStoreForm({
};

const handleFormSubmission = (event: any) => {
const searchParams = new URLSearchParams(document.location.search);
const parentGroupId = searchParams.get('parentGroupId');
// const searchParams = new URLSearchParams(document.location.search);
// const parentGroupId = searchParams.get('parentGroupId');

event.preventDefault();
let hasErrors = false;
Expand All @@ -53,20 +50,19 @@ export default function DataStoreForm({
if (hasErrors) {
return;
}
let path = '/process-groups';
if (mode === 'edit') {
path = `/process-groups/${modifyProcessIdentifierForPathParam(
processGroup.id
)}`;
}
let path = '/data-stores';
let httpMethod = 'POST';
if (mode === 'edit') {
path = `/data-stores/${dataStore.id}`;
httpMethod = 'PUT';
}
const postBody = {
display_name: processGroup.display_name,
description: processGroup.description,
id: dataStore.id,
name: dataStore.name,
description: dataStore.description,
type: dataStore.type,
};
/*
if (mode === 'new') {
if (parentGroupId) {
newProcessGroupId = `${parentGroupId}/${processGroup.id}`;
Expand All @@ -77,21 +73,22 @@ export default function DataStoreForm({
: `${processGroup.id}`,
});
}
*/

HttpService.makeCallToBackend({
path,
successCallback: navigateToProcessGroup,
successCallback: navigateToDataStores,
httpMethod,
postBody,
});
};

const updateProcessGroup = (newValues: any) => {
const processGroupToCopy = {
...processGroup,
const updateDataStore = (newValues: any) => {
const dataStoreToCopy = {
...dataStore,
};
Object.assign(processGroupToCopy, newValues);
setProcessGroup(processGroupToCopy);
Object.assign(dataStoreToCopy, newValues);
setDataStore(dataStoreToCopy);
};

const onNameChanged = (newName: any) => {
Expand All @@ -100,7 +97,7 @@ export default function DataStoreForm({
if (!idHasBeenUpdatedByUser && mode === 'new') {
Object.assign(updateDict, { id: newName });
}
updateProcessGroup(updateDict);
updateDataStore(updateDict);
};

const formElements = () => {
Expand All @@ -120,14 +117,14 @@ export default function DataStoreForm({
if (mode === 'new') {
textInputs.push(
<TextInput
id="process-group-identifier"
id="data-store-identifier"
name="id"
invalidText="Identifier is required and must be all lowercase characters and hyphens."
invalid={identifierInvalid}
labelText="Identifier*"
value={processGroup.id}
value={dataStore.id}
onChange={(event: any) => {
updateProcessGroup({ id: event.target.value });
updateDataStore({ id: event.target.value });
// was invalid, and now valid
if (identifierInvalid && hasValidIdentifier(event.target.value)) {
setIdentifierInvalid(false);
Expand All @@ -140,12 +137,12 @@ export default function DataStoreForm({

textInputs.push(
<TextArea
id="process-group-description"
id="data-store-description"
name="description"
labelText="Description"
value={processGroup.description}
value={dataStore.description}
onChange={(event: any) =>
updateProcessGroup({ description: event.target.value })
updateDataStore({ description: event.target.value })
}
/>
);
Expand Down

0 comments on commit 7a789ea

Please sign in to comment.