Skip to content

Comments

Fix: coding when no source was selected#215

Merged
jankapunkt merged 7 commits intomainfrom
fix/coding-no-source-selected
Dec 3, 2025
Merged

Fix: coding when no source was selected#215
jankapunkt merged 7 commits intomainfrom
fix/coding-no-source-selected

Conversation

@jankapunkt
Copy link
Member

On a new project it is likely that users forgot to lock sources for coding but navigate to the coding view.
In this scenario the page returns a 404 error.

With this fix the page will load but display a message that a source is required to be locked for coding.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a user experience issue where navigating to the coding view without locked sources resulted in a 404 error. The fix allows the page to load gracefully and display an informative message guiding users to lock sources.

Key changes:

  • Modified backend controller to return null instead of throwing an error when no source is available
  • Added null-safe access patterns throughout the frontend using optional chaining (source?.id, source?.selections)
  • Implemented conditional rendering in the Vue component to show a helpful empty state when no source is present

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
web/app/Http/Controllers/CodingController.php Changed query from firstOrFail() to first() to return null instead of throwing exception, reordered operations to handle null source, and added conditional content loading
web/resources/js/domain/codes/useCodes.js Added optional chaining for source?.id and source?.selections to handle null source gracefully
web/resources/js/Pages/coding/selections/useSelections.js Added optional chaining for source?.id to prevent errors when source is undefined
web/resources/js/Pages/CodingPage.vue Added conditional rendering with v-if="$props.source" for editor, created empty state UI with helpful message, added null-safe checks for source property access, and imported new UI components
Comments suppressed due to low confidence (1)

web/resources/js/Pages/CodingPage.vue:77

  • The menu section is displayed even when props.source is null/undefined, allowing users to potentially interact with code creation and management features. This could cause errors since useCodes() is called unconditionally (line 190) and passes source to Codes.create(), which will fail with a null reference error when accessing source.id. Consider wrapping the menu content in a v-if="props.source" condition or disabling interactive elements when no source is available.
        <ActivityIndicator v-if="!codingInitialized">
          Loading codes and selections...
        </ActivityIndicator>
        <div v-else class="inline md:flex items-center justify-between mb-4">
          <CreateDialog
            :schema="createNewCodeSchema"
            :title="`Create a new ${codesView === 'codes' ? 'Code' : 'Codebook'}`"
            :submit="createCodeHandler"
          >
            <template #trigger="createCodeTriggerProps">
              <Button
                variant="outline-secondary"
                class="w-full md:w-auto"
                @click="createCodeTriggerProps.onClick(openCreateCodeDialog)"
              >
                <PlusIcon class="w-4 h-4 me-1" />
                <span v-if="codesView === 'codes' && range?.length">
                  Create In-Vivo
                </span>
                <span v-else>Create</span>
              </Button>
            </template>
          </CreateDialog>
          <CreateDialog
            :title="`Edit ${editTarget?.name}`"
            :schema="editSchema"
            buttonTitle="Update code"
            :submit="updateCode"
            :show="!!editSchema"
          />
          <DeleteDialog
            :title="`Permanently delete ${deleteTarget?.name}`"
            :target="deleteTarget"
            :challenge="deleteChallenge"
            :message="deleteMessage"
            :submit="deleteCode"
          />
          <ResponsiveTabList
            :tabs="codesTabs"
            :initial="codesView"
            @change="(value) => (codesView = value)"
          />
        </div>
        <Cleanup v-if="codesView === 'cleanup'" />
        <CodeTree
          v-for="codebook in codebooks"
          :key="codebook.id"
          :codebook="codebook"
          :codes="codes.filter((code) => code.codebook === codebook.id)"
          v-if="codesView === 'codes'"
        />
        <FilesList
          v-if="codesView === 'sources'"
          :documents="sourceDocuments"
          :fixed="true"
          :focus-on-hover="true"
          :actions="[]"
          @select="switchFile"
        />
        <p
          v-if="codesView === 'sources' && !sourceDocuments?.length"
          class="p-3 text-foreground/60"
        >
          No other sources locked for coding. Go to
          <Link :href="route('source.index', projectId)"
            >the preparations page</Link
          >
          to edit and lock sources for coding.
        </p>
        <div class="mt-auto">
          <Footer />
        </div>
      </BaseContainer>

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jankapunkt jankapunkt added this to the 1.1.0 milestone Dec 3, 2025
@jankapunkt jankapunkt merged commit bd42250 into main Dec 3, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant