-
Notifications
You must be signed in to change notification settings - Fork 23
Feat: add delete functionality to Image component #570
Conversation
- add delete option to image component - add tests
src/components/image/index.test.tsx
Outdated
it("Should call saveSolidDatasetAt when clicking delete button", async () => { | ||
jest | ||
.spyOn(SolidFns, "saveSolidDatasetAt") | ||
.mockResolvedValue(mockDataset as any); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding
import type {
SolidDataset,
WithChangeLog,
WithServerResourceInfo,
} from "@inrupt/solid-client";
in the imports and replacing this with mockDataset as SolidDataset & WithServerResourceInfo & WithChangeLog
should remove the warning.
await saveSolidDatasetAt(datasetSourceUrl, updatedDataset, { | ||
fetch, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this only happen when autosave
is set ? Or is it by design that when deleting an image you're automatically deleting it from the remote storage ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. I am not sure but I have added a check for autosave since it is what we do with other operations as well.
src/components/image/index.tsx
Outdated
const handleDelete = async () => { | ||
if (!propThing || !solidDataset || !propProperty || !value) return; | ||
try { | ||
const updatedThing = removeUrl(propThing, propProperty, value as string); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the preceding if
was changed so that it tests typeof value === 'string'
rather than !value
, would the type assertions still be needed ?
78ab797
to
79cf869
Compare
Image component delete functionality
This PR adds an optional
allowDelete
prop to the Image component which renders a default delete button that will remove the image value from the dataset.It is also possible to pass a
deleteComponent
to render a custom delete button.Checklist
index.ts
, if applicable..ts
files) are listed in theexports
field inpackage.json
, if applicable..ts
files) are listed in thetypedocOptions.entryPoints
field intsconfig.json
, if applicable.