TheRolf b39c79bea1
Custom JS and CSS (#1950)
* First commit for custom styles and JS

* Adjusted classes

* Added ids and classes for services and bookmarks

* Apply suggestions from code review

* Remove mime dependency

* Update settings.json

* Detect custom css / js changes, no refresh

* Added preload to custom scripts and styles so they can load earlier

* Added data attribute name for bookmarks too

* Update [path].js

* code style, revert some pointer changes

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
2023-09-10 14:36:54 -07:00

41 lines
1.3 KiB
JavaScript

import { useContext } from "react";
import Error from "./error";
import { SettingsContext } from "utils/contexts/settings";
export default function Container({ error = false, children, service }) {
const { settings } = useContext(SettingsContext);
if (error) {
if (settings.hideErrors || service.widget.hide_errors) {
return null;
}
return <Error service={service} error={error} />
}
const childrenArray = Array.isArray(children) ? children : [children];
let visibleChildren = childrenArray;
let fields = service?.widget?.fields;
if (typeof fields === 'string') fields = JSON.parse(service.widget.fields);
const type = service?.widget?.type;
if (fields && type) {
// if the field contains a "." then it most likely contains a common loc value
// logic now allows a fields array that can look like:
// fields: [ "resources.cpu", "resources.mem", "field"]
// or even
// fields: [ "resources.cpu", "widget_type.field" ]
visibleChildren = childrenArray?.filter(child => fields.some(field => {
let fullField = field;
if (!field.includes(".")) {
fullField = `${type}.${field}`;
}
return fullField === child?.props?.label;
}));
}
return <div className="relative flex flex-row w-full service-container">{visibleChildren}</div>;
}