kirin-ri / memo

0 stars 0 forks source link

memo #1

Open kirin-ri opened 1 year ago

kirin-ri commented 1 year ago

(base) q_li@vm-I-DNA-daas-2:~/Desktop/catalog-web-app$ npm start npm ERR! code ENOENT npm ERR! syscall open npm ERR! path /home/uenv/q_li/Desktop/catalog-web-app/package.json npm ERR! errno -2 npm ERR! enoent ENOENT: no such file or directory, open '/home/uenv/q_li/Desktop/catalog-web-app/package.json' npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent

npm ERR! A complete log of this run can be found in: npm ERR! /home/uenv/q_li/.npm/_logs/2023-07-06T08_10_36_671Z-debug-0.log

kirin-ri commented 1 year ago

(base) q_li@vm-I-DNA-daas-2:~/Desktop/catalog-web-app/client$ npm install npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: chartjs-chart-error-bars@3.10.0 npm ERR! Found: chart.js@4.0.1 npm ERR! node_modules/chart.js npm ERR! dev chart.js@"^4.0.1" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer chart.js@"^3.9.1" from chartjs-chart-error-bars@3.10.0 npm ERR! node_modules/chartjs-chart-error-bars npm ERR! chartjs-chart-error-bars@"^3.10.0" from the root project npm ERR! npm ERR! Conflicting peer dependency: chart.js@3.9.1 npm ERR! node_modules/chart.js npm ERR! peer chart.js@"^3.9.1" from chartjs-chart-error-bars@3.10.0 npm ERR! node_modules/chartjs-chart-error-bars npm ERR! chartjs-chart-error-bars@"^3.10.0" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! See /home/uenv/q_li/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in: npm ERR! /home/uenv/q_li/.npm/_logs/2023-07-06T08_52_59_479Z-debug-0.log (base) q_li@vm-I-DNA-daas-2:~/Desktop/catalog-web-app/client$

kirin-ri commented 1 year ago
  <section className="content-footer">
    <p className="save-guide">上記でお間違えなければ「保存する」をクリックしてください</p>
    <button>cancel</button>
    <button className="btn btn-primary" onClick={handleSaveBtnClicked}>保存する</button>
  </section>
kirin-ri commented 1 year ago

下記のエラーが出ってます。 --- update CATALOG_META_INFO start --- snowflake connect start --- snowflake connect complete 001003 (42000): SQL compilation error: syntax error line 5 at position 34 unexpected '完成'.

ソースコードはこちらです。 import json from tools.snowflakeAccessor import SnowflakeAccessor from werkzeug.exceptions import InternalServerError

def postEditMetrics(json: json): try: print('--- update CATALOG_META_INFO start')

リクエスト情報取得

    category = json["category"]
    metricsName = json["metricsName"]
    description = json["description"]
    processing = json["processing"]
    # snowflake connection
    obj = SnowflakeAccessor()
    query = f'''
        UPDATE
            CATALOG_META_INFO
        SET
            ID = '{metricsName}',
            DESCRIPTION = {description},
            CATEGORY '{category}',
            PROCESSING='{processing}'
        WHERE
            ID = '{metricsName}'
        ;
    '''
    obj.execute(query)
    print('--- update CATALOG_META_INFO end')
except Exception as e:
    print(e)
    raise InternalServerError
finally:
    obj.close()
return {"message": "COMPLETE"}
kirin-ri commented 1 year ago

下記のコードで、もしoldMetricsName とmetricsName が異なるであった場合、もう一つのテーブルのIDをmetricsName に更新したい。コードを修正してください。

import json from tools.snowflakeAccessor import SnowflakeAccessor from werkzeug.exceptions import InternalServerError

def postEditMetrics(json: json): try: print('--- update CATALOG_META_INFO start')

リクエスト情報取得

    oldMetricsName = json["oldMetricsName"]
    category = json["category"]
    metricsName = json["metricsName"]
    description = json["description"]
    processing = json["processing"]
    print(metricsName)
    # snowflake connection
    obj = SnowflakeAccessor()
    query = f'''
        UPDATE
            CATALOG_META_INFO
        SET
            ID = '{metricsName}',
            DESCRIPTION = ' {description}',
            CATEGORY = '{category}',
            PROCESSING='{processing}'
        WHERE
            ID = '{oldMetricsName}'
        ;
    '''
    obj.execute(query)
    print('--- update CATALOG_META_INFO end')
