ActionEditor.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import React, { useState } from 'react';
  2. import { View, Text, TextInput, StyleSheet } from 'react-native';
  3. import InjectionSystem from 'trapilib/dist/lib/systems/InjectionSystem';
  4. import { Picker } from 'react-native';
  5. export default function ActionEditor(props) {
  6. let [action, setAction] = useState(props.value || {});
  7. let ActionSystem = InjectionSystem.inject('Actions');
  8. let RoutingSystem = InjectionSystem.inject('Routing');
  9. let Routes = RoutingSystem.topology.nodes
  10. if (!action.data || typeof action.data !== "object") action.data = {};
  11. console.log(ActionSystem)
  12. if (!action.type) action.type = ActionSystem.constructor.Actions[0].id
  13. return (
  14. <View style={styles.container}>
  15. <Text>{props.title}</Text>
  16. <View style={styles.row}>
  17. <Text>Action</Text>
  18. <Picker
  19. selectedValue={action.name}
  20. style={styles.picker}
  21. onValueChange={(itemValue, itemIndex) => {
  22. action.type = itemValue;
  23. props.onChange && props.onChange(action);
  24. setAction(action)
  25. }}>
  26. {ActionSystem.constructor.Actions.map((itemAction, index) => {
  27. return <Picker.Item label={itemAction.name} value={itemAction.id} key={index} />
  28. })}
  29. </Picker>
  30. </View>
  31. <View style={styles.row}>
  32. <Text>Page</Text>
  33. <Picker
  34. selectedValue={action.data.route}
  35. style={styles.picker}
  36. onValueChange={(itemValue, itemIndex) => {
  37. action.data.route = itemValue;
  38. props.onChange && props.onChange(action);
  39. setAction(action)
  40. }}>
  41. {Object.keys(Routes).map((k, index) => {
  42. return <Picker.Item label={k} value={k} key={index} />
  43. })}
  44. </Picker>
  45. </View>
  46. </View>
  47. );
  48. }
  49. const styles = StyleSheet.create({
  50. container: {
  51. flexDirection: 'column',
  52. borderBottomWidth: 1,
  53. borderColor: '#cecece'
  54. },
  55. capFirst: {
  56. fontSize: 14,
  57. fontFamily: 'roboto-light',
  58. textTransform: 'capitalize'
  59. },
  60. row:{
  61. flexDirection:'row',
  62. justifyContent:"space-between",
  63. alignItems:"center"
  64. },
  65. picker: {
  66. marginTop: 6,
  67. borderWidth: 1,
  68. backgroundColor: 'white',
  69. boxShadow: '0px 3px 6px #00000029',
  70. borderColor: '#FFFFFF66',
  71. borderRadius: 14
  72. },
  73. title: {
  74. }
  75. })