Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRO-6418: parked pages & singletons #74

Merged
merged 16 commits into from
Aug 22, 2024
Merged

Conversation

myovchev
Copy link
Contributor

@myovchev myovchev commented Aug 19, 2024

Summary

All singleton documents (parked pages and pieces having option singleton: true) are now marked as "duplicates" in order to get a user confirmation for override. This happen ONLY if the singleton document exists in the target site database. If it doesn't exist, the document is handled as a new generic document (fallback to the previous behavior).

The UI now accepts replaceIds pairs beside the usual dociIds. Those are sent back on confirmation (only for the checked documents). The backend is using them to perform document ID replacement while importing and for updating all document relationships at the end of the import process.

What are the specific steps to test this change?

Export parked pages (such as @apostrophecms/home-page, @apostrophecms/search-page) and a singleton piece(s) (such as @apostrophecms/global). Ensure that those documents have some relationships and attachments (e.g. images)
Import the previous exported in another (blank) site (e.g. change the database after the export). Ensure that all of the imported singletons are keeping the ID's from the target site. Ensure that all reverse relationships (in the related documents) have the proper ID's (the target site documents).

What kind of change does this PR introduce?

(Check at least one)

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Build-related changes
  • Other

Make sure the PR fulfills these requirements:

  • It includes a) the existing issue ID being resolved, b) a convincing reason for adding this feature, or c) a clear description of the bug it resolves
  • The changelog is updated
  • Related documentation has been updated
  • Related tests have been updated

If adding a new feature without an already open issue, it's best to open a feature request issue first and wait for approval before working on it.

Other information:

@myovchev myovchev marked this pull request as draft August 19, 2024 10:42
@myovchev myovchev changed the base branch from main to pro-6387-images-errors August 19, 2024 10:42
Base automatically changed from pro-6387-images-errors to main August 19, 2024 15:50
package.json Outdated
@@ -17,7 +18,7 @@
"author": "Apostrophe Technologies",
"license": "UNLICENSED",
"devDependencies": {
"apostrophe": "github:apostrophecms/apostrophe",
"apostrophe": "github:apostrophecms/apostrophe#pro-6418-parked-singletons",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIXME: Revert before merge/after core is merged.

@myovchev myovchev requested a review from ValJed August 20, 2024 09:59
@myovchev myovchev marked this pull request as ready for review August 20, 2024 10:22
Copy link
Contributor

@ValJed ValJed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few questions feedback

modules/@apostrophecms/import-export-doc-type/index.js Outdated Show resolved Hide resolved
aposDocId => this.duplicatedDocs.find(doc => doc.replaceId && doc.aposDocId === aposDocId)
)
.filter(Boolean)
.map(({ aposDocId, replaceId }) => [ aposDocId, replaceId ]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an object instead of an array would be clearer, and would avoid things like replaceItem[1] which is not really clear I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this follows the backend argument requirements - see await self.apos.doc.changeDocIds(replaceDocIdPairs, { skipReplace: true }); and the relevant code in overrideDuplicates.
For consistency, every "pair" is in that format.

modules/@apostrophecms/import-export-doc-type/index.js Outdated Show resolved Hide resolved
width: calc(100% + 60px);
height: 100%;
content: "";
background-color: var(--a-base-9);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does these changes are about linting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto formatted by stylelint.

ui/apos/components/AposExportModal.vue Outdated Show resolved Hide resolved
lib/methods/import.js Outdated Show resolved Hide resolved
@myovchev myovchev requested a review from ValJed August 20, 2024 16:04
"files": ["*.s{c,a}ss", "**/*.s{c,a}ss"],
"customSyntax": "postcss-scss"
}
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be needed, it already exists in stylelint-config-apostrophe. No extra config should be needed to use the same config in each project/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example error this fix:

 λ npm run stylelint                                    

> @apostrophecms/[email protected] stylelint
> stylelint ui/**/*.{scss,vue}


