From 5660e7e710aafdf45d9d80862196008b8e2ddfc8 Mon Sep 17 00:00:00 2001 From: jinbekim Date: Sun, 7 Aug 2022 11:44:54 +0900 Subject: [PATCH] fix(client): error if entityName & column is empty --- .../http/graphql/createQuery.ts | 1 - .../components/Dialog/RequestButton.tsx | 2 -- .../components/Dialog/SaveButton.tsx | 1 - .../presentation/components/Modal/Dataset.tsx | 1 - .../components/Modal/QueryFilterAttribute.tsx | 32 ++++++++--------- .../components/Modal/StickerStepper.tsx | 3 -- .../filterAttributes/FilterAttribute.tsx | 11 +++--- .../Modal/filterAttributes/ValueAttribute.tsx | 34 +++++++++++++++++++ .../menuItems/returnColumns.tsx | 20 +++++------ .../menuItems/returnValues.tsx | 23 +++++-------- .../components/SideBar/PresetListItem.tsx | 1 - .../components/Sticker/Filter.type.ts | 18 +++------- 12 files changed, 78 insertions(+), 69 deletions(-) create mode 100644 packages/client/src/dashboard/presentation/components/Modal/filterAttributes/ValueAttribute.tsx diff --git a/packages/client/src/dashboard/infrastructure/http/graphql/createQuery.ts b/packages/client/src/dashboard/infrastructure/http/graphql/createQuery.ts index 9793ead..0d0f21d 100644 --- a/packages/client/src/dashboard/infrastructure/http/graphql/createQuery.ts +++ b/packages/client/src/dashboard/infrastructure/http/graphql/createQuery.ts @@ -135,6 +135,5 @@ export function createBachelorQuery(filterNames: string[], labels: string[]) { ${returnQuerys(filterNames).join('\n')} } `; - console.log(query); return query; } diff --git a/packages/client/src/dashboard/presentation/components/Dialog/RequestButton.tsx b/packages/client/src/dashboard/presentation/components/Dialog/RequestButton.tsx index b160b66..a3d5796 100644 --- a/packages/client/src/dashboard/presentation/components/Dialog/RequestButton.tsx +++ b/packages/client/src/dashboard/presentation/components/Dialog/RequestButton.tsx @@ -19,11 +19,9 @@ export default function RequestButton(props: RequestButtonProps) { createSaveModifiedDataQuery(entityName), ); - console.log(error, loading, data); if (error) return ; if (loading) return ; if (data) { - console.log(data); if (data['saveModifiedDataFromSheet'] === SUCCESS) return ( 데이터 로딩중...; if (data) { window.open(data['getDataToModifyFromDB'], '_blank'); - console.log(data); return ( ('User'); - const [column, setColumn] = React.useState('coalition'); - const [operator, setOperator] = React.useState('='); - const [givenValue, setGivenValue] = React.useState(''); - const [latest, setLatest] = React.useState(true); - const [getValues, { data, loading, error }] = useLazyQuery( - createValueQuery(entityName, column), - ); - if (loading) return

Loading...

; - if (error) return

Error :

; + const [entityName, setEntityName] = useState(''); + const [column, setColumn] = useState(''); + const [operator, setOperator] = useState('='); + const [givenValue, setGivenValue] = useState(''); + const [latest, setLatest] = useState(true); const checkEmptyAttribute = () => { if (!entityName || !column || !operator || !givenValue || !latest) { @@ -50,12 +43,14 @@ export default function QueryFilterAttribute(props: DatasetFilterProps) { }; const handleEntityNameChange = (event: any) => { + setGivenValue(''); + setColumn(''); setEntityName(event.target.value); }; const handleColumnChange = (event: any) => { - setColumn(event.target.value); - getValues(); + setGivenValue(''); + setColumn(event.target.value || ''); }; const handleOperatorChange = (event: any) => { @@ -90,11 +85,12 @@ export default function QueryFilterAttribute(props: DatasetFilterProps) { onChange={handleOperatorChange} menuItems={returnOperators()} /> - { - console.log('handlenext'); setActiveStep((prevActiveStep) => prevActiveStep + 1); }; const handleBack = () => { - console.log('handleback'); setActiveStep((prevActiveStep) => prevActiveStep - 1); }; diff --git a/packages/client/src/dashboard/presentation/components/Modal/filterAttributes/FilterAttribute.tsx b/packages/client/src/dashboard/presentation/components/Modal/filterAttributes/FilterAttribute.tsx index fa4bd4f..a040aeb 100644 --- a/packages/client/src/dashboard/presentation/components/Modal/filterAttributes/FilterAttribute.tsx +++ b/packages/client/src/dashboard/presentation/components/Modal/filterAttributes/FilterAttribute.tsx @@ -10,14 +10,17 @@ export interface GivenValueFormPropsType { export default function FilterAttribute(props: GivenValueFormPropsType) { const { id, value, onChange, menuItems } = props; + const menuItemsElement = menuItems(); + return ( {id} ); diff --git a/packages/client/src/dashboard/presentation/components/Modal/filterAttributes/ValueAttribute.tsx b/packages/client/src/dashboard/presentation/components/Modal/filterAttributes/ValueAttribute.tsx new file mode 100644 index 0000000..8b6bb71 --- /dev/null +++ b/packages/client/src/dashboard/presentation/components/Modal/filterAttributes/ValueAttribute.tsx @@ -0,0 +1,34 @@ +import { useQuery } from '@apollo/client'; +import { FormControl, InputLabel, MenuItem, Select } from '@mui/material'; +import createValueQuery from '../../../../infrastructure/http/graphql/createValueQuery'; +import returnValues from './menuItems/returnValues'; + +export interface ValueAttributeProps { + id: string; + value: string; + entityName: string; + column: string; + onChange: (event: any) => void; +} + +export default function ValueAttribute(props: ValueAttributeProps) { + const { id, value, onChange, entityName, column } = props; + const { data, loading, error } = useQuery( + createValueQuery(entityName, column), + ); + + if (loading) return

Loading...

; + console.log(entityName, column, data); + return ( + + {id} + + + ); +} diff --git a/packages/client/src/dashboard/presentation/components/Modal/filterAttributes/menuItems/returnColumns.tsx b/packages/client/src/dashboard/presentation/components/Modal/filterAttributes/menuItems/returnColumns.tsx index 206090a..ebd388f 100644 --- a/packages/client/src/dashboard/presentation/components/Modal/filterAttributes/menuItems/returnColumns.tsx +++ b/packages/client/src/dashboard/presentation/components/Modal/filterAttributes/menuItems/returnColumns.tsx @@ -5,15 +5,13 @@ type EntityColumnType = typeof EntityColumn; export default function returnColumns(dependencies: { [key: string]: string }) { const { entityName } = dependencies; - return () => { - if (entityName) - return EntityColumn[entityName as keyof EntityColumnType].map( - (column: { spName: string; dbName: string }) => ( - - {column.spName} - - ), - ); - return null; - }; + if (entityName === 'None' || !entityName) return () => null; + return () => + EntityColumn[entityName as keyof EntityColumnType].map( + (column: { spName: string; dbName: string }) => ( + + {column.spName} + + ), + ); } diff --git a/packages/client/src/dashboard/presentation/components/Modal/filterAttributes/menuItems/returnValues.tsx b/packages/client/src/dashboard/presentation/components/Modal/filterAttributes/menuItems/returnValues.tsx index 205cf3e..27460f9 100644 --- a/packages/client/src/dashboard/presentation/components/Modal/filterAttributes/menuItems/returnValues.tsx +++ b/packages/client/src/dashboard/presentation/components/Modal/filterAttributes/menuItems/returnValues.tsx @@ -9,22 +9,17 @@ export default function returnValues(dependencies: { const findValue = (data: any, entityName: string, column: string) => { if (data) { const entity = 'get' + entityName; - const datasets = []; - for (let i = 0; i < data[entity].length; i++) { - datasets.push(data[entity][i][column]); - } - return datasets; + const values: object[] = data[entity]; + return values.map((val: any) => val[column]); } return []; }; - return () => { - if (data && column && entityName) - return findValue(data, entityName, column).map((value: string) => ( - - {value} - - )); - return null; - }; + if (data && column && entityName) + return findValue(data, entityName, column).map((value: string) => ( + + {value} + + )); + return null; } diff --git a/packages/client/src/dashboard/presentation/components/SideBar/PresetListItem.tsx b/packages/client/src/dashboard/presentation/components/SideBar/PresetListItem.tsx index d2b2456..4940636 100644 --- a/packages/client/src/dashboard/presentation/components/SideBar/PresetListItem.tsx +++ b/packages/client/src/dashboard/presentation/components/SideBar/PresetListItem.tsx @@ -25,7 +25,6 @@ function PresetListItem(props: PresetListItemProps) { function myOnClickHandler(e: any) { e.stopPropagation(); changePresetLabel(id, presetLabel); - console.log('edit'); setEdit(!edit); } diff --git a/packages/client/src/dashboard/presentation/components/Sticker/Filter.type.ts b/packages/client/src/dashboard/presentation/components/Sticker/Filter.type.ts index 5f907c8..85bf16b 100644 --- a/packages/client/src/dashboard/presentation/components/Sticker/Filter.type.ts +++ b/packages/client/src/dashboard/presentation/components/Sticker/Filter.type.ts @@ -1,17 +1,9 @@ +import { EntityColumn } from 'common/src'; + export type EntityNameType = - | 'User' - | 'UserPersonalInformation' - | 'UserProcessProgress' - | 'UserLeaveOfAbsence' - | 'UserBlackhole' - | 'UserReasonOfBreak' - | 'UserOtherInformation' - | 'UserLapiscineInformation' - | 'UserEmploymentAndFound' - | 'UserHrdNetUtilize' - | 'UserEducationFundState' - | 'UserComputationFund' - | 'UserAccessCardInformation'; + | Extract + | 'None' + | ''; export type ColumnType = string;