Skip to content

Commit

Permalink
feat: working clone button
Browse files Browse the repository at this point in the history
  • Loading branch information
danestves committed Dec 22, 2020
1 parent 6149cf5 commit 4a081b7
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 39 deletions.
82 changes: 82 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Changelog

## key

Changelog entries are classified using the following labels _(from [keep-a-changelog][]_):

- `added`: for new features
- `changed`: for changes in existing functionality
- `deprecated`: for once-stable features removed in upcoming releases
- `removed`: for deprecated features removed in this release
- `fixed`: for any bug fixes

## [0.1.4] - 2020-12-22

### Changed

- Notifications settings to use `.toggle()`, see [strapi api](https://strapi.io/documentation/developer-docs/latest/plugin-development/frontend-development.html#api) for more information [[e066cac](https://github.com/danestves/strapi-plugin-preview-content/commit/e066cac)]

## [0.1.3] - 2020-12-21

### Fixed

- Function to creatr or update the settings [[be947f5](https://github.com/danestves/strapi-plugin-preview-content/commit/be947f5)]

## [0.1.0] - 2020-12-21

### Fixed

- Import lodash in service [[4bf38ef](https://github.com/danestves/strapi-plugin-preview-content/commit/4bf38ef)]

## [0.0.8] - 2020-12-21

### Added

- Get preview url from database [[9a2176f](https://github.com/danestves/strapi-plugin-preview-content/commit/9a2176f)]

### Fixed

- Missing translations `en` [[c2e25e2](https://github.com/danestves/strapi-plugin-preview-content/commit/c2e25e2)]

## [0.0.6] - 2020-12-21

### Added

- Support for models in `npm` [[0ddb702](https://github.com/danestves/strapi-plugin-preview-content/commit/0ddb702)]

## [0.0.5] - 2020-12-21

### Removed

- Deleting packages not needed [[1200b81](https://github.com/danestves/strapi-plugin-preview-content/commit/1200b81)]

## [0.0.4] - 2020-12-21

### Added

- Script to compile and ignore files in `.gitignore` [[aaa5bed](https://github.com/danestves/strapi-plugin-preview-content/commit/aaa5bed)]

## [0.0.3] - 2020-12-21

### Added

- Support for Strapi 3.4 files [[669f535](https://github.com/danestves/strapi-plugin-preview-content/commit/669f535)]

## [0.0.2] - 2020-12-21

### Added

- All routes with initial vanilla javascript [[8b099b4](https://github.com/danestves/strapi-plugin-preview-content/commit/8b099b4)]
- TypeScript support for all the plugin [[d51b9f0](https://github.com/danestves/strapi-plugin-preview-content/commit/d51b9f0)]

## Fixed

- Empty strapi package [[9ff05cf](https://github.com/danestves/strapi-plugin-preview-content/commit/9ff05cf)]

## [0.0.1] - 2020-12-21

### Added

- Init repository with basic funcionality [[9a1ce22](https://github.com/danestves/strapi-plugin-preview-content/commit/9a1ce22)]

[keep-a-changelog]: https://github.com/olivierlacan/keep-a-changelog
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "strapi-plugin-preview-content",
"version": "0.1.3",
"version": "0.2.2",
"description": "Preview your content with custom URL.",
"main": "admin/main/index.js",
"strapi": {
Expand Down
54 changes: 21 additions & 33 deletions src/admin/main/preview-context/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,18 @@ export const PreviewProvider = ({
params,
}
);

if (data.url) {
window.open(data.url, "_blank");
} else {
strapi.notification.config({
type: "error",
message: getPreviewPluginTrad("error.previewUrl.notFound"),
});
strapi.notification.error(
getPreviewPluginTrad("error.previewUrl.notFound")
);
}
} catch (_e) {
strapi.notification.config({
type: "error",
message: getPreviewPluginTrad("error.previewUrl.notFound"),
});
strapi.notification.error(
getPreviewPluginTrad("error.previewUrl.notFound")
);
}
},
type: "button",
Expand All @@ -113,6 +112,7 @@ export const PreviewProvider = ({
paddingLeft: 15,
paddingRight: 15,
fontWeight: 600,
minWidth: 100,
},
});
} else {
Expand All @@ -128,6 +128,7 @@ export const PreviewProvider = ({
paddingLeft: 15,
paddingRight: 15,
fontWeight: 600,
minWidth: 75,
},
});
}
Expand All @@ -150,36 +151,25 @@ export const PreviewProvider = ({
try {
// Show the loading state
setButtonLoading(true);
const clonedPayload = await request(getRequestUrl(slug), {
method: "GET",
body: {
...initialData,
cloneOf: initialData.id,
options: {
...initialData.options,
previewable: true,
},
},
});

strapi.notification.config({
type: "success",
message: getPreviewPluginTrad("success.record.clone"),
});
strapi.notification.success(getPreviewPluginTrad("success.record.clone"));

window.location.replace(getFrontendEntityUrl(slug, clonedPayload.id));
window.location.replace(getFrontendEntityUrl(slug, initialData.id));
} catch (err) {
console.log(err);
const errorMessage = get(
err,
"response.payload.message",
formatMessage({ id: getPreviewPluginTrad("error.record.clone") })
);

strapi.notification.error(errorMessage);
} finally {
setButtonLoading(false);
toggleWarningClone();
}
};

const handleConfirmPreviewPublish = async () => {
try {
// Show the loading state
Expand All @@ -201,21 +191,19 @@ export const PreviewProvider = ({
method: "DELETE",
});

strapi.notification.config({
type: "success",
message: getPreviewPluginTrad("success.record.publish"),
});
strapi.notification.success(
getPreviewPluginTrad("success.record.publish")
);

window.location.replace(getFrontendEntityUrl(slug, targetId));
} catch (err) {
const errorMessage = get(
err,
"response.payload.message",
formatMessage({ id: getPreviewPluginTrad("error.record.publish") })
);
strapi.notification.config({
type: "error",
message: errorMessage,
});

strapi.notification.error(errorMessage);
} finally {
setButtonLoading(false);
toggleWarningPublish();
Expand Down Expand Up @@ -296,7 +284,7 @@ function prepareToPublish(payload) {
}

const getRequestUrl = (path) =>
`/${CONTENT_MANAGER_PLUGIN_ID}/collection-types/${path}/${id}`;
`/${CONTENT_MANAGER_PLUGIN_ID}/explorer/${path}`;
const getFrontendEntityUrl = (path, id) =>
`/admin/plugins/${CONTENT_MANAGER_PLUGIN_ID}/collectionType/${path}/create/clone/${id}`;

Expand Down
5 changes: 0 additions & 5 deletions src/services/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,6 @@ module.exports = {
const entity: any = _.first(results) || null;

const previewUrl = entity.baseUrl || "";
console.log({ entity });
console.log({ previewUrl });
console.log({
url: this.replacePreviewParams(contentType, contentId, previewUrl),
});

return this.replacePreviewParams(contentType, contentId, previewUrl);
},
Expand Down

0 comments on commit 4a081b7

Please sign in to comment.