Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/edit config #112

Open
wants to merge 8 commits into
base: dev-1.5.0-alpha.0
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix features
  • Loading branch information
nasyaoris committed Aug 2, 2020
commit c116a0f9df4d14c5e02e7c123897f6bc600f8a7a
102 changes: 55 additions & 47 deletions ui/src/containers/Config.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React, { useState, useEffect } from 'react';
import React, { useState } from 'react';
import { Input, List, Button } from 'antd';
import ConfigResourceContainer from './ConfigResource'
import { IDictionary, IResource, IConfig } from '../interfaces'
import { getResourceParams } from '../dictionary'

interface IProps {
dictionary: IDictionary;
config: IConfig;
dictionary: IDictionary;
config: IConfig;
}

function ConfigContainer({ dictionary, config }:IProps) {
function ConfigContainer({ dictionary, config }: IProps) {
const [configState, setConfig] = useState<IConfig>(config);

let handleFeaturesPathChange = ( event: any, idx: number) => {
let handleFeaturesPathChange = (event: any, idx: number) => {
let copy = config.features_path
copy[idx] = event.target.value

Expand All @@ -24,84 +24,92 @@ function ConfigContainer({ dictionary, config }:IProps) {

let handleResourceItemChange = (selectedName: string, newItem: IResource) => {
const newResourceItem = configState.resources.map((item: IResource) => {
if (item.name === selectedName) {
return newItem;
}
return item;
});
if (item.name === selectedName) {
return newItem;
}
return item;
});

setConfig({
features_path: configState.features_path,
resources: newResourceItem
features_path: configState.features_path,
resources: newResourceItem
});
}

let handleNewResourceItem = () => {
const newResourceItem = {
name: "new",
type: "httpclient",
parameters: {}
};
name: "new",
type: "httpclient",
parameters: {}
};

getResourceParams(dictionary, "httpclient").forEach((param) => {
newResourceItem.parameters[param.name] = ""
})
})

console.log(newResourceItem)

setConfig({
features_path: configState.features_path,
resources: [...configState.resources, newResourceItem]
features_path: configState.features_path,
resources: [...configState.resources, newResourceItem]
});
}

// useEffect(() =>

// ,[configState])
let handleNewFeatureItem = () => {
let newFeatures: string = ""

let validateConfig = (config: IConfig) => {
// validate & return error
setConfig({
...config,
features_path: [...config.features_path, newFeatures]
})
}

const handleSave = () => {

}

return (
<div className="App">
<label htmlFor="">Features Path</label>
<div className="App" style={{display: "flex", flexDirection: "column"}}>
<div className="features" style={{marginBottom: "10px"}}>
<label htmlFor="" style={{fontWeight: "bolder"}}>Features Path</label>
<List
itemLayout="horizontal"
dataSource={configState.features_path}
renderItem={(item, idx) => (
itemLayout="horizontal"
dataSource={configState.features_path}
renderItem={(item, idx) => (
<List.Item>
<Input placeholder="Features path" name={item} value={item} onChange={(event) => handleFeaturesPathChange(event, idx)}/>
<Input placeholder="Features path" name={item} value={item} onChange={(event) => handleFeaturesPathChange(event, idx)} />
</List.Item>
)}
)}
/>
<Button onClick={handleNewFeatureItem} type="primary">
New Feature
</Button>
</div>

<label htmlFor="">Resources</label>
<div className="resources">
<label htmlFor="" style={{fontWeight: "bolder"}}>Resources</label>
<List
itemLayout="horizontal"
dataSource={configState.resources}
renderItem={item => (
itemLayout="horizontal"
dataSource={configState.resources}
renderItem={item => (
<List.Item>
<ConfigResourceContainer
dictionary={dictionary}
item={item}
handleResourceItemChange={handleResourceItemChange}
/>
<ConfigResourceContainer
dictionary={dictionary}
item={item}
handleResourceItemChange={handleResourceItemChange}
/>
</List.Item>
)}
)}
/>
<Button onClick={handleNewResourceItem} type="primary">
<Button onClick={handleNewResourceItem} type="primary" style={{marginRight: "10px"}}>
New Resource
</Button>
<Button onClick={handleSave} type="primary">
Save
</Button>
</div>

<div>{JSON.stringify(configState)}</div>
<div>{JSON.stringify(configState)}</div>
</div>
);
}
Expand Down