Skip to content

Commit 0e1a3cf

Browse files
authored
feat: added query params to automatically open generate yaml modal (#1386)
Signed-off-by: Efren Lim <[email protected]>
1 parent 1e898ad commit 0e1a3cf

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

frontend/app/components/modules/project/services/project.query.service.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,19 @@ export const projectParamsSetter = (query: URLParams) => {
9494

9595
return tmpQuery;
9696
};
97+
98+
export const securityParamsGetter = (query: LocationQuery): URLParams => ({
99+
generateYaml: (query.generateYaml as string) || undefined,
100+
});
101+
102+
export const securityParamsSetter = (query: URLParams) => {
103+
const tmpQuery = { ...query };
104+
105+
if (query.generateYaml) {
106+
tmpQuery.generateYaml = 'true';
107+
} else {
108+
delete tmpQuery.generateYaml;
109+
}
110+
111+
return tmpQuery;
112+
};

frontend/app/components/modules/project/views/security.vue

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ SPDX-License-Identifier: MIT
170170
size="small"
171171
button-style="pill"
172172
class="whitespace-nowrap !hidden lg:!flex"
173-
@click="isGenerateYamlModalOpen = true"
173+
@click="handleGenerateYamlClick"
174174
>
175175
<lfx-icon name="file-shield" />
176176
Generate YAML file
@@ -192,6 +192,7 @@ SPDX-License-Identifier: MIT
192192
<lf-security-generate-yaml-modal
193193
v-if="isGenerateYamlModalOpen"
194194
v-model="isGenerateYamlModalOpen"
195+
@update:model-value="handleGenerateYamlUpdate"
195196
/>
196197
</template>
197198

@@ -200,6 +201,7 @@ import { useRoute } from 'nuxt/app';
200201
import { computed, onServerPrefetch, ref } from 'vue';
201202
import pluralize from 'pluralize';
202203
import { storeToRefs } from 'pinia';
204+
import { securityParamsGetter, securityParamsSetter } from '../services/project.query.service';
203205
import LfxCard from '~/components/uikit/card/card.vue';
204206
import LfxIcon from '~/components/uikit/icon/icon.vue';
205207
import LfxAccordion from '~/components/uikit/accordion/accordion.vue';
@@ -219,13 +221,16 @@ import LfxButton from '~/components/uikit/button/button.vue';
219221
import LfxTooltip from '~/components/uikit/tooltip/tooltip.vue';
220222
import LfSecurityGenerateYamlModal from '~/components/modules/project/components/security/yaml/generate-yaml-modal.vue';
221223
import { SECURITY_API_SERVICE } from '~/components/modules/project/services/security.api.service';
224+
import { useQueryParam } from '~/components/shared/utils/query-param';
222225
223226
const accordion = ref('');
224227
225228
const route = useRoute();
226229
const { name } = route.params;
227230
228-
const isGenerateYamlModalOpen = ref(false);
231+
const { queryParams } = useQueryParam(securityParamsGetter, securityParamsSetter);
232+
const { generateYaml } = queryParams.value;
233+
const isGenerateYamlModalOpen = ref(generateYaml === 'true' || false);
229234
230235
const { selectedReposValues, allArchived, archivedRepos, hasSelectedArchivedRepos } = storeToRefs(useProjectStore());
231236
@@ -283,6 +288,19 @@ const groupChecksByRepository = (checks: SecurityData[]) =>
283288
{} as Record<string, SecurityData[]>,
284289
);
285290
291+
const handleGenerateYamlClick = () => {
292+
isGenerateYamlModalOpen.value = true;
293+
queryParams.value = {
294+
generateYaml: true,
295+
};
296+
};
297+
298+
const handleGenerateYamlUpdate = (value: boolean) => {
299+
queryParams.value = {
300+
generateYaml: value,
301+
};
302+
};
303+
286304
onServerPrefetch(async () => {
287305
await suspense();
288306
});

frontend/app/components/shared/utils/query-param.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type URLParams = {
1515
collectionTab?: string;
1616
collectionSort?: string;
1717
repos?: string;
18+
generateYaml?: string;
1819
};
1920

2021
export const useQueryParam = (

0 commit comments

Comments
 (0)