Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
EDsCODE committed Oct 27, 2023
1 parent dbebbf7 commit 9dd6eee
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 54 deletions.
22 changes: 11 additions & 11 deletions frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ import {
BatchExportRun,
UserBasicType,
NotebookNodeResource,
ExternalDataStripeResourceCreatePayload,
ExternalDataStripeResource,
ExternalDataStripeSourceCreatePayload,

Check failure on line 53 in frontend/src/lib/api.ts

View workflow job for this annotation

GitHub Actions / Code quality checks

'"~/types"' has no exported member named 'ExternalDataStripeSourceCreatePayload'. Did you mean 'ExternalDataStripeResourceCreatePayload'?
ExternalDataStripeSource,

Check failure on line 54 in frontend/src/lib/api.ts

View workflow job for this annotation

GitHub Actions / Code quality checks

'"~/types"' has no exported member named 'ExternalDataStripeSource'. Did you mean 'ExternalDataStripeResource'?
} from '~/types'
import { getCurrentOrganizationId, getCurrentTeamId } from './utils/logics'
import { CheckboxValueType } from 'antd/lib/checkbox/Group'
Expand Down Expand Up @@ -568,9 +568,9 @@ class ApiRequest {
return this.batchExportRun(id, runId, teamId).addPathComponent('logs')
}

// External Data Resource
public externalDataResources(teamId?: TeamType['id']): ApiRequest {
return this.projectsDetail(teamId).addPathComponent('external_data_resources')
// External Data Source
public externalDataSources(teamId?: TeamType['id']): ApiRequest {
return this.projectsDetail(teamId).addPathComponent('external_data_sources')
}

// Request finalization
Expand Down Expand Up @@ -1578,14 +1578,14 @@ const api = {
},
},

