Skip to content

Commit

Permalink
🪟 🧹 Add cron string to segment calls, remove outdated schedule prop…
Browse files Browse the repository at this point in the history
…erty use (airbytehq#17672)

* update segment schedule frequency calls to include cron string, unify return value format

* remove unused frequencyType prop

* cleanup

* rename and move util
  • Loading branch information
teallarson authored Oct 6, 2022
1 parent c170173 commit ada1cbf
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
4 changes: 0 additions & 4 deletions airbyte-webapp/src/config/utils.ts

This file was deleted.

13 changes: 13 additions & 0 deletions airbyte-webapp/src/core/analytics/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ConnectionScheduleData } from "core/request/AirbyteClient";

export const getFrequencyFromScheduleData = (scheduleData?: ConnectionScheduleData) => {
if (!scheduleData) {
return "manual";
} else if (scheduleData.cron) {
return `${scheduleData.cron.cronExpression} ${scheduleData.cron.cronTimeZone}`;
} else if (scheduleData.basicSchedule) {
return `${scheduleData.basicSchedule.units} ${scheduleData.basicSchedule.timeUnit}`;
}
// this should never get called but the linter wants a catch-all
return null;
};
8 changes: 4 additions & 4 deletions airbyte-webapp/src/hooks/services/useConnectionHook.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useCallback } from "react";
import { useMutation, useQueryClient } from "react-query";

import { getFrequencyType } from "config/utils";
import { Action, Namespace } from "core/analytics";
import { getFrequencyFromScheduleData } from "core/analytics/utils";
import { SyncSchema } from "core/domain/catalog";
import { WebBackendConnectionService } from "core/domain/connection";
import { ConnectionService } from "core/domain/connection/ConnectionService";
Expand Down Expand Up @@ -100,7 +100,7 @@ export const useSyncConnection = () => {
connector_source_definition_id: connection.source?.sourceDefinitionId,
connector_destination: connection.destination?.destinationName,
connector_destination_definition_id: connection.destination?.destinationDefinitionId,
frequency: getFrequencyType(connection.scheduleData?.basicSchedule),
frequency: getFrequencyFromScheduleData(connection.scheduleData),
});

