:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { MakeLogicType, actions, afterMount, connect, kea, path, reducers, selectors } from 'kea'
import { loaders } from 'kea-loaders'
import api from 'lib/api'
import { teamLogic } from 'scenes/teamLogic'
import { batchExportsList } from 'products/batch_exports/frontend/generated/api'
import type { BatchExportApi } from 'products/batch_exports/frontend/generated/api.schemas'
import { compareBatchExportScheduleStatus, humanizeBatchExportName, normalizeBatchExportService } from './utils'
export type BatchExportsListFilters = {
search?: string
showPaused?: boolean
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface batchExportsListLogicValues {
currentTeamId: number | null // teamLogic
batchExports: BatchExportApi[] | null
batchExportsLoading: boolean
filteredBatchExports: BatchExportApi[]
filters: BatchExportsListFilters
hiddenBatchExports: BatchExportApi[]
sortedBatchExports: BatchExportApi[]
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface batchExportsListLogicActions {
loadBatchExports: () => any
loadBatchExportsFailure: (
error: string,
errorObject?: any
) => {
error: string
errorObject?: any
}
loadBatchExportsSuccess: (
batchExports: BatchExportApi[],
payload?: any
) => {
batchExports: BatchExportApi[]
payload?: any
}
resetFilters: () => {
value: true
}
setFilters: (filters: Partial<BatchExportsListFilters>) => {
filters: Partial<BatchExportsListFilters>
}
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface batchExportsListLogicMeta {
__keaTypeGenInternalSelectorTypes: {
sortedBatchExports: (batchExports: BatchExportApi[] | null) => BatchExportApi[]
filteredBatchExports: (
sortedBatchExports: BatchExportApi[],
filters: BatchExportsListFilters
) => BatchExportApi[]
hiddenBatchExports: (
sortedBatchExports: BatchExportApi[],
filteredBatchExports: BatchExportApi[]
) => BatchExportApi[]
}
}
export type batchExportsListLogicType = MakeLogicType<
batchExportsListLogicValues,
batchExportsListLogicActions,
Record<string, any>,
batchExportsListLogicMeta
>
export const batchExportsListLogic = kea<batchExportsListLogicType>([
path(['scenes', 'data-pipelines', 'batch-exports', 'batchExportsListLogic']),
connect(() => ({
values: [teamLogic, ['currentTeamId']],
})),
actions({
setFilters: (filters: Partial<BatchExportsListFilters>) => ({ filters }),
resetFilters: true,
}),
loaders(({ values }) => ({
batchExports: [
null as BatchExportApi[] | null,
{
loadBatchExports: async () => {
const firstPage = await batchExportsList(String(values.currentTeamId))
// nosemgrep: prefer-codegen-api -- Legacy raw API call with a URL built at runtime and an unchecked response type. Use a generated function if one covers this endpoint.
const otherPages = await api.loadPaginatedResults<BatchExportApi>(firstPage.next ?? null)
return [...firstPage.results, ...otherPages]
},
},
],
})),
reducers({
filters: [
{} as BatchExportsListFilters,
{
setFilters: (state, { filters }) => ({ ...state, ...filters }),
resetFilters: () => ({}),
},
],
}),
selectors({
sortedBatchExports: [
(s) => [s.batchExports],
(batchExports: BatchExportApi[] | null): BatchExportApi[] =>
[...(batchExports ?? [])].sort(compareBatchExportScheduleStatus),
],
filteredBatchExports: [
(s) => [s.sortedBatchExports, s.filters],
(sortedBatchExports: BatchExportApi[], filters: BatchExportsListFilters): BatchExportApi[] => {
const search = filters.search?.trim().toLowerCase()
return sortedBatchExports.filter((batchExport) => {
if (!filters.showPaused && batchExport.paused) {
return false
}
if (!search) {
return true
}
const service = humanizeBatchExportName(normalizeBatchExportService(batchExport.destination.type))
return batchExport.name.toLowerCase().includes(search) || service.toLowerCase().includes(search)
})
},
],
hiddenBatchExports: [
(s) => [s.sortedBatchExports, s.filteredBatchExports],
(sortedBatchExports: BatchExportApi[], filteredBatchExports: BatchExportApi[]): BatchExportApi[] =>
sortedBatchExports.filter((batchExport) => !filteredBatchExports.includes(batchExport)),
],
}),
afterMount(({ actions }) => {
actions.loadBatchExports()
}),
])