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

[4.x] Prevent handling field previews when previews are disabled #9353

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions resources/js/components/fieldtypes/ArrayFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ export default {
},

replicatorPreview() {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;

return _.reduce(this.value, (carry, value, key) => {
let str = `${key}: ${value}`;
if (carry) str = carry + ', ' + str;
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/fieldtypes/ButtonGroupFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export default {
},

replicatorPreview() {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;

var option = _.findWhere(this.config.options, {value: this.value});
return (option) ? option.label : this.value;
},
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/fieldtypes/CheckboxesFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export default {
},

replicatorPreview() {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;

return this.values.map(value => {
const option = _.findWhere(this.options, { value });
return option ? option.label : value;
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/fieldtypes/CodeFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export default {
return 'theme-' + this.config.theme;
},
replicatorPreview() {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;

return this.value.code ? truncate(this.value.code, 60) : '';
},
readOnlyOption() {
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/fieldtypes/ColorFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export default {
computed: {

replicatorPreview() {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;

return this.value
? `<span class="little-dot" style="background-color:${this.value}"></span>`
: null;
Expand Down
1 change: 1 addition & 0 deletions resources/js/components/fieldtypes/DateFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export default {
},

replicatorPreview() {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;
if (! this.value.date) return;

if (this.isRange) {
Expand Down
8 changes: 8 additions & 0 deletions resources/js/components/fieldtypes/Fieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export default {
type: Boolean,
default: false
},
showFieldPreviews: {
type: Boolean,
default: false
},
namePrefix: String,
fieldPathPrefix: String,
},
Expand Down Expand Up @@ -56,6 +60,8 @@ export default {
},

replicatorPreview() {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;

return this.value;
},

Expand All @@ -71,6 +77,8 @@ export default {
replicatorPreview: {
immediate: true,
handler(text) {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;

this.$emit('replicator-preview-updated', text);
}
}
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/fieldtypes/GroupFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export default {
return this.config.fields;
},
replicatorPreview() {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;

return Object.values(this.value).join(', ');
}
},
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/fieldtypes/RadioFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export default {
},

replicatorPreview() {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;

var option = _.findWhere(this.config.options, {value: this.value});
return (option) ? option.label : this.value;
},
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/fieldtypes/SelectFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export default {
},

replicatorPreview() {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;

return this.selectedOptions.map(option => option.label).join(', ');
},

Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/fieldtypes/TableFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ export default {
},

replicatorPreview() {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;

// Join all values with commas. Exclude any empties.
return _(this.data)
.map(row => row.value.cells.filter(cell => !!cell).join(', '))
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/fieldtypes/ToggleFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export default {
},

replicatorPreview() {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;

return (this.value ? '✓' : '✗') + ' ' + __(this.config.display);
}

Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/fieldtypes/assets/AssetsFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ export default {
},

replicatorPreview() {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;

return replicatorPreviewHtml(_.map(this.assets, (asset) => {
return (asset.isImage || asset.isSvg) ?
`<img src="${asset.thumbnail}" width="20" height="20" title="${asset.basename}" />`
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/fieldtypes/bard/BardFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ export default {
},

replicatorPreview() {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;

const stack = JSON.parse(this.value);
let text = '';
while (stack.length) {
Expand Down
1 change: 1 addition & 0 deletions resources/js/components/fieldtypes/bard/Set.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
:set-index="index"
:field-path="fieldPath(field)"
:read-only="isReadOnly"
:show-field-previews="showFieldPreviews"
@updated="updated(field.handle, $event)"
@meta-updated="metaUpdated(field.handle, $event)"
@focus="focused"
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/fieldtypes/grid/Grid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ export default {
},

replicatorPreview() {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;

return `${__(this.config.display)}: ${__n(':count row|:count rows', this.value.length)}`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ export default {
},

replicatorPreview() {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;

return marked(this.data || '', { renderer: new PlainTextRenderer })
.replace(/<\/?[^>]+(>|$)/g, "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ export default {
},

replicatorPreview() {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;

return this.value.map(id => {
const item = _.findWhere(this.meta.data, { id });
return item ? item.title : id;
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/fieldtypes/replicator/Field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
:field-path-prefix="fieldPath"
:has-error="hasError || hasNestedError"
:read-only="isReadOnly"
:show-field-previews="showFieldPreviews"
@input="$emit('updated', $event)"
@meta-updated="$emit('meta-updated', $event)"
@focus="$emit('focus')"
Expand Down Expand Up @@ -69,6 +70,7 @@ export default {
type: String
},
readOnly: Boolean,
showFieldPreviews: Boolean,
},

inject: ['storeName'],
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/fieldtypes/replicator/Replicator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ export default {
},

replicatorPreview() {
if (! this.showFieldPreviews || ! this.config.replicator_preview) return;

return `${__(this.config.display)}: ${__n(':count set|:count sets', this.value.length)}`;
}
},
Expand Down
1 change: 1 addition & 0 deletions resources/js/components/fieldtypes/replicator/Set.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
:set-index="index"
:field-path="fieldPath(field)"
:read-only="isReadOnly"
:show-field-previews="showFieldPreviews"
@updated="updated(field.handle, $event)"
@meta-updated="metaUpdated(field.handle, $event)"
@focus="$emit('focus')"
Expand Down
Loading