Add action to set localStorage value (#1280)

* Add action to set localStorage value

* Apply spacing between key and value of set localstorage action
This commit is contained in:
Sherfin Shamsudeen 2021-10-25 22:24:21 +05:30 committed by GitHub
parent e3087f737d
commit afa5dfc00d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 0 deletions

View file

@ -37,4 +37,12 @@ export const ActionTypes = [
id: 'copy-to-clipboard',
options: [{ name: 'copy-to-clipboard', type: 'text', default: '' }],
},
{
name: 'Set local storage',
id: 'set-localstorage-value',
options: [
{ name: 'key', type: 'code', default: '' },
{ name: 'value', type: 'code', default: '' },
],
},
];

View file

@ -266,6 +266,33 @@ export const EventManager = ({
</div>
</div>
)}
{event.actionId === 'set-localstorage-value' && (
<>
<div className="row">
<div className="col-3 p-2">Key</div>
<div className="col-9">
<CodeHinter
currentState={currentState}
initialValue={event.key}
onChange={(value) => handlerChanged(index, 'key', value)}
enablePreview={true}
/>
</div>
</div>
<div className="row mt-3">
<div className="col-3 p-2">Value</div>
<div className="col-9">
<CodeHinter
currentState={currentState}
initialValue={event.value}
onChange={(value) => handlerChanged(index, 'value', value)}
enablePreview={true}
/>
</div>
</div>
</>
)}
</div>
</Popover.Content>
</Popover>

View file

@ -188,6 +188,12 @@ function executeAction(_ref, event, mode) {
return Promise.resolve();
}
case 'set-localstorage-value': {
const key = resolveReferences(event.key, _ref.state.currentState);
const value = resolveReferences(event.value, _ref.state.currentState);
localStorage.setItem(key, value);
}
}
}
}