Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wallet): merge request policies and approval policy pages #502

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/wallet/build/plugins/with-locale-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ function compareLocales(
const wholeKey = root ? root + '.' + key : key;

if (typeof enLocale[key] === 'object') {
if (locale[key] === undefined) {
console.log(`Key ${wholeKey} is missing in ${localeName}`);
result = false;
continue;
}

if (!compareLocales(enLocale[key], locale[key] as LocaleKey, wholeKey, localeName)) {
result = false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,101 +1,80 @@
<template>
<PageLayout>
<template #main-header>
<PageHeader :title="pageTitle" :breadcrumbs="props.breadcrumbs">
<template #actions>
<AuthCheck :privileges="[Privilege.AddNamedRule]">
<NamedRuleDialogBtn :text="$t('pages.approval_policy.btn_new_entry')" />
</AuthCheck>
</template>
</PageHeader>
</template>
<template #main-body>
<PageBody>
<AuthCheck :privileges="[Privilege.ListRequests]">
<RecentRequests
class="mb-4"
:see-all-link="{
name: Routes.Requests,
query: { group_by: RequestDomains.System },
}"
:types="[{ AddNamedRule: null }, { EditNamedRule: null }, { RemoveNamedRule: null }]"
hide-not-found
<Teleport v-if="mounted" to="#policies-actions">
<AuthCheck :privileges="[Privilege.AddNamedRule]">
<NamedRuleDialogBtn :text="$t('pages.approval_rules.btn_new_entry')" />
</AuthCheck>
</Teleport>

<DataLoader
v-slot="{ loading }"
v-model:force-reload="forceReload"
:disable-refresh="disableRefresh"
:load="fetchList"
:refresh-interval-ms="5000"
@loaded="
result => {
namedRules = result.named_rules;
privileges = result.privileges;
}
"
>
<VDataTable
class="elevation-2 rounded"
:loading="loading"
:headers="headers"
:items="namedRules"
:items-per-page="-1"
:hover="true"
>
<template #bottom>
<!--this hides the footer as pagination is not required-->
</template>
<template #item.name="{ item: namedRule }">
<div class="text-body-2">{{ namedRule.name }}</div>
<div v-if="namedRule.description[0]" class="text-caption text-grey-lighten-1">
{{ namedRule.description[0] }}
</div>
</template>
<template #item.linked_policies="{ item: namedRule }">
<div v-if="linkedPolicies">
{{ linkedPolicies[namedRule.id] || '-' }}
</div>
</template>
<template #item.rule="{ item: namedRule }">
<RuleSummary :rule="namedRule.rule" />
</template>
<template #item.actions="{ item: namedRule }">
<div class="d-flex justify-end">
<ActionBtn
v-if="hasDeletePrivilege(namedRule.id)"
v-model="namedRule.id"
:icon="mdiTrashCanOutline"
:submit="id => station.service.removeNamedRule(id)"
:disabled="(linkedPolicies?.[namedRule.id] ?? 0) > 0"
@failed="useOnFailedOperation"
@submitted="useOnSuccessfulOperation"
/>
</AuthCheck>

<DataLoader
v-slot="{ loading }"
v-model:force-reload="forceReload"
:disable-refresh="disableRefresh"
:load="fetchList"
:refresh-interval-ms="5000"
@loaded="
result => {
namedRules = result.named_rules;
privileges = result.privileges;
}
"
>
<VDataTable
class="elevation-2 rounded"
:loading="loading"
:headers="headers"
:items="namedRules"
:items-per-page="-1"
:hover="true"
>
<template #bottom>
<!--this hides the footer as pagination is not required-->
</template>
<template #item.name="{ item: namedRule }">
<div class="text-body-2">{{ namedRule.name }}</div>
<div v-if="namedRule.description[0]" class="text-caption text-grey-lighten-1">
{{ namedRule.description[0] }}
</div>
</template>
<template #item.linked_policies="{ item: namedRule }">
<div v-if="linkedPolicies">
{{ linkedPolicies[namedRule.id] || '-' }}
</div>
</template>
<template #item.rule="{ item: namedRule }">
<RuleSummary :rule="namedRule.rule" />
</template>
<template #item.actions="{ item: namedRule }">
<div class="d-flex justify-end">
<ActionBtn
v-if="hasDeletePrivilege(namedRule.id)"
v-model="namedRule.id"
:icon="mdiTrashCanOutline"
:submit="id => station.service.removeNamedRule(id)"
:disabled="(linkedPolicies?.[namedRule.id] ?? 0) > 0"
@failed="useOnFailedOperation"
@submitted="useOnSuccessfulOperation"
/>
<NamedRuleDialogBtn
:icon="!hasEditPrivilege(namedRule.id) ? mdiEye : mdiPencil"
:named-rule-id="namedRule.id"
:readonly="!hasEditPrivilege(namedRule.id)"
variant="flat"
color="default"
size="small"
@opened="disableRefresh = $event"
/>
</div>
</template>
</VDataTable>
</DataLoader>
<VPagination
v-model="pagination.selectedPage"
class="mt-2"
:length="pagination.totalPages"
rounded
density="comfortable"
@update:model-value="triggerSearch"
/>
</PageBody>
</template>
</PageLayout>
<NamedRuleDialogBtn
:icon="!hasEditPrivilege(namedRule.id) ? mdiEye : mdiPencil"
:named-rule-id="namedRule.id"
:readonly="!hasEditPrivilege(namedRule.id)"
variant="flat"
color="default"
size="small"
@opened="disableRefresh = $event"
/>
</div>
</template>
</VDataTable>
</DataLoader>
<VPagination
v-model="pagination.selectedPage"
class="mt-2"
:length="pagination.totalPages"
rounded
density="comfortable"
@update:model-value="triggerSearch"
/>
</template>

<script lang="ts" setup>
Expand All @@ -106,19 +85,14 @@ import { useDisplay } from 'vuetify';
import { VDataTable, VPagination } from 'vuetify/components';
import AuthCheck from '~/components/AuthCheck.vue';
import DataLoader from '~/components/DataLoader.vue';
import PageLayout from '~/components/PageLayout.vue';
import ActionBtn from '~/components/buttons/ActionBtn.vue';
import PageBody from '~/components/layouts/PageBody.vue';
import PageHeader from '~/components/layouts/PageHeader.vue';
import NamedRuleDialogBtn from '~/components/request-policies/NamedRuleDialogBtn.vue';
import RuleSummary from '~/components/request-policies/rule/RuleSummary.vue';
import RecentRequests from '~/components/requests/RecentRequests.vue';
import { useFetchList, usePagination } from '~/composables/lists.composable';
import {
useOnFailedOperation,
useOnSuccessfulOperation,
} from '~/composables/notifications.composable';
import { Routes } from '~/configs/routes.config';
import {
ListRequestPoliciesResult,
NamedRule,
Expand All @@ -128,16 +102,12 @@ import {
UUID,
} from '~/generated/station/station.did';
import { useStationStore } from '~/stores/station.store';
import type { PageProps } from '~/types/app.types';
import { Privilege } from '~/types/auth.types';
import { ExtractOk } from '~/types/helper.types';
import { RequestDomains } from '~/types/station.types';
import { throttle, variantIs } from '~/utils/helper.utils';

const props = withDefaults(defineProps<PageProps>(), { title: undefined, breadcrumbs: () => [] });
const station = useStationStore();
const i18n = useI18n();
const pageTitle = computed(() => props.title || i18n.t('pages.approval_policy.title'));
const namedRules = ref<NamedRule[]>([]);
const privileges = ref<NamedRuleCallerPrivileges[]>([]);
const disableRefresh = ref(false);
Expand All @@ -146,6 +116,7 @@ const { xs } = useDisplay();
const pagination = usePagination();
const triggerSearch = throttle(() => (forceReload.value = true), 500);
const allPolicies = ref<RequestPolicy[] | null>(null);
const mounted = ref(false);

const headers = computed(() => {
return [
Expand All @@ -156,7 +127,7 @@ const headers = computed(() => {
: [
{ title: i18n.t('terms.rule'), key: 'rule', sortable: false },
{
title: i18n.t('pages.approval_policy.linked_policies'),
title: i18n.t('pages.approval_rules.linked_policies'),
key: 'linked_policies',
sortable: false,
},
Expand Down Expand Up @@ -218,6 +189,8 @@ const fetchList = useFetchList(
);

onMounted(async () => {
mounted.value = true;

const fetchedPolicies: RequestPolicy[] = [];
let componentUnmounted = false;

Expand Down
Loading
Loading