externalDataResources: {
async list(): Promise<PaginatedResponse<ExternalDataStripeResource>> {
return await new ApiRequest().externalDataResources().get()
externalDataSources: {
async list(): Promise<PaginatedResponse<ExternalDataStripeSource>> {
return await new ApiRequest().externalDataSources().get()
},
async create(
data: Partial<ExternalDataStripeResourceCreatePayload>
): Promise<ExternalDataStripeResourceCreatePayload> {
return await new ApiRequest().externalDataResources().create({ data })
data: Partial<ExternalDataStripeSourceCreatePayload>
): Promise<ExternalDataStripeSourceCreatePayload> {
return await new ApiRequest().externalDataSources().create({ data })
},
},

Expand Down
15 changes: 5 additions & 10 deletions frontend/src/scenes/data-warehouse/external/SourceModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import stripeLogo from 'public/stripe-logo.svg'
interface SourceModalProps extends LemonModalProps {}

export default function SourceModal(props: SourceModalProps): JSX.Element {
const { tableLoading, isExternalDataResourceSubmitting, selectedConnector, isManualLinkFormVisible, connectors } =
const { tableLoading, isExternalDataSourceSubmitting, selectedConnector, isManualLinkFormVisible, connectors } =
useValues(sourceModalLogic)
const { selectConnector, toggleManualLinkFormVisible, resetExternalDataResource, resetTable } =
const { selectConnector, toggleManualLinkFormVisible, resetExternalDataSource, resetTable } =
useActions(sourceModalLogic)

const MenuButton = (config: ConnectorConfigType): JSX.Element => {
Expand All @@ -29,7 +29,7 @@ export default function SourceModal(props: SourceModalProps): JSX.Element {
const onClear = (): void => {
selectConnector(null)
toggleManualLinkFormVisible(false)
resetExternalDataResource()
resetExternalDataSource()
resetTable()
}

Expand All @@ -40,12 +40,7 @@ export default function SourceModal(props: SourceModalProps): JSX.Element {
const formToShow = (): JSX.Element => {
if (selectedConnector) {
return (
<Form
logic={sourceModalLogic}
formKey={'externalDataResource'}
className="space-y-4"
enableFormOnSubmit
>
<Form logic={sourceModalLogic} formKey={'externalDataSource'} className="space-y-4" enableFormOnSubmit>
<Field name="account_id" label="Account Id">
<LemonInput className="ph-ignore-input" autoFocus data-attr="account-id" placeholder="acct_" />
</Field>
Expand All @@ -67,7 +62,7 @@ export default function SourceModal(props: SourceModalProps): JSX.Element {
center
htmlType="submit"
data-attr="source-link"
loading={isExternalDataResourceSubmitting}
loading={isExternalDataSourceSubmitting}
>
Link
</LemonButton>
Expand Down
16 changes: 8 additions & 8 deletions frontend/src/scenes/data-warehouse/external/sourceModalLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { actions, connect, kea, path, reducers, selectors, listeners } from 'kea

import type { sourceModalLogicType } from './sourceModalLogicType'
import { forms } from 'kea-forms'
import { ExternalDataStripeResourceCreatePayload } from '~/types'
import { ExternalDataStripeSourceCreatePayload } from '~/types'

Check failure on line 5 in frontend/src/scenes/data-warehouse/external/sourceModalLogic.ts

View workflow job for this annotation

GitHub Actions / Code quality checks

'"~/types"' has no exported member named 'ExternalDataStripeSourceCreatePayload'. Did you mean 'ExternalDataStripeResourceCreatePayload'?
import api from 'lib/api'
import { lemonToast } from '@posthog/lemon-ui'
import { dataWarehouseTableLogic } from '../dataWarehouseTableLogic'
Expand Down Expand Up @@ -78,29 +78,29 @@ export const sourceModalLogic = kea<sourceModalLogicType>([
],
}),
forms(() => ({
externalDataResource: {
defaults: { account_id: '', client_secret: '' } as ExternalDataStripeResourceCreatePayload,
externalDataSource: {
defaults: { account_id: '', client_secret: '' } as ExternalDataStripeSourceCreatePayload,
errors: ({ account_id, client_secret }) => {
return {
account_id: !account_id && 'Please enter an account id.',
client_secret: !client_secret && 'Please enter a client secret.',
}
},
submit: async (payload: ExternalDataStripeResourceCreatePayload) => {
const newResource = await api.externalDataResources.create(payload)
submit: async (payload: ExternalDataStripeSourceCreatePayload) => {
const newResource = await api.externalDataSources.create(payload)
return newResource
},
},
})),
listeners(({ actions }) => ({
submitExternalDataResourceSuccess: () => {
submitExternalDataSourceSuccess: () => {
lemonToast.success('New Data Resource Created')
actions.toggleSourceModal()
actions.resetExternalDataResource()
actions.resetExternalDataSource()
actions.loadSources()
router.actions.push(urls.dataWarehouseSettings())
},
submitExternalDataResourceFailure: () => {
submitExternalDataSourceFailure: () => {
lemonToast.error('Error creating new Data Resource. Check that provided credentials are valid.')
},
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { afterMount, kea, path, selectors } from 'kea'
import type { dataWarehouseSettingsLogicType } from './dataWarehouseSettingsLogicType'
import { loaders } from 'kea-loaders'
import api, { PaginatedResponse } from 'lib/api'
import { ExternalDataStripeResource, Breadcrumb } from '~/types'
import { ExternalDataStripeSource, Breadcrumb } from '~/types'
import { urls } from 'scenes/urls'

export interface DataWarehouseSource {}
Expand All @@ -12,10 +12,10 @@ export const dataWarehouseSettingsLogic = kea<dataWarehouseSettingsLogicType>([
path(['scenes', 'data-warehouse', 'settings', 'dataWarehouseSettingsLogic']),
loaders({
dataWarehouseSources: [
null as PaginatedResponse<ExternalDataStripeResource> | null,
null as PaginatedResponse<ExternalDataStripeSource> | null,
{
loadSources: async () => {
return api.externalDataResources.list()
return api.externalDataSources.list()
},
},
],
Expand Down
8 changes: 4 additions & 4 deletions posthog/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from posthog.api.routing import DefaultRouterPlusPlus
from posthog.batch_exports import http as batch_exports
from posthog.settings import EE_AVAILABLE
from posthog.warehouse.api import external_data_resource, saved_query, table, view_link
from posthog.warehouse.api import external_data_source, saved_query, table, view_link
from ..session_recordings.session_recording_api import SessionRecordingViewSet
from . import (
activity_log,
Expand Down Expand Up @@ -212,9 +212,9 @@ def api_not_found(request):

# External data resources
projects_router.register(
r"external_data_resources",
external_data_resource.ExternalDataReourceViewSet,
"project_external_data_resources",
r"external_data_sources",
external_data_source.ExternalDataSourceViewSet,
"project_external_data_sources",
["team_id"],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Migration(migrations.Migration):

operations = [
migrations.CreateModel(
name="ExternalDataResource",
name="ExternalDataSource",
fields=[
("created_at", models.DateTimeField(auto_now_add=True)),
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@
from rest_framework.exceptions import NotAuthenticated
from rest_framework.permissions import IsAuthenticated
from rest_framework import filters, serializers, viewsets
from posthog.warehouse.models import ExternalDataResource
from posthog.warehouse.external_data_resource.source import StripeSourcePayload, create_stripe_source
from posthog.warehouse.external_data_resource.connection import create_connection
from posthog.warehouse.external_data_resource.destination import create_destination
from posthog.warehouse.models import ExternalDataSource
from posthog.warehouse.external_data_source.source import StripeSourcePayload, create_stripe_source
from posthog.warehouse.external_data_source.connection import create_connection
from posthog.warehouse.external_data_source.destination import create_destination
from posthog.api.routing import StructuredViewSetMixin

from posthog.models import User
from typing import Any


class ExternalDataReourceSerializers(serializers.ModelSerializer):
class ExternalDataSourceSerializers(serializers.ModelSerializer):
account_id = serializers.CharField(write_only=True)
client_secret = serializers.CharField(write_only=True)

class Meta:
model = ExternalDataResource
model = ExternalDataSource
fields = ["id", "source_id", "created_at", "created_by", "status", "client_secret", "account_id", "source_type"]
read_only_fields = ["id", "source_id", "created_by", "created_at", "status", "source_type"]


class ExternalDataReourceViewSet(StructuredViewSetMixin, viewsets.ModelViewSet):
class ExternalDataSourceViewSet(StructuredViewSetMixin, viewsets.ModelViewSet):
"""
Create, Read, Update and Delete External data Sources.
"""

queryset = ExternalDataResource.objects.all()
serializer_class = ExternalDataReourceSerializers
queryset = ExternalDataSource.objects.all()
serializer_class = ExternalDataSourceSerializers
permission_classes = [IsAuthenticated, OrganizationMemberPermissions]
filter_backends = [filters.SearchFilter]
search_fields = ["source_id"]
Expand All @@ -58,7 +58,7 @@ def create(self, request: Request, *args: Any, **kwargs: Any) -> Response:
new_destination = create_destination(self.team_id)
new_connection = create_connection(new_source.source_id, new_destination.destination_id)

ExternalDataResource.objects.create(
ExternalDataSource.objects.create(
source_id=new_source.source_id,
connection_id=new_connection.connection_id,
team=self.request.user.current_team,
Expand Down
2 changes: 1 addition & 1 deletion posthog/warehouse/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from .credential import *
from .datawarehouse_saved_query import *
from .view_link import *
from .external_data_resource import *
from .external_data_source import *
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from posthog.models.team import Team


class ExternalDataResource(CreatedMetaFields, UUIDModel):
class ExternalDataSource(CreatedMetaFields, UUIDModel):
class Type(models.TextChoices):
STRIPE = "Stripe", "Stripe"

Expand Down
10 changes: 5 additions & 5 deletions posthog/warehouse/sync_resource.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from posthog.warehouse.models.external_data_resource import ExternalDataResource
from posthog.warehouse.models.external_data_source import ExternalDataSource
from posthog.warehouse.models import DataWarehouseCredential, DataWarehouseTable
from posthog.warehouse.external_data_resource.connection import retrieve_sync
from posthog.warehouse.external_data_source.connection import retrieve_sync
from posthog.celery import app

from django.conf import settings
Expand All @@ -10,20 +10,20 @@


def sync_resources():
resources = ExternalDataResource.objects.filter(are_tables_created=False, status="running")
resources = ExternalDataSource.objects.filter(are_tables_created=False, status="running")

for resource in resources:
_sync_resource.delay(resource.pk)


@app.task(ignore_result=True)
def _sync_resource(resource_id):
resource = ExternalDataResource.objects.get(pk=resource_id)
resource = ExternalDataSource.objects.get(pk=resource_id)
job = retrieve_sync(resource.connection_id)

if job["status"] == "succeeded":

resource = ExternalDataResource.objects.get(pk=resource_id)
resource = ExternalDataSource.objects.get(pk=resource_id)
credential, _ = DataWarehouseCredential.objects.get_or_create(
team_id=resource.team.pk,
access_key=settings.AIRBYTE_BUCKET_KEY,
Expand Down

0 comments on commit 9dd6eee

Please sign in to comment.