mirror of
https://github.com/MODSetter/SurfSense.git
synced 2025-09-01 10:09:08 +00:00
Merge pull request #261 from CREDO23/feature-google-calendar-connector/allow-indexing-future-events
Some checks failed
pre-commit / pre-commit (push) Has been cancelled
Some checks failed
pre-commit / pre-commit (push) Has been cancelled
[Improvement] Google calendar connector | Allow indexing for future events (dates
This commit is contained in:
commit
c6921a4083
4 changed files with 61 additions and 24 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
Revision ID: 4
|
||||
Revises: 3
|
||||
|
||||
Create Date: 2025-08-13
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
@ -17,31 +17,29 @@ depends_on: str | Sequence[str] | None = None
|
|||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
|
||||
# Manually add the command to add the enum value
|
||||
op.execute("ALTER TYPE searchsourceconnectortype ADD VALUE 'LINKUP_API'")
|
||||
|
||||
# Pass for the rest, as autogenerate didn't run to add other schema details
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
# Add enum value only if it doesn't already exist.
|
||||
# Postgres will no-op with a NOTICE when the value is present.
|
||||
op.execute(
|
||||
"ALTER TYPE searchsourceconnectortype ADD VALUE IF NOT EXISTS 'LINKUP_API'"
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
|
||||
# Downgrading removal of an enum value requires recreating the type
|
||||
# To "remove" an enum value in Postgres, we must recreate the type
|
||||
# without that value, migrate the column, then drop the old type.
|
||||
op.execute(
|
||||
"ALTER TYPE searchsourceconnectortype RENAME TO searchsourceconnectortype_old"
|
||||
)
|
||||
op.execute(
|
||||
"CREATE TYPE searchsourceconnectortype AS ENUM('SERPER_API', 'TAVILY_API', 'SLACK_CONNECTOR', 'NOTION_CONNECTOR', 'GITHUB_CONNECTOR', 'LINEAR_CONNECTOR')"
|
||||
"CREATE TYPE searchsourceconnectortype AS ENUM("
|
||||
"'SERPER_API', 'TAVILY_API', 'SLACK_CONNECTOR', "
|
||||
"'NOTION_CONNECTOR', 'GITHUB_CONNECTOR', 'LINEAR_CONNECTOR'"
|
||||
")"
|
||||
)
|
||||
op.execute(
|
||||
"ALTER TABLE search_source_connectors ALTER COLUMN connector_type TYPE searchsourceconnectortype USING "
|
||||
"connector_type::text::searchsourceconnectortype"
|
||||
"ALTER TABLE search_source_connectors "
|
||||
"ALTER COLUMN connector_type "
|
||||
"TYPE searchsourceconnectortype "
|
||||
"USING connector_type::text::searchsourceconnectortype"
|
||||
)
|
||||
op.execute("DROP TYPE searchsourceconnectortype_old")
|
||||
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
|
|
|
@ -40,6 +40,7 @@ import {
|
|||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { EnumConnectorName } from "@/contracts/enums/connector";
|
||||
import { useSearchSourceConnectors } from "@/hooks/useSearchSourceConnectors";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
|
@ -61,6 +62,7 @@ export default function ConnectorsPage() {
|
|||
const router = useRouter();
|
||||
const params = useParams();
|
||||
const searchSpaceId = params.search_space_id as string;
|
||||
const today = new Date();
|
||||
|
||||
const { connectors, isLoading, error, deleteConnector, indexConnector } =
|
||||
useSearchSourceConnectors();
|
||||
|
@ -139,6 +141,28 @@ export default function ConnectorsPage() {
|
|||
}
|
||||
};
|
||||
|
||||
const getDisabledEndDates = (date: Date) => {
|
||||
const connector = connectors.find((c) => c.id === selectedConnectorForIndexing);
|
||||
|
||||
switch (connector?.connector_type) {
|
||||
case EnumConnectorName.GOOGLE_CALENDAR_CONNECTOR:
|
||||
return startDate ? date < startDate : false;
|
||||
default:
|
||||
return date > today || (startDate ? date < startDate : false);
|
||||
}
|
||||
};
|
||||
|
||||
const getDisabledStartDates = (date: Date) => {
|
||||
const connector = connectors.find((c) => c.id === selectedConnectorForIndexing);
|
||||
|
||||
switch (connector?.connector_type) {
|
||||
case EnumConnectorName.GOOGLE_CALENDAR_CONNECTOR:
|
||||
return endDate ? date > endDate : false;
|
||||
default:
|
||||
return date > today || (endDate ? date > endDate : false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="container mx-auto py-8 max-w-6xl">
|
||||
<motion.div
|
||||
|
@ -342,7 +366,7 @@ export default function ConnectorsPage() {
|
|||
mode="single"
|
||||
selected={startDate}
|
||||
onSelect={setStartDate}
|
||||
disabled={(date) => date > new Date() || (endDate ? date > endDate : false)}
|
||||
disabled={getDisabledStartDates}
|
||||
initialFocus
|
||||
/>
|
||||
</PopoverContent>
|
||||
|
@ -369,9 +393,7 @@ export default function ConnectorsPage() {
|
|||
mode="single"
|
||||
selected={endDate}
|
||||
onSelect={setEndDate}
|
||||
disabled={(date) =>
|
||||
date > new Date() || (startDate ? date < startDate : false)
|
||||
}
|
||||
disabled={getDisabledEndDates}
|
||||
initialFocus
|
||||
/>
|
||||
</PopoverContent>
|
||||
|
@ -393,7 +415,6 @@ export default function ConnectorsPage() {
|
|||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
const today = new Date();
|
||||
const thirtyDaysAgo = new Date(today);
|
||||
thirtyDaysAgo.setDate(today.getDate() - 30);
|
||||
setStartDate(thirtyDaysAgo);
|
||||
|
@ -406,7 +427,6 @@ export default function ConnectorsPage() {
|
|||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
const today = new Date();
|
||||
const yearAgo = new Date(today);
|
||||
yearAgo.setFullYear(today.getFullYear() - 1);
|
||||
setStartDate(yearAgo);
|
||||
|
|
15
surfsense_web/contracts/enums/connector.ts
Normal file
15
surfsense_web/contracts/enums/connector.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
export enum EnumConnectorName {
|
||||
SERPER_API = "SERPER_API",
|
||||
TAVILY_API = "TAVILY_API",
|
||||
LINKUP_API = "LINKUP_API",
|
||||
SLACK_CONNECTOR = "SLACK_CONNECTOR",
|
||||
NOTION_CONNECTOR = "NOTION_CONNECTOR",
|
||||
GITHUB_CONNECTOR = "GITHUB_CONNECTOR",
|
||||
LINEAR_CONNECTOR = "LINEAR_CONNECTOR",
|
||||
JIRA_CONNECTOR = "JIRA_CONNECTOR",
|
||||
DISCORD_CONNECTOR = "DISCORD_CONNECTOR",
|
||||
CONFLUENCE_CONNECTOR = "CONFLUENCE_CONNECTOR",
|
||||
CLICKUP_CONNECTOR = "CLICKUP_CONNECTOR",
|
||||
GOOGLE_CALENDAR_CONNECTOR = "GOOGLE_CALENDAR_CONNECTOR",
|
||||
GOOGLE_GMAIL_CONNECTOR = "GOOGLE_GMAIL_CONNECTOR",
|
||||
}
|
|
@ -10,6 +10,10 @@ export const getConnectorTypeDisplay = (type: string): string => {
|
|||
JIRA_CONNECTOR: "Jira",
|
||||
DISCORD_CONNECTOR: "Discord",
|
||||
LINKUP_API: "Linkup",
|
||||
CONFLUENCE_CONNECTOR: "Confluence",
|
||||
CLICKUP_CONNECTOR: "ClickUp",
|
||||
GOOGLE_CALENDAR_CONNECTOR: "Google Calendar",
|
||||
GOOGLE_GMAIL_CONNECTOR: "Google Gmail",
|
||||
};
|
||||
return typeMap[type] || type;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue