Skip to content

Commit

Permalink
Fix catalog issue (#2284)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamakase authored Mar 3, 2021
1 parent f7ada7c commit a39eb4f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const CreateConnectionContent: React.FC<IProps> = ({
await createConnection({
values: {
frequency: values.frequency,
syncCatalog: schema,
syncCatalog: values.schema,
},
source: source,
destination: destination,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const FrequencyForm: React.FC<IProps> = ({

const [modalIsOpen, setResetModalIsOpen] = useState(false);
const formatMessage = useIntl().formatMessage;
// TODO: newSchema config should be part of formik schema
const [newSchema, setNewSchema] = useState(initialSchema);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ const TitleContainer = styled.div<{ hasButton: boolean }>`
margin: ${({ hasButton }) => (hasButton ? "-5px 0" : 0)};
`;

type FormValues = {
frequency: string;
schema: SyncSchema;
};

const SettingsView: React.FC<IProps> = ({
onAfterSaveSchema,
connectionId,
Expand All @@ -45,10 +50,10 @@ const SettingsView: React.FC<IProps> = ({
const formatMessage = useIntl().formatMessage;
const [saved, setSaved] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const [currentValues, setCurrentValues] = useState<{
frequency: string;
schema: SyncSchema;
}>({ frequency: "", schema: { streams: [] } });
const [currentValues, setCurrentValues] = useState<FormValues>({
frequency: "",
schema: { streams: [] },
});
const [errorMessage, setErrorMessage] = useState("");
const {
updateConnection,
Expand All @@ -75,31 +80,7 @@ const SettingsView: React.FC<IProps> = ({
connection &&
FrequencyConfig.find((item) => equal(connection.schedule, item.config));

const onSubmitResetModal = async () => {
if (activeUpdatingSchemaMode) {
setIsUpdateModalOpen(false);
await onSubmit(currentValues);
} else {
onSubmitModal();
}
};

const onSubmitForm = async (values: {
frequency: string;
schema: SyncSchema;
}) => {
if (activeUpdatingSchemaMode) {
setCurrentValues(values);
setIsUpdateModalOpen(true);
} else {
await onSubmit(values);
}
};

const onSubmit = async (values: {
frequency: string;
schema: SyncSchema;
}) => {
const onSubmit = async (values: FormValues) => {
setIsLoading(true);
const frequencyData = FrequencyConfig.find(
(item) => item.value === values.frequency
Expand Down Expand Up @@ -135,20 +116,23 @@ const SettingsView: React.FC<IProps> = ({
}
};

const onSubmitModal = () => {
setActiveUpdatingSchemaMode(true);
setIsUpdateModalOpen(false);
const onSubmitResetModal = async () => {
if (activeUpdatingSchemaMode) {
setIsUpdateModalOpen(false);
await onSubmit(currentValues);
} else {
setActiveUpdatingSchemaMode(true);
setIsUpdateModalOpen(false);
}
};

const endControl = () => {
if (!activeUpdatingSchemaMode) {
return (
<Button onClick={() => setIsUpdateModalOpen(true)}>
<FormattedMessage id="connection.updateSchema" />
</Button>
);
const onSubmitForm = async (values: FormValues) => {
if (activeUpdatingSchemaMode) {
setCurrentValues(values);
setIsUpdateModalOpen(true);
} else {
await onSubmit(values);
}
return null;
};

return (
Expand All @@ -157,7 +141,11 @@ const SettingsView: React.FC<IProps> = ({
title={
<TitleContainer hasButton={!activeUpdatingSchemaMode}>
<FormattedMessage id="connection.connectionSettings" />{" "}
{endControl()}
{!activeUpdatingSchemaMode && (
<Button onClick={() => setIsUpdateModalOpen(true)}>
<FormattedMessage id="connection.updateSchema" />
</Button>
)}
</TitleContainer>
}
>
Expand Down

0 comments on commit a39eb4f

Please sign in to comment.