| 132 | } |
| 133 | |
| 134 | function stripUnknownFields(script: Script): SettingsOptionValue[] { |
| 135 | const clone = [] |
| 136 | for (const optionValue of script.settings_values ?? []) { |
| 137 | const definition = script.settings_definitions?.find(v => v.data.name === optionValue.name) |
| 138 | if (!definition) { |
| 139 | console.log(`Could not find option definition for ${optionValue.name}`) |
| 140 | continue |
| 141 | } |
| 142 | |
| 143 | if (definition.kind === "List") { |
| 144 | if (!Array.isArray(optionValue.value)) { |
| 145 | console.log(`Skipped bad type for list ${optionValue.name}`) |
| 146 | continue; |
| 147 | } |
| 148 | |
| 149 | const newRows = [] |
| 150 | |
| 151 | for (const row of optionValue.value as SettingsOptionValue[][]) { |
| 152 | const newRow = [] |
| 153 | for (const field of row) { |
| 154 | let fieldDefinition = definition.data.template.find(v => v.name === field.name) |
| 155 | if (!fieldDefinition) { |
| 156 | console.log(`Skipped unknown value in list ${optionValue.name}, field: ${field.name}`) |
| 157 | continue |
| 158 | } |
| 159 | newRow.push(field) |
| 160 | } |
| 161 | newRows.push(newRow) |
| 162 | } |
| 163 | |
| 164 | clone.push({ |
| 165 | name: optionValue.name, |
| 166 | value: newRows |
| 167 | }) |
| 168 | } else { |
| 169 | clone.push(optionValue) |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | return clone |
| 174 | } |
| 175 | |
| 176 | function ScriptSettings({ script }: { script: Script }) { |
| 177 | const session = useSession() |