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

✨ Adding DependencyBuilder #5

Merged
merged 11 commits into from
Dec 5, 2023
Merged

✨ Adding DependencyBuilder #5

merged 11 commits into from
Dec 5, 2023

Conversation

intraordinaire
Copy link
Contributor

@intraordinaire intraordinaire commented Feb 9, 2023

In order to correctly build the dependencies variable to instantiate the CDC, add an helper to ease the work of module devs.

So, we have to add a module_dependencies.json file in the root dir of the module.

{
    "dependencies": [
      {
        "name" : "ps_accounts"
      },
      {
        "name" : "ps_eventbus"
      }
    ]
}

And then, in the module :

$mboInstaller = new Prestashop\ModuleLibMboInstaller\DependencyBuilder($this);
$requiredDependencies = $mboInstaller->handleDependencies();
return $twig->render('mytpl.html.twig', [
    'requiredDependencies' => $requiredDependencies,
]);

And later, in the tpl

<!-- Load cdc library -->
<script src="http://127.0.0.1:5173/dist/mbo-cdc-dependencies-resolver.umd.js"></script>

<!-- cdc container -->
<div id="cdc-container"></div>

<script defer>
  const renderMboCdcDependencyResolver = window.mboCdcDependencyResolver.render
  const context = {
    ...{$requiredDependencies|json_encode},
    // Optional callbacks to handle the display of the page
    onDependenciesResolved: () => console.log('Everything works!'),
    onDependencyResolved: (dependencyData) => console.log('Dependency installed', dependencyData),
    onDependencyFailed: (dependencyData) => console.log('Failed to install dependency', dependencyData),
    onDependenciesFailed: () => console.log('There are some errors'),
  }
  renderMboCdcDependencyResolver(context, '#cdc-container')
</script>

Here you will find a module (compatible from 1.7.0) in order to test/try it :
prestashopexamplemodule.zip

UPDATED 27/11/2023

Go to the config page, and you will see something like this :
image

In order to correctly build the dependencies variable to instanciate the CDC, add an helper to ease the work of module devs.
@intraordinaire intraordinaire force-pushed the feat/dependency-builder branch 5 times, most recently from 682e06f to 1a5ed51 Compare February 9, 2023 17:29
@intraordinaire intraordinaire force-pushed the feat/dependency-builder branch 5 times, most recently from 42936a1 to d60710c Compare February 10, 2023 14:08
@intraordinaire intraordinaire force-pushed the feat/dependency-builder branch from d60710c to 120891d Compare February 10, 2023 14:12
@julienr114
Copy link

julienr114 commented Mar 7, 2023

Hi, I remade the zip by including a first version of the cdc in the configuration page of the example module.
prestashopexamplemodule.zip
EDIT 23/10/2023 : Pick the one in the description

if you go on config page you should show something like this
Capture d’écran 2023-03-07 à 10 25 31

@intraordinaire intraordinaire force-pushed the feat/dependency-builder branch 3 times, most recently from 8985ca3 to d1c4fc1 Compare March 9, 2023 16:59
Set up new context variable to interact with the CDC.
Install or enable the MBO module if needed.
@intraordinaire intraordinaire force-pushed the feat/dependency-builder branch from d1c4fc1 to a6fadc2 Compare March 9, 2023 17:02
@intraordinaire intraordinaire force-pushed the feat/dependency-builder branch 2 times, most recently from 924f679 to 7d5f526 Compare March 10, 2023 12:00
@intraordinaire intraordinaire force-pushed the feat/dependency-builder branch from 7d5f526 to d54a753 Compare March 10, 2023 12:06
@intraordinaire intraordinaire force-pushed the feat/dependency-builder branch from 3972faf to 607d134 Compare March 10, 2023 16:24
@intraordinaire
Copy link
Contributor Author

intraordinaire commented Mar 14, 2023

You can find an updated example module version here prestashopexamplemodule.zip
EDIT 23/10/2023 : Pick the one in the description

The ID have been added to the dependencies file in order to be able to correctly retrieve last available version & module name.

jokesterfr
jokesterfr previously approved these changes Aug 24, 2023
src/DependencyBuilder.php Outdated Show resolved Hide resolved
src/DependencyBuilder.php Outdated Show resolved Hide resolved
@sowbiba sowbiba force-pushed the feat/dependency-builder branch from c9fca43 to 02eae86 Compare October 27, 2023 11:17
@prestamodule
Copy link

Hi,

Could a method like checkDependencies be added to the DependencyBuilder class, returning a simple boolean, allowing module developers to check if all dependencies are already installed instead of having to parse the return of handleDependencies?

Thanks!

@intraordinaire
Copy link
Contributor Author

@prestamodule
Thanks for your feedback !
Indeed, it's a good idea and it will ease the development.

@prestamodule
Copy link

Are there any plans to let module developers customize this dependencies installation page (like Billing allows for customization of some elements of the UI)? Or expose some methods to let them build the routes themselves and take over the entire process?
I think this would allow developers to better integrate this new process with their brand/module identity

@intraordinaire
Copy link
Contributor Author

@prestamodule
It's the idea, yes.
You could take the dependencies object and choose to display a page yourself, or deal with it as you want.
We will add a documentation with the structure of the data, and the correct routes you should call to launch the installation process.

So it will be up to each dev to choose. Use the "all in one" solution, or build a custom one.

@sowbiba sowbiba force-pushed the feat/dependency-builder branch 2 times, most recently from 461f763 to 567a1ae Compare November 13, 2023 17:11
@sowbiba sowbiba force-pushed the feat/dependency-builder branch from eeb91f4 to 63bdd7b Compare November 14, 2023 12:21
@sowbiba sowbiba force-pushed the feat/dependency-builder branch from 9ebd02e to 4ca20b1 Compare November 27, 2023 11:13
@sowbiba sowbiba requested a review from jokesterfr December 5, 2023 09:34
@sowbiba sowbiba merged commit 97ff9a2 into main Dec 5, 2023
10 checks passed
@sowbiba sowbiba deleted the feat/dependency-builder branch December 5, 2023 09:37
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.

5 participants