Skip to content

Commit

Permalink
refactor(widget): move error widget back to its own place (#4143)
Browse files Browse the repository at this point in the history
* refactor(widget): move error widget back to its own place

* move away HC colors
  • Loading branch information
Rathoz authored Apr 4, 2024
1 parent 27c81b4 commit 645eedb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
33 changes: 2 additions & 31 deletions components/infobox/commons/infobox_widget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
--
local Class = require('Module:Class')
local Lua = require('Module:Lua')
local String = require('Module:StringUtils')

local Injector = Lua.import('Module:Infobox/Widget/Injector')

Expand All @@ -16,11 +15,6 @@ local Injector = Lua.import('Module:Infobox/Widget/Injector')
---@field public injector WidgetInjector?
local Widget = Class.new()

local _ERROR_TEXT = '<span style="color:#ff0000;font-weight:bold" class="show-when-logged-in">' ..
'Unexpected Error, report this in #bugs on our [https://discord.gg/liquipedia Discord]. ' ..
'${errorMessage}' ..
'</span>[[Category:Pages with script errors]]'

---Asserts the existence of a value and copies it
---@param value string
---@return string
Expand Down Expand Up @@ -48,7 +42,8 @@ function Widget:tryMake()
mw.logObject(errorMessage, 'error')
mw.logObject(self, 'widget')
mw.log(debug.traceback())
return {Widget.Error({errorMessage = errorMessage})}
local ErrorWidget = Lua.import('Module:Infobox/Widget/Error')
return {ErrorWidget({errorMessage = errorMessage})}
end
)

Expand All @@ -64,28 +59,4 @@ function Widget:setContext(context)
end
end

-- error widget for displaying errors of widgets
-- have to add it here instead of a sep. module to avoid circular requires
local ErrorWidget = Class.new(
Widget,
function(self, input)
self.errorMessage = input.errorMessage
end
)

function ErrorWidget:make()
return {
ErrorWidget:_create(self.errorMessage)
}
end

function ErrorWidget:_create(errorMessage)
local errorOutput = String.interpolate(_ERROR_TEXT, {errorMessage = errorMessage})
local errorDiv = mw.html.create('div'):node(errorOutput)

return mw.html.create('div'):node(errorDiv)
end

Widget.Error = ErrorWidget

return Widget
31 changes: 30 additions & 1 deletion components/infobox/commons/infobox_widget_error.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,36 @@
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Class = require('Module:Class')
local Lua = require('Module:Lua')
local String = require('Module:StringUtils')
local Widget = Lua.import('Module:Infobox/Widget')

return Widget.Error
local ERROR_TEXT = '<span class="error show-when-logged-in">' ..
'Unexpected Error, report this in #bugs on our [https://discord.gg/liquipedia Discord]. ' ..
'${errorMessage}' ..
'</span>[[Category:Pages with script errors]]'


-- For displaying errors
local ErrorWidget = Class.new(
Widget,
function(self, input)
self.errorMessage = input.errorMessage
end
)

function ErrorWidget:make()
return {
ErrorWidget:_create(self.errorMessage)
}
end

function ErrorWidget:_create(errorMessage)
local errorOutput = String.interpolate(ERROR_TEXT, {errorMessage = errorMessage})
local errorDiv = mw.html.create('div'):node(errorOutput)

return mw.html.create('div'):node(errorDiv)
end

return ErrorWidget

0 comments on commit 645eedb

Please sign in to comment.