Skip to content

Commit

Permalink
fix: fix ui and ownerships (#1591)
Browse files Browse the repository at this point in the history
* fix: fix ui and ownerships

Set accessor as owner of the job if present.

Use credentials in httpClient for all requests across the UI

* fix: use httpClient in references

* fix: record show
  • Loading branch information
vcastellm authored Oct 6, 2024
1 parent 0f79eec commit b83ed25
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 55 deletions.
6 changes: 6 additions & 0 deletions dkron/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ func (h *HTTPTransport) jobCreateOrUpdateHandler(c *gin.Context) {
h.logger.Error(err)
return
}
// Get the owner from the context, if it exists
// this is coming from the ACL middleware
accessor := c.GetString("accessor")
if accessor != "" {
job.Owner = accessor
}
}

// Validate job
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dkron/ui-dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
window.DKRON_FAILED_JOBS = {{.DKRON_FAILED_JOBS}};
window.DKRON_UNTRIGGERED_JOBS = {{.DKRON_UNTRIGGERED_JOBS}};
window.DKRON_ACL_ENABLED = {{.DKRON_ACL_ENABLED}};</script>
<script type="module" crossorigin src="./assets/index-244e3810.js"></script>
<script type="module" crossorigin src="./assets/index-6dc28a61.js"></script>
<link rel="stylesheet" href="./assets/index-73a69410.css">
</head>

Expand Down
4 changes: 2 additions & 2 deletions ui/src/dataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DataProvider } from 'react-admin';

export const apiUrl = window.DKRON_API_URL || 'http://localhost:8080/v1'

const httpClient = (url: String, options: fetchUtils.Options = {}) => {
export const httpClient = (url: String, options: fetchUtils.Options = {}) => {
if (!options.headers) {
options.headers = fetchUtils.createHeadersFromOptions(options);
}
Expand Down Expand Up @@ -36,7 +36,7 @@ const dkronDataProvider: DataProvider = {
};
const url = `${apiUrl}/${params.target}/${params.id}/${resource}?${stringify(query)}`;

return fetchUtils.fetchJson(url).then(({ headers, json }) => {
return httpClient(url).then(({ headers, json }) => {
if (!headers.has('x-total-count')) {
throw new Error(
'The X-Total-Count header is missing in the HTTP Response. The jsonServer Data Provider expects responses for lists of resources to contain this header with the total number of results to build the pagination. If you are using CORS, did you declare X-Total-Count in the Access-Control-Expose-Headers header?'
Expand Down
4 changes: 2 additions & 2 deletions ui/src/jobs/BulkRunButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
useUnselectAll,
useRefresh,
} from 'react-admin';
import { apiUrl } from '../dataProvider';
import { apiUrl, httpClient } from '../dataProvider';
import RunIcon from '@mui/icons-material/PlayArrow';

const BulkRunButton = ({selectedIds}: any) => {
Expand All @@ -17,7 +17,7 @@ const BulkRunButton = ({selectedIds}: any) => {
const runMany = () => {
for(let id of selectedIds) {
setLoading(true);
fetch(`${apiUrl}/jobs/${id}`, { method: 'POST' })
httpClient(`${apiUrl}/jobs/${id}`, { method: 'POST' })
.then(() => {
notify('Success running job');
})
Expand Down
4 changes: 2 additions & 2 deletions ui/src/jobs/BulkToggleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
useUnselectAll,
useRefresh,
} from 'react-admin';
import { apiUrl } from '../dataProvider';
import { apiUrl, httpClient } from '../dataProvider';
import RunIcon from '@mui/icons-material/PlayArrow';

const BulkToggleButton = ({selectedIds}: any) => {
Expand All @@ -16,7 +16,7 @@ const BulkToggleButton = ({selectedIds}: any) => {
const toggleMany = () => {
for(let id of selectedIds) {
setLoading(true);
fetch(`${apiUrl}/jobs/${id}/toggle`, { method: 'POST' })
httpClient(`${apiUrl}/jobs/${id}/toggle`, { method: 'POST' })
.then(() => {
notify('Job toggled');
})
Expand Down
12 changes: 8 additions & 4 deletions ui/src/jobs/JobShow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
TabbedShowLayout,
Tab,
ReferenceManyField,
useNotify, Button,
useNotify,
Button,
useRecordContext
} from 'react-admin';
import ToggleButton from "./ToggleButton"
import RunButton from "./RunButton"
Expand All @@ -20,7 +22,7 @@ import JobIcon from '@mui/icons-material/Update';
import FullIcon from '@mui/icons-material/BatteryFull';
import { Tooltip } from '@mui/material';
import { useState } from 'react';
import { apiUrl } from '../dataProvider';
import { apiUrl, httpClient } from '../dataProvider';

// basePath={basePath}
const JobShowActions = ({ basePath, data, resource }: any) => (
Expand All @@ -43,7 +45,7 @@ const FullButton = ({record}: any) => {
const [loading, setLoading] = useState(false);
const handleClick = () => {
setLoading(true);
fetch(`${apiUrl}/jobs/${record.job_name}/executions/${record.id}`)
httpClient(`${apiUrl}/jobs/${record.job_name}/executions/${record.id}`)
.then((response) => {
if (response.ok) {
notify('Success loading full output');
Expand Down Expand Up @@ -73,7 +75,9 @@ const FullButton = ({record}: any) => {
);
};

const SpecialOutputPanel = ({ id, record, resource }: any) => {
const SpecialOutputPanel = () => {
const record = useRecordContext();
if (!record) return null;
return (
<div className="execution-output">
{record.output_truncated ? <div><FullButton record={record} /></div> : ""}
Expand Down
4 changes: 2 additions & 2 deletions ui/src/jobs/RunButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';
import { useNotify, useRefresh, Button, useRecordContext } from 'react-admin';
import { apiUrl } from '../dataProvider';
import { apiUrl, httpClient } from '../dataProvider';
import RunIcon from '@mui/icons-material/PlayArrow';

const RunButton = () => {
Expand All @@ -10,7 +10,7 @@ const RunButton = () => {
const [loading, setLoading] = useState(false);
const handleClick = () => {
setLoading(true);
fetch(`${apiUrl}/jobs/${record.id}`, { method: 'POST' })
httpClient(`${apiUrl}/jobs/${record.id}`, { method: 'POST' })
.then(() => {
notify('Success running job');
refresh();
Expand Down
4 changes: 2 additions & 2 deletions ui/src/jobs/ToggleButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';
import { useNotify, useRefresh, Button, useRecordContext } from 'react-admin';
import { apiUrl } from '../dataProvider';
import { apiUrl, httpClient } from '../dataProvider';
import ToggleIcon from '@mui/icons-material/Pause';

const ToggleButton = () => {
Expand All @@ -10,7 +10,7 @@ const ToggleButton = () => {
const [loading, setLoading] = useState(false);
const handleClick = () => {
setLoading(true);
fetch(`${apiUrl}/jobs/${record.id}/toggle`, { method: 'POST' })
httpClient(`${apiUrl}/jobs/${record.id}/toggle`, { method: 'POST' })
.then(() => {
notify('Job toggled');
refresh();
Expand Down

0 comments on commit b83ed25

Please sign in to comment.