From 0fd850937c66f0f11247dee120cb27324eb95f02 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Mon, 14 Aug 2023 18:20:48 +0530 Subject: [PATCH] common refractor --- webapp/src/components/EnumSelect.tsx | 12 +-- webapp/src/components/ImportButton.tsx | 4 +- webapp/src/components/LabelsSelect.tsx | 80 +++++++++---------- .../components/NotificationMethodSelect.tsx | 4 +- webapp/src/components/OptionalFunction.tsx | 18 ++--- webapp/src/components/SplitForm.tsx | 2 +- webapp/src/components/Table.tsx | 2 +- webapp/src/components/ViewSelect.tsx | 4 +- webapp/src/domain/schemas/FindUsagesModal.tsx | 4 +- webapp/src/domain/schemas/Labels.tsx | 16 ++-- 10 files changed, 73 insertions(+), 73 deletions(-) diff --git a/webapp/src/components/EnumSelect.tsx b/webapp/src/components/EnumSelect.tsx index 412a8a196..73a797246 100644 --- a/webapp/src/components/EnumSelect.tsx +++ b/webapp/src/components/EnumSelect.tsx @@ -9,21 +9,21 @@ type EnumSelectProps = { isDisabled?: boolean } -export default function EnumSelect(props: EnumSelectProps) { +export default function EnumSelect({options, selected, onSelect, isDisabled}: EnumSelectProps) { const [isOpen, setOpen] = useState(false) return ( { - if (expanded && props.onOpen) { - props.onOpen() + if (expanded && onOpen) { + onOpen() } setOpen(expanded) }} - selections={[props.selection === null ? props.all : props.selection]} + selections={[selection === null && all || selection]} onSelect={(_, item) => { - props.onSelect(item === props.all ? null : item) + onSelect(item === all && null || item) setOpen(false) }} - onClear={props.hasOnlyOneOption ? undefined : () => props.onSelect(undefined)} + onClear={hasOnlyOneOption ? undefined : () => onSelect(undefined)} menuAppendTo="parent" - placeholderText={props.placeholderText} - style={props.style} - width={props.style?.width || "auto"} + placeholderText={placeholderText} + style={style} + width={style?.width || "auto"} > - {props.options.map((labels: SelectOptionObject | string, i: number) => ( + {options.map((labels: SelectOptionObject | string, i: number) => ( ))} diff --git a/webapp/src/components/NotificationMethodSelect.tsx b/webapp/src/components/NotificationMethodSelect.tsx index e6badfdb0..070ba07f3 100644 --- a/webapp/src/components/NotificationMethodSelect.tsx +++ b/webapp/src/components/NotificationMethodSelect.tsx @@ -27,8 +27,8 @@ export default function NotificationMethodSelect({isDisabled, method, onChange}: }} placeholderText="Please select..." > - {methods.map((m, i) => ( - + {methods.map((method, i) => ( + ))} ) diff --git a/webapp/src/components/OptionalFunction.tsx b/webapp/src/components/OptionalFunction.tsx index 8e076cb11..f15893e7a 100644 --- a/webapp/src/components/OptionalFunction.tsx +++ b/webapp/src/components/OptionalFunction.tsx @@ -11,40 +11,40 @@ type OptionalFunctionProps = { defaultFunc: string } -export default function OptionalFunction(props: OptionalFunctionProps) { - if (props.func === undefined || props.func === null) { - if (props.readOnly) { - return <>{props.undefinedText} +export default function OptionalFunction({func, onChange, readOnly, undefinedText, addText, defaultFunc}: OptionalFunctionProps) { + if (func === undefined || func === null) { + if (readOnly) { + return <>{undefinedText} } else { return ( ) } } else { // failsafe if the wrong type gets passed in - const funcAsString = typeof props.func === "string" ? props.func : (props.func as any).toString() + const funcAsString = typeof func === "string" ? func : (func as any).toString() return (
{ - props.onChange(value?.trim() || "") + onChange(value?.trim() || "") }} language="typescript" options={{ wordWrap: "on", wrappingIndent: "DeepIndent", - readOnly: props.readOnly, + readOnly: readOnly, }} />
diff --git a/webapp/src/components/SplitForm.tsx b/webapp/src/components/SplitForm.tsx index 5cf3e4446..920cc972a 100644 --- a/webapp/src/components/SplitForm.tsx +++ b/webapp/src/components/SplitForm.tsx @@ -83,7 +83,7 @@ export default function SplitForm(props: SplitFormProps) { const newItems = props.items.filter(t => t.id !== props.selected?.id) props.onDelete(item) props.onChange(newItems) - props.onSelected(newItems.length > 0 ? newItems[0] : undefined) + props.onSelected(newItems.length > 0 && newItems[0] || undefined) } } return ( diff --git a/webapp/src/components/Table.tsx b/webapp/src/components/Table.tsx index ffaf4b314..1d2d65421 100644 --- a/webapp/src/components/Table.tsx +++ b/webapp/src/components/Table.tsx @@ -127,7 +127,7 @@ function Table({ diff --git a/webapp/src/components/ViewSelect.tsx b/webapp/src/components/ViewSelect.tsx index e7a6d1a50..db8ed4036 100644 --- a/webapp/src/components/ViewSelect.tsx +++ b/webapp/src/components/ViewSelect.tsx @@ -18,8 +18,8 @@ export default function ViewSelect({views, viewId, onChange}: ViewSelectProps) { onToggle={setOpen} selections={selected !== undefined ? { ...selected, toString: () => selected.name } : undefined} onSelect={(_, item) => { - onChange((item as View).id) - setOpen(false) + onChange((item as View).id) + setOpen(false) }} > {views.map(view => ( diff --git a/webapp/src/domain/schemas/FindUsagesModal.tsx b/webapp/src/domain/schemas/FindUsagesModal.tsx index 81f053c4a..970b4b2d6 100644 --- a/webapp/src/domain/schemas/FindUsagesModal.tsx +++ b/webapp/src/domain/schemas/FindUsagesModal.tsx @@ -142,10 +142,10 @@ export default function FindUsagesModal(props: FindUsagesModalProps) { {schemas ? ( - {schemas.map((s, i) => ( + {schemas.map((shema, i) => ( {/* TODO: looks like this is not navigating anywhere but IDK why */} - props.onClose()} descriptor={s} /> + props.onClose()} descriptor={shema} /> ))} diff --git a/webapp/src/domain/schemas/Labels.tsx b/webapp/src/domain/schemas/Labels.tsx index 2657b8296..0be265950 100644 --- a/webapp/src/domain/schemas/Labels.tsx +++ b/webapp/src/domain/schemas/Labels.tsx @@ -41,7 +41,7 @@ type LabelsProps = { funcsRef: TabFunctionsRef } -export default function Labels(props: LabelsProps) { +export default function Labels({schemaId, schemaUri, funcsRef}: LabelsProps) { const [loading, setLoading] = useState(false) const [labels, setLabels] = useState([]) const [selected, setSelected] = useState() @@ -53,7 +53,7 @@ export default function Labels(props: LabelsProps) { const isTesterForLabel = useTester(selected?.owner || "__no_owner__") const defaultTeam = useSelector(defaultTeamSelector) const dispatch = useDispatch() - props.funcsRef.current = { + funcsRef.current = { save: () => Promise.all([ ...labels @@ -96,7 +96,7 @@ export default function Labels(props: LabelsProps) { const history = useHistory() useEffect(() => { setLoading(true) - Api.schemaServiceLabels(props.schemaId) + Api.schemaServiceLabels(schemaId) .then( labels => { setLabels(labels) @@ -118,11 +118,11 @@ export default function Labels(props: LabelsProps) { dispatch, error, "LIST_LABELS", - "Failed to fetch labels for schema " + props.schemaUri + "Failed to fetch labels for schema " + schemaUri ).catch(noop) ) .finally(() => setLoading(false)) - }, [props.schemaId, resetCounter]) + }, [schemaId, resetCounter]) return ( <> @@ -143,7 +143,7 @@ export default function Labels(props: LabelsProps) { extractors: [], owner: defaultTeam || "", access: 0 as Access, - schemaId: props.schemaId, + schemaId: schemaId, filtering: true, metrics: true, modified: true, @@ -217,7 +217,7 @@ export default function Labels(props: LabelsProps) { {selected.extractors.map((extractor, i) => { return ( setTestLabelModalOpen(false)}