Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using update_only when doing background discover and content change #955

Merged
merged 19 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/api/discovers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ export const discover = (
entityName: string,
config: any,
connectorID: string,
draftID: string
draftID: string,
updateOnly?: boolean
) => {
return insertSupabase(TABLES.DISCOVERS, {
capture_name: entityName,
endpoint_config: config,
connector_tag_id: connectorID,
draft_id: draftID,
update_only: updateOnly ?? false,
});
};
10 changes: 10 additions & 0 deletions src/components/capture/GenerateButton.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Button } from '@mui/material';
import { buttonSx } from 'components/shared/Entity/Header';
import { useEntityWorkflow_Editing } from 'context/Workflow';
import { Dispatch, SetStateAction, useEffect } from 'react';
import { FormattedMessage } from 'react-intl';
import {
useDetailsForm_connectorImage_connectorId,
useDetailsForm_entityNameChanged,
useDetailsForm_previousConnectorImage_connectorId,
} from 'stores/DetailsForm/hooks';
import { useEndpointConfigStore_changed } from 'stores/EndpointConfig/hooks';
import { useFormStateStore_status } from 'stores/FormState/hooks';
import { FormStatus } from 'stores/FormState/types';
import { useResourceConfig_rediscoveryRequired } from 'stores/ResourceConfig/hooks';
Expand All @@ -27,10 +29,18 @@ function CaptureGenerateButton({
disabled,
createWorkflowMetadata,
}: Props) {
const isEdit = useEntityWorkflow_Editing();
const endpointConfigChanged = useEndpointConfigStore_changed();
const rediscoveryRequired = useResourceConfig_rediscoveryRequired();

const { generateCatalog, isSaving, formActive } = useDiscoverCapture(
entityType,
{
// We only want to set updateOnly if the user is editing and not updating the config
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and not updating the config

Given the presence of the useResourceConfig_rediscoveryRequired hook above, it should be clear that the resource config is what is being referred to by the term config. However, it could not hurt to explicitly state that updateOnly should be set if the user (clicked the Next CTA and) did not change the resource config in an edit workflow.

// This should cover when a user has enable previously disabled collection(s)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a user has enable previously disabled collection(s)

Removing the passive voice from this comment will increase its clarity: This should cover when a user enables previously disabled collection(s).

updateOnly: Boolean(
rediscoveryRequired && isEdit && !endpointConfigChanged()
),
initiateDiscovery: createWorkflowMetadata?.initiateDiscovery,
initiateRediscovery: rediscoveryRequired,
}
Expand Down
10 changes: 8 additions & 2 deletions src/components/capture/useDiscoverCapture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ import useDiscoverStartDiscovery from './useDiscoverStartDiscovery';

function useDiscoverCapture(
entityType: Entity,
options?: { initiateRediscovery?: boolean; initiateDiscovery?: boolean }
options?: {
initiateRediscovery?: boolean;
initiateDiscovery?: boolean;
updateOnly?: boolean;
}
) {
const draftUpdate = useDiscoverDraftUpdate(options);
const configEncrypt = useDiscoverConfigEncrypt();
Expand Down Expand Up @@ -111,7 +115,8 @@ function useDiscoverCapture(
const discoveryStartSuccess = await startDiscovery(
processedEntityName,
encryptedEndpointConfig.data,
options.initiateRediscovery
options.initiateRediscovery,
options.updateOnly
);

return discoveryStartSuccess;
Expand All @@ -138,6 +143,7 @@ function useDiscoverCapture(
endpointConfigErrorsExist,
options?.initiateDiscovery,
options?.initiateRediscovery,
options?.updateOnly,
persistedDraftId,
processedEntityName,
resetEditorState,
Expand Down
14 changes: 12 additions & 2 deletions src/components/capture/useDiscoverStartDiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import {
useEditorStore_persistedDraftId,
useEditorStore_setCatalogName,
useEditorStore_setId,
} from 'components/editor/Store/hooks';
import useEntityWorkflowHelpers from 'components/shared/Entity/hooks/useEntityWorkflowHelpers';
import { useCallback } from 'react';
Expand All @@ -19,6 +20,7 @@
useDiscoverStartSubscription(entityType);
const { callFailed } = useEntityWorkflowHelpers();

const setDraftId = useEditorStore_setId();
const persistedDraftId = useEditorStore_persistedDraftId();
const setCatalogName = useEditorStore_setCatalogName();

Expand All @@ -32,7 +34,8 @@
async (
processedEntityName: string,
encryptedEndpointConfigResponse: any,
rediscover?: boolean
rediscover?: boolean,
updateOnly?: boolean
) => {
// If we are doing a rediscovery and we have a draft then go ahead and use that draft
// that way the most recent changes to bindings and endpoints will get added to the draft before rediscovery
Expand Down Expand Up @@ -64,9 +67,16 @@
processedEntityName,
encryptedEndpointConfigResponse,
imageConnectorTagId,
newDraftId
newDraftId,
updateOnly
);

if (discoverResponse.error) {
// If we failed at discovery we need to clear draft ID like we do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is a little muddled to me. What do you think of the following:

// If discovery fails, clear the draft ID to preserve the _Next_ CTA and allow the user to attempt to discover another time.

// when we createDiscoversSubscription. Otherwise, the Test|Save
// buttons will appear.
setDraftId(null);

callFailed({
error: {
title: 'captureCreate.generate.failedErrorTitle',
Expand All @@ -88,7 +98,7 @@

return true;
},
[

Check warning on line 101 in src/components/capture/useDiscoverStartDiscovery.ts

View workflow job for this annotation

GitHub Actions / Check Quality

React Hook useCallback has a missing dependency: 'setDraftId'. Either include it or remove the dependency array
callFailed,
createDiscoversSubscription,
endpointConfigData,
Expand Down
2 changes: 1 addition & 1 deletion src/lang/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ const CaptureEdit: ResolvedIntlConfig['messages'] = {
'captureEdit.editor.default': `Before you can edit the capture specification, you must fill out the Connection Configuration section and click "${CTAs['cta.generateCatalog.capture']}." `,
'captureEdit.finalReview.instructions': `The following Flow specification was generated from the details you provided. To make changes, you can enter new values in the form above or edit the YAML file directly. Click "${CTAs['cta.saveEntity']}" to proceed.`,

'captureEdit.collections.heading': `3. Source Collections`,
'captureEdit.collections.heading': `3. Target Collections`,
'captureEdit.collectionSelector.heading': `Collection Selector`,
'captureEdit.collectionSelector.instructions': `The collections bound to your existing capture. To update the configuration, please update the fields under the Config tab. To update the schema, click Edit under the Collection tab.`,

Expand Down