ui/apos/components/AposDuplicateImportModal.vue
 366:21  ✖  Unexpected unit "s" for property  declaration-property-unit-allowed-list
            "transition"
 366:21  ✖  Expected a minimum of 200         time-min-milliseconds
            milliseconds

2 problems (2 errors, 0 warnings)

Same when removing it:

 λ npm run stylelint

> @apostrophecms/[email protected] stylelint
> stylelint ui/**/*.{scss,vue}

/apostrophe/import-export/ui/apos/components/AposDuplicateImportModal.vue: you should use the "customSyntax" option when linting something other than CSS
/apostrophe/import-export/ui/apos/components/AposExportModal.vue: you should use the "customSyntax" option when linting something other than CSS
/apostrophe/import-export/ui/apos/components/AposImportModal.vue: you should use the "customSyntax" option when linting something other than CSS

ui/apos/components/AposDuplicateImportModal.vue
 15:16  ✖  Unknown word  CssSyntaxError

ui/apos/components/AposExportModal.vue
 15:16  ✖  Unknown word  CssSyntaxError

ui/apos/components/AposImportModal.vue
 15:16  ✖  Unknown word  CssSyntaxError

3 problems (3 errors, 0 warnings)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok this is because you don't use the latest version of our stylelint config.
Please upgrade to 4.1 and remove the added config.

lib/methods/import.js Outdated Show resolved Hide resolved
lib/methods/import.js Outdated Show resolved Hide resolved
});
continue;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Optional]: Maybe we could have used a Map here to store singletons list id -> replaceId in order to use the same array map above that build the duplicatedDocs and having another loop on replaceId.
Just an idea here not sure it would really improve code readability / maintainability here

Copy link
Contributor Author

@myovchev myovchev Aug 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried many variants, including trying to extract the whole logic in a function. The real problem is the complex continue logic (extremely sensitive to bugs). I prefer to keep it as it is now until we have really good idea how to do it.
I think the current is clean because its 2 phase logic - 1. either replace or duplicate (no change) set, 1.5. duplicate set only logic (no change), 2. append replace set directly to the result, it's prebuilt.

A better design is to move the whole logic (for a single document) in a separate method. This would "relax" the code depth and open possibilities for improvements. I don't think we are still there/forced to do this effort yett.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's good for me.

lib/methods/import.js Outdated Show resolved Hide resolved
@myovchev myovchev requested a review from ValJed August 21, 2024 10:09
Copy link
Contributor

@ValJed ValJed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just upgrade the stylelint to avoid extra config. Otherwise LGTM.

@myovchev myovchev requested a review from ValJed August 21, 2024 12:34
@myovchev
Copy link
Contributor Author

Just upgrade the stylelint to avoid extra config. Otherwise LGTM.

FYI after stylelint upgrade (still works):

> @apostrophecms/[email protected] stylelint
> stylelint ui/**/*.{scss,vue}

(node:212536) [stylelint:005] DeprecationWarning: `context.fix` is being deprecated.
Please pass a `fix` callback to the `report` utility of "scale-unlimited/declaration-strict-value" instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:212536) [stylelint:005] DeprecationWarning: `context.fix` is being deprecated.
Please pass a `fix` callback to the `report` utility of "scale-unlimited/declaration-strict-value" instead.
(node:212536) [stylelint:005] DeprecationWarning: `context.fix` is being deprecated.
Please pass a `fix` callback to the `report` utility of "scale-unlimited/declaration-strict-value" instead.

Deprecation warnings:
 - The "scss/at-import-partial-extension" rule is deprecated.
 - 'at-import-partial-extension has been deprecated, and will be removed in '7.0'. Use 'load-partial-extension' instead. See: https://github.com/stylelint-scss/stylelint-scss/blob/v6.3.0/src/rules/at-import-partial-extension/README.md

@myovchev myovchev merged commit beb3abc into main Aug 22, 2024
6 checks passed
@myovchev myovchev deleted the pro-6418-parked-singletons branch August 22, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants