Skip to content

Commit

Permalink
Fix layer generator with 2nd layer (#204)
Browse files Browse the repository at this point in the history
* Added logic to add layer in the useEffect when the source is already added to the view.

Co-authored-by: Víctor Velarde <victor.velarde@gmail.com>
Co-authored-by: Dani Arlandis <daniarlandis@gmail.com>
  • Loading branch information
3 people authored Mar 10, 2021
1 parent 291d361 commit 506db09
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Change BigQuery source type name from 'bq' to 'bigquery' [#203](https://github.com/CartoDB/carto-react-template/pull/203)
- Add new hygen generators for components, models and slices [#171](https://github.com/CartoDB/carto-react-template/pull/171)
- Adapt to new **multi-package** structure for carto-react libs [#206](https://github.com/CartoDB/carto-react-lib/pull/206)
- Fix layer generator with second layer [#204](https://github.com/CartoDB/carto-react-template/pull/204)

## 1.0.0-beta12 (2021-02-08)
- Refactor on basic JSX & JS stuff [#170](https://github.com/CartoDB/carto-react-template/pull/170)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
inject: true
to: "<%= attach ? `src/${view_path}` : null %>"
after: "'react'"
skip_if: "addLayer"
after: "from 'react'"
skip_if: \{ addLayer,
---

import { addLayer, removeLayer, addSource, removeSource } from '@carto/react-redux';
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ to: "<%= attach ? `src/${view_path}` : null %>"
after: "from 'react'"
skip_if: "import { <%= h.changeCase.constantCase(name) %>_ID"
---
import { <%= h.changeCase.constantCase(name) %>_ID } from 'components/layers/<%= h.changeCase.pascalCase(name) -%>';
import { <%= h.changeCase.constantCase(name) %>_ID } from 'components/layers/<%= h.changeCase.pascalCase(name) -%>';
2 changes: 1 addition & 1 deletion hygen/_templates/layer/new/inject_view_import_source.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ to: "<%= attach ? `src/${view_path}` : null %>"
after: "from 'react'"
skip_if: "<%= `data/sources/${source_file}` %>"
---
import <%= h.changeCase.camelCase(source_file) %> from 'data/sources/<%= h.changeCase.camelCase(source_file) %>';
import <%= h.changeCase.camelCase(source_file) %> from 'data/sources/<%= h.changeCase.camelCase(source_file) %>';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
inject: true
to: "<%= attach ? `src/${view_path}` : null %>"
after: addSource\(<%= h.changeCase.camelCase(source_file) %>\)\n[ \t]*\)|addSource\(<%= h.changeCase.camelCase(source_file) %>\)\);
skip_if: <%= h.changeCase.constantCase(name) %>_ID,
---

dispatch(
addLayer({
id: <%= h.changeCase.constantCase(name) %>_ID,
source: <%= h.changeCase.camelCase(source_file) %>.id,
})
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
inject: true
to: "<%= attach ? `src/${view_path}` : null %>"
before: dispatch\(removeSource\(<%= h.changeCase.camelCase(source_file) %>.id\)\);
skip_if: dispatch\(removeLayer\(<%= h.changeCase.constantCase(name) %>_ID\)\);
---

dispatch(removeLayer(<%= h.changeCase.constantCase(name) %>_ID));

1 comment on commit 506db09

@vercel
Copy link

@vercel vercel bot commented on 506db09 Mar 10, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.