@@ -4,6 +4,7 @@ import {
|
||||
PreloadedQuery,
|
||||
usePreloadedQuery,
|
||||
useQueryLoader,
|
||||
useMutation,
|
||||
} from "react-relay";
|
||||
import { useSearchParams } from "react-router";
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||
@@ -44,17 +45,26 @@ const PeopleListPageQuery = graphql`
|
||||
}
|
||||
`;
|
||||
|
||||
const deletePeopleMutation = graphql`
|
||||
mutation PeopleListPageDeletePeopleMutation($input: DeletePeopleInput!) {
|
||||
deletePeople(input: $input)
|
||||
}
|
||||
`;
|
||||
|
||||
function PeopleListPageContent({
|
||||
queryRef,
|
||||
onPageChange,
|
||||
loadQuery
|
||||
}: {
|
||||
queryRef: PreloadedQuery<PeopleListPageQueryType>;
|
||||
onPageChange: (params: { first?: number; after?: string; last?: number; before?: string }) => void;
|
||||
loadQuery: LoadQueryType;
|
||||
}) {
|
||||
const data = usePreloadedQuery(PeopleListPageQuery, queryRef);
|
||||
const peoples = data.node.peoples?.edges.map(edge => edge?.node) ?? [];
|
||||
const pageInfo = data.node.peoples?.pageInfo;
|
||||
const [isPending, startTransition] = useTransition();
|
||||
const [deletePeople] = useMutation(deletePeopleMutation);
|
||||
|
||||
const handlePageChange = (direction: 'prev' | 'next') => {
|
||||
startTransition(() => {
|
||||
@@ -107,6 +117,33 @@ function PeopleListPageContent({
|
||||
<Badge variant="outline" className="text-muted-foreground">
|
||||
Not onboarded
|
||||
</Badge>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
if (window.confirm('Are you sure you want to delete this person?')) {
|
||||
deletePeople({
|
||||
variables: {
|
||||
input: {
|
||||
peopleId: person.id
|
||||
}
|
||||
},
|
||||
onCompleted() {
|
||||
loadQuery({
|
||||
first: ITEMS_PER_PAGE,
|
||||
after: undefined,
|
||||
last: undefined,
|
||||
before: undefined,
|
||||
}, { fetchPolicy: 'network-only' });
|
||||
},
|
||||
});
|
||||
}
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
@@ -168,6 +205,8 @@ function PeopleListPageFallback() {
|
||||
);
|
||||
}
|
||||
|
||||
type LoadQueryType = ReturnType<typeof useQueryLoader<PeopleListPageQueryType>>[1];
|
||||
|
||||
export default function PeopleListPage() {
|
||||
const [searchParams] = useSearchParams();
|
||||
const [queryRef, loadQuery] = useQueryLoader<PeopleListPageQueryType>(PeopleListPageQuery);
|
||||
@@ -206,7 +245,7 @@ export default function PeopleListPage() {
|
||||
<title>People - Probo Console</title>
|
||||
</Helmet>
|
||||
<Suspense fallback={<PeopleListPageFallback />}>
|
||||
<PeopleListPageContent queryRef={queryRef} onPageChange={handlePageChange} />
|
||||
<PeopleListPageContent queryRef={queryRef} onPageChange={handlePageChange} loadQuery={loadQuery} />
|
||||
</Suspense>
|
||||
</>
|
||||
);
|
||||
|
||||
79
apps/console/src/pages/__generated__/PeopleListPageDeletePeopleMutation.graphql.ts
generated
Normal file
79
apps/console/src/pages/__generated__/PeopleListPageDeletePeopleMutation.graphql.ts
generated
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* @generated SignedSource<<0dfa6dd207341bf77daca8afe8418c41>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import { ConcreteRequest } from 'relay-runtime';
|
||||
export type DeletePeopleInput = {
|
||||
peopleId: string;
|
||||
};
|
||||
export type PeopleListPageDeletePeopleMutation$variables = {
|
||||
input: DeletePeopleInput;
|
||||
};
|
||||
export type PeopleListPageDeletePeopleMutation$data = {
|
||||
readonly deletePeople: any;
|
||||
};
|
||||
export type PeopleListPageDeletePeopleMutation = {
|
||||
response: PeopleListPageDeletePeopleMutation$data;
|
||||
variables: PeopleListPageDeletePeopleMutation$variables;
|
||||
};
|
||||
|
||||
const node: ConcreteRequest = (function(){
|
||||
var v0 = [
|
||||
{
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "input"
|
||||
}
|
||||
],
|
||||
v1 = [
|
||||
{
|
||||
"alias": null,
|
||||
"args": [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "input",
|
||||
"variableName": "input"
|
||||
}
|
||||
],
|
||||
"kind": "ScalarField",
|
||||
"name": "deletePeople",
|
||||
"storageKey": null
|
||||
}
|
||||
];
|
||||
return {
|
||||
"fragment": {
|
||||
"argumentDefinitions": (v0/*: any*/),
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "PeopleListPageDeletePeopleMutation",
|
||||
"selections": (v1/*: any*/),
|
||||
"type": "Mutation",
|
||||
"abstractKey": null
|
||||
},
|
||||
"kind": "Request",
|
||||
"operation": {
|
||||
"argumentDefinitions": (v0/*: any*/),
|
||||
"kind": "Operation",
|
||||
"name": "PeopleListPageDeletePeopleMutation",
|
||||
"selections": (v1/*: any*/)
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "ee5d2a94a7fae0b106873b6cd1cc7d0b",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "PeopleListPageDeletePeopleMutation",
|
||||
"operationKind": "mutation",
|
||||
"text": "mutation PeopleListPageDeletePeopleMutation(\n $input: DeletePeopleInput!\n) {\n deletePeople(input: $input)\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "d6077ac452cabbacf8678fe527ce928a";
|
||||
|
||||
export default node;
|
||||
@@ -290,6 +290,7 @@ type Query {
|
||||
type Mutation {
|
||||
createVendor(input: CreateVendorInput!): Vendor!
|
||||
deleteVendor(input: DeleteVendorInput!): Void!
|
||||
deletePeople(input: DeletePeopleInput!): Void!
|
||||
}
|
||||
|
||||
input CreateVendorInput {
|
||||
@@ -300,3 +301,7 @@ input CreateVendorInput {
|
||||
input DeleteVendorInput {
|
||||
vendorId: ID!
|
||||
}
|
||||
|
||||
input DeletePeopleInput {
|
||||
peopleId: ID!
|
||||
}
|
||||
@@ -155,6 +155,7 @@ type ComplexityRoot struct {
|
||||
|
||||
Mutation struct {
|
||||
CreateVendor func(childComplexity int, input types.CreateVendorInput) int
|
||||
DeletePeople func(childComplexity int, input types.DeletePeopleInput) int
|
||||
DeleteVendor func(childComplexity int, input types.DeleteVendorInput) int
|
||||
}
|
||||
|
||||
@@ -270,6 +271,7 @@ type FrameworkResolver interface {
|
||||
type MutationResolver interface {
|
||||
CreateVendor(ctx context.Context, input types.CreateVendorInput) (*types.Vendor, error)
|
||||
DeleteVendor(ctx context.Context, input types.DeleteVendorInput) (string, error)
|
||||
DeletePeople(ctx context.Context, input types.DeletePeopleInput) (string, error)
|
||||
}
|
||||
type OrganizationResolver interface {
|
||||
Frameworks(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.FrameworkConnection, error)
|
||||
@@ -713,6 +715,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||
|
||||
return e.complexity.Mutation.CreateVendor(childComplexity, args["input"].(types.CreateVendorInput)), true
|
||||
|
||||
case "Mutation.deletePeople":
|
||||
if e.complexity.Mutation.DeletePeople == nil {
|
||||
break
|
||||
}
|
||||
|
||||
args, err := ec.field_Mutation_deletePeople_args(context.TODO(), rawArgs)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return e.complexity.Mutation.DeletePeople(childComplexity, args["input"].(types.DeletePeopleInput)), true
|
||||
|
||||
case "Mutation.deleteVendor":
|
||||
if e.complexity.Mutation.DeleteVendor == nil {
|
||||
break
|
||||
@@ -1135,6 +1149,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
|
||||
ec := executionContext{opCtx, e, 0, 0, make(chan graphql.DeferredResult)}
|
||||
inputUnmarshalMap := graphql.BuildUnmarshalerMap(
|
||||
ec.unmarshalInputCreateVendorInput,
|
||||
ec.unmarshalInputDeletePeopleInput,
|
||||
ec.unmarshalInputDeleteVendorInput,
|
||||
)
|
||||
first := true
|
||||
@@ -1525,6 +1540,7 @@ type Query {
|
||||
type Mutation {
|
||||
createVendor(input: CreateVendorInput!): Vendor!
|
||||
deleteVendor(input: DeleteVendorInput!): Void!
|
||||
deletePeople(input: DeletePeopleInput!): Void!
|
||||
}
|
||||
|
||||
input CreateVendorInput {
|
||||
@@ -1535,7 +1551,10 @@ input CreateVendorInput {
|
||||
input DeleteVendorInput {
|
||||
vendorId: ID!
|
||||
}
|
||||
`, BuiltIn: false},
|
||||
|
||||
input DeletePeopleInput {
|
||||
peopleId: ID!
|
||||
}`, BuiltIn: false},
|
||||
}
|
||||
var parsedSchema = gqlparser.MustLoadSchema(sources...)
|
||||
|
||||
@@ -1874,6 +1893,29 @@ func (ec *executionContext) field_Mutation_createVendor_argsInput(
|
||||
return zeroVal, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) field_Mutation_deletePeople_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) {
|
||||
var err error
|
||||
args := map[string]any{}
|
||||
arg0, err := ec.field_Mutation_deletePeople_argsInput(ctx, rawArgs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args["input"] = arg0
|
||||
return args, nil
|
||||
}
|
||||
func (ec *executionContext) field_Mutation_deletePeople_argsInput(
|
||||
ctx context.Context,
|
||||
rawArgs map[string]any,
|
||||
) (types.DeletePeopleInput, error) {
|
||||
ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("input"))
|
||||
if tmp, ok := rawArgs["input"]; ok {
|
||||
return ec.unmarshalNDeletePeopleInput2githubᚗcomᚋgetproboᚋproboᚋpkgᚋapiᚋconsoleᚋv1ᚋtypesᚐDeletePeopleInput(ctx, tmp)
|
||||
}
|
||||
|
||||
var zeroVal types.DeletePeopleInput
|
||||
return zeroVal, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) field_Mutation_deleteVendor_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) {
|
||||
var err error
|
||||
args := map[string]any{}
|
||||
@@ -4720,6 +4762,49 @@ func (ec *executionContext) fieldContext_Mutation_deleteVendor(ctx context.Conte
|
||||
return fc, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Mutation_deletePeople(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
fc, err := ec.fieldContext_Mutation_deletePeople(ctx, field)
|
||||
if err != nil {
|
||||
return graphql.Null
|
||||
}
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return ec.resolvers.Mutation().DeletePeople(rctx, fc.Args["input"].(types.DeletePeopleInput))
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalNVoid2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) fieldContext_Mutation_deletePeople(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||
fc = &graphql.FieldContext{
|
||||
Object: "Mutation",
|
||||
Field: field,
|
||||
IsMethod: true,
|
||||
IsResolver: true,
|
||||
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
||||
return nil, errors.New("field of type Void does not have child fields")
|
||||
},
|
||||
}
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
if fc.Args, err = ec.field_Mutation_deletePeople_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return fc, err
|
||||
}
|
||||
return fc, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Organization_id(ctx context.Context, field graphql.CollectedField, obj *types.Organization) (ret graphql.Marshaler) {
|
||||
fc, err := ec.fieldContext_Organization_id(ctx, field)
|
||||
if err != nil {
|
||||
@@ -8598,6 +8683,33 @@ func (ec *executionContext) unmarshalInputCreateVendorInput(ctx context.Context,
|
||||
return it, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalInputDeletePeopleInput(ctx context.Context, obj any) (types.DeletePeopleInput, error) {
|
||||
var it types.DeletePeopleInput
|
||||
asMap := map[string]any{}
|
||||
for k, v := range obj.(map[string]any) {
|
||||
asMap[k] = v
|
||||
}
|
||||
|
||||
fieldsInOrder := [...]string{"peopleId"}
|
||||
for _, k := range fieldsInOrder {
|
||||
v, ok := asMap[k]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
switch k {
|
||||
case "peopleId":
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("peopleId"))
|
||||
data, err := ec.unmarshalNID2githubᚗcomᚋgetproboᚋproboᚋpkgᚋgidᚐGID(ctx, v)
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
it.PeopleID = data
|
||||
}
|
||||
}
|
||||
|
||||
return it, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalInputDeleteVendorInput(ctx context.Context, obj any) (types.DeleteVendorInput, error) {
|
||||
var it types.DeleteVendorInput
|
||||
asMap := map[string]any{}
|
||||
@@ -9596,6 +9708,13 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet)
|
||||
if out.Values[i] == graphql.Null {
|
||||
out.Invalids++
|
||||
}
|
||||
case "deletePeople":
|
||||
out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) {
|
||||
return ec._Mutation_deletePeople(ctx, field)
|
||||
})
|
||||
if out.Values[i] == graphql.Null {
|
||||
out.Invalids++
|
||||
}
|
||||
default:
|
||||
panic("unknown field " + strconv.Quote(field.Name))
|
||||
}
|
||||
@@ -11070,6 +11189,11 @@ func (ec *executionContext) marshalNDatetime2timeᚐTime(ctx context.Context, se
|
||||
return res
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalNDeletePeopleInput2githubᚗcomᚋgetproboᚋproboᚋpkgᚋapiᚋconsoleᚋv1ᚋtypesᚐDeletePeopleInput(ctx context.Context, v any) (types.DeletePeopleInput, error) {
|
||||
res, err := ec.unmarshalInputDeletePeopleInput(ctx, v)
|
||||
return res, graphql.ErrorOnPath(ctx, err)
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalNDeleteVendorInput2githubᚗcomᚋgetproboᚋproboᚋpkgᚋapiᚋconsoleᚋv1ᚋtypesᚐDeleteVendorInput(ctx context.Context, v any) (types.DeleteVendorInput, error) {
|
||||
res, err := ec.unmarshalInputDeleteVendorInput(ctx, v)
|
||||
return res, graphql.ErrorOnPath(ctx, err)
|
||||
|
||||
@@ -65,6 +65,10 @@ type CreateVendorInput struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type DeletePeopleInput struct {
|
||||
PeopleID gid.GID `json:"peopleId"`
|
||||
}
|
||||
|
||||
type DeleteVendorInput struct {
|
||||
VendorID gid.GID `json:"vendorId"`
|
||||
}
|
||||
|
||||
@@ -88,6 +88,16 @@ func (r *mutationResolver) DeleteVendor(ctx context.Context, input types.DeleteV
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// DeletePeople is the resolver for the deletePeople field.
|
||||
func (r *mutationResolver) DeletePeople(ctx context.Context, input types.DeletePeopleInput) (string, error) {
|
||||
err := r.svc.DeletePeople(ctx, input.PeopleID)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot delete people: %w", err)
|
||||
}
|
||||
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// Frameworks is the resolver for the frameworks field.
|
||||
func (r *organizationResolver) Frameworks(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.FrameworkConnection, error) {
|
||||
cursor := types.NewCursor(first, after, last, before)
|
||||
|
||||
@@ -141,6 +141,24 @@ VALUES (
|
||||
return err
|
||||
}
|
||||
|
||||
func (p People) Delete(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope *Scope,
|
||||
) error {
|
||||
q := `
|
||||
DELETE FROM peoples WHERE %s AND id = @people_id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.NamedArgs{"people_id": p.ID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *Peoples) LoadByOrganizationID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
|
||||
23
pkg/probo/delete_people.go
Normal file
23
pkg/probo/delete_people.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package probo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/getprobo/probo/pkg/gid"
|
||||
"github.com/getprobo/probo/pkg/probo/coredata"
|
||||
"go.gearno.de/kit/pg"
|
||||
)
|
||||
|
||||
func (s Service) DeletePeople(
|
||||
ctx context.Context,
|
||||
peopleID gid.GID,
|
||||
) error {
|
||||
people := coredata.People{ID: peopleID}
|
||||
|
||||
return s.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return people.Delete(ctx, conn, s.scope)
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user