Skip to content

Commit

Permalink
feat(view): add option for custom host
Browse files Browse the repository at this point in the history
fixes #496
  • Loading branch information
MauriceNino committed Dec 31, 2022
1 parent 75ec11e commit 01d35e0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
3 changes: 2 additions & 1 deletion apps/api/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const CONFIG: Config = {
disable_integrations: penv('DISABLE_INTEGRATIONS') === 'true',

show_host: penv('SHOW_HOST') === 'true',
custom_host: penv('CUSTOM_HOST'),
page_title: penv('PAGE_TITLE') ?? 'dash.',
use_imperial: penv('USE_IMPERIAL') === 'true',
enable_storage_split_view: penv('ENABLE_STORAGE_SPLIT_VIEW') === 'true',
Expand All @@ -47,7 +48,7 @@ export const CONFIG: Config = {
) as any[],
gpu_label_list: lst(penv('GPU_LABEL_LIST') ?? 'brand,model,memory') as any[],

os_widget_grow: numNull(penv('OS_WIDGET_GROW')) ?? 1.5,
os_widget_grow: numNull(penv('OS_WIDGET_GROW')) ?? 2.5,
os_widget_min_width: numNull(penv('OS_WIDGET_MIN_WIDTH')) ?? 300,

enable_cpu_temps: penv('ENABLE_CPU_TEMPS') === 'true',
Expand Down
7 changes: 7 additions & 0 deletions apps/docs/docs/config/ui-features.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ If you want to show the host part in the server widget (e.g. `dash.` -> `dash.ma
| ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| <img src="/img/server_view_normal.png" alt="Server widget normal" style={{maxHeight: "250px"}} /> | <img src="/img/server_view_with_host.png" alt="Server widget with host" style={{maxHeight: "250px"}} /> |

## `DASHDOT_CUSTOM_HOST`

If you want to show a custom host in the server widget (needs [`DASHDOT_SHOW_HOST`](./ui-features#dashdot_show_host) enabled to work).

- type: `string`
- default: `unset`

## `DASHDOT_ENABLE_CPU_TEMPS`

If you want to show the CPU temperature in the graph. This will probably not work on a VPS, so you need to try it on your own if this works. For home servers it might work just fine.
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/docs/config/widget-specific/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ title: Server
To adjust the relative size of the OS widget.

- type: `number`
- default: `1.5`
- default: `2.5`

## `DASHDOT_OS_WIDGET_MIN_WIDTH`

Expand Down
1 change: 1 addition & 0 deletions apps/view/src/components/glass-pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const Container = styled.div<SCProps>`
max-height: ${({ mobile }) => (mobile ? 'unset' : '500px')};
flex-grow: ${props => props.grow ?? 1};
flex-basis: ${({ mobile }) => (mobile ? 'unset' : '0')};
transition: opacity 0.3 ease-in-out;
display: flex;
Expand Down
12 changes: 7 additions & 5 deletions apps/view/src/widgets/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const Container = styled.div`

const Heading = styled(ThemedText)`
width: 100%;
max-width: 100%;
margin-top: 31px;
margin-bottom: 15px;
Expand All @@ -57,6 +56,7 @@ const Heading = styled(ThemedText)`
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
padding-bottom: 5px;
}
`;

Expand Down Expand Up @@ -180,7 +180,9 @@ export const ServerWidget: FC<ServerWidgetProps> = ({ data, config }) => {
return () => clearInterval(interval);
}, [data.uptime]);

const domain = useMemo(() => {
const host = useMemo(() => {
if (config?.custom_host) return config?.custom_host;

const href = window.location.href;
const result = parseDomain(fromUrl(href));

Expand All @@ -190,7 +192,7 @@ export const ServerWidget: FC<ServerWidgetProps> = ({ data, config }) => {
} else {
return undefined;
}
}, []);
}, [config?.custom_host]);

const dateInfos = [
{
Expand Down Expand Up @@ -245,10 +247,10 @@ export const ServerWidget: FC<ServerWidgetProps> = ({ data, config }) => {
/>

<Heading>
{config?.show_host && domain ? (
{config?.show_host && host ? (
<>
<Appendix>dash.</Appendix>
<ServerName>{domain}</ServerName>
<ServerName>{host}</ServerName>
</>
) : (
<StandaloneAppendix>dash.</StandaloneAppendix>
Expand Down
1 change: 1 addition & 0 deletions libs/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export type Config = {
disable_integrations: boolean;

show_host: boolean;
custom_host?: string;
page_title: string;
use_imperial: boolean;
enable_cpu_temps: boolean;
Expand Down

0 comments on commit 01d35e0

Please sign in to comment.