Skip to content

Commit

Permalink
fix(dashboardeditor): keep state of images to upload
Browse files Browse the repository at this point in the history
  • Loading branch information
tay1orjones committed Dec 7, 2020
1 parent 08b17bd commit 0bd0a77
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
14 changes: 12 additions & 2 deletions src/components/DashboardEditor/DashboardEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ const DashboardEditor = ({

// show the card gallery if no card is being edited
const [dashboardJson, setDashboardJson] = useState(initialValue);
const [imagesToUpload, setImagesToUpload] = useState([]);
const [selectedCardId, setSelectedCardId] = useState();
const [selectedBreakpointIndex, setSelectedBreakpointIndex] = useState(
breakpointSwitcher?.initialValue
Expand Down Expand Up @@ -326,7 +327,16 @@ const DashboardEditor = ({
cardConfig.content.src = availableImages.find(
(image) => image.id === cardConfig.content.id
)?.src;
} else if (
cardConfig.content.imgState === 'new' &&
!imagesToUpload.some((image) => image.id === cardConfig.content.id)
) {
setImagesToUpload((prevImagesToUpload) => [
...prevImagesToUpload,
{ id: cardConfig.content.id, src: cardConfig.content.src },
]);
}

// TODO: this is really inefficient
setDashboardJson((oldJSON) => ({
...oldJSON,
Expand Down Expand Up @@ -399,10 +409,10 @@ const DashboardEditor = ({
breadcrumbs={headerBreadcrumbs}
onEditTitle={onEditTitle}
onImport={onImport}
onExport={() => onExport(dashboardJson)}
onExport={() => onExport(dashboardJson, imagesToUpload)}
onDelete={onDelete}
onCancel={onCancel}
onSubmit={onSubmit}
onSubmit={(params) => onSubmit(params, imagesToUpload)}
isSubmitDisabled={isSubmitDisabled}
isSubmitLoading={isSubmitLoading}
i18n={mergedI18n}
Expand Down
17 changes: 10 additions & 7 deletions src/components/DashboardEditor/DashboardEditor.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,17 @@ describe('DashboardEditor', () => {
const submitBtn = screen.getByText('Save and close');
expect(submitBtn).toBeInTheDocument();
fireEvent.click(submitBtn);
expect(mockOnSubmit).toBeCalledWith({
cards: [],
layouts: {
lg: [],
md: [],
xl: [],
expect(mockOnSubmit).toBeCalledWith(
{
cards: [],
layouts: {
lg: [],
md: [],
xl: [],
},
},
});
[]
);
});

it('selecting cancel should fire onCancel', () => {
Expand Down

0 comments on commit 0bd0a77

Please sign in to comment.