except Exception as e:
    print(e)
    raise InternalServerError
finally:
    obj.close()
return {"message": "COMPLETE"}
kirin-ri commented 1 year ago

こちらのエラー原因を教えてください。 (base) q_li@vm-I-DNA-daas-2:~/Desktop/catalog-web-app$ flake8 /home/uenv/q_li/Desktop/catalog-web-app/client/src/app2/components/pages/metricsEdit.tsx /home/uenv/q_li/Desktop/catalog-web-app/client/src/app2/components/pages/metricsEdit.tsx:1:8: E999 SyntaxError: invalid syntax

コードは以下です。 import { commonAjax } from '../../../components/commonAjax'; import React, { useState, useEffect, ChangeEvent, MouseEvent, FormEvent } from 'react'; import { useHistory } from 'react-router-dom'; import { useForm } from 'react-hook-form'; import * as Defs from './metricsDefs';

interface MyProps { match: { params: { id: string; }; }; }

kirin-ri commented 1 year ago

下のコード、二つのボタンを少し分けたい

上記でお間違えなければ「保存する」をクリックしてください

kirin-ri commented 1 year ago

下のコード、二つのボタンを少し分けたい

上記でお間違えなければ「保存する」をクリックしてください

kirin-ri commented 1 year ago

下のコード、二つのボタンを少し分けたい

上記でお間違えなければ「保存する」をクリックしてください

kirin-ri commented 1 year ago

下のコード、二つのボタンを少し分けたい

<section className="content-footer">
        <p className="save-guide">上記でお間違えなければ「保存する」をクリックしてください</p>
        <div>
          <button className="btn btn-secondary" onClick={handleCancelBtnClicked}>戻る</button>          
          <button className="btn btn-primary" onClick={handleSaveBtnClicked}>保存する</button>
        </div>
      </section>
kirin-ri commented 1 year ago

以下のエラーに対して解決してください。 販売計画誤差率:年次 販売計画誤差率:年次 --- snowflake connect start --- snowflake connect complete local variable 'update_query' referenced before assignment 127.0.0.1 - - [07/Jul/2023 08:26:40] "POST /api/editMetrics HTTP/1.1" 500 -

コードはこちらです。 import json from tools.snowflakeAccessor import SnowflakeAccessor from werkzeug.exceptions import InternalServerError

def postEditMetrics(json: json): try: print('--- update CATALOG_META_INFO start')

リクエスト情報取得

    oldMetricsName = json["oldMetricsName"]
    category = json["category"]
    metricsName = json["metricsName"]
    description = json["description"]
    processing = json["processing"]
    print(metricsName)
    print(oldMetricsName)
    # snowflake connection
    obj = SnowflakeAccessor()

    if oldMetricsName != metricsName:
        update_query = f'''
        UPDATE
            CATALOG_PROVIDE_INFO
        SET
            ID = '{metricsName}'
        WHERE
            ID = '{oldMetricsName}'
        ;
        '''

    query = f'''
        UPDATE
            CATALOG_META_INFO
        SET
            ID = '{metricsName}',
            DESCRIPTION = ' {description}',
            CATEGORY = '{category}',
            PROCESSING='{processing}'
        WHERE
            ID = '{oldMetricsName}'
        ;
    '''
    obj.execute(query)
    obj.execute(update_query)
    print('--- update CATALOG_META_INFO end')
except Exception as e:
    print(e)
    raise InternalServerError
finally:
    obj.close()
return {"message": "COMPLETE"}
kirin-ri commented 1 year ago

import { commonAjax } from '../../../components/commonAjax'; import React, { useState, useEffect, ChangeEvent, MouseEvent, FormEvent } from 'react'; import { useHistory } from 'react-router-dom'; import { useForm } from 'react-hook-form'; import * as Defs from './metricsDefs';

interface MyProps { match: { params: { id: string; }; }; }

