Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion src/components/Home/ProjectsSection/AllProjectsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export function AllProjectsTable() {
const missingAuthor = me && !author.createdBy;
const page = useProjects(
{
createdBy: me ? author.createdBy : creator || undefined,
myProjectsFor: me ? author.createdBy : undefined,
createdBy: me ? undefined : creator || undefined,
workspaceId,
pageSize: 10,
pageToken: pageTokens.at(-1),
Expand Down
38 changes: 23 additions & 15 deletions src/components/Home/ProjectsSection/ProjectsSection.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { render, screen, waitFor, within } from "@testing-library/react";
import { render, screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import type { ReactNode } from "react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
Expand Down Expand Up @@ -128,7 +128,10 @@ function mockPagedDirectory() {
const projects = [project, otherProject, ...archivedProjects];
vi.mocked(listProjects).mockImplementation(async (params = {}) => {
const matching = projects.filter(
({ createdBy, workspaceId }) =>
({ id, createdBy, workspaceId }) =>
(!params.myProjectsFor ||
id === project.id ||
id === otherProject.id) &&
(!params.createdBy || createdBy === params.createdBy) &&
(!params.workspaceId || workspaceId === params.workspaceId),
);
Expand Down Expand Up @@ -327,29 +330,34 @@ describe("ProjectsSection", () => {
expect(screen.getByText("Page 1")).toBeVisible();
});

it("uses the current user's ID for Me and returns everyone's projects when cleared", async () => {
it("shows projects I created or contributed to with Me and clears back to the directory", async () => {
mockPagedDirectory();
const user = userEvent.setup();
renderSection();
const table = within(screen.getByRole("table", { name: "All projects" }));
await table.findByRole("link", { name: "Forecasting" });
expect(screen.queryByRole("button", { name: "My projects" })).toBeNull();
await user.click(screen.getByRole("button", { name: "Next" }));
await table.findByRole("link", { name: "Archived project 11" });

await user.click(screen.getByRole("button", { name: "Me" }));
await screen.findByRole("button", { name: "Clear user filter" });
await waitFor(() => {
expect(listProjects).toHaveBeenLastCalledWith(
expect.objectContaining({ createdBy: project.createdBy }),
backendUrl,
);
expect(table.queryByRole("link", { name: "Forecasting" })).toBeNull();
});
expect(
await table.findByRole("link", { name: "Churn model" }),
).toBeVisible();
await table.findByRole("link", { name: "Churn model" });
expect(table.getByRole("link", { name: "Forecasting" })).toBeVisible();
expect(table.getAllByRole("link")).toHaveLength(2);
expect(listProjects).toHaveBeenLastCalledWith(
expect.objectContaining({
myProjectsFor: project.createdBy,
createdBy: undefined,
pageToken: undefined,
}),
backendUrl,
);

await user.click(screen.getByRole("button", { name: "Clear user filter" }));
expect(
await table.findByRole("link", { name: "Forecasting" }),
await table.findByRole("link", { name: "Archived project 1" }),
).toBeVisible();
expect(screen.getByText("Page 1")).toBeVisible();
});

it("keeps cached directory results out of Me when the current user is unknown", async () => {
Expand Down
7 changes: 5 additions & 2 deletions src/components/Home/ProjectsSection/useMyProjects.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const render = () => renderHook(() => useMyProjects(), { wrapper });
describe("useMyProjects", () => {
beforeEach(() => {
vi.mocked(useBackend).mockReturnValue({
backendUrl: "https://backend.example",
configured: true,
available: true,
} as unknown as ReturnType<typeof useBackend>);
Expand All @@ -53,7 +54,8 @@ describe("useMyProjects", () => {

await waitFor(() =>
expect(listProjects).toHaveBeenCalledWith(
expect.objectContaining({ createdBy: "someone@example.com" }),
expect.objectContaining({ myProjectsFor: "someone@example.com" }),
"https://backend.example",
),
);
});
Expand All @@ -72,7 +74,8 @@ describe("useMyProjects", () => {

await waitFor(() =>
expect(listProjects).toHaveBeenCalledWith(
expect.objectContaining({ createdBy: undefined }),
expect.objectContaining({ myProjectsFor: undefined }),
"https://backend.example",
),
);
});
Expand Down
16 changes: 13 additions & 3 deletions src/components/Home/ProjectsSection/useMyProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface MyProjects {
* ways under two cache keys.
*/
export function useMyProjects(): MyProjects {
const { configured, available } = useBackend();
const { configured, available, backendUrl } = useBackend();
const {
createdBy,
isPending: isUserPending,
Expand All @@ -41,9 +41,19 @@ export function useMyProjects(): MyProjects {
fetchNextPage,
isFetchingNextPage,
} = useInfiniteQuery({
queryKey: ProjectsQueryKeys.List({ createdBy, pageSize: PAGE_SIZE }),
queryKey: [
...ProjectsQueryKeys.List({
myProjectsFor: createdBy,
pageSize: PAGE_SIZE,
}),
backendUrl,
"infinite",
],
queryFn: ({ pageParam }) =>
listProjects({ createdBy, pageSize: PAGE_SIZE, pageToken: pageParam }),
listProjects(
{ myProjectsFor: createdBy, pageSize: PAGE_SIZE, pageToken: pageParam },
backendUrl,
),
initialPageParam: undefined as string | undefined,
getNextPageParam: (page) => page.nextPageToken ?? undefined,
enabled: configured && available && !isUserPending && userError === null,
Expand Down
4 changes: 3 additions & 1 deletion src/components/Project/AddDocumentDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export function AddDocumentDialog({
open,
onOpenChange,
}: AddDocumentDialogProps) {
const createResource = useCreateProjectResource(projectId);
const createResource = useCreateProjectResource(projectId, {
recordContribution: true,
});
const notify = useToastNotification();
const { track } = useAnalytics();

Expand Down
2 changes: 1 addition & 1 deletion src/components/Project/AddPipelineDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function AddPipelineDialog({
}: AddPipelineDialogProps) {
const { data: names, isPending, error } = useLocalPipelineNames();
const { mutate: createResource, isPending: isCreating } =
useCreateProjectResource(projectId);
useCreateProjectResource(projectId, { recordContribution: true });
const notify = useToastNotification();
const { track } = useAnalytics();

Expand Down
4 changes: 3 additions & 1 deletion src/components/Project/DocumentEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ interface DocumentEditorProps {
export function DocumentEditor({ projectId, resource }: DocumentEditorProps) {
const saved = documentBody(resource) ?? "";
const [edit, setEdit] = useState<Edit | null>(null);
const update = useUpdateProjectResource(projectId);
const update = useUpdateProjectResource(projectId, {
recordContribution: true,
});
const { track } = useAnalytics();

if (edit !== null && edit.draft === saved && !update.isPending) {
Expand Down
28 changes: 28 additions & 0 deletions src/components/Project/ProjectContributors.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { BlockStack } from "@/components/ui/layout";
import { Text } from "@/components/ui/typography";
import { useProjectContributors } from "@/services/projects/useProjectContributors";

export function ProjectContributors({ projectId }: { projectId: string }) {
const { data, error, isPending } = useProjectContributors(projectId);
if (data === null) return null;

return (
<BlockStack gap="1">
<Text size="sm" weight="medium">
Contributors
</Text>
{data?.length ? (
<ul aria-label="Contributors" className="space-y-1 break-words text-sm">
{data.map((person) => (
<li key={person}>{person}</li>
))}
</ul>
) : (
<Text size="sm" tone="subdued">
{error?.message ??
(isPending ? "Loading contributors…" : "No contributors yet.")}
</Text>
)}
</BlockStack>
);
}
4 changes: 4 additions & 0 deletions src/components/Project/ProjectPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ vi.mock("@/services/projects/useProjects", () => ({
useUpdateProjectMetadata: () => ({ mutate: vi.fn(), isPending: false }),
}));

vi.mock("@/services/projects/useProjectContributors", () => ({
useProjectContributors: () => ({ data: ["alice@example.com"] }),
}));

vi.mock("@/services/projects/useProjectResources", () => ({
useProjectResources: () => ({
data: { items: [], nextPageToken: null, totalCount: 0 },
Expand Down
7 changes: 7 additions & 0 deletions src/components/Project/ProjectSidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { formatDate } from "@/utils/date";

import { ProjectSidebar } from "./ProjectSidebar";

vi.mock("@/services/projects/useProjectContributors", () => ({
useProjectContributors: () => ({ data: ["teammate@example.com"] }),
}));

vi.mock("@tanstack/react-router", async (importOriginal) => ({
...(await importOriginal<typeof import("@tanstack/react-router")>()),
useNavigate: () => vi.fn(),
Expand Down Expand Up @@ -90,6 +94,9 @@ describe("ProjectSidebar", () => {
it("says who made the project and when", () => {
renderSidebar();

expect(
screen.getByRole("list", { name: "Contributors" }),
).toHaveTextContent("teammate@example.com");
expect(screen.getByText("alice@example.com")).toBeInTheDocument();
expect(screen.getByText(formatDate(project.createdAt))).toBeInTheDocument();
});
Expand Down
3 changes: 3 additions & 0 deletions src/components/Project/ProjectSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { formatDate, formatRelativeTime } from "@/utils/date";
import { ColumnHeadingRow } from "./ColumnHeadingRow";
import { ProjectAbout } from "./ProjectAbout";
import { ProjectActions } from "./ProjectActions";
import { ProjectContributors } from "./ProjectContributors";

const HEADING_ID = "project-sidebar-heading";

Expand Down Expand Up @@ -61,6 +62,8 @@ export function ProjectSidebar({ project }: ProjectSidebarProps) {

<Separator />

<ProjectContributors projectId={project.id} />

<ProjectActions project={project} />
</BlockStack>
</BlockStack>
Expand Down
12 changes: 10 additions & 2 deletions src/components/shared/Submitters/Tangle/useSubmitPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import { useAwaitAuthorization } from "@/components/shared/Authentication/useAwa
import { useBackend } from "@/providers/BackendProvider";
import { ONBOARDING_MY_RUN_COUNT_KEY } from "@/providers/OnboardingProvider/onboardingQueryKeys";
import { useRunSubmissionAnnotations } from "@/providers/RunSubmissionScopeProvider";
import { useRecordProjectContribution } from "@/services/projects/useProjectContributors";
import { invalidateProjectRunQueries } from "@/services/projects/useProjectRuns";
import type { PipelineRun } from "@/types/pipelineRun";
import type { ArgumentType, ComponentSpec } from "@/utils/componentSpec";
import { projectRunAnnotations } from "@/utils/projectRunAnnotation";
import {
projectIdsFromAnnotations,
projectRunAnnotations,
} from "@/utils/projectRunAnnotation";
import { submitPipelineRun } from "@/utils/submitPipeline";

import { isAuthorizationRequired } from "../../Authentication/helpers";
Expand All @@ -29,6 +33,7 @@ export function useSubmitPipeline() {
const { getToken } = useAuthLocalStorage();

const { backendUrl } = useBackend();
const recordContribution = useRecordProjectContribution();
const scopeAnnotations = useRunSubmissionAnnotations();

const authorizationToken = useRef<string | undefined>(getToken());
Expand All @@ -55,13 +60,16 @@ export function useSubmitPipeline() {
}
}

const annotations = annotationsFor(projectIds);
return new Promise<PipelineRun>((resolve, reject) => {
submitPipelineRun(componentSpec, backendUrl, {
authorizationToken: authorizationToken.current,
teamId,
taskArguments,
runAnnotations: annotationsFor(projectIds),
runAnnotations: annotations,
onSuccess: (data) => {
for (const id of projectIdsFromAnnotations(annotations))
recordContribution(id);
resolve(data);
onSuccess(data);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ export function AddResourceButton({
}: AddResourceButtonProps) {
const { open } = useDialog();
const notify = useToastNotification();
const { mutate: createResource, isPending } =
useCreateProjectResource(projectId);
const { mutate: createResource, isPending } = useCreateProjectResource(
projectId,
{ recordContribution: true },
);

async function openResourceDialog(config: DialogConfig<CreateResourceInput>) {
const result = await open<CreateResourceInput>({
Expand Down
7 changes: 7 additions & 0 deletions src/routes/v2/pages/Tangent/components/ProjectChatArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ import { useRefreshSessionResources } from "@/routes/v2/pages/Tangent/hooks/useR
import { AiProviderSetup } from "@/routes/v2/shared/components/AiChat/components/AiProviderSetup";
import { TANGENT_AI_SETUP } from "@/routes/v2/shared/components/AiChat/components/aiSetupCopy";
import { ChatEntityRevealProvider } from "@/routes/v2/shared/components/AiChat/components/ChatEntityRevealContext";
import { useProjectAuthor } from "@/services/projects/useProjectAuthor";
import { useRecordProjectContribution } from "@/services/projects/useProjectContributors";
import { getErrorMessage } from "@/utils/string";

export const ProjectChatArea = observer(function ProjectChatArea() {
const store = useTangentProject();
const notify = useToastNotification();
const { isConfigured } = useAiProviderSettings();
const references = useChatReferences(store.projectId);
const { createdBy } = useProjectAuthor();
const recordContribution = useRecordProjectContribution();
const commands = useChatCommands(store.projectId);
const refreshSessionResources = useRefreshSessionResources();
const activeSessionId = store.activeSessionId;
Expand Down Expand Up @@ -73,6 +77,9 @@ export const ProjectChatArea = observer(function ProjectChatArea() {
}
}}
onSendPrompt={(content) => store.recordSessionPrompt(content)}
onPromptAuthor={(authorId) => {
if (authorId === createdBy) recordContribution(store.projectId);
}}
onError={(message) => notify(message, "error")}
onResourcesChange={() => refreshSessionResources(activeSessionId)}
headerAction={<ProjectSettingsButton />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { useProject } from "@/services/projects/useProjects";

import { ProjectSettingsDialog } from "./ProjectSettingsDialog";

vi.mock("@/services/projects/useProjectContributors", () => ({
useProjectContributors: () => ({ data: ["teammate@example.com"] }),
}));

vi.mock("@/routes/v2/pages/Tangent/context/TangentProjectContext", () => ({
useTangentProject: () => ({
projectId: "project-1",
Expand Down Expand Up @@ -153,6 +157,9 @@ describe("ProjectSettingsDialog", () => {
projectLoaded();
renderSettings();

expect(
screen.getByRole("list", { name: "Contributors" }),
).toHaveTextContent("teammate@example.com");
expect(
screen.getByText(/Created by alice@example\.com/),
).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ProjectDescriptionField,
ProjectInstructionsField,
} from "@/components/Project/ProjectAbout";
import { ProjectContributors } from "@/components/Project/ProjectContributors";
import { ProjectWorkspaceLabel } from "@/components/Project/ProjectWorkspaceLabel";
import { Button } from "@/components/ui/button";
import {
Expand Down Expand Up @@ -169,7 +170,12 @@ export const ProjectSettingsDialog = observer(function ProjectSettingsDialog({
</SettingsGroup>
)}

{project && <ProjectHistory project={project} />}
{project && (
<>
<ProjectContributors projectId={project.id} />
<ProjectHistory project={project} />
</>
)}
</DialogContent>
</Dialog>

Expand Down
Loading
Loading