spiff-arena/spiffworkflow-frontend/src/routes/SecretList.tsx

105 lines
2.7 KiB
TypeScript
Raw Normal View History

import { useEffect, useState } from 'react';
import { Link, useSearchParams } from 'react-router-dom';
import { Button, Table } from 'react-bootstrap';
Squashed 'spiffworkflow-frontend/' changes from 572d779f7..d68d521d7 d68d521d7 also alert for unexpected errors from the api result w/ burnettk 698f7595a show an alert if backend gives a 403 w/ burnettk fa65efbb3 Merge branch 'main' of github.com:sartography/spiffworkflow-frontend f2a629110 do not null out error message in useEffect to avoid endless redirects w/ burnettk b5b79bae7 Remove the AllowedModel stuff from secrets Clean up spacing on SecretNew Don't allow spaces in Secret key. Change them to dashes. 9ab1da07f Merge branch 'main' into feature/secrets 4936296bd add link for path column too 4272ad5ac No slugify, too extreme for this use case d5cdfed18 Merge remote-tracking branch 'origin/main' into feature/secrets 4a81b2a10 add SecretAllowedModelEdit 87f640e3a Don't allow spaces on secret keys c627ef9e8 Don't display value on SecretList d42bd4ced fix method shorthand 82340ddc2 commit for KB a2c210a5a First stab at edit 1a2646249 fix typo - allowed_process_models -> allowed_processes 519555919 add interface for allowed SecretAllowedProcessModel, and use it in Secret interface use Secret and SecretAllowedProcessModel interfaces instead of `any` in SecretShow 6ccc7dd31 Merge branch 'main' into feature/secrets accd8e364 Moved button to bottom Added Secrets heading 18b80556a delete allowed model path 2dfe4c41a remove unused code df006b2af Rename Allowed Process Path to Allowed Model 8a68de12a add SecretAllowedModelNew eadf54357 Merge branch 'main' into feature/secrets f016b90b8 Cleaning up delete 7e5db93f0 Committing so the machine can look at an error 8655e437d Delete 2 ways -- icon and button w/icon ce537d7e8 display list of allowed processes skeleton of delete using MdDelete icon ab19657c0 install react-icons git-subtree-dir: spiffworkflow-frontend git-subtree-split: d68d521d78f747d156cfd45e6a7b26f4a5f5d63b
2022-10-14 00:45:09 +00:00
import { MdDelete } from 'react-icons/md';
import PaginationForTable from '../components/PaginationForTable';
import HttpService from '../services/HttpService';
import { getPageInfoFromSearchParams } from '../helpers';
export default function SecretList() {
const [searchParams] = useSearchParams();
const [secrets, setSecrets] = useState([]);
const [pagination, setPagination] = useState(null);
useEffect(() => {
const setSecretsFromResult = (result: any) => {
setSecrets(result.results);
setPagination(result.pagination);
};
const { page, perPage } = getPageInfoFromSearchParams(searchParams);
HttpService.makeCallToBackend({
path: `/secrets?per_page=${perPage}&page=${page}`,
successCallback: setSecretsFromResult,
});
}, [searchParams]);
Squashed 'spiffworkflow-frontend/' changes from 572d779f7..d68d521d7 d68d521d7 also alert for unexpected errors from the api result w/ burnettk 698f7595a show an alert if backend gives a 403 w/ burnettk fa65efbb3 Merge branch 'main' of github.com:sartography/spiffworkflow-frontend f2a629110 do not null out error message in useEffect to avoid endless redirects w/ burnettk b5b79bae7 Remove the AllowedModel stuff from secrets Clean up spacing on SecretNew Don't allow spaces in Secret key. Change them to dashes. 9ab1da07f Merge branch 'main' into feature/secrets 4936296bd add link for path column too 4272ad5ac No slugify, too extreme for this use case d5cdfed18 Merge remote-tracking branch 'origin/main' into feature/secrets 4a81b2a10 add SecretAllowedModelEdit 87f640e3a Don't allow spaces on secret keys c627ef9e8 Don't display value on SecretList d42bd4ced fix method shorthand 82340ddc2 commit for KB a2c210a5a First stab at edit 1a2646249 fix typo - allowed_process_models -> allowed_processes 519555919 add interface for allowed SecretAllowedProcessModel, and use it in Secret interface use Secret and SecretAllowedProcessModel interfaces instead of `any` in SecretShow 6ccc7dd31 Merge branch 'main' into feature/secrets accd8e364 Moved button to bottom Added Secrets heading 18b80556a delete allowed model path 2dfe4c41a remove unused code df006b2af Rename Allowed Process Path to Allowed Model 8a68de12a add SecretAllowedModelNew eadf54357 Merge branch 'main' into feature/secrets f016b90b8 Cleaning up delete 7e5db93f0 Committing so the machine can look at an error 8655e437d Delete 2 ways -- icon and button w/icon ce537d7e8 display list of allowed processes skeleton of delete using MdDelete icon ab19657c0 install react-icons git-subtree-dir: spiffworkflow-frontend git-subtree-split: d68d521d78f747d156cfd45e6a7b26f4a5f5d63b
2022-10-14 00:45:09 +00:00
const reloadSecrets = (_result: any) => {
window.location.reload();
};
const handleDeleteSecret = (key: any) => {
HttpService.makeCallToBackend({
path: `/secrets/${key}`,
successCallback: reloadSecrets,
httpMethod: 'DELETE',
});
};
const buildTable = () => {
const rows = secrets.map((row) => {
return (
<tr key={(row as any).key}>
Squashed 'spiffworkflow-frontend/' changes from 572d779f7..d68d521d7 d68d521d7 also alert for unexpected errors from the api result w/ burnettk 698f7595a show an alert if backend gives a 403 w/ burnettk fa65efbb3 Merge branch 'main' of github.com:sartography/spiffworkflow-frontend f2a629110 do not null out error message in useEffect to avoid endless redirects w/ burnettk b5b79bae7 Remove the AllowedModel stuff from secrets Clean up spacing on SecretNew Don't allow spaces in Secret key. Change them to dashes. 9ab1da07f Merge branch 'main' into feature/secrets 4936296bd add link for path column too 4272ad5ac No slugify, too extreme for this use case d5cdfed18 Merge remote-tracking branch 'origin/main' into feature/secrets 4a81b2a10 add SecretAllowedModelEdit 87f640e3a Don't allow spaces on secret keys c627ef9e8 Don't display value on SecretList d42bd4ced fix method shorthand 82340ddc2 commit for KB a2c210a5a First stab at edit 1a2646249 fix typo - allowed_process_models -> allowed_processes 519555919 add interface for allowed SecretAllowedProcessModel, and use it in Secret interface use Secret and SecretAllowedProcessModel interfaces instead of `any` in SecretShow 6ccc7dd31 Merge branch 'main' into feature/secrets accd8e364 Moved button to bottom Added Secrets heading 18b80556a delete allowed model path 2dfe4c41a remove unused code df006b2af Rename Allowed Process Path to Allowed Model 8a68de12a add SecretAllowedModelNew eadf54357 Merge branch 'main' into feature/secrets f016b90b8 Cleaning up delete 7e5db93f0 Committing so the machine can look at an error 8655e437d Delete 2 ways -- icon and button w/icon ce537d7e8 display list of allowed processes skeleton of delete using MdDelete icon ab19657c0 install react-icons git-subtree-dir: spiffworkflow-frontend git-subtree-split: d68d521d78f747d156cfd45e6a7b26f4a5f5d63b
2022-10-14 00:45:09 +00:00
<td>
<Link to={`/admin/secrets/${(row as any).key}`}>
{(row as any).id}
</Link>
</td>
<td>
<Link to={`/admin/secrets/${(row as any).key}`}>
{(row as any).key}
</Link>
</td>
<td>{(row as any).username}</td>
Squashed 'spiffworkflow-frontend/' changes from 572d779f7..d68d521d7 d68d521d7 also alert for unexpected errors from the api result w/ burnettk 698f7595a show an alert if backend gives a 403 w/ burnettk fa65efbb3 Merge branch 'main' of github.com:sartography/spiffworkflow-frontend f2a629110 do not null out error message in useEffect to avoid endless redirects w/ burnettk b5b79bae7 Remove the AllowedModel stuff from secrets Clean up spacing on SecretNew Don't allow spaces in Secret key. Change them to dashes. 9ab1da07f Merge branch 'main' into feature/secrets 4936296bd add link for path column too 4272ad5ac No slugify, too extreme for this use case d5cdfed18 Merge remote-tracking branch 'origin/main' into feature/secrets 4a81b2a10 add SecretAllowedModelEdit 87f640e3a Don't allow spaces on secret keys c627ef9e8 Don't display value on SecretList d42bd4ced fix method shorthand 82340ddc2 commit for KB a2c210a5a First stab at edit 1a2646249 fix typo - allowed_process_models -> allowed_processes 519555919 add interface for allowed SecretAllowedProcessModel, and use it in Secret interface use Secret and SecretAllowedProcessModel interfaces instead of `any` in SecretShow 6ccc7dd31 Merge branch 'main' into feature/secrets accd8e364 Moved button to bottom Added Secrets heading 18b80556a delete allowed model path 2dfe4c41a remove unused code df006b2af Rename Allowed Process Path to Allowed Model 8a68de12a add SecretAllowedModelNew eadf54357 Merge branch 'main' into feature/secrets f016b90b8 Cleaning up delete 7e5db93f0 Committing so the machine can look at an error 8655e437d Delete 2 ways -- icon and button w/icon ce537d7e8 display list of allowed processes skeleton of delete using MdDelete icon ab19657c0 install react-icons git-subtree-dir: spiffworkflow-frontend git-subtree-split: d68d521d78f747d156cfd45e6a7b26f4a5f5d63b
2022-10-14 00:45:09 +00:00
<td>
<MdDelete onClick={() => handleDeleteSecret((row as any).key)} />
</td>
</tr>
);
});
return (
<Table striped bordered>
<thead>
<tr>
Squashed 'spiffworkflow-frontend/' changes from 572d779f7..d68d521d7 d68d521d7 also alert for unexpected errors from the api result w/ burnettk 698f7595a show an alert if backend gives a 403 w/ burnettk fa65efbb3 Merge branch 'main' of github.com:sartography/spiffworkflow-frontend f2a629110 do not null out error message in useEffect to avoid endless redirects w/ burnettk b5b79bae7 Remove the AllowedModel stuff from secrets Clean up spacing on SecretNew Don't allow spaces in Secret key. Change them to dashes. 9ab1da07f Merge branch 'main' into feature/secrets 4936296bd add link for path column too 4272ad5ac No slugify, too extreme for this use case d5cdfed18 Merge remote-tracking branch 'origin/main' into feature/secrets 4a81b2a10 add SecretAllowedModelEdit 87f640e3a Don't allow spaces on secret keys c627ef9e8 Don't display value on SecretList d42bd4ced fix method shorthand 82340ddc2 commit for KB a2c210a5a First stab at edit 1a2646249 fix typo - allowed_process_models -> allowed_processes 519555919 add interface for allowed SecretAllowedProcessModel, and use it in Secret interface use Secret and SecretAllowedProcessModel interfaces instead of `any` in SecretShow 6ccc7dd31 Merge branch 'main' into feature/secrets accd8e364 Moved button to bottom Added Secrets heading 18b80556a delete allowed model path 2dfe4c41a remove unused code df006b2af Rename Allowed Process Path to Allowed Model 8a68de12a add SecretAllowedModelNew eadf54357 Merge branch 'main' into feature/secrets f016b90b8 Cleaning up delete 7e5db93f0 Committing so the machine can look at an error 8655e437d Delete 2 ways -- icon and button w/icon ce537d7e8 display list of allowed processes skeleton of delete using MdDelete icon ab19657c0 install react-icons git-subtree-dir: spiffworkflow-frontend git-subtree-split: d68d521d78f747d156cfd45e6a7b26f4a5f5d63b
2022-10-14 00:45:09 +00:00
<th>ID</th>
<th>Secret Key</th>
<th>Creator</th>
Squashed 'spiffworkflow-frontend/' changes from 572d779f7..d68d521d7 d68d521d7 also alert for unexpected errors from the api result w/ burnettk 698f7595a show an alert if backend gives a 403 w/ burnettk fa65efbb3 Merge branch 'main' of github.com:sartography/spiffworkflow-frontend f2a629110 do not null out error message in useEffect to avoid endless redirects w/ burnettk b5b79bae7 Remove the AllowedModel stuff from secrets Clean up spacing on SecretNew Don't allow spaces in Secret key. Change them to dashes. 9ab1da07f Merge branch 'main' into feature/secrets 4936296bd add link for path column too 4272ad5ac No slugify, too extreme for this use case d5cdfed18 Merge remote-tracking branch 'origin/main' into feature/secrets 4a81b2a10 add SecretAllowedModelEdit 87f640e3a Don't allow spaces on secret keys c627ef9e8 Don't display value on SecretList d42bd4ced fix method shorthand 82340ddc2 commit for KB a2c210a5a First stab at edit 1a2646249 fix typo - allowed_process_models -> allowed_processes 519555919 add interface for allowed SecretAllowedProcessModel, and use it in Secret interface use Secret and SecretAllowedProcessModel interfaces instead of `any` in SecretShow 6ccc7dd31 Merge branch 'main' into feature/secrets accd8e364 Moved button to bottom Added Secrets heading 18b80556a delete allowed model path 2dfe4c41a remove unused code df006b2af Rename Allowed Process Path to Allowed Model 8a68de12a add SecretAllowedModelNew eadf54357 Merge branch 'main' into feature/secrets f016b90b8 Cleaning up delete 7e5db93f0 Committing so the machine can look at an error 8655e437d Delete 2 ways -- icon and button w/icon ce537d7e8 display list of allowed processes skeleton of delete using MdDelete icon ab19657c0 install react-icons git-subtree-dir: spiffworkflow-frontend git-subtree-split: d68d521d78f747d156cfd45e6a7b26f4a5f5d63b
2022-10-14 00:45:09 +00:00
<th>Delete</th>
</tr>
</thead>
<tbody>{rows}</tbody>
</Table>
);
};
const SecretsDisplayArea = () => {
const { page, perPage } = getPageInfoFromSearchParams(searchParams);
let displayText = null;
if (secrets?.length > 0) {
displayText = (
<PaginationForTable
page={page}
perPage={perPage}
pagination={pagination as any}
tableToDisplay={buildTable()}
path="/admin/secrets"
/>
);
} else {
displayText = <p>No Secrets to Display</p>;
}
return displayText;
};
if (pagination) {
return (
Squashed 'spiffworkflow-frontend/' changes from 572d779f7..d68d521d7 d68d521d7 also alert for unexpected errors from the api result w/ burnettk 698f7595a show an alert if backend gives a 403 w/ burnettk fa65efbb3 Merge branch 'main' of github.com:sartography/spiffworkflow-frontend f2a629110 do not null out error message in useEffect to avoid endless redirects w/ burnettk b5b79bae7 Remove the AllowedModel stuff from secrets Clean up spacing on SecretNew Don't allow spaces in Secret key. Change them to dashes. 9ab1da07f Merge branch 'main' into feature/secrets 4936296bd add link for path column too 4272ad5ac No slugify, too extreme for this use case d5cdfed18 Merge remote-tracking branch 'origin/main' into feature/secrets 4a81b2a10 add SecretAllowedModelEdit 87f640e3a Don't allow spaces on secret keys c627ef9e8 Don't display value on SecretList d42bd4ced fix method shorthand 82340ddc2 commit for KB a2c210a5a First stab at edit 1a2646249 fix typo - allowed_process_models -> allowed_processes 519555919 add interface for allowed SecretAllowedProcessModel, and use it in Secret interface use Secret and SecretAllowedProcessModel interfaces instead of `any` in SecretShow 6ccc7dd31 Merge branch 'main' into feature/secrets accd8e364 Moved button to bottom Added Secrets heading 18b80556a delete allowed model path 2dfe4c41a remove unused code df006b2af Rename Allowed Process Path to Allowed Model 8a68de12a add SecretAllowedModelNew eadf54357 Merge branch 'main' into feature/secrets f016b90b8 Cleaning up delete 7e5db93f0 Committing so the machine can look at an error 8655e437d Delete 2 ways -- icon and button w/icon ce537d7e8 display list of allowed processes skeleton of delete using MdDelete icon ab19657c0 install react-icons git-subtree-dir: spiffworkflow-frontend git-subtree-split: d68d521d78f747d156cfd45e6a7b26f4a5f5d63b
2022-10-14 00:45:09 +00:00
<div>
<h2>Secrets</h2>
{SecretsDisplayArea()}
Squashed 'spiffworkflow-frontend/' changes from 572d779f7..d68d521d7 d68d521d7 also alert for unexpected errors from the api result w/ burnettk 698f7595a show an alert if backend gives a 403 w/ burnettk fa65efbb3 Merge branch 'main' of github.com:sartography/spiffworkflow-frontend f2a629110 do not null out error message in useEffect to avoid endless redirects w/ burnettk b5b79bae7 Remove the AllowedModel stuff from secrets Clean up spacing on SecretNew Don't allow spaces in Secret key. Change them to dashes. 9ab1da07f Merge branch 'main' into feature/secrets 4936296bd add link for path column too 4272ad5ac No slugify, too extreme for this use case d5cdfed18 Merge remote-tracking branch 'origin/main' into feature/secrets 4a81b2a10 add SecretAllowedModelEdit 87f640e3a Don't allow spaces on secret keys c627ef9e8 Don't display value on SecretList d42bd4ced fix method shorthand 82340ddc2 commit for KB a2c210a5a First stab at edit 1a2646249 fix typo - allowed_process_models -> allowed_processes 519555919 add interface for allowed SecretAllowedProcessModel, and use it in Secret interface use Secret and SecretAllowedProcessModel interfaces instead of `any` in SecretShow 6ccc7dd31 Merge branch 'main' into feature/secrets accd8e364 Moved button to bottom Added Secrets heading 18b80556a delete allowed model path 2dfe4c41a remove unused code df006b2af Rename Allowed Process Path to Allowed Model 8a68de12a add SecretAllowedModelNew eadf54357 Merge branch 'main' into feature/secrets f016b90b8 Cleaning up delete 7e5db93f0 Committing so the machine can look at an error 8655e437d Delete 2 ways -- icon and button w/icon ce537d7e8 display list of allowed processes skeleton of delete using MdDelete icon ab19657c0 install react-icons git-subtree-dir: spiffworkflow-frontend git-subtree-split: d68d521d78f747d156cfd45e6a7b26f4a5f5d63b
2022-10-14 00:45:09 +00:00
<Button href="/admin/secrets/new">Add a secret</Button>
</div>
);
}
return null;
}