Skip to content

Commit

Permalink
H-3951: Allow users to update dependent types when updating an entity…
Browse files Browse the repository at this point in the history
… type (#6366)
  • Loading branch information
CiaranMn authored Feb 6, 2025
1 parent 5c5451f commit 4391c63
Show file tree
Hide file tree
Showing 18 changed files with 915 additions and 100 deletions.
2 changes: 2 additions & 0 deletions apps/hash-api/src/graphql/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import {
queryEntityTypesResolver,
unarchiveEntityTypeResolver,
updateEntityTypeResolver,
updateEntityTypesResolver,
} from "./ontology/entity-type";
import {
archivePropertyTypeResolver,
Expand Down Expand Up @@ -180,6 +181,7 @@ export const resolvers: Omit<Resolvers, "Query" | "Mutation"> & {
),
createEntityType: loggedInAndSignedUpMiddleware(createEntityTypeResolver),
updateEntityType: loggedInAndSignedUpMiddleware(updateEntityTypeResolver),
updateEntityTypes: loggedInAndSignedUpMiddleware(updateEntityTypesResolver),
archiveEntityType: loggedInAndSignedUpMiddleware(archiveEntityTypeResolver),
unarchiveEntityType: loggedInAndSignedUpMiddleware(
unarchiveEntityTypeResolver,
Expand Down
41 changes: 41 additions & 0 deletions apps/hash-api/src/graphql/resolvers/ontology/entity-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type {
MutationCreateEntityTypeArgs,
MutationUnarchiveEntityTypeArgs,
MutationUpdateEntityTypeArgs,
MutationUpdateEntityTypesArgs,
QueryCheckUserPermissionsOnEntityTypeArgs,
QueryGetClosedMultiEntityTypeArgs,
QueryGetEntityTypeArgs,
Expand Down Expand Up @@ -218,6 +219,46 @@ export const updateEntityTypeResolver: ResolverFn<
},
);

export const updateEntityTypesResolver: ResolverFn<
Promise<EntityTypeWithMetadata[]>,
Record<string, never>,
LoggedInGraphQLContext,
MutationUpdateEntityTypesArgs
> = async (_, params, graphQLContext) =>
Promise.all(
params.updates.map((update) =>
updateEntityType(
graphQLContextToImpureGraphContext(graphQLContext),
graphQLContext.authentication,
{
entityTypeId: update.entityTypeId,
schema: update.updatedEntityType,
relationships: [
{
relation: "setting",
subject: {
kind: "setting",
subjectId: "updateFromWeb",
},
},
{
relation: "viewer",
subject: {
kind: "public",
},
},
{
relation: "instantiator",
subject: {
kind: "public",
},
},
],
},
),
),
);

export const checkUserPermissionsOnEntityTypeResolver: ResolverFn<
Promise<UserPermissionsOnEntityType>,
Record<string, never>,
Expand Down
40 changes: 0 additions & 40 deletions apps/hash-frontend/src/components/forms/checkbox.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ export const updateEntityTypeMutation = gql`
}
`;

export const updateEntityTypesMutation = gql`
mutation updateEntityTypes($updates: [EntityTypeUpdate!]!) {
updateEntityTypes(updates: $updates)
}
`;

export const archiveEntityTypeMutation = gql`
mutation archiveEntityType($entityTypeId: VersionedUrl!) {
archiveEntityType(entityTypeId: $entityTypeId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ export const ArrayEditor: ValueCellEditorComponent = ({
const canAddMore = isNumber(maxItems) ? items.length < maxItems : true;
const isAddingDraft = editingRow === DRAFT_ROW_KEY;

const hasConstraints = minItems !== undefined || maxItems !== undefined;

return (
<GridEditorWrapper>
<ListWrapper
Expand Down Expand Up @@ -333,14 +335,15 @@ export const ArrayEditor: ValueCellEditorComponent = ({

{isAddingDraft && (
<DraftRow
arrayConstraints={hasConstraints ? { minItems, maxItems } : undefined}
existingItemCount={items.length}
expectedTypes={permittedDataTypes}
onDraftSaved={addItem}
onDraftDiscarded={() => setEditingRow("")}
/>
)}

{(!canAddMore || isAddingDraft) && (
{!canAddMore && hasConstraints && (
<ItemLimitInfo min={minItems} max={maxItems} />
)}
</GridEditorWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ export const AddAnotherButton = ({
variant="tertiary_quiet"
fullWidth
startIcon={<FontAwesomeIcon icon={faPlus} />}
sx={{ justifyContent: "flex-start", borderRadius: 0 }}
sx={{
justifyContent: "flex-start",
borderRadius: 0,
fontSize: 13,
color: ({ palette }) => palette.gray[60],
}}
>
{title}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ import { DRAFT_ROW_KEY } from "../array-editor";
import { getEditorSpecs } from "../editor-specs";
import { EditorTypePicker } from "../editor-type-picker";
import { isBlankStringOrNullish } from "../utils";
import { ItemLimitInfo } from "./item-limit-info";
import { SortableRow } from "./sortable-row";

interface DraftRowProps {
arrayConstraints?: {
minItems?: number;
maxItems?: number;
};
expectedTypes: ClosedDataTypeDefinition[];
existingItemCount: number;
onDraftSaved: (value: unknown, dataTypeId: VersionedUrl) => void;
onDraftDiscarded: () => void;
}

export const DraftRow = ({
arrayConstraints,
expectedTypes,
existingItemCount,
onDraftSaved,
Expand Down Expand Up @@ -58,23 +64,31 @@ export const DraftRow = ({
}

return (
<SortableRow
editing
item={{
dataType,
id: DRAFT_ROW_KEY,
index: existingItemCount,
value: undefined,
}}
onSaveChanges={(_, value) => {
if (isBlankStringOrNullish(value)) {
return onDraftDiscarded();
}
<>
<SortableRow
editing
item={{
dataType,
id: DRAFT_ROW_KEY,
index: existingItemCount,
value: undefined,
}}
onSaveChanges={(_, value) => {
if (isBlankStringOrNullish(value)) {
return onDraftDiscarded();
}

onDraftSaved(value, dataType.$id);
}}
onDiscardChanges={onDraftDiscarded}
expectedTypes={expectedTypes}
/>
onDraftSaved(value, dataType.$id);
}}
onDiscardChanges={onDraftDiscarded}
expectedTypes={expectedTypes}
/>
{arrayConstraints && (
<ItemLimitInfo
min={arrayConstraints.minItems}
max={arrayConstraints.maxItems}
/>
)}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const EditorTypePicker = ({
return (
<DataTypeSelector
dataTypes={dataTypeTrees}
handleScroll
onSelect={onSelect}
selectedDataTypeId={selectedDataTypeId}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const Page: NextPageWithLayout = () => {
accountId={routeNamespace.accountId}
draftEntityType={draftEntityType}
entityTypeBaseUrl={entityTypeBaseUrl}
key={`${entityTypeBaseUrl}-${requestedVersion}`}
requestedVersion={requestedVersion}
/>
);
Expand Down
Loading

0 comments on commit 4391c63

Please sign in to comment.