ActionEditor.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. if (!action.type) action.type = ActionSystem.constructor.Actions[0].id
  12. return (
  13. <View style={styles.container}>
  14. <Text>{props.title}</Text>
  15. <View style={styles.row}>
  16. <Text>Action</Text>
  17. <Picker
  18. selectedValue={action.name}
  19. style={styles.picker}
  20. onValueChange={(itemValue, itemIndex) => {
  21. action.type = itemValue;
  22. props.onChange && props.onChange(action);
  23. setAction(action)
  24. }}>
  25. {ActionSystem.constructor.Actions.map((itemAction, index) => {
  26. return <Picker.Item label={itemAction.name} value={itemAction.id} key={index} />
  27. })}
  28. <Picker.Item label="java" value="java" />
  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. })