/ textareaのheightを行数によって可変設定 / function setTextareaHeight() { // textareaタグを全て取得 const textareaEls = document.querySelectorAll('textarea'); textareaEls.forEach((textareaEl) => { // valueから行数を取得 const line = textareaEl.value.split('\n').length; // 行数分のrowsに変更 textareaEl.rows = line + 3; }); }

function MetricsEdit(props: MyProps) { const id = props.match.params.id; const history = useHistory(); const [metricsDetails, setMetricsDetails] = useState(); const [categorySel, setCategorySel] = useState(""); const [categoryTxt, setCategoryTxt] = useState(""); const [categoryList, setCategoryList] = useState<{val: string, name: string}[]>(); const [isCategoryTxtDisplayed, setCategoryTxtDisplayed] = useState(false); const [metricsName, setMetricsName] = useState(""); const [description, setDescription] = useState(""); const [processing, setProcessing] = useState(""); const [oldMetricsName,setOldMetricsName] = useState("");

const load = () => { commonAjax .axios({}) .get<string[]>('/api/categoryNames') .then(res => { const list = []; res.data.map(e => list.push({val: e, name: e})); list.push({val: "*", name: "その他..."}); setCategoryList(list); });

commonAjax
  .axios({loading: true})
  .get(`/api/metrics/${id}`)
  .then((res) => {
    const details: Defs.MetricsDetails = res.data;
    setMetricsDetails(details);
    setOldMetricsName(details.id);
    setMetricsName(details.id);
    setCategorySel(details.category);
    setDescription(details.description);
    setProcessing(details.processing);

    setValue("metricsName", details.id);
    setValue("categoryTxt", "");
    setValue("description", details.description);
    setValue("processing", details.processing);
  });

}

useEffect(() => { load(); }, [history]);

useEffect(() => { setTextareaHeight(); }, [processing]);

function handleCategorySelChanged(e: ChangeEvent) { let val = e.target.value; setCategorySel(val); setCategoryTxtDisplayed(val == "*"); } function handleCategoryTxtChanged(e: ChangeEvent) { categoryTxtFld.onChange(e); setCategoryTxt(e.target.value); } function handleMetricsNameChanged(e: ChangeEvent) { metricsNameFld.onChange(e); setMetricsName(e.target.value); } function handleDescriptionChanged(e: ChangeEvent) { descriptionFld.onChange(e); setDescription(e.target.value); } function handleProcessingChanged(e: ChangeEvent) { processingFld.onChange(e); setProcessing(e.target.value); }

async function handleSaveBtnClicked(e: MouseEvent) { const isValid = await trigger(undefined, {shouldFocus: true}); if (!isValid) return;

// 更新値にシングルクオーテーションがある場合SQL終了文が誤認識されるため「''」にreplace
const processingForUpdate = processing.replaceAll("'", "''");

const metricsData = {
  category: categorySel == "*" ? categoryTxt : categorySel,
  oldMetricsName: oldMetricsName,
  metricsName: metricsName,
  description: description,
  processing: processingForUpdate,
};

// メトリクス編集API呼び出し
commonAjax
  .axios({swalFire: true, loading: true})
  .post('/api/editMetrics',
    metricsData,
    {headers: {'Content-Type': 'application/json'}}
  ).then((res: any) => {
  }).finally(() => {
    setTextareaHeight();
  });

}

/ Validation / const { register, resetField, formState: { isDirty, isValid, errors }, trigger, setValue, } = useForm({ defaultValues: { categoryTxt: categoryTxt, metricsName: metricsName, description: description, processing: processing }, mode: 'onChange', criteriaMode: 'all', }); const metricsNameFld = register("metricsName", { required: { value: true, message: "メトリクスのタイトルを入力してください。" } }); const processingFld = register("processing", { required: { value: true, message: "メトリクス処理内容を入力してください。" } }); const descriptionFld = register("description", { required: { value: true, message: "説明を入力してください。" } }); const categoryTxtFld = register("categoryTxt", { required: { value: categorySel == "*", message: "カテゴリ「その他...」を選択した場合、下の任意設定欄への入力が必要です。" } });

return (

{metricsDetails?.category}

{metricsDetails?.id}
{/* Content Header (Page header) */}

メトリクス編集画面

{errors.metricsName?.message && (
{errors.metricsName.message}
)}
{isCategoryTxtDisplayed && <> {errors.categoryTxt?.message && (
{errors.categoryTxt.message}
)} }
{errors.description?.message && (
{errors.description.message}
)}