Skip to content

Commit

Permalink
Merge pull request #41 from 2060-io/38-services-edition-update-templa…
Browse files Browse the repository at this point in the history
…te-params

feat: Services edition update template params
  • Loading branch information
lotharking authored Aug 27, 2024
2 parents e33f687 + ac0c77b commit df94568
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 18 deletions.
46 changes: 29 additions & 17 deletions src/components/Services/DtsViewEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { usePathname, useRouter } from 'next/navigation';
import SelectDtsTemplate from '../Templates/SelectDtsTemplate';
import {v4 as uuidv4} from 'uuid';
import Ajv from 'ajv';
import { load } from 'js-yaml';
import { load, dump } from 'js-yaml';

type ApiGitHub = {
name: string;
Expand Down Expand Up @@ -118,7 +118,18 @@ function DtsViewEdit() {

const listTemplateNames = async () => {
try {
const response = await fetch(`https://api.github.com/repos/${process.env.NEXT_PUBLIC_TEMPLATE_DIR??''}/contents`);
const configParameters: ConfigurationParameters = {
headers: {
Authorization: "Bearer " + auth.user?.access_token,
},
basePath: process.env.NEXT_PUBLIC_BACKEND_BASE_PATH,
};
const config = new Configuration(configParameters);
const api = new DtsResourceApi(config);
const dtscCollectionList = await api.dtscListPost();
const dtscCollecion = dtscCollectionList[0];

const response = await fetch(`https://api.github.com/repos/${dtscCollecion.template+'/'+dtscCollecion.templateRepo}/contents`);
const data: ApiGitHub[] = await response.json();
const folders = data.filter((item:ApiGitHub) => item.type === 'dir' && !item.name.startsWith('.'));

Expand All @@ -127,8 +138,6 @@ function DtsViewEdit() {
value: folder.name,
schema: folder.name === "Fastbot" ? process.env.NEXT_PUBLIC_TEMPLATE_DIR : null
}));
// const currentTemplate = { name: "Current", value: "current", schema:null };
// templates = [currentTemplate, ...templates];

templates = [...templates];
setTemplateNames(templates);
Expand Down Expand Up @@ -171,7 +180,7 @@ function DtsViewEdit() {
const config = new Configuration(configParameters);
const api = new DtsResourceApi(config);

api.dtsGetIdGet({ id: idinurl}).then((resp) => {
api.dtsGetIdGet({ id: idinurl}).then((resp) => {
if (resp) {
setDtsVO(resp);
setIsOptionSelected(true);
Expand All @@ -198,14 +207,19 @@ useEffect(() => {
});

function getDeploymentConfigKeys(): string[] {
const deploymentConfig = dtsVO?.deploymentConfig ? load(String(dtsVO.deploymentConfig)) : null;
return deploymentConfig ? Object.keys(deploymentConfig) : [];
}

let keylist: string[] = [];
function getDeploymentConfigValues(key: string): string {
const deploymenConfig = JSON.parse(JSON.stringify(load(String(dtsVO?.deploymentConfig))));
return String(deploymenConfig[key] ?? '')
}

for (const key in dtsVO?.deploymentConfig)
{
keylist.push(key);
}
return keylist;
function getDeployMentConfig(prevState: DtsVO, e: React.ChangeEvent<HTMLInputElement>, key: string): string{
const objeto = JSON.parse(JSON.stringify(load(String(prevState.deploymentConfig))));
const config = {...objeto, [key]: e.target.value}
return dump(config)
}

async function saveDtsVO() {
Expand All @@ -230,6 +244,7 @@ useEffect(() => {
await saveDtsTemplateVO()
await api.dtsSavePost({ dtsVO: dtsVO });
} catch (error) {
console.error(error)
}
const id = dtsVO?.id ?? "new";
if (pathname.includes("new")) router.push(pathname.replace("new",id))
Expand Down Expand Up @@ -448,17 +463,14 @@ useEffect(() => {
</label>
<input
type="text"
value={dtsVO?.deploymentConfig && dtsVO.deploymentConfig[key] || ''}
value={getDeploymentConfigValues(key)}
onChange={(e) => {
setDtsVO(prevState => ({
...prevState,
deploymentConfig: {
...prevState?.deploymentConfig,
[key]: e.target.value
}
deploymentConfig: getDeployMentConfig(prevState, e, key)
}));
}}
className={`w-full rounded border-[1.5px] px-5 py-3 text-black outline-none transition focus:border-primary active:border-primary disabled:cursor-default disabled:bg-whiter dark:text-white ${dtsVO?.deploymentConfig ? checkErrorMinSize(String(dtsVO.deploymentConfig[key])) ? "bg-red-200 placeholder-gray-3" : "border-stroke bg-transparent dark:focus:border-primary dark:border-form-strokedark dark:bg-form-input" : "" }`}
className={`w-full rounded border-[1.5px] px-5 py-3 text-black outline-none transition focus:border-primary active:border-primary disabled:cursor-default disabled:bg-whiter dark:text-white ${dtsVO?.deploymentConfig ? checkErrorMinSize(getDeploymentConfigValues(key)) ? "bg-red-200 placeholder-gray-3" : "border-stroke bg-transparent dark:focus:border-primary dark:border-form-strokedark dark:bg-form-input" : "" }`}
/>
</div>
))}
Expand Down
33 changes: 33 additions & 0 deletions src/openapi-client/apis/DtsResourceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import type {
import {
DtsFilterFromJSON,
DtsFilterToJSON,
DtscCollectionVO,
DtscCollectionVOToJSON,
DtsVOFromJSON,
DtsVOToJSON,
ErrorResponseFromJSON,
Expand Down Expand Up @@ -225,4 +227,35 @@ export class DtsResourceApi extends runtime.BaseAPI {
await this.dtsSavePostRaw(requestParameters, initOverrides);
}

/**
* List Dts Collections
* List Dts Collections
*/
async dtscListPostRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<DtscCollectionVO>>> {
const queryParameters: any = {};

const headerParameters: runtime.HTTPHeaders = {}

headerParameters['Content-Type'] = 'application/json';

const response = await this.request({
path: '/dtsc/list',
method: 'POST',
headers: headerParameters,
query: queryParameters,
body: DtscCollectionVOToJSON
});

return new runtime.JSONApiResponse(response)
}

/**
* List Dts Collections
* List Dts Collections
*/
async dtscListPost(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<DtscCollectionVO>>{
const response = await this.dtscListPostRaw(initOverrides);
return await response.value();
}

}
10 changes: 9 additions & 1 deletion src/openapi-client/models/DtsVO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export interface DtsVO {
* @memberof DtsVO
*/
templateFk?: string;
/**
*
* @type {string}
* @memberof DtsVO
*/
collectionFk?: string;
/**
*
* @type {boolean}
Expand All @@ -97,7 +103,7 @@ export interface DtsVO {
* @type {{ [key: string]: string; }}
* @memberof DtsVO
*/
deploymentConfig?: { [key: string]: string; };
deploymentConfig?: string;
}

/**
Expand Down Expand Up @@ -126,6 +132,7 @@ export function DtsVOFromJSONTyped(json: any, ignoreDiscriminator: boolean): Dts
'name': json['name'] == null ? undefined : json['name'],
'config': json['config'] == null ? undefined : json['config'],
'templateFk': json['templateFk'] == null ? undefined : json['templateFk'],
'collectionFk': json['collectionFk'] == null ? undefined : json['collectionFk'],
'debug': json['debug'] == null ? undefined : json['debug'],
'createdTs': json['createdTs'] == null ? undefined : (new Date(json['createdTs'])),
'deploymentConfig': json['deploymentConfig'] == null ? undefined : json['deploymentConfig'],
Expand All @@ -147,6 +154,7 @@ export function DtsVOToJSON(value?: DtsVO | null): any {
'name': value['name'],
'config': value['config'],
'templateFk': value['templateFk'],
'collectionFk': value['collectionFk'],
'debug': value['debug'],
'createdTs': value['createdTs'] == null ? undefined : ((value['createdTs']).toISOString()),
'deploymentConfig': value['deploymentConfig'],
Expand Down
76 changes: 76 additions & 0 deletions src/openapi-client/models/DtscCollectionVO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
export interface DtscCollectionVO {
/**
* @type {string}
* @memberof DtscCollectionVO
*/
description?:string;

/**
* @type {string}
* @memberof DtscCollectionVO
*/
id?:string;

/**
* @type {string}
* @memberof DtscCollectionVO
*/
name?:string;

/**
* @type {string}
* @memberof DtscCollectionVO
*/
template?:string;

/**
* @type {string}
* @memberof DtscCollectionVO
*/
templateRepo?:string;

/**
* @type {Date}
* @memberof DtscCollectionVO
*/
createdTs?: Date;
}

/**
* Check if a given object implements the DtscCollectionVO interface.
*/
export function instanceOfDtscCollectionVO(value: object): boolean {
return true;
}

export function DtscCollectionVOFromJSON(json: any): DtscCollectionVO {
return DtscCollectionVOFromJSONTyped(json, false);
}

export function DtscCollectionVOFromJSONTyped(json: any, ignoreDiscriminator: boolean): DtscCollectionVO {
if(null == json){
return json;
}
return {
description: json['description'] === null ? undefined : json['description'],
id: json['id'] === null ? undefined : json['id'],
name: json['name'] === null ? undefined : json['name'],
template: json['template'] === null ? undefined : json['template'],
templateRepo: json['templateRepo'] === null ? undefined : json['templateRepo'],
createdTs: json['createdTs'] === null ? undefined : new Date(json['createdTs']),
}
}

export function DtscCollectionVOToJSON(value?: DtscCollectionVO | null): any {
if(null == value){
return value;
}
return {
description: value['description'],
id: value['id'],
name: value['name'],
template: value['template'],
templateRepo: value['templateRepo'],
createdTs: value['createdTs'],
}
}
1 change: 1 addition & 0 deletions src/openapi-client/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './CampaignScheduleVO';
export * from './CampaignType';
export * from './CampaignTypeFilter';
export * from './CampaignVO';
export * from './DtscCollectionVO';
export * from './DtsFilter';
export * from './DtsTemplateFilter';
export * from './DtsTemplateVO';
Expand Down

0 comments on commit df94568

Please sign in to comment.