Skip to content

Commit

Permalink
ID-4818 [FIX] The TimeStamp field issue has been fixed and now works …
Browse files Browse the repository at this point in the history
…correctly with the security rules (#669)
  • Loading branch information
armine-fliplet authored Sep 26, 2024
1 parent 9c3e0bb commit e1c65ed
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
36 changes: 33 additions & 3 deletions js/components/timeStamp.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
Fliplet.FormBuilder.field('timeStamp', {
name: 'Time Stamp',
category: 'Date & time',
submit: false,
props: {
value: {
type: Object
},
placeholder: {
type: String
},
Expand All @@ -29,6 +31,29 @@ Fliplet.FormBuilder.field('timeStamp', {
destroyed: function() {
Fliplet.Hooks.off('afterFormSubmit', this.afterFormSubmit);
},
mounted: function() {
this.value = {
createdAt: this.createdAt,
updatedAt: this.updatedAt
};
this.$emit('_input', this.name, this.value);
},
watch: {
createdAt: function(val) {
this.value = {
createdAt: val,
updatedAt: this.updatedAt
};
this.$emit('_input', this.name, this.value);
},
updatedAt: function(val) {
this.value = {
createdAt: this.createdAt,
updatedAt: val
};
this.$emit('_input', this.name, this.value);
}
},
methods: {
afterFormSubmit: async function(data, form) {
const fields = form.$instance.fields;
Expand All @@ -46,11 +71,16 @@ Fliplet.FormBuilder.field('timeStamp', {

const connection = await Fliplet.DataSources.connect(dataSourceId);

if (data.result.createdAt !== data.result.updatedAt && this.updatedAt) {
if (data.result.createdAt !== data.result.updatedAt && this.updatedAt && this.createdAt) {
connection.update(data.result.id, {
'Created at': data.result.createdAt,
'Last updated': data.result.updatedAt
});
} else if (data.result.createdAt !== data.result.updatedAt && this.updatedAt) {
connection.update(data.result.id, {
'Last updated': data.result.updatedAt
});
} else if (this.createdAt) {
} else {
connection.update(data.result.id, {
'Created at': data.result.createdAt
});
Expand Down
12 changes: 12 additions & 0 deletions js/libs/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,18 @@ Fliplet().then(function() {

break;

case 'flTimeStamp':
if (field.createdAt && !field.updatedAt) {
fieldNames.push('Created at');
} else if (!field.createdAt && field.updatedAt) {
fieldNames.push('Last updated');
} else {
fieldNames.push('Created at');
fieldNames.push('Last updated');
}

break;

case 'flMatrix':
_.forEach(field.rowOptions, function(row) {
var val = row.id ? row.id : row.label;
Expand Down
2 changes: 1 addition & 1 deletion js/libs/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Fliplet.FormBuilder = (function() {
}

component.computed._isFormField = function() {
return (this.showLabel || this.showLabel === undefined) && !(component.props._componentName.default === 'flCustomButton' || component.props._componentName.default === 'flTimeStamp');
return (this.showLabel || this.showLabel === undefined) && component.props._componentName.default !== 'flCustomButton';
};

component.computed._labelName = function() {
Expand Down
9 changes: 8 additions & 1 deletion js/libs/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,14 @@ Fliplet().then(function() {
appendField(field.name, value ? value[0] : null);
appendField(`${field.name} (accuracy)`, value ? value[1] : null);
} else if (type === 'flTimeStamp') {
return;
if (value.createdAt && !value.updatedAt) {
appendField('Created at', '');
} else if (!value.createdAt && value.updatedAt) {
appendField('Last updated', '');
} else {
appendField('Created at', '');
appendField('Last updated', '');
}
} else {
// Other inputs
appendField(field.name, value);
Expand Down

0 comments on commit e1c65ed

Please sign in to comment.