-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added Foreign component, fixed EnumFilter
- Loading branch information
1 parent
3debcd7
commit e18184d
Showing
9 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"/js/app.js": "/js/app.js?id=82c6422f61e56e2fcf4f223d37ae20ba", | ||
"/js/app.js": "/js/app.js?id=2ac5d4ba555b3dee9bab9b39626c201f", | ||
"/js/manifest.js": "/js/manifest.js?id=35aa9d461e033ff05abe890341153838", | ||
"/js/vendor.js": "/js/vendor.js?id=b53083a0bb34e922d0d09ba0e52241c6", | ||
"/css/app.css": "/css/app.css?id=d75c395a1c5c29d8b4c39d09727b550c" | ||
"/css/app.css": "/css/app.css?id=e23eef270fc9a2679846e04a9a6e0a85" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react'; | ||
import components from "../rendering/components"; | ||
|
||
class Foreign extends React.Component { | ||
|
||
static defaultProps = { | ||
components: [], | ||
path: {}, | ||
data: {}, | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.componentList = []; | ||
} | ||
|
||
handleSubmit(data) { | ||
this.componentList.forEach(obj => { | ||
obj.ref.current.handleSubmit(data); | ||
}); | ||
} | ||
|
||
getData(data) { | ||
this.componentList.forEach(obj => { | ||
obj.ref.current.getData(data); | ||
}); | ||
return data; | ||
} | ||
|
||
render() { | ||
|
||
this.componentList = components.renderComponentsWith(this.props.components, this.props.data, this.props.path, (component, i) => { | ||
return ( | ||
<div className="foreign__component" key={i}> | ||
{component} | ||
</div> | ||
); | ||
}, true, this.props.errors); | ||
|
||
let componentListRenders = this.componentList.map(obj => obj.component); | ||
|
||
return ( | ||
<div className="foreign"> | ||
{componentListRenders} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Foreign; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@include block(foreign) | ||
{ | ||
display: grid; | ||
grid-gap: $rule; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace ReinVanOyen\Cmf\Components; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use ReinVanOyen\Cmf\Http\Resources\ModelResource; | ||
use ReinVanOyen\Cmf\RelationshipMetaGuesser; | ||
|
||
class Foreign extends Compound | ||
{ | ||
/** | ||
* @var string $relationship | ||
*/ | ||
private $relationship; | ||
|
||
/** | ||
* @param string $relationship | ||
* @param array $components | ||
*/ | ||
public function __construct(string $relationship, array $components) | ||
{ | ||
$this->relationship = $relationship; | ||
|
||
parent::__construct($components); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function type(): string | ||
{ | ||
return 'foreign'; | ||
} | ||
|
||
/** | ||
* @param ModelResource $model | ||
* @param array $attributes | ||
* @return void | ||
* @throws \ReinVanOyen\Cmf\Exceptions\CouldntGuessMetaException | ||
*/ | ||
public function provision(ModelResource $model, array &$attributes) | ||
{ | ||
$foreignModel = $model->{$this->relationship}; | ||
$modelResource = new ModelResource($foreignModel); | ||
|
||
foreach ($this->components as $component) { | ||
$component->provision($modelResource, $attributes); | ||
} | ||
} | ||
|
||
/** | ||
* @param Model $model | ||
* @param \Illuminate\Http\Request $request | ||
*/ | ||
public function save(Model $model, $request) | ||
{ | ||
$foreignModel = $model->{$this->relationship}; | ||
|
||
foreach ($this->components as $component) { | ||
$component->save($foreignModel, $request); | ||
} | ||
|
||
$foreignModel->save(); | ||
} | ||
} |