return service.sync(connection.connectionId);
Expand Down Expand Up @@ -145,7 +145,7 @@ const useCreateConnection = () => {

analyticsService.track(Namespace.CONNECTION, Action.CREATE, {
actionDescription: "New connection created",
frequency: getFrequencyType(values.scheduleData?.basicSchedule),
frequency: getFrequencyFromScheduleData(values.scheduleData),
connector_source_definition: source?.sourceName,
connector_source_definition_id: sourceDefinition?.sourceDefinitionId,
connector_destination_definition: destination?.destinationName,
Expand Down Expand Up @@ -228,7 +228,7 @@ export const useEnableConnection = () => {
const action = connection.status === ConnectionStatus.active ? Action.REENABLE : Action.DISABLE;

analyticsService.track(Namespace.CONNECTION, action, {
frequency: getFrequencyType(connection.scheduleData?.basicSchedule),
frequency: getFrequencyFromScheduleData(connection.scheduleData),
connector_source: connection.source?.sourceName,
connector_source_definition_id: connection.source?.sourceDefinitionId,
connector_destination: connection.destination?.destinationName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Navigate, Route, Routes, useParams } from "react-router-dom";
import { LoadingPage, MainPageWithScroll } from "components";
import HeadTitle from "components/HeadTitle";

import { getFrequencyType } from "config/utils";
import { Action, Namespace } from "core/analytics";
import { getFrequencyFromScheduleData } from "core/analytics/utils";
import { ConnectionStatus } from "core/request/AirbyteClient";
import { useAnalyticsService, useTrackPage, PageTrackingCodes } from "hooks/services/Analytics";
import { useGetConnection } from "hooks/services/useConnectionHook";
Expand Down Expand Up @@ -38,7 +38,7 @@ export const ConnectionItemPage: React.FC = () => {
connector_source_definition_id: source.sourceDefinitionId,
connector_destination: destination.destinationName,
connector_destination_definition_id: destination.destinationDefinitionId,
frequency: getFrequencyType(connection.scheduleData?.basicSchedule),
frequency: getFrequencyFromScheduleData(connection.scheduleData),
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { Button } from "components/ui/Button";
import { Card } from "components/ui/Card";
import { Tooltip } from "components/ui/Tooltip";

import { getFrequencyType } from "config/utils";
import { Action, Namespace } from "core/analytics";
import { getFrequencyFromScheduleData } from "core/analytics/utils";
import { ConnectionStatus, JobWithAttemptsRead, WebBackendConnectionRead } from "core/request/AirbyteClient";
import Status from "core/statuses";
import { useTrackPage, PageTrackingCodes, useAnalyticsService } from "hooks/services/Analytics";
Expand Down Expand Up @@ -144,7 +144,7 @@ export const ConnectionStatusTab: React.FC<ConnectionStatusTabProps> = ({ connec
connector_source_definition_id: connection.source?.sourceDefinitionId,
connector_destination: connection.destination?.destinationName,
connector_destination_definition_id: connection.destination?.destinationDefinitionId,
frequency: getFrequencyType(connection.schedule),
frequency: getFrequencyFromScheduleData(connection.scheduleData),
job_page_size: jobPageSize,
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import styled from "styled-components";
import { Switch } from "components/ui/Switch";

import { Action, Namespace } from "core/analytics";
import { getFrequencyFromScheduleData } from "core/analytics/utils";
import { buildConnectionUpdate } from "core/domain/connection";
import { ConnectionStatus, WebBackendConnectionRead } from "core/request/AirbyteClient";
import { useAnalyticsService } from "hooks/services/Analytics";
Expand All @@ -31,11 +32,10 @@ const Content = styled.div`
interface EnabledControlProps {
connection: WebBackendConnectionRead;
disabled?: boolean;
frequencyType?: string;
onStatusUpdating?: (updating: boolean) => void;
}

const EnabledControl: React.FC<EnabledControlProps> = ({ connection, disabled, frequencyType, onStatusUpdating }) => {
const EnabledControl: React.FC<EnabledControlProps> = ({ connection, disabled, onStatusUpdating }) => {
const { mutateAsync: updateConnection, isLoading } = useUpdateConnection();
const analyticsService = useAnalyticsService();

Expand All @@ -54,7 +54,7 @@ const EnabledControl: React.FC<EnabledControlProps> = ({ connection, disabled, f
connector_source_definition_id: connection.source?.sourceDefinitionId,
connector_destination: connection.destination?.destinationName,
connector_destination_definition_id: connection.destination?.destinationDefinitionId,
frequency: frequencyType,
frequency: getFrequencyFromScheduleData(connection.scheduleData),
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Link } from "react-router-dom";

import { ConnectorCard } from "components";

import { getFrequencyType } from "config/utils";
import { ConnectionStatus, SourceRead, DestinationRead, WebBackendConnectionRead } from "core/request/AirbyteClient";
import { FeatureItem, useFeature } from "hooks/services/Feature";
import { RoutePaths } from "pages/routePaths";
Expand Down Expand Up @@ -59,12 +58,7 @@ export const StatusMainInfo: React.FC<StatusMainInfoProps> = ({
</div>
{connection.status !== ConnectionStatus.deprecated && (
<div className={styles.enabledControlContainer}>
<EnabledControl
onStatusUpdating={onStatusUpdating}
disabled={!allowSync}
connection={connection}
frequencyType={getFrequencyType(connection.scheduleData?.basicSchedule)}
/>
<EnabledControl onStatusUpdating={onStatusUpdating} disabled={!allowSync} connection={connection} />
</div>
)}
</div>
Expand Down

0 comments on commit ada1cbf

Please sign in to comment.